Skip site navigation (1)Skip section navigation (2)
Date:      Tue, 20 Mar 2018 17:45:19 -0700
From:      "Ronald F. Guilmette" <>
Subject:   "Portable" conditionalization of Makefiles
Message-ID:  <>

Next in thread | Raw E-Mail | Index | Archive | Help

I have a pile of (mostly) C code that I wrote myself over the past
several years.  I developed it on FreeBSD but have always thought
that it would be Nice if it compiled and ran also on Linux.

I just spent about a day editing the various files to make it all
compile and link OK on Linux.  So that part is all done now.  But
here's the one remaining problem:

There's a chance that I may distribute this stuff someday.  When and
if I do, I'd like to be able to tell people to "just run make" in the
top-level directory, regardless of whether they are on Linux or *BSD.
(I -could- just tell people to use gmake if they are on *BSD, but I'd
rather not.)

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

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.

Of course, these two make programs have implemented different, and
apparently incompatable syntaxes for conditionalization... with the
FreeBSD make using directives like ifeq/else/endif and GNU make using
directives like .if/.else/.endif

I *really* don't want to use any mechanism which builds the Makefile
on the fly, like configure/autoconf and friends.  (I have always felt
that those things were abominations... basically elephant guns, often
used ridiculously to kill mere gnats.)

It occurs to me that I can't have been the first person to have come
up against this problem.  But I don't know that solution.  Is there
already a well known and widely used motif or convention for how to
code up conditional parts of Makefiles in such a way that they will
do what's needed, conditionally, when run through -either- GNU Make
or FreeBSD make?

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