# Copyright (c) 2005-2008 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) # # Now, this is probably not the right way to do it (tm), but it saves us fom # a major restructuring of the source tree, again. # # saga_lite is a shared library which contains # - the saga engine # - all available packages # - all available adaptors # that whole bunch is linked into one giant shared lib. So, we use the static # engine lib, the static package libs, etc. # # Actually, we do _not_ really use the engine lib, as we want to replace # engine.o with a version which knows about the available adaptors (which are # only available after the engine built, as the dynamic adaptors link against # the engine itself: thats the sole reason for this hack in the first place). # # So, we fetch the engine.cpp source, recompile it with a special define which # uses the now available dynamic adaptor list (which gets created by this very # makefile on the fly, btw), then link this, all other engine objects, the packges, # and the adaptors into our libsaga_lite. # # # NOTE: at the moment, we can only build the shared lib version of # libsaga_lite. Reason is the following: # # creating a static lib uses ar, which packs all object files into the static # lib archive. ar can not resolve external symbols, thus we need to add object # files from depending libs as well. For that, we can pull the depending # static libs, extract the objects living therein, and add them to our new # static lib. That has to be done recursivly. In fact, that even works, but # (a) the resulting static lib is HUGE (it does not only contain the symbols we # need, but _all_ symbols from _all_ depending libs. just one word: globus). # (b) if we miss a symbol, we won't realize it, and the end user has no chance # to find out which additional lib he needs to link. # # On the opposit end, the linking of the dynamic libsaga_lite will pull all # required symbols from the depending libs, recursivly. Where these depending # libs are statically available, the dynamic lib linking will autimatically # pull all these symbols into our lib -- but only those which are in fact # needed. SAGA_ROOT = ../ include $(SAGA_ROOT)/make/saga.util.mk # we create the makefiles etc in any case, but will not # build the library if HAVE_LITE is not set to yes ifeq "x$(SAGA_HAVE_LITE)" "xyes" ifeq "x$(SAGA_IS_CHECKING)" "xyes" SAGA_SUBDIRS = test endif ifeq "x$(SAGA_IS_CLEANING)" "xyes" SAGA_SUBDIRS = test endif SAGA_LIB = saga_lite ADAPTOR_DATA_IN = static_adaptor_data.hpp.in ADAPTOR_DATA = dynamic_adaptor_data.hpp ADAPTOR_LIST = dynamic_adaptor.list CSAD_SRC = create_static_adaptor_data.cpp CSAD_OBJ = create_static_adaptor_data.o CSAD_BIN = create_static_adaptor_data SAGA_OBJ += $(CSAD_OBJ) LITE_ENGINE_SRC = engine.cpp LITE_ENGINE_OBJ = engine.o ORIG_ENGINE_OBJ = $(SAGA_ROOT)/saga/impl/engine/engine.o ORIG_ENGINE_SRC = $(SAGA_ROOT)/saga/impl/engine/engine.cpp ORIG_ENGINE_LIB = $(SAGA_ROOT)/saga/impl/engine/libsaga_engine.$(SAGA_LEXT) LITE_MK = saga.lite.mk CHECK_MK = saga.test.env.mk SAGA_MAK_D = $(LITE_MK) $(CHECK_MK) ENGINE_CONF = $(wildcard saga.lite.engine.engine.c.mk) EXTERNAL_CONFS = $(wildcard saga.lite.external.*.c.mk) ADAPTOR_CONFS = $(wildcard saga.lite.adaptor.*.c.mk) UTIL_CONFS = $(wildcard saga.lite.util.*.c.mk) PACKAGE_CONFS = $(wildcard saga.lite.package.*.c.mk) ALL_CONFS = $(ENGINE_CONF) $(EXTERNAL_CONFS) $(PACKAGE_CONFS) $(ADAPTOR_CONFS) $(UTIL_CONFS) ifneq "$(ALL_CONFS)" " " include $(ALL_CONFS) endif SAGA_LDFLAGS_SYS += $(LITE_LDFLAGS_SYS) SAGA_LDFLAGS_SYS += $(LITE_LDFLAGS_EXT) SAGA_LIB_OBJ = $(LITE_OBJ) $(LITE_ENGINE_OBJ) SAGA_LIB_OBJC = $(LITE_OBJC) endif include $(SAGA_ROOT)/make/saga.mk ifneq "$(SAGA_HAVE_LITE)" "yes" include $(SAGA_ROOT)/make/saga.nothing.mk endif ifndef SAGA_IS_CLEANING subdirs_before:: $(SAGA_ARCNAME) $(SAGA_LIBNAME) $(CHECK_MK) install_mk endif # only clean in this directory, thus overwrite clean tgt SAGA_CLEAN_TGT = $(LITE_MK) $(CHECK_MK) SAGA_CLEAN_TGT += $(ENGINE_OBJ) $(CSAD_OBJ) $(CSAD_BIN) $(ADAPTOR_DATA) $(SAGA_ARCNAME_CLEAN) $(SAGA_LIBNAME_CLEAN) SAGA_DISTCLEAN_TGT += $(ALL_CONFS) # needed by the engine rebuild SAGA_CPPDEFS += -DBUILD_SAGA_LITE=1 -DSAGA_HAVE_DYNAMIC_ADAPTOR_DATA=1 SAGA_CPPINCS += -I$(SAGA_PWD) # # LITE_LIB = libsaga_lite.$(SAGA_AEXT) # LITE_OBJ_D = ./tmp_obj # # all:: $(LITE_LIB) # # $(LITE_LIB): $(LITE_OBJ_D) $(LITE_ENGINE_OBJ) # @$(ECHO) " liblinking saga lite (static)" # @$(AR) rcs $(LITE_LIB) `find $(LITE_OBJ_D) -name \*.o` $(LITE_ENGINE_OBJ) # # # for all static libs (engine, packages, adaptors), extract contained object # # files. Remove original engine.o (we have our own, remember?) # $(LITE_OBJ_D): $(LITE_ENGINE_OBJ) # @$(ECHO) " extracting engine, package and adaptor objects" # @$(MKDIR) ./$(LITE_OBJ_D) # @for s in $(LITE_S_LIB); do \ # set short=`echo $$s | rev | cut -f 1 -d '/' | rev`; \ # $(MKDIR) -p $(LITE_OBJ_D)/$$s; \ # cd $(LITE_OBJ_D)/$$s; \ # $(AR) x $$s; \ # cd $(SAGA_PWD); \ # done # @$(ECHO) " extracting original engine.o" # @$(RM) $(LITE_OBJ_LITE_OBJ_D)/$(ORIG_ENGINE_OBJ) # the new engine object gets created by saga.mk's default rule # the source for the new engine obj gets created by copying the original source, # and at the same time, we create the static adaptor data $(LITE_ENGINE_SRC): $(ORIG_ENGINE_SRC) $(ADAPTOR_DATA) @$(ECHO) " copying engine sources" @$(CP) $(ORIG_ENGINE_SRC) $(SAGA_PWD)/$(LITE_ENGINE_SRC) # for the static adaptor data, we need the adaptor list, mangled by CSAD_BIN $(ADAPTOR_DATA): $(CSAD_BIN) $(ADAPTOR_LIST) @$(ECHO) " creating dynamic adaptor data" @$(SAGA_ROOT)/config/saga-run.sh $(SAGA_PWD)/$(CSAD_BIN) \ $(ADAPTOR_LIST) \ $(ADAPTOR_DATA_IN) \ $(ADAPTOR_DATA) $(CSAD_BIN): $(CSAD_OBJ) @$(ECHO) " binlinking $(CSAD_BIN)" @$(SAGA_LD) -o $@ $< # CSAD_BIN mangles the static adaptor list created here, by parsing the adaptor # and package configs $(ADAPTOR_LIST): @$(ECHO) " creating dynamic adaptor list" @for aconf in saga.lite.adaptor.*.c.mk; do \ adaptor_name=`$(GREP) ADAPTOR_NAME $$aconf | cut -f 2- -d '='`; \ adaptor_pack=`$(GREP) ADAPTOR_PACKAGES $$aconf | cut -f 2- -d '='`; \ adaptor_name=`$(ECHO) $$adaptor_name | $(SED) -e 's/^ //'`; \ adaptor_pack=`$(ECHO) $$adaptor_pack | $(SED) -e 's/^ //'`; \ adaptor_plist=","; \ for apack in $$adaptor_pack; do \ pconf=saga.lite.package.$$apack.c.mk; \ adaptor_packs=`$(GREP) PACKAGE_DEPS $$pconf | cut -f 2- -d '='`; \ adaptor_packs=`$(ECHO) $$adaptor_packs | $(SED) -e 's/ /,/g'`; \ if ! test "x$$adaptor_packs" = "x"; then \ adaptor_packs=",$$adaptor_packs"; \ fi; \ adaptor_plist="$$adaptor_plist,$$apack$$adaptor_packs"; \ done; \ $(ECHO) "$$adaptor_name$$adaptor_plist" | $(SED) -e 's/,,/,/g' >> $@; \ done clean:: @$(RM) $(ADAPTOR_LIST) $(ADAPTOR_DATA) $(CSAD_BIN) @$(RM) $(LITE_ENGINE_SRC) $(LITE_ENGINE_OBJ) @$(RM) -r $(LITE_OBJ_D) $(LITE_MK): @$(ECHO) " creating saga.lite.mk" @$(CAT) $@.in | $(SED) -e 's!@LITE_LDFLAGS_SYS@!$(LITE_LDFLAGS_SYS)!g' \ | $(SED) -e 's!@LITE_LDFLAGS_EXT@!!g' \ | $(SED) -e 's!@SAGA_HAVE_LITE_MK@!$(SAGA_HAVE_LITE)!g' \ > $@ .PHONY: install_mk install_mk: $(LITE_MK) $(CHECK_MK) ifeq "$(SAGA_HAVE_LITE)" "yes" @$(ECHO) " installing saga.lite.mk" @$(CP) $(LITE_MK) $(CHECK_MK) $(SAGA_ROOT)/make/ endif $(CHECK_MK): @$(ECHO) " creating saga.test.env.mk" @$(ECHO) > $@ @$(ECHO) -n "SAGA_LD_LIBRARY_PATH += :" >> $@ @$(ECHO) $(LITE_LDFLAGS_SYS) \ | $(AWK) '{ OFS = "\n"; $$1 = $$1 ; print $$0}' \ | $(GREP) -e '^-L' \ | $(SORT) \ | $(UNIQ) \ | $(CUT) -c 3- \ | $(XARGS) $(ECHO) \ | $(AWK) '{ OFS = ":"; $$1 = $$1 ; print $$0}' \ >> $@ @$(ECHO) >> $@