Thread View: comp.unix.programmer
4 messages
4 total messages
Started by Alex Vinokur
Thu, 21 Aug 2003 11:32
Generic and platform-specific Makefiles
Author: Alex Vinokur
Date: Thu, 21 Aug 2003 11:32
Date: Thu, 21 Aug 2003 11:32
34 lines
1857 bytes
1857 bytes
Hi,
I would like to create Makefile which suits different platforms and operating systems.
#########################
# 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?
Thanks,
=====================================
Alex Vinokur
mailto:alexvn@connect.to
http://mathforum.org/library/view/10978.html
=====================================
Re: Generic and platform-specific Makefiles
Author: Gisle Vanem
Date: Thu, 21 Aug 2003 12:52
Date: Thu, 21 Aug 2003 12:52
33 lines
2082 bytes
2082 bytes
"Alex Vinokur" <alexvn@bigfoot.com> wrote: > 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 trust unname on Linux to exist and include "linux". On Cygwin if it exist, it should include "Windows....". So this could work: ifeq ($(findstring Windows, $(shell uname)), Windows) LIBS += -lwsock32 endif --gv There are only 10 types of people in this world... those who understand binary, and those who don't.
Re: Generic and platform-specific Makefiles
Author: Martijn
Date: Thu, 21 Aug 2003 13:18
Date: Thu, 21 Aug 2003 13:18
48 lines
2247 bytes
2247 bytes
Alex Vinokur wrote:
> Hi,
>
> I would like to create Makefile which suits different platforms and
> operating systems.
>
> #########################
> # 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
> -------------------------
What you could do is make targets for the different architectures. You
could set variables specific to these targets. Just remember that the first
target is the "default" one (specifying a specific first target named so
could prevent confusion):
# first target is the default
default: linux
linux:
LIBS =
win32:
LIBS = -lwsock32
Or you could use a define (which I believe is nicer seems nicer):
# specify -DWIN32 as a parameter to make to set this var
ifdef WIN32
LIBS = -lwsock32
else
LIBS =
endif
Of course if you want to have these decisions made without required actions
by the user, you will have to look at the environment some way, like Gisle
suggested.
--
Martijn
http://www.sereneconcepts.nl
Re: Generic and platform-specific Makefiles
Author: Valentin Nechayev
Date: Sat, 23 Aug 2003 06:49
Date: Sat, 23 Aug 2003 06:49
34 lines
2498 bytes
2498 bytes
>>> Alex Vinokur wrote: AV> If I compile the program on Cygwin (Windows 2000) AV> the Makefile must contain the following line : AV> ------------------------- AV> LIBS = -lwsock32 AV> ------------------------- AV> If I compile the program on Linux AV> the Makefile must not contain that line. AV> What ways should be used to create such a Makefile? : AV> * generic Makefile for all platforms? AV> * main Makefile including platform-specific definitions? AV> * something else? AV> What techniques exist to do that? Look at existing methods and choose one the best for you. There are two main global approaches: 1) use feature tests, independently on target platform 2) use predefined knowledge of target platform features and one can also use mix of them (e.g. most data are from feature tests, but some rare or highly-specific platforms are registered as having some predefined characteristics). For first approach, look at GNU autoconf and at huge bunch of programs using it. For second approach, look at, e.g., sendmail, postfix, exim - they all do minimum of tests, but create makefiles using knowledge of platform features. -netch-
Thread Navigation
This is a paginated view of messages in the thread with full content displayed inline.
Messages are displayed in chronological order, with the original post highlighted in green.
Use pagination controls to navigate through all messages in large threads.
Back to All Threads