NetBSD-Users archive

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

Re: Portable Makefile ideas



Hello,

On Sun, Feb 10, 2019 at 05:40:26PM +0000, Sad Clouds 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?

I made this using only a small subset of POSIX.2 utilities, generating
by sed(1) and sh(1) magic a Makefile for the minimal POSIX.2 make(1),
with sh(1) parameters files for the various OSes, using POSIX CC as a
frontend to the preprocessor, the assembler and the linker.

It was an "home" project but went into public because I use it for
kerTeX (the TeX and al. distribution).

I have internal notes but never took the time to build a documentation,
but the sh(1) script are heavily commented (and kerTeX is an example of
use).

If you want to give it a try, I will take the time to answer questions
and put the documentation (should be rather small one since it is rather
simple in spirit) online.

It was designed from the beginning with these goals:

1) Cross-compilation ;
2) Basic tools requirements. I ended with a very small subset of POSIX.2
and requiring the minimal conformity with POSIX;
3) Multi-OSes;
4) The possibility to use the smallest disk space: it can remove
intermediate objects when the target is reached meaning that it requires
almost only the space needed to install;
5) Ability to compile part or whole in static.

It does the job, supporting for now NetBSD (primary target), all the
*BSD, the various Linuces (including Android) and Plan9. Windows for now
is supported only with the POSIX tools available (was SFU; today
probably some Linux distribution; Cygwin; the project was to add just
the basic utilities---more or less mingw plus wrappers for Microsoft own
compiler and linker---but I have not tackled the task yet).

Link:

http://downloads.kergis.com/kertex/risk_comp_1.16.9.0.tar.gz

It cost me at the beginning less time to write it than to try to
understand how the other tools work (and not all have the requirements I
mentionned).

It could be the same for you now with it... But, if it can help...

HTH,
-- 
        Thierry Laronde <tlaronde +AT+ polynum +dot+ com>
                     http://www.kergis.com/
                       http://www.sbfa.fr/
Key fingerprint = 0FF7 E906 FBAF FE95 FD89  250D 52B1 AE95 6006 F40C


Home | Main Index | Thread Index | Old Index