From owner-freebsd-questions@freebsd.org Wed Mar 21 07:29:47 2018 Return-Path: Delivered-To: freebsd-questions@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id B452AF4FA33 for ; Wed, 21 Mar 2018 07:29:47 +0000 (UTC) (envelope-from trond@fagskolen.gjovik.no) Received: from smtp.fagskolen.gjovik.no (smtp.fagskolen.gjovik.no [IPv6:2001:700:1100:1:200:ff:fe00:b]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client CN "smtp.fagskolen.gjovik.no", Issuer "Fagskolen i Gj??vik" (not verified)) by mx1.freebsd.org (Postfix) with ESMTPS id 3E28680C93 for ; Wed, 21 Mar 2018 07:29:46 +0000 (UTC) (envelope-from trond@fagskolen.gjovik.no) Received: from mail.fig.ol.no (localhost [127.0.0.1]) by mail.fig.ol.no (8.15.2/8.15.2) with ESMTPS id w2L7TeJW082451 (version=TLSv1.2 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NO) for ; Wed, 21 Mar 2018 08:29:40 +0100 (CET) (envelope-from trond@fagskolen.gjovik.no) Received: from localhost (trond@localhost) by mail.fig.ol.no (8.15.2/8.15.2/Submit) with ESMTP id w2L7Te6I082448 for ; Wed, 21 Mar 2018 08:29:40 +0100 (CET) (envelope-from trond@fagskolen.gjovik.no) X-Authentication-Warning: mail.fig.ol.no: trond owned process doing -bs Date: Wed, 21 Mar 2018 08:29:39 +0100 (CET) From: =?ISO-8859-1?Q?Trond_Endrest=F8l?= Sender: Trond.Endrestol@fagskolen.gjovik.no To: FreeBSD questions Subject: Re: "Portable" conditionalization of Makefiles In-Reply-To: <99925.1521593119@segfault.tristatelogic.com> Message-ID: References: <99925.1521593119@segfault.tristatelogic.com> User-Agent: Alpine 2.21 (BSF 202 2017-01-01) Organization: Fagskolen Innlandet OpenPGP: url=http://fig.ol.no/~trond/trond.key MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII X-Spam-Status: No, score=-2.9 required=5.0 tests=ALL_TRUSTED,AWL,BAYES_00 autolearn=ham autolearn_force=no version=3.4.1 X-Spam-Checker-Version: SpamAssassin 3.4.1 (2015-04-28) on mail.fig.ol.no X-BeenThere: freebsd-questions@freebsd.org X-Mailman-Version: 2.1.25 Precedence: list List-Id: User questions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 21 Mar 2018 07:29:47 -0000 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.