summaryrefslogtreecommitdiff
path: root/makefiles/gmake/compiler.mk
diff options
context:
space:
mode:
Diffstat (limited to 'makefiles/gmake/compiler.mk')
-rw-r--r--makefiles/gmake/compiler.mk240
1 files changed, 214 insertions, 26 deletions
diff --git a/makefiles/gmake/compiler.mk b/makefiles/gmake/compiler.mk
index 4f93160..01e9837 100644
--- a/makefiles/gmake/compiler.mk
+++ b/makefiles/gmake/compiler.mk
@@ -4,9 +4,20 @@
# - INCLUDE_DIRS
#
# provides:
-# - BIN_OBJS: the object files we need for the binaries (containing the main)
+# - BIN_OBJS: the object files we need for the binaries which we build always
+# - CPP_BIN_OBJS: same for binaries which have C++ code in them
+# - TEST_BIN_OBJS: same as BIN_OBJS but for test binaries compiled only when
+# testing
+# - TEST_CPP_BIN_OBJS: same for C++ tests
#
+# start of gcc section
+
+ifeq "$(COMPILER)" "gcc"
+
+GCC_MAJOR_VERSION ?= $(shell $(TOPDIR)/makefiles/gmake/guess_env --gcc-major-version $(CC) "$(CURDIR)" $(TOPDIR))
+GCC_MINOR_VERSION ?= $(shell $(TOPDIR)/makefiles/gmake/guess_env --gcc-minor-version $(CC) "$(CURDIR)" $(TOPDIR))
+
# -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!
@@ -22,12 +33,13 @@
# -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)
+# TODO: reenable -O2
# -Waggregate-return: is for K&R code and mostly useless nowadays
-# -funit-at-a-time: TODO check first gcc version it appears
+# -Wno-long-long: sqlite.h on FreeBSD 6.2 shows problems otherwise
# compilation flags and compilers
COMMON_COMPILE_FLAGS = \
- -g -D_REENTRANT \
+ -g -Wno-long-long \
-fstrict-aliasing \
-pedantic -Wall -Werror \
-Wunused -Wno-import \
@@ -35,18 +47,25 @@ COMMON_COMPILE_FLAGS = \
-Wswitch-enum -Wunknown-pragmas -Wfloat-equal \
-Wundef -Wshadow -Wpointer-arith \
-Wcast-qual -Wcast-align \
- -Wwrite-strings -Wconversion \
+ -Wwrite-strings \
-Wmissing-noreturn \
-Wno-multichar -Wparentheses -Wredundant-decls \
-Winline \
- -Wdisabled-optimization \
- $(INCLUDE_DIRS)
-
+ -Wdisabled-optimization
ifeq "$(GCC_MAJOR_VERSION)" "4"
COMMON_COMPILE_FLAGS += \
-Wfatal-errors -Wmissing-include-dirs -Wvariadic-macros \
-Wvolatile-register-var \
-Wstrict-aliasing=2 -Wextra -Winit-self
+# -Wconversion had to meanings before gcc 4.3 (warn about ABI changes when porting
+# old K&R code without function prototypes) and warn about conversions loosing
+# precision. So we enable only -Wconversion (not -Wtraditional-conversion) for gcc
+# >= 4.3 and no -Wconversion for older gcc versions!
+# (see also http://gcc.gnu.org/wiki/NewWconversion)
+ifeq "$(GCC_MINOR_VERSION)" "3"
+COMMON_COMPILE_FLAGS += -Wconversion
+endif
+
endif
ifeq "$(GCC_MAJOR_VERSION)" "3"
@@ -65,9 +84,12 @@ endif
endif
+STD99_COMPILE_FLAGS = \
+ -std=c99
+
COMPILE_FLAGS = \
$(COMMON_COMPILE_FLAGS) \
- -std=c99 \
+ $(STD99_COMPILE_FLAGS) \
-Wnonnull \
-Wbad-function-cast -Wstrict-prototypes \
-Wmissing-prototypes -Wmissing-declarations \
@@ -76,7 +98,8 @@ COMPILE_FLAGS = \
# gcc 4.x
ifeq "$(GCC_MAJOR_VERSION)" "4"
COMPILE_FLAGS += \
- -Wc++-compat -Wdeclaration-after-statement -Wold-style-definition
+ -Wc++-compat -Wdeclaration-after-statement -Wold-style-definition \
+ -funit-at-a-time
endif
ifeq "$(GCC_MAJOR_VERSION)" "3"
@@ -84,7 +107,8 @@ ifeq "$(GCC_MAJOR_VERSION)" "3"
# gcc 3.4, not tested yet
ifeq "$(GCC_MINOR_VERSION)" "4"
COMPILE_FLAGS += \
- -Wdeclaration-after-statement -Wold-style-definition
+ -Wdeclaration-after-statement -Wold-style-definition \
+ -funit-at-a-time
endif
# gcc 3.3, testend on OpenBSD 4.2
@@ -93,7 +117,6 @@ ifeq "$(GCC_MINOR_VERSION)" "3"
# -Wdeclaration-after-statement
endif
-
endif
CCPP_COMPILE_FLAGS = \
@@ -103,8 +126,7 @@ CCPP_COMPILE_FLAGS = \
# gcc 4.x
ifeq "$(GCC_MAJOR_VERSION)" "4"
CCPP_COMPILE_FLAGS += \
- -Wno-invalid-offsetof \
- -funit-at-a-time
+ -Wno-invalid-offsetof -funit-at-a-time
endif
ifeq "$(GCC_MAJOR_VERSION)" "3"
@@ -123,13 +145,175 @@ endif
endif
-CFLAGS = $(COMPILE_FLAGS) $(PLATFORM_COMPILE_FLAGS) $(DEBUGLEVELFLAGS)
-CCPPFLAGS = $(CCPP_COMPILE_FLAGS) $(PLATFORM_COMPILE_FLAGS) $(DEBUGLEVELFLAGS)
-CC = gcc
+#CC = gcc
CCPP = g++
-LDFLAGS = $(LDFLAGS_DIR)
-LIBS = $(LIBS_DL) $(LIBS_SSP) $(LIBS_DIR)
+endif
+
+# end of gcc section
+
+# start of tcc section
+
+# currently we don't need this, the tcc flags are fairly consistent
+#TCC_MAJOR_VERSION ?= $(shell $(TOPDIR)/makefiles/gmake/guess_env --tcc-major-version $(CC) "$(CURDIR)" $(TOPDIR))
+#TCC_MINOR_VERSION ?= $(shell $(TOPDIR)/makefiles/gmake/guess_env --tcc-minor-version $(CC) "$(CURDIR)" $(TOPDIR))
+
+ifeq "$(COMPILER)" "tcc"
+COMPILE_FLAGS = \
+ -Wall -Werror
+endif
+
+# end of tcc section
+
+# start of icc section
+
+# currently we don't need this, the icc flags are fairly consistent
+#ICC_MAJOR_VERSION ?= $(shell $(TOPDIR)/makefiles/gmake/guess_env --icc-major-version $(CC) "$(CURDIR)" $(TOPDIR))
+#ICC_MINOR_VERSION ?= $(shell $(TOPDIR)/makefiles/gmake/guess_env --icc-minor-version $(CC) "$(CURDIR)" $(TOPDIR))
+
+# -vec-report0: turn of SSE2 vector usage messages (they are common since P-4 anyway!)
+
+ifeq "$(COMPILER)" "icc"
+COMPILE_FLAGS = \
+ -Wall -Werror -w1 -vec-report0
+endif
+
+# end of icc section
+
+# start of spro section
+
+# -xc99=all: full C99 compliance for the code (syntax and library functions)
+# -Xc: full ISO compliance, no K&R stuf
+# -mt: enable mutlithreading (-D_REENTRANT for header files, -lthread for ld)
+# -errwarn=%all: convert all warnings to errors
+# -v: do more restrictive syntax checking
+# TODO: enable -O2
+
+ifeq "$(COMPILER)" "spro"
+STD99_COMPILE_FLAGS = \
+ -xc99=all
+COMPILE_FLAGS = \
+ $(STD99_COMPILE_FLAGS) -Xc -errwarn=%all -mt -v
+endif
+
+# end of spro section
+
+# start of pcc section
+
+# currently we don't need this, the pcc flags are fairly consistent
+#PCC_MAJOR_VERSION ?= $(shell $(TOPDIR)/makefiles/gmake/guess_env --pcc-major-version $(CC) "$(CURDIR)" $(TOPDIR))
+#PCC_MINOR_VERSION ?= $(shell $(TOPDIR)/makefiles/gmake/guess_env --pcc-minor-version $(CC) "$(CURDIR)" $(TOPDIR))
+
+ifeq "$(COMPILER)" "pcc"
+COMPILE_FLAGS = \
+ --fatal-warnings
+endif
+
+# end of pcc section
+
+# set flags for threading support using POSIX threads. This is completly different
+# between compiler/platforms
+ifeq "$(COMPILER)" "gcc"
+ifeq "$(PLATFORM)" "LINUX"
+PTHREADS_CFLAGS = -D_REENTRANT -pthread
+PTHREADS_LDFLAGS = -pthread
+PTHREADS_LIBS =
+endif
+ifeq "$(PLATFORM)" "SUNOS"
+PTHREADS_CFLAGS = -D_REENTRANT -pthreads
+PTHREADS_LDFLAGS = -pthreads
+PTHREADS_LIBS =
+endif
+ifeq "$(PLATFORM)" "FREEBSD"
+PTHREADS_CFLAGS = -D_REENTRANT -pthread
+PTHREADS_LDFLAGS = -pthread
+PTHREADS_LIBS =
+endif
+ifeq "$(PLATFORM)" "NETBSD"
+PTHREADS_CFLAGS = -D_REENTRANT -pthread
+PTHREADS_LDFLAGS = -pthread
+PTHREADS_LIBS =
+endif
+ifeq "$(PLATFORM)" "OPENBSD"
+PTHREADS_CFLAGS = -D_REENTRANT -pthread
+PTHREADS_LDFLAGS = -pthread
+PTHREADS_LIBS =
+endif
+ifeq "$(PLATFORM)" "CYGWIN"
+PTHREADS_CFLAGS =
+PTHREADS_LDFLAGS =
+PTHREADS_LIBS =
+endif
+endif
+
+ifeq "$(COMPILER)" "tcc"
+ifeq "$(PLATFORM)" "LINUX"
+PTHREADS_CFLAGS = -D_REENTRANT
+PTHREADS_LDFLAGS =
+PTHREADS_LIBS = -lpthread
+endif
+endif
+
+ifeq "$(COMPILER)" "pcc"
+ifeq "$(PLATFORM)" "LINUX"
+PTHREADS_CFLAGS = -D_REENTRANT -pthread
+PTHREADS_LDFLAGS = -pthread
+PTHREADS_LIBS =
+endif
+endif
+
+ifeq "$(COMPILER)" "icc"
+ifeq "$(PLATFORM)" "LINUX"
+PTHREADS_CFLAGS = -D_REENTRANT -pthread
+PTHREADS_LDFLAGS = -pthread
+PTHREADS_LIBS =
+endif
+endif
+
+# set flags for position independend code (as required for shared libraries
+# on some platforms)
+ifeq "$(COMPILER)" "gcc"
+ifeq "$(PLATFORM)" "LINUX"
+SO_COMPILE_FLAGS = -fPIC
+endif
+ifeq "$(PLATFORM)" "SUNOS"
+SO_COMPILE_FLAGS = -fPIC
+endif
+ifeq "$(PLATFORM)" "FREEBSD"
+SO_COMPILE_FLAGS = -fPIC
+endif
+ifeq "$(PLATFORM)" "NETBSD"
+SO_COMPILE_FLAGS = -fPIC
+endif
+ifeq "$(PLATFORM)" "OPENBSD"
+SO_COMPILE_FLAGS = -fPIC
+endif
+ifeq "$(PLATFORM)" "CYGWIN"
+# code on Cygwin is always position independend
+SO_COMPILE_FLAGS =
+endif
+endif
+
+ifeq "$(COMPILER)" "icc"
+ifeq "$(PLATFORM)" "LINUX"
+SO_COMPILE_FLAGS = -fPIC
+endif
+endif
+
+# TODO: test this
+#ifeq "$(COMPILER)" "spro"
+#ifeq "$(PLATFORM)" "SUNOS"
+#ifeq "$(ARCH)" "sun4u"
+#SO_COMPILE_FLAGS = -xcode=pic32
+#endif
+#endif
+#endif
+
+CFLAGS = $(COMPILE_FLAGS) $(PLATFORM_COMPILE_FLAGS) $(INCLUDE_DIRS) $(PTHREADS_CFLAGS)
+CCPPFLAGS = $(CCPP_COMPILE_FLAGS) $(PLATFORM_COMPILE_FLAGS) $(INCLUDE_DIRS) $(PTHREADS_CFLAGS)
+
+LDFLAGS = $(INCLUDE_LDFLAGS) $(PTHREADS_LDFLAGS) $(LDFLAGS_NET) $(LDFLAGS_LT)
+LIBS = $(INCLUDE_LIBS) $(PTHREADS_LIBS) $(LIBS_NET) $(LIBS_LT)
LINK = $(CC)
CCPP_LINK = $(CCPP)
@@ -139,20 +323,24 @@ CCPP_LINK = $(CCPP)
%.o : %.cpp
$(CCPP) -c -o $@ $(CCPPFLAGS) $<
-%$(EXE): %.o $(OBJS)
- $(CCPP_LINK) -o $@ $(LIBS) $(OBJS) $<
+%$(EXE): %.o $(OBJS) $(TEST_OBJS)
+ $(CCPP_LINK) -o $@ $(LDFLAGS) $(OBJS) $(TEST_OBJS) $< $(LIBS)
%.sho : %.c
- $(CC) -c -o $@ -fPIC -DSHARED $(CFLAGS) $<
+ $(CC) -c -o $@ $(SO_COMPILE_FLAGS) -DSHARED $(CFLAGS) $<
-%$(SO) : %.sho $(OBJS)
- $(LINK) -shared -o $@ $(LDFLAGS) $(LIBS) $(OBJS) $<
+#%$(SO) : %.sho $(OBJS)
+# $(LINK) -shared -o $@ $(LDFLAGS) $(LIBS) $(OBJS) $<
%.sho++ : %.cpp
- $(CCPP) -c -o $@ -fPIC -DSHARED $(CCPPFLAGS) $<
+ $(CCPP) -c -o $@ $(SO_COMPILE_FLAGS) -DSHARED $(CCPPFLAGS) $<
-%$(SO) : %.sho++ $(OBJS) $(CPPOBJS)
- $(CCPP_LINK) -shared -o $@ $(LDFLAGS) $(LIBS) $(OBJS) $(CPPOBJS) $<
+#%$(SO) : %.sho++ $(OBJS) $(CPPOBJS)
+# $(CCPP_LINK) -shared -o $@ $(LDFLAGS) $(LIBS) $(OBJS) $(CPPOBJS) $<
BIN_OBJS = $(BINS:$(EXE)=.o)
+TEST_BIN_OBJS = $(TEST_BINS:$(EXE)=.o)
CPP_BIN_OBJS = $(CPP_BINS:$(EXE)=.o)
+TEST_CPP_BIN_OBJS = $(TEST_CPP_BINS:$(EXE)=.o)
+SH_OBJS = $(OBJS:.o=.sho)
+SHPP_OBJS = $(CPP_OBJS:.o=.sho++)