Re: Need help with a makefile [RESOLVED]

From: Mehmet Erol Sanliturk <m.e.sanliturk_at_gmail.com>
Date: Wed, 07 Feb 2024 19:36:33 UTC
On Wed, Feb 7, 2024 at 10:10 PM Jonathan Adams <jfadams1963@proton.me>
wrote:

> On Tuesday, February 6th, 2024 at 10:38 PM, Greg 'groggy' Lehey <
> grog@freebsd.org> wrote:
>
> > However, I've put this through gmake, and it complains:
> >
> > $ gmake
> > Makefile:7: extraneous text after 'ifeq' directive
>
> Hi Greg, et al.,
>   The above error was do to the line continuation backslashes. Installed
> gmake, took out the backslashes and, presto, it "just works". On FBSD, that
> is.
>   In my little project, I was using getpass(), but have changed to
> readpassphrase(). Great, but on Linux that's in /usr/include/bsd. So I
> added to my main source file:
>
> #ifdef BSD
>     #include <readpassphrase.h>
> #endif
>
> #ifdef LINUX
>     #include <bsd/readpassphrase.h>
> #endif
>
> And as I say, no problem on FBSD.
>
>   To try it on Linux, I fired up my GitPod Ubuntu/Debian instance and
> found that I had to install the libbsd0 and libbsd-dev packages first.
> However, when I first compiled, GCC complained:
> undefined reference to `readpassphrase'
> Oops! I added `-l:libbsd.a` to the linker arguments and it compiles fine
> under Linux now.
>
> ifeq ($(UNAME),FreeBSD)
>         CFLAGS += -DBSD
> else ifeq ($(UNAME),Linux)
>         CFLAGS += -DLINUX
>         LDFLAGS += -l:libbsd.a
> endif
>
>   Unfortunatly, the program segfaults when I run it! Works fine on FBSD.
> Well, I've got something "constructive" to do today!
>
> Thanks again everyone,
>
> - Jonathan
> ____________________________________________
> "Before Turing, things were done to numbers.
> After Turing, numbers began doing things"
> - George Dyson



Assume you have a program to be compiled in different operating systems .
Actually to maintain  ONE make file for ALL involved operating systems may
be
very difficult not only for you but also for your users .

Instead of trying to use one make file , the following approach may be more
easy to manage
( This idea is not originally developed by me , but I have learned it from
other people ) :

For each different OS , define a directory with a make file specific to the
OS .
Since the make file is specific to the OS , if a user does not use that OS
, make file
will not cause any difficulty .

If a change is made in one of the OS make files , it will not affect the
other OS make files .

If some parts are common to different OS make files , these parts may be
stored into a separate
directory and may be included into relevant make files .

Use of such a division of make files may eliminate a large number of "if"
conditional and sometimes conflicting
statements required to be used in a single common file .


Mehmet Erol Sanliturk