Skip site navigation (1)Skip section navigation (2)
Date:      Wed, 21 Mar 2018 21:04:50 -0000 (UTC)
From:      Christian Weisgerber <>
Subject:   Re: "Portable" conditionalization of Makefiles
Message-ID:  <>
References:  <>

Next in thread | Previous in thread | Raw E-Mail | Index | Archive | Help
On 2018-03-21, "Ronald F. Guilmette" <> wrote:

> So anyway, the problem is that on Linux, I have to link in some different
> libraries to make the stuff work.  Specifically, I have to add -lresolv
> to the link command.  But that's a no-go for FreeBSD, whose linker
> will rightly complain about the missing library if it sees that extra
> option.
> Obviously, I need to conditionalize some small bits of my Makefile, but
> I need to do that in a way that will cause -neither- GNU Make nor FreeBSD
> make to barf all over everything.

There is no standard syntax for Makefile conditionals and none that
is in common between GNU make and FreeBSD's make.

You can set variables based on the value of other variables in a way
that is similar to conditionals:


	@echo cc -o prog prog.o $(LIBRESOLV)

But you still need people to set at least one variable (here OPSYS)
either by editing the Makefile or overriding the value from the
command line:

$ make OPSYS=Linux

It is possible to recursively call make from within a Makefile, so
you could use a trick like this to call make again with a distinguishing
variable set to, say, the output of uname:


	$(MAKE) OPSYS=`uname` prog

	@echo cc -o prog prog.o $(LIBRESOLV)

Christian "naddy" Weisgerber                

Want to link to this message? Use this URL: <>