NetBSD-Users archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
Portable Makefile ideas
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?
Home |
Main Index |
Thread Index |
Old Index