From 6b1b9863d8fccfe09c2f72c68e1ebfeea54efbe8 Mon Sep 17 00:00:00 2001 From: Andreas Baumann Date: Sat, 27 Sep 2008 17:52:05 +0000 Subject: - added first runnig version --- makefiles/clean.mk | 35 +++++++++++ makefiles/compiler.mk | 158 ++++++++++++++++++++++++++++++++++++++++++++++++++ makefiles/depend.mk | 30 ++++++++++ makefiles/dist.mk | 21 +++++++ makefiles/guess_env | 106 +++++++++++++++++++++++++++++++++ makefiles/platform.mk | 34 +++++++++++ makefiles/sub.mk | 25 ++++++++ makefiles/top.mk | 33 +++++++++++ 8 files changed, 442 insertions(+) create mode 100644 makefiles/clean.mk create mode 100644 makefiles/compiler.mk create mode 100644 makefiles/depend.mk create mode 100644 makefiles/dist.mk create mode 100755 makefiles/guess_env create mode 100644 makefiles/platform.mk create mode 100644 makefiles/sub.mk create mode 100644 makefiles/top.mk (limited to 'makefiles') diff --git a/makefiles/clean.mk b/makefiles/clean.mk new file mode 100644 index 0000000..efeef68 --- /dev/null +++ b/makefiles/clean.mk @@ -0,0 +1,35 @@ +# cleans up directories +# +# requires: +# - BINS, OBJS, CPPOBJS, BIN_OBJS +# - CMODULES, CPPMODULES +# - SUBDIRS +# +# provides: +# - target: clean +# - target: distclean + +.PHONY: clean_recursive clean local_clean + +clean_recursive: + @test -z "$(SUBDIRS)" || ( set -e; for d in $(SUBDIRS)""; do \ + (set -e; $(MAKE) -C $$d clean || exit 1); done) + +clean: clean_recursive local_clean + -@rm *.bak 2>/dev/null + -@rm *~ 2>/dev/null + -@rm *.d port/*.d 2>/dev/null + -@rm $(BINS) $(CPP_BINS) 2>/dev/null + -@rm $(OBJS) $(CPPOBJS) $(BIN_OBJS) $(CPP_BIN_OBJS) 2>/dev/null + -@rm exec/* + -@rm *.core + -@rm $(CMODULES) $(CPPMODULES) + -@rm $(CMODULES .o=.d) $(CPPMODULES .o=.d) + +.PHONY: distclean_recursive distclean local_distclean + +distclean_recursive: + @test -z "$(SUBDIRS)" || ( set -e; for d in $(SUBDIRS)""; do \ + (set -e; $(MAKE) -C $$d distclean || exit 1); done) + +distclean: distclean_recursive local_distclean clean diff --git a/makefiles/compiler.mk b/makefiles/compiler.mk new file mode 100644 index 0000000..63f7806 --- /dev/null +++ b/makefiles/compiler.mk @@ -0,0 +1,158 @@ +# sets compiler settings +# +# requires: +# - INCLUDE_DIRS +# +# provides: +# - BIN_OBJS: the object files we need for the binaries (containing the main) +# + +# -Wswitch-default: not good for switches with enums +# -Wsystem-headers: bad idea, as header files are usually happily broken :-) +# -Wtraditional: we don't want to program tradition K&R C anymore! +# -Wunsafe-loop-optimizations: ?? +# -Wno-attributes, -Wmissing-format-attribute: ?? later +# -Wpacked -Wpadded: ?? very questionable +# -Wunreachable-code: doesn't work +# -Wno-div-by-zero: we get NaN and friend over macros, so need for funny tricks :-) +# -Wstrict-overflow=5 is relatively new, later maybe +# -fstack-protector or -fstack-protector-all: should be used, but U +# have currently big problems to get it around compiler gcc and -lssl +# probing! FIXME later +# -fstack-protector-all: does something funny to the shared objects.. +# -Wstack-protector makes no sense without SSP +# everything implied by -Wall is not explicitly specified (gcc 4.2.3) +# -Waggregate-return: is for K&R code and mostly useless nowadays + +#-Werror + +# compilation flags and compilers +COMMON_COMPILE_FLAGS = \ + -g -D_REENTRANT \ + -fstrict-aliasing \ + -pedantic -Wall \ + -Wunused -Wno-import \ + -Wformat -Wformat-y2k -Wformat-nonliteral -Wformat-security -Wformat-y2k \ + -Wswitch-enum -Wunknown-pragmas -Wfloat-equal \ + -Wundef -Wshadow -Wpointer-arith \ + -Wcast-qual -Wcast-align \ + -Wwrite-strings -Wconversion \ + -Wmissing-noreturn \ + -Wno-multichar -Wparentheses -Wredundant-decls \ + -Winline \ + -Wdisabled-optimization \ + $(INCLUDE_DIRS) + +ifeq "$(GCC_MAJOR_VERSION)" "4" +COMMON_COMPILE_FLAGS += \ + -Wfatal-errors -Wmissing-include-dirs -Wvariadic-macros \ + -Wvolatile-register-var \ + -Wstrict-aliasing=2 -Wextra -Winit-self +endif + +ifeq "$(GCC_MAJOR_VERSION)" "3" + +# gcc 3.3, testend on OpenBSD 4.2 +ifeq "$(GCC_MINOR_VERSION)" "3" +COMMON_COMPILE_FLAGS += \ + -W +endif + +# gcc 3.4, not tested yet +ifeq "$(GCC_MINOR_VERSION)" "4" +COMMON_COMPILE_FLAGS += \ + -Wstrict-aliasing=2 -Wextra -Winit-self +endif + +endif + +COMPILE_FLAGS = \ + $(COMMON_COMPILE_FLAGS) \ + -std=c99 \ + -Wnonnull \ + -Wbad-function-cast -Wstrict-prototypes \ + -Wmissing-prototypes -Wmissing-declarations \ + -Wnested-externs + +# gcc 4.x +ifeq "$(GCC_MAJOR_VERSION)" "4" +COMPILE_FLAGS += \ + -Wc++-compat -Wdeclaration-after-statement -Wold-style-definition +endif + +ifeq "$(GCC_MAJOR_VERSION)" "3" + +# gcc 3.4, not tested yet +ifeq "$(GCC_MINOR_VERSION)" "4" +COMPILE_FLAGS += \ + -Wdeclaration-after-statement -Wold-style-definition +endif + +# gcc 3.3, testend on OpenBSD 4.2 +ifeq "$(GCC_MINOR_VERSION)" "3" +#COMPILE_FLAGS += \ +# -Wdeclaration-after-statement +endif + + +endif + +CCPP_COMPILE_FLAGS = \ + $(COMMON_COMPILE_FLAGS) \ + -std=c++98 + +# gcc 4.x +ifeq "$(GCC_MAJOR_VERSION)" "4" +CCPP_COMPILE_FLAGS += \ + -Wno-invalid-offsetof +endif + +ifeq "$(GCC_MAJOR_VERSION)" "3" + +# gcc 3.4, not tested yet +ifeq "$(GCC_MINOR_VERSION)" "4" +CCPP_COMPILE_FLAGS += \ + -Wno-invalid-offsetof +endif + +# gcc 3.3, testend on OpenBSD 4.2 +ifeq "$(GCC_MINOR_VERSION)" "3" +#CCPP_COMPILE_FLAGS += \ +# -Wdeclaration-after-statement +endif + +endif + +CFLAGS = $(COMPILE_FLAGS) $(PLATFORM_COMPILE_FLAGS) $(DEBUGLEVELFLAGS) +CCPPFLAGS = $(CCPP_COMPILE_FLAGS) $(PLATFORM_COMPILE_FLAGS) $(DEBUGLEVELFLAGS) +CC = gcc +CCPP = g++ + +LDFLAGS = $(LDFLAGS_DIR) +LIBS = $(LIBS_DL) $(LIBS_SSP) $(LIBS_DIR) +LINK = $(CC) +CCPP_LINK = $(CCPP) + +%.o : %.c + $(CC) -c -o $@ $(CFLAGS) $< + +%.o : %.cpp + $(CCPP) -c -o $@ $(CCPPFLAGS) $< + +%$(EXE): %.o $(OBJS) + $(CCPP_LINK) -o $@ $(LIBS) $(OBJS) $< + +%.sho : %.c + $(CC) -c -o $@ -fPIC -DSHARED $(CFLAGS) $< + +%$(SO) : %.sho $(OBJS) + $(LINK) -shared -o $@ $(LDFLAGS) $(LIBS) $(OBJS) $< + +%.sho++ : %.cpp + $(CCPP) -c -o $@ -fPIC -DSHARED $(CCPPFLAGS) $< + +%$(SO) : %.sho++ $(OBJS) $(CPPOBJS) + $(CCPP_LINK) -shared -o $@ $(LDFLAGS) $(LIBS) $(OBJS) $(CPPOBJS) $< + +BIN_OBJS = $(BINS:$(EXE)=.o) +CPP_BIN_OBJS = $(CPP_BINS:$(EXE)=.o) diff --git a/makefiles/depend.mk b/makefiles/depend.mk new file mode 100644 index 0000000..bd49fe1 --- /dev/null +++ b/makefiles/depend.mk @@ -0,0 +1,30 @@ +# provides generic rules for C/C++ dependeny generation using +# 'makedepend', 'gcc -MM' or similar mechanisms +# +# requires: +# - compilers CC and CCPP +# - INCLUDEDIRS +# - OBJS, CPP_OBJS and BIN_OBJS +# +# provides: +# - included dependency files +# +# author: Andreas Baumann, abaumann at yahoo dot com + +MAKEDEPEND = $(CC) -MM $(INCLUDE_DIRS) +CCPP_MAKEDEPEND = $(CCPP) -MM $(INCLUDE_DIRS) + +%.d : %.c + @echo Generating dependencies for $< + @$(MAKEDEPEND) $(CFLAGS) $< | \ + sed "s,\($*\.o\)[ :]*\(.*\),$@ : $$\(wildcard \2\)\&\&\&\1 : \2,g" | tr -s '&' "\n" > $@ + +%.d : %.cpp + @echo Generating dependencies for $< + @$(CCPP_MAKEDEPEND) $(CCPPFLAGS) $< | \ + sed "s,\($*\.o\)[ :]*\(.*\),$@ : $$\(wildcard \2\)\&\&\&\1 : \2,g" | tr -s '&' "\n" > $@ + +-include $(OBJS:.o=.d) +-include $(CPP_OBJS:.o=.d) +-include $(BIN_OBJS:.o=.d) +-include $(CPP_BIN_OBJS:.o=.d) diff --git a/makefiles/dist.mk b/makefiles/dist.mk new file mode 100644 index 0000000..01464da --- /dev/null +++ b/makefiles/dist.mk @@ -0,0 +1,21 @@ +# creates distribution tarball +# +# requires: +# - PACKAGE_NAME +# - PACKAGE_VERSION +# +# provides: +# - target 'dist' + +.PHONY: dist +dist: distclean + test -f $(PACKAGE_NAME)-$(PACKAGE_VERSION).tar || rm -f $(PACKAGE_NAME)-$(PACKAGE_VERSION).tar + test -d /tmp/$(PACKAGE_NAME)-$(PACKAGE_VERSION) || rm -rf /tmp/$(PACKAGE_NAME)-$(PACKAGE_VERSION) + find . -type f | grep -v .svn | \ + xargs tar cf /tmp/pre + mkdir /tmp/$(PACKAGE_NAME)-$(PACKAGE_VERSION) + cd /tmp/$(PACKAGE_NAME)-$(PACKAGE_VERSION) && \ + tar xf ../pre && rm -f ../pre && cd .. && \ + tar cvf /tmp/$(PACKAGE_NAME)-$(PACKAGE_VERSION).tar $(PACKAGE_NAME)-$(PACKAGE_VERSION) + rm -rf /tmp/$(PACKAGE_NAME)-$(PACKAGE_VERSION) + mv -f /tmp/$(PACKAGE_NAME)-$(PACKAGE_VERSION).tar . diff --git a/makefiles/guess_env b/makefiles/guess_env new file mode 100755 index 0000000..f11ef5a --- /dev/null +++ b/makefiles/guess_env @@ -0,0 +1,106 @@ +#!/bin/sh + +UNAME_SYSTEM=`(uname -s) 2>/dev/null` +UNAME_RELEASE=`(uname -r) 2>/dev/null` +UNAME_VERSION=`(uname -v) 2>/dev/null` +UNAME_MACHINE=`(uname -m) 2>/dev/null` + +# operating system and major, minor version, more should not be necessary +case "$UNAME_SYSTEM.$UNAME_RELEASE" in + Linux*) PLATFORM=LINUX + OS_MAJOR_VERSION=`echo $UNAME_RELEASE | cut -d . -f 1` + OS_MINOR_VERSION=`echo $UNAME_RELEASE | cut -d . -f 2` + LIBS_DL='-ldl' + ;; + + FreeBSD*) PLATFORM=FREEBSD + OS_MAJOR_VERSION=`echo $UNAME_RELEASE | cut -d . -f 1` + OS_MINOR_VERSION=`echo $UNAME_RELEASE | cut -d . -f 2 | cut -d - -f 1` + LIBS_DL= + LIBS_SSP= + ;; + + OpenBSD*) PLATFORM=OPENBSD + OS_MAJOR_VERSION=`echo $UNAME_RELEASE | cut -d . -f 1` + OS_MINOR_VERSION=`echo $UNAME_RELEASE | cut -d . -f 2 | cut -d - -f 1` + LIBS_DL= + LIBS_SSP= + ;; + + SunOS*) PLATFORM=SUNOS + OS_MAJOR_VERSION=`echo $UNAME_RELEASE | cut -d . -f 1` + OS_MINOR_VERSION=`echo $UNAME_RELEASE | cut -d . -f 2` + LIBS_DL='-ldl' + LIBS_SSP= + ;; + + CYGWIN_NT*) PLATFORM=CYGWIN + _tmp=`echo $UNAME_SYSTEM | cut -d - -f 2` + OS_MAJOR_VERSION=`echo $_tmp | cut -d . -f 1` + OS_MINOR_VERSION=`echo $_tmp | cut -d . -f 2` + LIBS_SSP= + ;; + + *) + PLATFORM=UNKNOWN + echo "Unknown platform '$UNAME_SYSTEM#$UNAME_RELEASE'" + exit 1 +esac + +# the architecture +case "$UNAME_MACHINE" in + i*86*) ARCH=x86 + ;; + + sun4u) ARCH=sun4u + ;; + + *) ARCH=UNKNOWN + echo "Unknown architecture '$UNAME_MACHINE'" + exit 1 + +esac + +# the compiler and version +GCC_VERSION=`gcc -dumpversion` +GCC_MAJOR_VERSION=`echo $GCC_VERSION | cut -d . -f 1` +GCC_MINOR_VERSION=`echo $GCC_VERSION | cut -d . -f 2` + +case "$1" in + --platform) echo $PLATFORM + ;; + + --os-major-version) echo $OS_MAJOR_VERSION + ;; + + --os-minor-version) echo $OS_MINOR_VERSION + ;; + + --arch) echo $ARCH + ;; + + --libs-dl) echo $LIBS_DL + ;; + + --libs-ssl) echo $LIBS_SSL + ;; + + --gcc-major-version) echo $GCC_MAJOR_VERSION + ;; + + --gcc-minor-version) echo $GCC_MINOR_VERSION + ;; + + *) + cat <