From owner-freebsd-questions@freebsd.org Wed Mar 21 00:45:26 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 A94FEF5AC86 for ; Wed, 21 Mar 2018 00:45:26 +0000 (UTC) (envelope-from rfg@tristatelogic.com) Received: from outgoing.tristatelogic.com (segfault.tristatelogic.com [69.62.255.118]) by mx1.freebsd.org (Postfix) with ESMTP id 3FA86729CE for ; Wed, 21 Mar 2018 00:45:25 +0000 (UTC) (envelope-from rfg@tristatelogic.com) Received: from segfault-nmh-helo.tristatelogic.com (localhost [127.0.0.1]) by segfault.tristatelogic.com (Postfix) with ESMTP id B1F633AEF2 for ; Tue, 20 Mar 2018 17:45:19 -0700 (PDT) From: "Ronald F. Guilmette" To: freebsd-questions@freebsd.org Subject: "Portable" conditionalization of Makefiles Date: Tue, 20 Mar 2018 17:45:19 -0700 Message-ID: <99925.1521593119@segfault.tristatelogic.com> 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 00:45:26 -0000 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?