# 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-114-g1b1fb1a
+# Version: 0.2-177-g8b0dfa8
#
# The OMK build system is distributed under the GNU General Public
# License. See file COPYING for details.
# 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
@$(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
# =======================
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 -s 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 \
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)
#%.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) $(CXXFLAGS) $(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
fi
endef
-# Syntax: $(call CMETRIC_o_h_template,<object_file>,<target_header>)
-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
$(Q) $$(idl_COMPILE) $$($(2)_IDLFLAGS) $(1)
endef
+RTEMS_SYSM?=rtems-syms
+
# Syntax: $(call PROGRAM_template,<executable-name>,<dir>,<link-variant>)
define PROGRAM_template
USER_IDLS += $$($(1)_SERVER_IDL) $$($(1)_CLIENT_IDL) $$($(1)_IDL)
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
-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
$(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=%))))
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
# 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,<object_file>,<target_header>)
+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,<stamp_dir>,<header_file_path>,<list_of_options_to_export>,<header_barrier>)
define BUILD_CONFIG_H_template
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 ; \
)