summaryrefslogtreecommitdiff
path: root/makefiles
diff options
context:
space:
mode:
authorAndreas Baumann <abaumann@yahoo.com>2008-09-27 17:52:05 +0000
committerAndreas Baumann <abaumann@yahoo.com>2008-09-27 17:52:05 +0000
commit6b1b9863d8fccfe09c2f72c68e1ebfeea54efbe8 (patch)
tree0c4e761c5b5aad7010c210a4519a2a72760af55d /makefiles
parenteedc9cd68aef078e4584e43d8055d70e1fa07351 (diff)
downloadnagios-plugin-curl-6b1b9863d8fccfe09c2f72c68e1ebfeea54efbe8.tar.gz
nagios-plugin-curl-6b1b9863d8fccfe09c2f72c68e1ebfeea54efbe8.tar.bz2
- added first runnig version
Diffstat (limited to 'makefiles')
-rw-r--r--makefiles/clean.mk35
-rw-r--r--makefiles/compiler.mk158
-rw-r--r--makefiles/depend.mk30
-rw-r--r--makefiles/dist.mk21
-rwxr-xr-xmakefiles/guess_env106
-rw-r--r--makefiles/platform.mk34
-rw-r--r--makefiles/sub.mk25
-rw-r--r--makefiles/top.mk33
8 files changed, 442 insertions, 0 deletions
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 <<EOF
+ARCH = $ARCH
+PLATFORM = $PLATFORM
+OS_MAJOR_VERSION = $OS_MAJOR_VERSION
+OS_MINOR_VERSION = $OS_MINOR_VERSION
+LIBS_DL = $LIBS_DL
+LIBS_SSL = $LIBS_SSL
+GCC_MAJOR_VERSION = $GCC_MAJOR_VERSION
+GCC_MINOR_VERSION = $GCC_MINOR_VERSION
+EOF
+ ;;
+esac
diff --git a/makefiles/platform.mk b/makefiles/platform.mk
new file mode 100644
index 0000000..175e25f
--- /dev/null
+++ b/makefiles/platform.mk
@@ -0,0 +1,34 @@
+# sets e. g. to LINUX, OS_MAJOR_VERSION to 2 and OS_MINOR_VERSION to 6
+# by calling the 'guess_env' shell script, where the actual probing happens
+# Also sets PLATFORM_COMPILE_FLAGS to be included when compiling C/C++ code
+#
+# requires:
+# - TOPDIR
+#
+# provides:
+# - PLATFORM
+# - OS_MAJOR_VERSION
+# - OS_MINOR_VERSION
+# - PLATFORM_COMPILE_FLAGS
+# - EXE
+# - SO
+#
+# author: Andreas Baumann, abaumann at yahoo dot com
+
+PLATFORM = $(shell $(TOPDIR)/makefiles/guess_env --platform)
+OS_MAJOR_VERSION = $(shell $(TOPDIR)/makefiles/guess_env --os-major-version)
+OS_MINOR_VERSION = $(shell $(TOPDIR)/makefiles/guess_env --os-minor-version)
+
+PLATFORM_COMPILE_FLAGS = \
+ -D$(PLATFORM) \
+ -DOS_MAJOR_VERSION=$(OS_MAJOR_VERSION) \
+ -DOS_MINOR_VERSION=$(OS_MINOR_VERSION)
+
+LIBS_DL = $(shell $(TOPDIR)/makefiles/guess_env --libs-dl)
+LIBS_SSP = $(shell $(TOPDIR)/makefiles/guess_env --libs-ssl)
+
+EXE =
+SO = .so
+
+GCC_MAJOR_VERSION = $(shell $(TOPDIR)/makefiles/guess_env --gcc-major-version $(CC))
+GCC_MINOR_VERSION = $(shell $(TOPDIR)/makefiles/guess_env --gcc-minor-version $(CC))
diff --git a/makefiles/sub.mk b/makefiles/sub.mk
new file mode 100644
index 0000000..ef40301
--- /dev/null
+++ b/makefiles/sub.mk
@@ -0,0 +1,25 @@
+# makefile for a sub package
+#
+# requires:
+# - TOPDIR
+# - SUBDIRS
+# - INCLUDE_DIRS
+#
+# provides:
+# - target: all targets
+
+-include $(TOPDIR)/makefiles/platform.mk
+-include $(TOPDIR)/makefiles/compiler.mk
+
+.PHONY: all $(SUBDIRS) local_all
+all: local_all $(OBJS) $(CPPOBJS) $(BIN_OBJS) $(CPP_BIN_OBJS) $(BINS) $(CPP_BINS) $(CMODULES) $(CPPMODULES)
+ @test -z "$(SUBDIRS)" || ( set -e; for d in $(SUBDIRS)""; do \
+ (set -e; $(MAKE) -C $$d all || exit 1); done)
+
+.PHONY: test local_test
+test: local_test $(OBJS) $(CPPOBJS) $(BIN_OBJS) $(BINS) $(CPP_BINS) $(CMODULES) $(CPPMODULES)
+ @test -z "$(SUBDIRS)" || ( set -e; for d in $(SUBDIRS)""; do \
+ (set -e; $(MAKE) -C $$d test || exit 1); done)
+
+-include $(TOPDIR)/makefiles/depend.mk
+-include $(TOPDIR)/makefiles/clean.mk
diff --git a/makefiles/top.mk b/makefiles/top.mk
new file mode 100644
index 0000000..4602e91
--- /dev/null
+++ b/makefiles/top.mk
@@ -0,0 +1,33 @@
+# top-level makefile for a package
+#
+# requires:
+# - TOPDIR
+# - SUBDIRS
+#
+# provides:
+# - target 'all'
+# - target 'clean'
+# - target 'distclean'
+# - target 'test'
+# - target 'dist'
+
+.PHONY: all
+all:
+ @test -z "$(SUBDIRS)" || ( set -e; for d in $(SUBDIRS)""; do \
+ (set -e; $(MAKE) -C $$d all || exit 1); done)
+
+.PHONY: clean
+clean:
+ @test -z "$(SUBDIRS)" || ( set -e; for d in $(SUBDIRS)""; do \
+ (set -e; $(MAKE) -C $$d clean || exit 1); done)
+
+.PHONY: distclean
+distclean: clean
+ test -z "$(SUBDIRS)" || ( set -e; for d in $(SUBDIRS)""; do \
+ (set -e; $(MAKE) -C $$d distclean || exit 1); done)
+
+.PHONY: test
+test: all
+ @$(MAKE) -C tests test
+
+-include $(TOPDIR)/makefiles/dist.mk