Skip site navigation (1)Skip section navigation (2)
Date:      Wed, 21 Mar 2018 08:29:39 +0100 (CET)
From:      =?ISO-8859-1?Q?Trond_Endrest=F8l?= <Trond.Endrestol@fagskolen.gjovik.no>
To:        FreeBSD questions <freebsd-questions@freebsd.org>
Subject:   Re: "Portable" conditionalization of Makefiles
Message-ID:  <alpine.BSF.2.21.1803210826060.66427@mail.fig.ol.no>
In-Reply-To: <99925.1521593119@segfault.tristatelogic.com>
References:  <99925.1521593119@segfault.tristatelogic.com>

next in thread | previous in thread | raw e-mail | index | archive | help
On Tue, 20 Mar 2018 17:45-0700, Ronald F. Guilmette wrote:

> 
> 
> 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
> 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.
> 
> 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?

While not a perfect solution, how about using BSDmakefile for use with 
make(1) on the BSDs, and GNUmakefile for use with GNU Make on 
GNU/Linux? Maybe you can couple this with a Makefile.commom to handle 
the common bits.

Should a user run gmake on BSD under these conditions, they might get 
a surprise.

-- 
Trond.



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?alpine.BSF.2.21.1803210826060.66427>