# Copyright (c) 2005-2007 Andre Merzky (andre@merzky.net) # # Distributed under the Boost Software License, Version 1.0. (See accompanying # file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) # vim: ft=make ifndef SAGA_MK_INC_INC SAGA_MK_INC_INC = yes ########################################################### # # make configuration # ifdef SAGA_ROOT include $(SAGA_ROOT)/make/saga.util.mk else include $(SAGA_LOCATION)/share/saga/make/saga.util.mk endif ########################################################### # # setup environment # SAGA_PWD = $(shell $(PWD)) # ########################################################### ########################################################### # # saga related compiler flags etc # ifdef SAGA_ROOT SAGA_CXXFLAGS += -I$(SAGA_ROOT)/src/ -I$(SAGA_EXT_ROOT)/boost SAGA_CCFLAGS += -I$(SAGA_ROOT)/src/ -I$(SAGA_EXT_ROOT)/boost else SAGA_CXXFLAGS += -I$(SAGA_LOCATION)/include/ SAGA_CCFLAGS += -I$(SAGA_LOCATION)/include/ endif SAGA_MKDEP = $(SAGA_CPP) -MM # ########################################################### ########################################################### # # headers get installed under SAGA_LOCATION/include/, # but beneath that directory the original directory # hierarchy is maintained. For example, # saga/impl/engine.hpp # goes into # $SAGA_LOCATION/include/saga/impl/engine.hpp # # REL = PWD - ROOT # # fix for old make versions which don't know realpath # SAGA_TMP_PWD = $(realpath $(SAGA_PWD))/ # SAGA_TMP_ROOT = $(realpath $(SAGA_ROOT)) SAGA_TMP_PWD = $(shell cd $(SAGA_PWD) && $(PWD))/ SAGA_TMP_ROOT = $(shell cd $(SAGA_ROOT) && $(PWD)) ifeq "$(SAGA_TMP_PWD)$(SAGA_TMP_ROOT)" "" SAGA_TMP_PWD = $(subst //,/,$(SAGA_PWD)/) SAGA_TMP_ROOT = $(subst //,/,$(SAGA_ROOT)/) endif # $(warning SAGA_TMP_PWD $(SAGA_TMP_PWD)) # $(warning SAGA_TMP_ROOT $(SAGA_TMP_ROOT)) # $(warning $(ECHO) $(SAGA_TMP_PWD)/ | $(SED) -e 's|$(SAGA_TMP_ROOT)/||g') SAGA_REL_PWD = $(shell $(ECHO) $(SAGA_TMP_PWD) \ | $(SED) -e 's|$(SAGA_TMP_ROOT)/||g' \ | $(SED) -e 's|/$$||g' \ ) ifneq "$(SAGA_REL_PWD)" "" SAGA_REL_PWD := $(SAGA_REL_PWD)/ endif ifndef SAGA_HDR_DIR SAGA_HDR_DIR = $(shell $(ECHO) $(SAGA_REL_PWD) \ | $(SED) -e 's/^src\/impl\//saga\/impl/' \ | $(SED) -e 's/^src\///' \ | $(SED) -e 's/^external\/boost\///') endif # ########################################################### ########################################################### # # 'make/' should be cleaned last - put it to the # end of targets # ifneq "$(filter clean distclean confclean,$(MAKECMDGOALS))" "" CLEAN_AFTER := $(filter make%,$(SAGA_SUBDIRS)) SAGA_SUBDIRS := $(filter-out make%,$(SAGA_SUBDIRS)) SAGA_SUBDIRS += $(CLEAN_AFTER) endif # ########################################################### ########################################################### # # main targets: all, install, subdirs # SAGA_ALL_OBJ = $(SAGA_LIB_OBJ) $(SAGA_OBJ) $(SAGA_ADD_LIB_OBJ) $(SAGA_ADD_BIN_OBJ) SAGA_ALL_OBJC = $(SAGA_LIB_OBJC) $(SAGA_OBJC) $(SAGA_ADD_LIB_OBJC) $(SAGA_ADD_BIN_OBJC) ifdef SAGA_LIB SAGA_SLIB = lib$(SAGA_LIB).$(SAGA_LEXT) endif all:: error makefiles depend subdirs $(SAGA_ALL_OBJ) $(SAGA_ALL_OBJC) $(SAGA_SLIB) @$(TRUE) all:: $(SAGA_BIN) $(SAGA_MAK) @$(TRUE) .PHONY: error error:: @$(TRUE) SAGA_CONF_IN = $(wildcard configure.in) SAGA_CONF = $(wildcard configure) SAGA_M4 = $(wildcard *.m4) .PHONY: subdirs $(SAGA_SUBDIRS) subdirs:: $(SAGA_SUBDIRS) $(SAGA_SUBDIRS):: @$(ECHO) " --> $(SAGA_REL_PWD)$@/" @$(MAKE) SAGA_DEEP=1 -C $@ $(MAKECMDGOALS) @$(ECHO) " <-- $(SAGA_REL_PWD)$@/" .PHONY: configure configure:: $(SAGA_CONF_IN) $(SAGA_M4) ifneq "$(SAGA_CONF_IN)" "" @$(ECHO) " creating configure" @autoconf @$(RM) -r autom4te.cache endif @$(TRUE) ifeq "$(realpath $(SAGA_PWD))" "" SAGA_REAL_PWD = $(SAGA_PWD) SAGA_REAL_ROOT = $(SAGA_ROOT) else SAGA_REAL_PWD = $(realpath $(SAGA_PWD)) SAGA_REAL_ROOT = $(realpath $(SAGA_ROOT)) endif .PHONY: makefiles makefiles:: makeconfigs @$(TRUE) makeconfigs:: $(SAGA_MAK_C) subdirs ifdef SAGA_MAK_C @$(CP) $(SAGA_MAK_C) $(SAGA_ROOT)/make endif $(SAGA_MAK_C): @$(ECHO) "" @$(ECHO) " ================================= " @$(ECHO) " you need to run configure first " @$(ECHO) " ================================= " @$(ECHO) "" @$(FALSE) Makefile.nok: Makefile.ok ifndef SAGA_DEEP ifeq "$(SAGA_CONF)" "" @$(MAKE) -C . configure endif @$(ECHO) " running configure" @./configure endif @$(TRUE) Makefile.ok: ifndef SAGA_DEEP ifeq "$(SAGA_CONF)" "" @$(MAKE) -C . configure endif @$(ECHO) " running configure" @./configure endif @$(TRUE) install:: all ifneq "$(SAGA_HDR)" "" @$(ECHO) " install headers" @$(MKDIR) $(SAGA_HDR_ROOT)/$(SAGA_HDR_DIR) @$(CP) $(SAGA_HDR) $(SAGA_HDR_ROOT)/$(SAGA_HDR_DIR) endif ifneq "$(SAGA_SLIB)" "" @$(ECHO) " install lib" @$(MKDIR) $(SAGA_LIB_ROOT)/$(SAGA_LIB_DIR) @$(CP) $(SAGA_SLIB) $(SAGA_LIB_ROOT)/$(SAGA_LIB_DIR) endif ifneq "$(SAGA_BIN)" "" @$(ECHO) " install bin" @$(MKDIR) $(SAGA_BIN_ROOT)/$(SAGA_BIN_DIR) @$(CP) $(SAGA_BIN) $(SAGA_BIN_ROOT)/$(SAGA_BIN_DIR) endif ifneq "$(SAGA_INI)" "" @$(ECHO) " install inis" @$(MKDIR) $(SAGA_INI_ROOT) @$(CP) $(SAGA_INI) $(SAGA_INI_ROOT) endif ifneq "$(SAGA_MAK)" "" @$(ECHO) " install makefiles" @$(MKDIR) $(SAGA_MAK_ROOT) @$(CP) $(SAGA_MAK) $(SAGA_MAK_ROOT) endif ifneq "$(SAGA_MAK_D)" "" @$(ECHO) " install make includes" @$(MKDIR) $(SAGA_MAK_ROOT) @$(CP) $(SAGA_MAK_D) $(SAGA_MAK_ROOT) endif # ########################################################### ########################################################### # # Handle dependencies for all cpp sources # SAGA_DEPEND = $(addprefix .depend/,$(SAGA_SRC:.cpp=.d)) SAGA_DEPEND += $(addprefix .depend/,$(SAGA_CSRC:.c=.d)) # include dependencies if we have any ifneq "$(SAGA_DEPEND)" "" ifeq "$(filter clean distclean libclean depclean confclean configure makefiles, $(MAKECMDGOALS))" "" -include $(SAGA_DEPEND) endif endif # 'make depend' re-creates dependencies if needed .PHONY: makes depend deps deps:: depend depend: error makes subdirs $(SAGA_DEPEND) @$(TRUE) makes:: $(SAGA_MAK_I) subdirs @$(TRUE) # dependencies depend on source file, and get # re-created automatically .depend/%.d:: %.cpp # $(SAGA_ROOT)/config/saga.config.c.mk @$(ECHO) " check dependencies for $<" @$(MKDIR) .depend @$(SAGA_MKDEP) $(SAGA_CXXFLAGS) $< > $@ .depend/%.d:: %.c # $(SAGA_ROOT)/config/saga.config.c.mk @$(ECHO) " check dependencies for $<" @$(MKDIR) .depend @$(SAGA_MKDEP) $(SAGA_CCFLAGS) $< > $@ # ########################################################### ########################################################### # # main rule set # $(SAGA_ALL_OBJ): %.o : %.cpp @$(ECHO) " compile $@" @$(SAGA_CXX) $(SAGA_CXXFLAGS) -c -o $@ $< $(SAGA_ALL_OBJC): %.o : %.c @$(ECHO) " compile $@" @$(SAGA_CC) $(SAGA_CCFLAGS) -c -o $@ $< $(SAGA_BIN):: % : %.o $(SAGA_ADD_BIN_OBJ) $(SAGA_ADD_BIN_OBJC) @$(ECHO) " binlink $@" @$(SAGA_LD_BIN) -o $@ $^ $(SAGA_LDFLAGS) $(SAGA_LDFLAGS_EXT) $(SAGA_SLIB):: $(SAGA_LIB_OBJ) $(SAGA_ADD_LIB_OBJ) $(SAGA_LIB_OBJC) $(SAGA_ADD_LIB_OBJC) @$(ECHO) " liblink $@" @$(SAGA_LD_LIB) -o $@ $^ $(SAGA_LDFLAGS) $(SAGA_LDFLAGS_EXT) # ########################################################### ########################################################### # # cleanup rules # SAGA_CLEAN_TGT += $(wildcard autom4te.cache) SAGA_CLEAN_TGT += $(wildcard config.log) SAGA_CLEAN_TGT += $(wildcard confdefs.h) SAGA_CLEAN_TGT += $(SAGA_SLIB) $(SAGA_BIN) SAGA_CLEAN_TGT += $(SAGA_ALL_OBJ) $(SAGA_ALL_OBJC) SAGA_CLEAN_TGT += $(SAGA_MAK) SAGA_DISTCLEAN_TGT += $(wildcard config.status) SAGA_DISTCLEAN_TGT += $(SAGA_MAK_I) SAGA_DISTCLEAN_TGT += $(SAGA_MAK_C) SAGA_CONFCLEAN_TGT += $(SAGA_CONF) clean:: subdirs @$(ECHO) " clean" ifdef SAGA_CLEAN_TGT @$(RM) -r $(SAGA_CLEAN_TGT) endif @$(TRUE) libclean:: subdirs ifdef SAGA_SLIB @$(ECHO) " cleaning lib" @$(RM) $(SAGA_SLIB) endif @$(TRUE) distclean:: depclean subdirs clean ifdef SAGA_DISTCLEAN_TGT @$(RM) -r $(SAGA_DISTCLEAN_TGT) endif @$(TRUE) confclean:: distclean ifdef SAGA_CONFCLEAN_TGT @$(RM) -r $(SAGA_CONFCLEAN_TGT) endif @$(TRUE) depclean:: subdirs -@$(RM) -r .deps .depend # ########################################################### endif # guard