diff options
author | Andreas Baumann <abaumann@yahoo.com> | 2010-05-18 16:30:11 +0200 |
---|---|---|
committer | Andreas Baumann <abaumann@yahoo.com> | 2010-05-18 16:30:11 +0200 |
commit | dacc8d2149f9095d612d95ec8dfcf596681be18b (patch) | |
tree | 1220c641c4942c338fe6eef992f1700620a63cfa /makefiles/gmake | |
parent | 0f8614c42aacb4f0b47fa843541281be97b8a574 (diff) | |
download | wolfbones-dacc8d2149f9095d612d95ec8dfcf596681be18b.tar.gz wolfbones-dacc8d2149f9095d612d95ec8dfcf596681be18b.tar.bz2 |
merged makefile system with SMERP
Diffstat (limited to 'makefiles/gmake')
-rw-r--r-- | makefiles/gmake/clean.mk | 5 | ||||
-rw-r--r-- | makefiles/gmake/compiler.mk | 51 | ||||
-rwxr-xr-x | makefiles/gmake/guess_env | 28 | ||||
-rw-r--r-- | makefiles/gmake/help.mk | 1 | ||||
-rw-r--r-- | makefiles/gmake/i18n.mk | 15 | ||||
-rw-r--r-- | makefiles/gmake/install.mk | 34 | ||||
-rw-r--r-- | makefiles/gmake/libs.mk | 53 | ||||
-rw-r--r-- | makefiles/gmake/platform.mk | 9 | ||||
-rw-r--r-- | makefiles/gmake/sub.mk | 5 | ||||
-rw-r--r-- | makefiles/gmake/top.mk | 7 |
10 files changed, 197 insertions, 11 deletions
diff --git a/makefiles/gmake/clean.mk b/makefiles/gmake/clean.mk index 3c7a8a9..92061d4 100644 --- a/makefiles/gmake/clean.mk +++ b/makefiles/gmake/clean.mk @@ -27,7 +27,10 @@ clean: clean_recursive clean_po local_clean -@rm -f exec/* 2>/dev/null -@rm -f *.core 2>/dev/null -@rm -f $(CMODULES) $(CPPMODULES) 2>/dev/null - -@rm -f $(CMODULES .o=.d) $(CPPMODULES .o=.d) 2>/dev/null + -@rm -f $(CMODULES:.o=.d) $(CPPMODULES:.o=.d) 2>/dev/null + -@rm -rf $(STATIC_LIB) 2>/dev/null + -@rm -rf $(DYNAMIC_LIB).$(DYNAMIC_LIB_MAJOR).$(DYNAMIC_LIB_MINOR).$(DYNAMIC_LIB_PATCH) 2>/dev/null + -@rm -f $(SH_OBJS) rm -f $(SHPP_OBJS) 2>/dev/null .PHONY: distclean_recursive distclean local_distclean diff --git a/makefiles/gmake/compiler.mk b/makefiles/gmake/compiler.mk index 0962f11..dff1c74 100644 --- a/makefiles/gmake/compiler.mk +++ b/makefiles/gmake/compiler.mk @@ -269,8 +269,47 @@ PTHREADS_LIBS = endif endif -CFLAGS = $(COMPILE_FLAGS) $(PLATFORM_COMPILE_FLAGS) $(INCLUDE_DIRS) $(PTHREADS_CFLAGS) -CCPPFLAGS = $(CCPP_COMPILE_FLAGS) $(PLATFORM_COMPILE_FLAGS) $(INCLUDE_DIRS) $(PTHREADS_CFLAGS) +# 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) $(INCLUDE_CFLAGS) $(PTHREADS_CFLAGS) +CCPPFLAGS = $(CCPP_COMPILE_FLAGS) $(PLATFORM_COMPILE_FLAGS) $(INCLUDE_DIRS) $(INCLUDE_CPPFLAGS) $(PTHREADS_CFLAGS) LDFLAGS = $(INCLUDE_LDFLAGS) $(PTHREADS_LDFLAGS) $(LDFLAGS_NET) $(LDFLAGS_LT) $(LDFLAGS_DL) LIBS = $(INCLUDE_LIBS) $(PTHREADS_LIBS) $(LIBS_NET) $(LIBS_LT) $(LIBS_DL) @@ -284,16 +323,16 @@ CCPP_LINK = $(CCPP) $(CCPP) -c -o $@ $(CCPPFLAGS) $< %$(EXE): %.o $(OBJS) $(TEST_OBJS) - $(LINK) -o $@ $(LDFLAGS) $(OBJS) $(TEST_OBJS) $< $(LIBS) + $(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) $< %.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) $< @@ -302,3 +341,5 @@ 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++) diff --git a/makefiles/gmake/guess_env b/makefiles/gmake/guess_env index 667de97..2e4f3de 100755 --- a/makefiles/gmake/guess_env +++ b/makefiles/gmake/guess_env @@ -11,6 +11,23 @@ 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` + + if test -f /etc/arch-release; then + LINUX_DIST='arch' + LINUX_REV='current' + elif test -f /etc/debian_version; then + LINUX_DIST='debian' + LINUX_REV=`cat /etc/debian_version | cut -d . -f 1` + elif test -f /etc/slackware-version; then + LINUX_DIST='slackware' + LINUX_REV=`cat /etc/slackware-version | cut -d ' ' -f 2 | cut -d . -f 1` + elif test -f /etc/redhat-release; then + LINUX_DIST='redhat' + LINUX_REV=`cat /etc/redhat-release | sed s/.*release\ // | sed s/\ .*// | cut -f 1 -d .` + else + LINUX_DIST='unknown' + LINUX_REV='unknown' + fi ;; FreeBSD*) PLATFORM=FREEBSD @@ -61,11 +78,18 @@ case "$UNAME_MACHINE" in esac +# get last line, old 'tail' syntax and POSIX syntax, both exist out there +if test "x${PLATFORM}" = "xSUNOS"; then + TAIL1='tail -1' +else + TAIL1='tail -n 1' +fi + # the compiler and version # what compiler do we have (we can't relly on it's name as it may be a cc link to the binary!) CC=$2 -(( $CC -v 2>&1 ) | grep -i GCC ) 2>/dev/null 1>/dev/null +(( $CC -v 2>&1 | $TAIL1 ) | grep -i GCC ) 2>/dev/null 1>/dev/null if test $? = 0; then COMPILER='gcc' else @@ -194,5 +218,7 @@ ICC_MINOR_VERSION=$ICC_MINOR_VERSION SPRO_MAJOR_VERSION=$SPRO_MAJOR_VERSION PCC_MAJOR_VERSION=$PCC_MAJOR_VERSION PCC_MINOR_VERSION=$PCC_MINOR_VERSION +LINUX_DIST=$LINUX_DIST +LINUX_REV=$LINUX_REV EOF fi diff --git a/makefiles/gmake/help.mk b/makefiles/gmake/help.mk index 324ff04..fc7e321 100644 --- a/makefiles/gmake/help.mk +++ b/makefiles/gmake/help.mk @@ -7,6 +7,7 @@ make doc build the documentation make clean clean up build artifacts make distclean clean up all generated artifacts make install install (set 'DESTDIR' and 'prefix' at will) +make uninstall uninstall (set 'DESTDIR' and 'prefix' at will) make dist[-Z|-gz|-bz2] create tarball containing all sources make help show this very help page make init-po create initial version of the gettext files diff --git a/makefiles/gmake/i18n.mk b/makefiles/gmake/i18n.mk index a153f6c..08a29e4 100644 --- a/makefiles/gmake/i18n.mk +++ b/makefiles/gmake/i18n.mk @@ -13,8 +13,10 @@ # - target: init-po # - target: merge-po # - taget: check-po +# - target: install_po +# - target: uninstall_po -.PHONY: init-po update-po all_po clean_po install_po +.PHONY: init-po update-po all_po clean_po install_po uninstall_po ifeq "$(ENABLE_NLS)" "1" @@ -72,11 +74,19 @@ all_po: $(MO_FILES) install_po: @test -z "$(GETTEXT_LANGUAGES)" || \ for lang in $(GETTEXT_LANGUAGES)""; do ( \ - echo "install po/$$lang.mo to $(localedir)/$$lang/LC_MESSAGES.." && \ + echo "installing po/$$lang.mo to $(localedir)/$$lang/LC_MESSAGES.." && \ $(INSTALL) -d -m 755 $(localedir)/$$lang/LC_MESSAGES && \ $(INSTALL) -m 644 po/$$lang.mo $(localedir)/$$lang/LC_MESSAGES/$(CATALOG_NAME).mo || exit 1 \ ) done +uninstall_po: + @test -z "$(GETTEXT_LANGUAGES)" || \ + for lang in $(GETTEXT_LANGUAGES)""; do ( \ + echo "uninstalling $(localedir)/$$lang/LC_MESSAGES.." && \ + rm $(localedir)/$$lang/LC_MESSAGES/$(CATALOG_NAME).mo && \ + rmdir $(localedir)/$$lang/LC_MESSAGES || exit 1 \ + ) done + else # No NLS supported wanted, provide dummy targets @@ -88,5 +98,6 @@ check-po: all_po: clean_po: install_po: +uninstall_po: endif diff --git a/makefiles/gmake/install.mk b/makefiles/gmake/install.mk index 225c999..ac6d49d 100644 --- a/makefiles/gmake/install.mk +++ b/makefiles/gmake/install.mk @@ -6,6 +6,7 @@ # # provides: # - target: install +# - target: uninstall # default values DESTDIR= @@ -28,3 +29,36 @@ install_recursive: (set -e; $(MAKE) -C $$d install || exit 1); done) install: install_recursive local_install install_po + @test -d "$(libdir)" || mkdir -p "$(libdir)" + @test -z "$(STATIC_LIB)" || ( \ + $(INSTALL) -m 644 $(STATIC_LIB) $(libdir)/$(STATIC_LIB) ) + @test -z "$(DYNAMIC_LIB)" || ( \ + $(INSTALL) -m 755 $(DYNAMIC_LIB).$(DYNAMIC_LIB_MAJOR).$(DYNAMIC_LIB_MINOR).$(DYNAMIC_LIB_PATCH) \ + $(libdir)/$(DYNAMIC_LIB).$(DYNAMIC_LIB_MAJOR).$(DYNAMIC_LIB_MINOR).$(DYNAMIC_LIB_PATCH) ) + @test -z "$(DYNAMIC_LIB)" || ( \ + rm -f "$(libdir)/$(DYNAMIC_LIB).$(DYNAMIC_LIB_MAJOR)" && \ + ln -s "$(DYNAMIC_LIB).$(DYNAMIC_LIB_MAJOR).$(DYNAMIC_LIB_MINOR).$(DYNAMIC_LIB_PATCH)" \ + "$(libdir)/$(DYNAMIC_LIB).$(DYNAMIC_LIB_MAJOR)" ) + @test -z "$(DYNAMIC_LIB)" || ( \ + rm -f "$(libdir)/$(DYNAMIC_LIB)" && \ + ln -s "$(DYNAMIC_LIB).$(DYNAMIC_LIB_MAJOR).$(DYNAMIC_LIB_MINOR).$(DYNAMIC_LIB_PATCH)" \ + "$(libdir)/$(DYNAMIC_LIB)" ) + +.PHONY: uninstall_recursive uninstall local_uninstall + +uninstall_recursive: + @test -z "$(SUBDIRS)" || ( set -e; for d in $(SUBDIRS)""; do \ + (set -e; $(MAKE) -C $$d uninstall || exit 1); done) + +uninstall: uninstall_recursive local_uninstall uninstall_po + test -z "$(DYNAMIC_LIB)" || ( \ + test ! -f "$(libdir)/$(DYNAMIC_LIB).$(DYNAMIC_LIB_MAJOR).$(DYNAMIC_LIB_MINOR).$(DYNAMIC_LIB_PATCH)" || \ + rm "$(libdir)/$(DYNAMIC_LIB).$(DYNAMIC_LIB_MAJOR).$(DYNAMIC_LIB_MINOR).$(DYNAMIC_LIB_PATCH)" ) + test -z "$(DYNAMIC_LIB)" || ( \ + test ! -h "$(libdir)/$(DYNAMIC_LIB).$(DYNAMIC_LIB_MAJOR)" || \ + rm "$(libdir)/$(DYNAMIC_LIB).$(DYNAMIC_LIB_MAJOR)" ) + test -z "$(DYNAMIC_LIB)" || ( \ + test ! -h "$(libdir)/$(DYNAMIC_LIB)" || \ + rm "$(libdir)/$(DYNAMIC_LIB)" ) + test -z "$(STATIC_LIB)" || ( \ + test ! -f "$(libdir)/$(STATIC_LIB)" || rm "$(libdir)/$(STATIC_LIB)" ) diff --git a/makefiles/gmake/libs.mk b/makefiles/gmake/libs.mk new file mode 100644 index 0000000..08899c3 --- /dev/null +++ b/makefiles/gmake/libs.mk @@ -0,0 +1,53 @@ +# provides explicit library rules +# +# requires: +# - STATIC_LIB: name of the static library +# - DYNAMIC_LIB: soname and versions of the shared library +# - all others like OBJS, CPP_OBJS, LIBS, SH_OBJS, SHPP_OBJS, LDFLAGS +# +# provides: +# - targets to build the static and dynamic version of the project's library +# + +ifeq "$(PLATFORM)" "LINUX" +SO_FLAGS = -shared -Wl,-soname,$(DYNAMIC_LIB).$(DYNAMIC_LIB_MAJOR) +endif + +ifeq "$(PLATFORM)" "SUNOS" +ifeq "$(COMPILER)" "gcc" +SO_FLAGS = -shared -Wl,-h,$(DYNAMIC_LIB).$(DYNAMIC_LIB_MAJOR) +endif +ifeq "$(COMPILER)" "spro" +SO_FLAGS = -G -h $(DYNAMIC_LIB).$(DYNAMIC_LIB_MAJOR) +endif +endif + +ifeq "$(PLATFORM)" "FREEBSD" +SO_FLAGS = -shared -Wl,-x,-soname,$(DYNAMIC_LIB).$(DYNAMIC_LIB_MAJOR) +endif + +ifeq "$(PLATFORM)" "OPENBSD" +SO_FLAGS = -shared -Wl,-soname,$(DYNAMIC_LIB).$(DYNAMIC_LIB_MAJOR) +endif + +ifeq "$(PLATFORM)" "NETBSD" +SO_FLAGS = -shared -Wl,-soname,$(DYNAMIC_LIB).$(DYNAMIC_LIB_MAJOR) +endif + +ifeq "$(PLATFORM)" "CYGWIN" +SO_FLAGS = -shared -Wl,-soname,$(DYNAMIC_LIB).$(DYNAMIC_LIB_MAJOR) +endif + +ifneq "$(STATIC_LIB)" "" +$(STATIC_LIB) : $(OBJS) $(CPP_OBJS) + $(AR) cr $@ $(OBJS) $(CPP_OBJS) +else +$(STATIC_LIB) : +endif + +ifneq "$(DYNAMIC_LIB)" "" +$(DYNAMIC_LIB).$(DYNAMIC_LIB_MAJOR).$(DYNAMIC_LIB_MINOR).$(DYNAMIC_LIB_PATCH) : $(SH_OBJS) $(SHPP_OBJS) + $(CCPP_LINK) $(SO_FLAGS) -o $@ $(LDFLAGS) $(SH_OBJS) $(SHPP_OBJS) $(LIBS) +else +$(DYNAMIC_LIB).$(DYNAMIC_LIB_MAJOR).$(DYNAMIC_LIB_MINOR).$(DYNAMIC_LIB_PATCH) : +endif diff --git a/makefiles/gmake/platform.mk b/makefiles/gmake/platform.mk index 3b04ecc..aaa8846 100644 --- a/makefiles/gmake/platform.mk +++ b/makefiles/gmake/platform.mk @@ -22,6 +22,10 @@ PLATFORM ?= $(shell $(SHELL) $(TOPDIR)/makefiles/gmake/guess_env --platform $(C OS_MAJOR_VERSION ?= $(shell $(SHELL) $(TOPDIR)/makefiles/gmake/guess_env --os-major-version $(CC) "$(CURDIR)" $(TOPDIR)) OS_MINOR_VERSION ?= $(shell $(SHELL) $(TOPDIR)/makefiles/gmake/guess_env --os-minor-version $(CC) "$(CURDIR)" $(TOPDIR)) COMPILER ?= $(shell $(SHELL) $(TOPDIR)/makefiles/gmake/guess_env --compiler $(CC) "$(CURDIR)" $(TOPDIR)) +ifeq "$(PLATFORM)" "LINUX" +LINUX_DIST ?= $(shell $(SHELL) $(TOPDIR)/makefiles/gmake/guess_env --linux-dist $(CC) "$(CURDIR)" $(TOPDIR)) +LINUX_REV ?= $(shell $(SHELL) $(TOPDIR)/makefiles/gmake/guess_env --linux-rev $(CC) "$(CURDIR)" $(TOPDIR)) +endif # platform specific flags ######################### @@ -31,6 +35,11 @@ PLATFORM_COMPILE_FLAGS = \ -DOS_MAJOR_VERSION=$(OS_MAJOR_VERSION) \ -DOS_MINOR_VERSION=$(OS_MINOR_VERSION) +ifeq "$(PLATFORM)" "LINUX" +PLATFORM_COMPILE_FLAGS += \ + -DLINUX_DIST=$(LINUX_DIST) -DLINUX_REV=$(LINUX_REV) +endif + # extensions for binaries ifeq "$(PLATFORM)" "CYGWIN" EXE = .exe diff --git a/makefiles/gmake/sub.mk b/makefiles/gmake/sub.mk index 71a08c7..962c63f 100644 --- a/makefiles/gmake/sub.mk +++ b/makefiles/gmake/sub.mk @@ -12,12 +12,12 @@ -include $(TOPDIR)/makefiles/gmake/compiler.mk .PHONY: all $(SUBDIRS) local_all -all: $(OBJS) $(CPPOBJS) $(BIN_OBJS) $(CPP_BIN_OBJS) $(BINS) $(CPP_BINS) $(CMODULES) $(CPPMODULES) local_all all_po +all: $(OBJS) $(CPPOBJS) $(BIN_OBJS) $(CPP_BIN_OBJS) $(BINS) $(CPP_BINS) $(CMODULES) $(CPPMODULES) $(STATIC_LIB) $(DYNAMIC_LIB).$(DYNAMIC_LIB_MAJOR).$(DYNAMIC_LIB_MINOR).$(DYNAMIC_LIB_PATCH) local_all all_po @test -z "$(SUBDIRS)" || ( set -e; for d in $(SUBDIRS)""; do \ (set -e; $(MAKE) -C $$d all || exit 1); done) .PHONY: test local_test -test: $(OBJS) $(TEST_OBJS) $(CPPOBJS) $(BIN_OBJS) $(BINS) $(CPP_BINS) $(TEST_BIN_OBJS) $(TEST_BINS) $(TEST_CPP_BINS) $(CMODULES) $(CPPMODULES) local_test +test: $(OBJS) $(TEST_OBJS) $(CPPOBJS) $(BIN_OBJS) $(BINS) $(CPP_BINS) $(TEST_BIN_OBJS) $(TEST_BINS) $(TEST_CPP_BINS) $(CMODULES) $(CPPMODULES) $(STATIC_LIB) local_test @test -z "$(SUBDIRS)" || ( set -e; for d in $(SUBDIRS)""; do \ (set -e; $(MAKE) -C $$d test || exit 1); done) @@ -25,3 +25,4 @@ test: $(OBJS) $(TEST_OBJS) $(CPPOBJS) $(BIN_OBJS) $(BINS) $(CPP_BINS) $(TEST_BIN -include $(TOPDIR)/makefiles/gmake/clean.mk -include $(TOPDIR)/makefiles/gmake/install.mk -include $(TOPDIR)/makefiles/gmake/i18n.mk +-include $(TOPDIR)/makefiles/gmake/libs.mk diff --git a/makefiles/gmake/top.mk b/makefiles/gmake/top.mk index c276758..810bedc 100644 --- a/makefiles/gmake/top.mk +++ b/makefiles/gmake/top.mk @@ -12,6 +12,8 @@ # - target 'doc' # - target 'dist' # - target 'help' +# - target 'install' +# - target 'uninstall' -include makefiles/gmake/platform.mk @@ -37,6 +39,11 @@ install: @test -z "$(SUBDIRS)" || ( set -e; for d in $(SUBDIRS)""; do \ (set -e; $(MAKE) -C $$d install || exit 1); done) +.PHONY: uninstall +uninstall: + @test -z "$(SUBDIRS)" || ( set -e; for d in $(SUBDIRS)""; do \ + (set -e; $(MAKE) -C $$d uninstall || exit 1); done) + .PHONY: test test: all @$(MAKE) -C tests test |