NetBSD-Users archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

Re: Portable Makefile ideas



My hot take on this: Don't roll your own build system.

No matter how easy and portable you think you made it, it is not going
to be working for part of your users (think Linux, BSD, Solaris, etc.,
with a number of architectures each), and it is not going to be
trivial to understand for packagers. Package maintainers are familiar
with the most important standard build systems.

Perhaps take a look at CMake. I found it to be easier than expected,
and it is common enough that package systems like pkgsrc support it
directly.


On Sun, Feb 10, 2019 at 6:57 PM Sad Clouds <cryintothebluesky%gmail.com@localhost> wrote:
>
> Hello, I've been looking into ways of writing portable Makefiles and
> would like to ask for ideas and find out what works for various people.
>
> First, I would like to set out a few basic requirements:
>
> 1. It needs to be small, simple and easy to maintain. So I guess this
> would rule out tools like Libtool, Automake, etc.
>
> 2. It needs to support building C programs and libraries on different
> OSes with different compilers.
>
> Pkgsrc has various Makefiles and bootstrap tools for building software
> on different OSes, but it's too heavyweight for personal hacking
> projects. I won't be distributing my code and don't want to waste too
> much time on various package frameworks/formats.
>
> I also used "GNAT Project Manager", which can build not only Ada, but
> C and C++ projects. It's one of the best build tools I've used, but I
> only used it on Linux and NetBSD, so not sure how well it works on
> other OSes, and it may have heavyweight dependencies like GNAT tools,
> Python, etc. I need to look into this in the future.
>
> My personal research suggests that pure POSIX make is too vague and
> too simplistic, hence not very useful when it comes to larger
> projects. GNU make seems to be quite ubiquitous and many people
> standardize on using that.
>
> When it comes to different OSes and compiler combinations,
> auto-detection seems a bit complicated, so to keep it simple, I'm
> thinking of passing parameters to make, this may be a good way to
> solve this without complex frameworks and configure scripts.
>
> For example
>
> make OS=OS_SOLARIS CC_VENDOR=GCC CC=gcc
> make OS=OS_SOLARIS CC_VENDOR=SUNPRO CC=cc
> make OS=OS_LINUX CC_VENDOR=GCC CC=gcc
> make OS=OS_NETBSD CC_VENDOR=CLANG CC=clang
>
> Then Makefile would have logic like this:
>
> If LINUX and GCC:
> CFLAGS="-D$(OS) -D_FILE_OFFSET_BITS=64 -D_POSIX_C_SOURCE=200809L -D_DEFAULT_SOURCE -O2"
> CFLAGS_PIC="-fPIC"
> CFLAGS_SHARED="-shared"
> CFLAGS_SONAME="-Wl,--default-symver -Wl,-soname,"
> CFLAGS_MT="-D_REENTRANT -lpthread"
> CFLAGS_RPATH="-Wl,-rpath,$(LIB_DIR)"
>
> If SOLARIS and SUNPRO:
> CFLAGS="-D$(OS) -D_FILE_OFFSET_BITS=64 -D__EXTENSIONS__ -xO"
> CFLAGS_PIC="-KPIC"
> CFLAGS_SHARED="-G"
> CFLAGS_SONAME="-h"
> CFLAGS_MT="-D_REENTRANT -lpthread"
> CFLAGS_RPATH="-R$(LIB_DIR)"
>
> So the idea is to keep it small and simple, i.e. a few variable, some
> simple if/else logic and "Bob's your Uncle".
>
> I guess the question I have, can anyone suggest more elegant
> solutions/tools?
>


-- 
Benny


Home | Main Index | Thread Index | Old Index