X-Git-Url: http://rtime.felk.cvut.cz/gitweb/rtems-devel.git/blobdiff_plain/3f0b4b6620f4a783075c60c1f52c578d0e3ba9c1..HEAD:/rtems-omk-template/Makefile.rules?ds=sidebyside diff --git a/rtems-omk-template/Makefile.rules b/rtems-omk-template/Makefile.rules index 5638119..3888749 100644 --- a/rtems-omk-template/Makefile.rules +++ b/rtems-omk-template/Makefile.rules @@ -1,10 +1,10 @@ # Makefile.rules - OCERA make framework common project rules -*- makefile-gmake -*- #OMK:base.omk # # (C) Copyright 2003, 2006, 2007, 2008, 2009 by Pavel Pisa - OCERA team member -# (C) Copyright 2006, 2007, 2008, 2009, 2010, 2011 by Michal Sojka - Czech Technical University, FEE, DCE +# (C) Copyright 2006, 2007, 2008, 2009, 2010, 2011, 2013, 2015 by Michal Sojka - Czech Technical University, FEE, DCE # # Homepage: http://rtime.felk.cvut.cz/omk/ -# Version: 0.2-97-g532aeb1 +# Version: 0.2-177-g8b0dfa8 # # The OMK build system is distributed under the GNU General Public # License. See file COPYING for details. @@ -30,7 +30,10 @@ # xxx_SOURCES .. list of specific target sources # xxx_LIBS .. list of specific target libraries # INCLUDES .. additional include directories and defines for user-space -# tar_EMBEDFILES .. list of tars with embedded files +# xxx_EMBEDTARFILES .. list of source subdirectories which are embedded as tar files to the application +# xxx_EXPORTSYMBOLS .. if "y" then include symbol table in the application for dlopen functionality +# cmetric_include_HEADERS .. generate header file with offsets and sizes of structure fields #OMK:cmetric.omk +# xxx_CMETRIC_SOURCES .. the source cmetric generation # LOCAL_CONFIG_H .. name of local config.h file generated from values #OMK:config_h.omk # of options defined in the current directory # config_include_HEADERS .. names of global config files (possibly @@ -293,8 +296,10 @@ $(pass)-this-dir: $(foreach subdir,$(SUBDIRS),$(pass)-$(subdir)-subdir) @$(call mkdir_def,$(2)) +@$(MAKE) --no-builtin-rules $(NO_PRINT_DIRECTORY) SOURCES_DIR=$(SOURCES_DIR) RELATIVE_DIR=$(RELATIVE_DIR) -C $(2) \ -f $(SOURCESDIR_MAKEFILE) $(3) $(check-target) $(1:%=%-local) +ifneq ($(pass),clean) $(pass)-local: $($(pass)_HOOKS) endif +endif endef # ======================= @@ -324,7 +329,7 @@ omkize: fi $(Q)for i in `find -L . -name Makefile.omk` ; do \ d=`dirname $${i}`; \ - if ! test -f "$${d}/Makefile.rules" && ( test -f "$${d}/Makefile" && ! cmp --silent Makefile "$${d}/Makefile" ); then \ + if ! test -f "$${d}/Makefile.rules" && ! cmp -s Makefile "$${d}/Makefile"; then \ rm -f "$${d}/Makefile"; \ cp -v Makefile "$${d}/Makefile"; \ fi \ @@ -336,14 +341,15 @@ endif ifneq ($(LN_HEADERS),y) define cp_cmd -if ! cmp --quiet $(1) $(2); then \ +if ! cmp -s $(1) $(2); then \ echo " CP $(1:$(OUTPUT_DIR)/%=%) -> $(2:$(OUTPUT_DIR)/%=%)"; \ - install -D $(CPHEADER_FLAGS) $(1) $(2) || exit 1; \ + install -d $(CPHEADER_FLAGS) `dirname $(2)` && \ + install $(CPHEADER_FLAGS) $(1) $(2) || exit 1; \ fi endef else define cp_cmd -if ! cmp --quiet $(1) $(2); then \ +if ! cmp -s $(1) $(2); then \ echo " LN $(1:$(OUTPUT_DIR)/%=%) -> $(2:$(OUTPUT_DIR)/%=%)"; \ if [ -f $(1) ]; then d=$(2); mkdir -p $${d%/*} && ln -sf $(LNHEADER_FLAGS) $(1) $(2) || exit 1; else exit 1; fi; \ fi @@ -396,10 +402,10 @@ CPPFLAGS += -I $(USER_INCLUDE_DIR) CPPFLAGS += $(CONFIG_OMK_DEFINES) -#CPPFLAGS += $(AM_CPPFLAGS) -#CFLAGS += $(AM_CFLAGS) -#CXXFLAGS += $(AM_CXXFLAGS) -#LDFLAGS += $(CFLAGS) $(AM_CFLAGS) $(LD_PATHS:%=-L%) +#CPPFLAGS += $(OMK_CPPFLAGS) +#CFLAGS += $(OMK_CFLAGS) +#CXXFLAGS += $(OMK_CXXFLAGS) +#LDFLAGS += $(CFLAGS) $(OMK_CFLAGS) $(LD_PATHS:%=-L%) LOADLIBES += -L$(USER_LIB_DIR) @@ -465,14 +471,14 @@ ifdef USER_RULE_TEMPLATES #%.lo: %.c # $(CC) -o $@ $(LCFLAGS) -c $< -c_o_COMPILE = $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(AM_CPPFLAGS) \ - $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) $(INCLUDES) -DOMK_FOR_USER +c_o_COMPILE = $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(OMK_CPPFLAGS) \ + $(CPPFLAGS) $(OMK_CFLAGS) $(CFLAGS) $(INCLUDES) -DOMK_FOR_USER -cc_o_COMPILE = $(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(AM_CPPFLAGS) \ - $(CPPFLAGS) $(AM_CXXFLAGS) $(CFLAGS) $(INCLUDES) -DOMK_FOR_USER +cc_o_COMPILE = $(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(OMK_CPPFLAGS) \ + $(CPPFLAGS) $(OMK_CXXFLAGS) $(CFLAGS) $(CXXFLAGS) $(INCLUDES) -DOMK_FOR_USER -S_o_COMPILE = $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) \ - $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) $(ASFLAGS) -DOMK_FOR_USER +S_o_COMPILE = $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(OMK_CPPFLAGS) \ + $(CPPFLAGS) $(OMK_CFLAGS) $(CFLAGS) $(ASFLAGS) -DOMK_FOR_USER # Check GCC version for user build ifndef CC_MAJOR_VERSION @@ -518,31 +524,6 @@ $(2): $(1) $$(GEN_HEADERS) fi endef -# Syntax: $(call CMETRIC_o_h_template,,) -define CMETRIC_o_h_template -$(2): $(1) - @$(QUIET_CMD_ECHO) " CMETRIC $$@" - $(Q)if [ -n `dirname $$@` ] ; then \ - if [ ! -e `dirname $$@` ] ; then \ - mkdir -p `dirname $$@` ; fi ; fi - $(Q)echo >$$@.tmp '/* Automatically generated from $$< */' - $(Q)echo >>$$@.tmp '/* Conditionals to control compilation */' -# Bellow, the tricks with redirection are for shells without set -o pipefail -# (see http://www.mail-archive.com/dash@vger.kernel.org/msg00149.html) - $(Q)exec 3>&1; status=`exec 4>&1 >&3; { $(NM) $$<; echo $$$$? >&4; }\ - | $(SED4OMK) -n 's/^ *0*\(0[0-9A-Fa-f]*\) *A *_cmetric2cond_\([A-Za-z_0-9]*\) */#define \2 0x\1/p' \ - | sort >>$$@.tmp` && exit $$$$status - $(Q)echo >>$$@.tmp '/* Defines from the values defined to symbols in hexadecimal format */' - $(Q)exec 3>&1; status=`exec 4>&1 >&3; { $(NM) $$<; echo $$$$? >&4; }\ - | $(SED4OMK) -n 's/^ *0*\(0[0-9A-Fa-f]*\) *A *_cmetric2def_\([A-Za-z_0-9]*\) */#define \2 0x\1/p' \ - | sort >>$$@.tmp` && exit $$$$status - $(Q)echo >>$$@.tmp '/* Defines from the values defined to symbols in decimal format */' - $(Q)exec 3>&1; status=`exec 4>&1 >&3; { $(NM) -td $$<; echo $$$$? >&4; }\ - | $(SED4OMK) -n 's/^ *0*\(0\|[1-9][0-9]*\) *A *_cmetric2defdec_\([A-Za-z_0-9]*\) */#define \2 \1/p' \ - | sort >>$$@.tmp` && exit $$$$status - $(Q)mv $$@.tmp $$@ -endef - idl_COMPILE = $(IDL_COMPILER) define COMPILE_idl_template @@ -551,6 +532,8 @@ $(2).c $(2)-stubs.c $(2)-skels.c $(2)-common.c $(2).h: $(1) $$(wildcard $$(first $(Q) $$(idl_COMPILE) $$($(2)_IDLFLAGS) $(1) endef +RTEMS_SYSM?=rtems-syms + # Syntax: $(call PROGRAM_template,,,) define PROGRAM_template USER_IDLS += $$($(1)_SERVER_IDL) $$($(1)_CLIENT_IDL) $$($(1)_IDL) @@ -572,14 +555,26 @@ USER_OBJS += $$($(1)_OBJS) USER_SOURCES += $$($(1)_SOURCES) USER_EMBEDTARFILES += $$($(1)_EMBEDTARFILES) +$(1)_LDFLAGS += $$(if $$(filter COMPLETE,$$($(1)_EXPORTSYMBOLS)),-Xlinker --whole-archive,) + +$(1)_LDCOMMAND += $$(shell if [ -z "$$(filter %.cc,$$($(1)_SOURCES))" ] ; \ + then echo $$(CC) $$(CPPFLAGS) $$(OMK_CPPFLAGS) $$(OMK_CFLAGS) $$(CFLAGS) ; \ + else echo $$(CXX) $$(CPPFLAGS) $$(OMK_CPPFLAGS) $$(OMK_CXXFLAGS) $$(CXXFLAGS) ; fi) \ + $$($(1)_LDFLAGS) $$(OMK_LDFLAGS) $$(LDFLAGS) $$($(1)_OBJS) + $(2)/$(1): $(USER_LIB_DIR)/timestamp $(2)/$(1): $$($(1)_OBJS) @$(QUIET_CMD_ECHO) " LINK $$@" - $(Q) $$(shell if [ -z "$$(filter %.cc,$$($(1)_SOURCES))" ] ; \ - then echo $$(CC) $$(CPPFLAGS) $$(AM_CPPFLAGS) $$(AM_CFLAGS) $$(CFLAGS) ; \ - else echo $$(CXX) $$(CPPFLAGS) $$(AM_CPPFLAGS) $$(AM_CXXFLAGS) $$(CXXFLAGS) ; fi) \ - $$(AM_LDFLAGS) $$(LDFLAGS) $$($(1)_OBJS) $$(LOADLIBES) $$($(1)_LIBS:%=-l%) \ - -o $(2)/$(1) + $(Q) if [ -z "$$($(1)_EXPORTSYMBOLS)" ] ; then \ + $$($(1)_LDCOMMAND) $$(LOADLIBES) $$($(1)_LIBS:%=-l%) -Wl,-Map,$(USER_OBJS_DIR)/$(1).exe.map -o $(2)/$(1) || exit 1; \ + else \ + rm -f $(1).prelink ; \ + $$($(1)_LDCOMMAND) $$(LOADLIBES) $$($(1)_LIBS:%=-l%) -Wl,-Map,$(USER_OBJS_DIR)/$(1).exe.map -o $(1).prelink || exit 1 ; \ + $(RTEMS_SYSM) -e -c "$$(CC) $$(CPPFLAGS) $$(OMK_CPPFLAGS) $$(OMK_CFLAGS) $$(CFLAGS)" \ + -S $(1)-symbol-table.c -o $(1)-symbol-table.o $(1).prelink || exit 1 ; \ + $$($(1)_LDCOMMAND) $(1)-symbol-table.o $$(LOADLIBES) $$($(1)_LIBS:%=-l%) -o $(2)/$(1) || exit 1 ; \ + fi + #@echo "$(2)/$(1): \\" >$(USER_OBJS_DIR)/$(1).exe.d #@$(SED4OMK) -n -e 's/^LOAD \(.*\)$$$$/ \1 \\/p' $(USER_OBJS_DIR)/$(1).exe.map >>$(USER_OBJS_DIR)/$(1).exe.d #@echo >>$(USER_OBJS_DIR)/$(1).exe.d @@ -647,21 +642,10 @@ endef -library-pass-local: $(addprefix $(USER_INCLUDE_DIR)/,$(cmetric_include_HEADERS)) \ - $(lib_LIBRARIES:%=$(USER_LIB_DIR)/lib%.a) $(shared_LIBRARIES:%=$(USER_LIB_DIR)/lib%.so) +library-pass-local: $(lib_LIBRARIES:%=$(USER_LIB_DIR)/lib%.a) $(shared_LIBRARIES:%=$(USER_LIB_DIR)/lib%.so) binary-pass-local: $(bin_PROGRAMS:%=$(USER_BIN_DIR)/%) $(utils_PROGRAMS:%=$(USER_UTILS_DIR)/%) $(test_PROGRAMS:%=$(USER_TESTS_DIR)/%) -# Special rules for CMETRIC generated headers - -$(foreach cmetrh,$(cmetric_include_HEADERS),$(eval $(call COMPILE_c_o_template,\ - $(SOURCES_DIR)/$($(basename $(notdir $(cmetrh)))_CMETRIC_SOURCES),\ - $($(basename $(notdir $(cmetrh)))_CMETRIC_SOURCES:%.c=%.o),))) -$(foreach cmetrh,$(cmetric_include_HEADERS),$(eval $(call CMETRIC_o_h_template,\ - $($(basename $(notdir $(cmetrh)))_CMETRIC_SOURCES:%.c=%.o),\ - $(addprefix $(USER_INCLUDE_DIR)/,$(cmetrh))))) - -GEN_HEADERS+=$(cmetric_include_HEADERS:%=$(USER_INCLUDE_DIR)/%) GEN_HEADERS+=$(filter %.h,$(USER_IDLS:%.idl=%.h)) # Generate rules for compilation of programs and libraries @@ -676,6 +660,12 @@ $(foreach lib,$(lib_LIBRARIES),$(eval $(call LIBRARY_template,$(lib)))) $(foreach lib,$(shared_LIBRARIES),$(eval $(call SOLIB_template,$(lib)))) +# Create _build directories for sources in subdirectories i.e. *_SOURCES=dir/file.c +_dirs_to_create=$(filter-out ./,$(sort $(dir $(USER_SOURCES) $(SOLIB_SOURCES)))) +ifneq ($(_dirs_to_create),) +$(shell mkdir -p $(addprefix $(LOCAL_BUILD_DIR)/,$(_dirs_to_create))) +endif + # IDL compilation USER_IDLS := $(sort $(USER_IDLS)) $(foreach src,$(filter %.idl,$(USER_IDLS)),$(eval $(call COMPILE_idl_template,$(SOURCES_DIR)/$(src),$(src:%.idl=%)))) @@ -741,13 +731,15 @@ $(foreach tarfile,$(USER_EMBEDTARFILES),$(eval $(call TARFILE_template,$(tarfile endif -clean-local: +clean-local:: @echo Cleaning in $(USER_OBJS_DIR) @rm -f $(USER_OBJS_DIR)/*.o $(USER_OBJS_DIR)/*.lo \ $(USER_OBJS_DIR)/*.d \ $(USER_OBJS_DIR)/*.map \ $(LOCAL_CONFIG_H:%=$(USER_OBJS_DIR)/%) \ - $(tar_EMBEDFILES:%=$(USER_OBJS_DIR)/%_tarfile) + $(USER_OBJS_DIR)/*_tarfile \ + $(USER_OBJS_DIR)/*.prelink \ + $(USER_OBJS_DIR)/*.tmp default: include-pass library-pass binary-pass @@ -758,6 +750,46 @@ include-pass-submakes: extra-rules-subdirs # directory, since the executables compiled in EXTRA_RULES_SUBDIRS # might be needed there. include-pass-this-dir $(foreach subdir,$(SUBDIRS),include-pass-$(subdir)-subdir): extra-rules-subdirs + #OMK:cmetric.omk@Makefile.rules.rtems +NM ?= nm + +# Syntax: $(call CMETRIC_o_h_template,,) +define CMETRIC_o_h_template +$(2): $(1) + @$(QUIET_CMD_ECHO) " CMETRIC $$@" + $(Q)if [ -n `dirname $$@` ] ; then \ + if [ ! -e `dirname $$@` ] ; then \ + mkdir -p `dirname $$@` ; fi ; fi + $(Q)echo >$$@.tmp '/* Automatically generated from $$< */' + $(Q)echo >>$$@.tmp '/* Conditionals to control compilation */' +# Bellow, the tricks with redirection are for shells without set -o pipefail +# (see http://www.mail-archive.com/dash@vger.kernel.org/msg00149.html) + $(Q)exec 3>&1; status=`exec 4>&1 >&3; { $(NM) $$<; echo $$$$? >&4; }\ + | $(SED4OMK) -n 's/^ *0*\(0[0-9A-Fa-f]*\) *A *_cmetric2cond_\([A-Za-z_0-9]*\) */#define \2 0x\1/p' \ + | sort >>$$@.tmp` && exit $$$$status + $(Q)echo >>$$@.tmp '/* Defines from the values defined to symbols in hexadecimal format */' + $(Q)exec 3>&1; status=`exec 4>&1 >&3; { $(NM) $$<; echo $$$$? >&4; }\ + | $(SED4OMK) -n 's/^ *0*\(0[0-9A-Fa-f]*\) *A *_cmetric2def_\([A-Za-z_0-9]*\) */#define \2 0x\1/p' \ + | sort >>$$@.tmp` && exit $$$$status + $(Q)echo >>$$@.tmp '/* Defines from the values defined to symbols in decimal format */' + $(Q)exec 3>&1; status=`exec 4>&1 >&3; { $(NM) -td $$<; echo $$$$? >&4; }\ + | $(SED4OMK) -n 's/^ *0*\(0\|[1-9][0-9]*\) *A *_cmetric2defdec_\([A-Za-z_0-9]*\) */#define \2 \1/p' \ + | sort >>$$@.tmp` && exit $$$$status + $(Q)mv $$@.tmp $$@ +endef + +library-pass-local: $(addprefix $(USER_INCLUDE_DIR)/,$(cmetric_include_HEADERS)) + +# Special rules for CMETRIC generated headers + +$(foreach cmetrh,$(cmetric_include_HEADERS),$(eval $(call COMPILE_c_o_template,\ + $(SOURCES_DIR)/$($(basename $(notdir $(cmetrh)))_CMETRIC_SOURCES),\ + $($(basename $(notdir $(cmetrh)))_CMETRIC_SOURCES:%.c=%.o),))) +$(foreach cmetrh,$(cmetric_include_HEADERS),$(eval $(call CMETRIC_o_h_template,\ + $($(basename $(notdir $(cmetrh)))_CMETRIC_SOURCES:%.c=%.o),\ + $(addprefix $(USER_INCLUDE_DIR)/,$(cmetrh))))) + +GEN_HEADERS+=$(cmetric_include_HEADERS:%=$(USER_INCLUDE_DIR)/%) #OMK:config_h.omk@Makefile.rules.rtems # Syntax: $(call BUILD_CONFIG_H_template,,,,) define BUILD_CONFIG_H_template @@ -778,7 +810,7 @@ $(addprefix $(1)/,$(notdir $(addsuffix .stamp,$(2)))) : $(CONFIG_FILES) >> "$(2).tmp" @echo "#endif /*$(4)*/" >> "$(2).tmp" @touch "$$@" - @if cmp --quiet "$(2).tmp" "$(2)" ; then rm "$(2).tmp"; \ + @if cmp -s "$(2).tmp" "$(2)" ; then rm "$(2).tmp"; \ else mv "$(2).tmp" "$(2)" ; \ echo "Updated configuration $(2)" ; fi @@ -823,9 +855,7 @@ include-pass-local: $(kern_config_h_stamp_files) endif -clean-local: clean-local-config-h - -clean-local-config-h: +clean-local:: @$(foreach confh,$(config_h_stamp_files) $(kern_config_h_stamp_files),\ if [ -e $(confh) ] ; then rm $(confh) ; fi ; \ )