[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Generic and platform-specific Makefiles
From: |
Manu |
Subject: |
Re: Generic and platform-specific Makefiles |
Date: |
Fri, 22 Aug 2003 23:39:05 +0200 |
Alex Vinokur wrote:
> Hi,
>
> I would like to create Makefile which suits different platforms and operating
> systems.
Interesting topic.
> #########################
> # GNU Make version 3.79.1
> #########################
>
> For instance, I have some program.
>
> If I compile the program on Cygwin (Windows 2000)
> the Makefile must contain the following line :
> -------------------------
> LIBS = -lwsock32
> -------------------------
>
> If I compile the program on Linux
> the Makefile must not contain that line.
>
>
> What ways should be used to create such a Makefile? :
> * generic Makefile for all platforms?
> * main Makefile including platform-specific definitions?
> * something else?
>
> What techniques exist to do that?
You can use some conditionnal tests in your makefile.
For my projects, I use several configurations:
# Configuration 1, "Debug"
#
ifeq ($(CFG),Debug)
# stuff for Debug config
# ...
endif
# Configuration 2, "Release"
#
ifeq ($(CFG),Release)
# stuff for Release config
# ...
endif
Then, under MinGW, I build "Debug" with:
mingw32-make CFG="Debug" -fMakefile
Such method can help for small projects.
(see the complete Makefile in attachment)
Another example, to build Windows sources
under Winelib, it is common to use something like:
ifndef WINE
CC = gcc
CPP = cpp
CXX = g++
RC = windres
else
CC = winegcc
CPP = $(CC) -E
CXX = wineg++
RC = wrc
endif
Another way would be to generate makefiles
from a "configure" script.
Such script and makefile intermediate files are
usually generated with autoconf and automake.
(AKA the autotools)
But, this gets harder :)
Manu.
Makefile.zip
Description: Zip compressed data