X-Git-Url: http://rtime.felk.cvut.cz/gitweb/omk.git/blobdiff_plain/285b226ff16603a9bf230be671843c37b36378a6..ca54517a66460ac64138e7a8944209f5c6b62ced:/snippets/rtems.omk diff --git a/snippets/rtems.omk b/snippets/rtems.omk index ad5d47f..83c78eb 100644 --- a/snippets/rtems.omk +++ b/snippets/rtems.omk @@ -12,13 +12,14 @@ # 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 -ifdef OMK_TESTSROOT -ifeq ($(RTEMS_MAKEFILE_PATH),) -$(error $(shell $(call canttest,RTEMS_MAKEFILE_PATH not defined))) -endif -endif +# Output variables: +# OBJ_EXT - extension of object files +# LIB_EXT - extension of library files +# LIB_PREF - prefix for library files +# ASM_EXT - extension of assembler sources include $(RTEMS_MAKEFILE_PATH)/Makefile.inc include $(RTEMS_CUSTOM) @@ -38,17 +39,16 @@ USER_BUILD_DIR := $(MAKERULES_DIR)/$(BUILD_DIR_NAME)/user LOCAL_BUILD_DIR = $(USER_OBJS_DIR) - DEFAULT_INCLUDES = -I $(PROJECT_INCLUDE) 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) @@ -56,6 +56,11 @@ LOADLIBES += $(lib_LOADLIBES:%=-l%) SOLIB_PICFLAGS += -shared -fpic +OBJ_EXT = .o +LIB_EXT = .a +LIB_PREF = lib +ASM_EXT = .S + ifndef RELATIVE_DIR RELATIVE_DIR := $(SOURCES_DIR:$(MAKERULES_DIR)%=%) endif @@ -100,7 +105,8 @@ $(2): $(2).o: $(2) @$(QUIET_CMD_ECHO) " TARFILE $$@" - $(Q) $(OBJCOPY) -I binary -O elf32-littlearm $$^ $$@ + $(Q) $(LD) -r --accept-unknown-input-arch -b binary -o $$@.tmp $$^ + $(Q) $(OBJCOPY) --rename-section .data=.rodata,alloc,load,readonly,data,contents $$@.tmp $$@ endef @@ -113,18 +119,18 @@ 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 -CC_MAJOR_VERSION := $(shell $(CC) -dumpversion | sed -e 's/\([^.]\)\..*/\1/') +CC_MAJOR_VERSION := $(shell $(CC) -dumpversion | $(SED4OMK) -e 's/\([^.]\)\..*/\1/') endif # Prepare suitable define for dependency building ifeq ($(CC_MAJOR_VERSION),2) @@ -166,30 +172,30 @@ $(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 >$$@ '/* Automatically generated from $$< */' - $(Q)echo >>$$@ '/* Conditionals to control compilation */' - $(Q)set -o pipefail ; $(NM) $$< \ - | sed -n 's/^ *0*\(0[0-9A-Fa-f]*\) *A *_cmetric2cond_\([A-Za-z_0-9]*\) */#define \2 0x\1/p' \ - | sort >>$$@ - $(Q)echo >>$$@ '/* Defines from the values defined to symbols */' - $(Q)set -o pipefail ; $(NM) $$< \ - | sed -n 's/^ *0*\(0[0-9A-Fa-f]*\) *A *_cmetric2def_\([A-Za-z_0-9]*\) */#define \2 0x\1/p' \ - | sort >>$$@ +idl_COMPILE = $(IDL_COMPILER) + +define COMPILE_idl_template +$(2).c $(2)-stubs.c $(2)-skels.c $(2)-common.c $(2).h: $(1) $$(wildcard $$(firstword $$(idl_COMPILE))) + @$(QUIET_CMD_ECHO) " IDL $$@" + $(Q) $$(idl_COMPILE) $$($(2)_IDLFLAGS) $(1) endef -# Syntax: $(call PROGRAM_template,,,) +RTEMS_SYSM?=rtems-syms + +# Syntax: $(call PROGRAM_template,,,) define PROGRAM_template -$(1)_OBJS += $$(filter %.o,$$($(1)_SOURCES:%.c=%.o)) -$(1)_OBJS += $$(filter %.o,$$($(1)_SOURCES:%.cc=%.o)) -$(1)_OBJS += $$(filter %.o,$$($(1)_SOURCES:%.cxx=%.o)) -$(1)_OBJS += $$(filter %.o,$$($(1)_SOURCES:%.S=%.o)) +USER_IDLS += $$($(1)_SERVER_IDL) $$($(1)_CLIENT_IDL) $$($(1)_IDL) +$(1)_GEN_SOURCES += $$(filter %.c,$$($(1)_SERVER_IDL:%.idl=%-skels.c)) +$(1)_GEN_SOURCES += $$(filter %.c,$$($(1)_SERVER_IDL:%.idl=%-common.c)) +$(1)_GEN_SOURCES += $$(filter %.c,$$($(1)_CLIENT_IDL:%.idl=%-stubs.c)) +$(1)_GEN_SOURCES += $$(filter %.c,$$($(1)_CLIENT_IDL:%.idl=%-common.c)) +$(1)_GEN_SOURCES += $$(filter %.c,$$($(1)_IDL:%.idl=%.c)) +USER_GEN_SOURCES += $$($(1)_GEN_SOURCES) + +$(1)_OBJS += $$(filter %.o,$$($(1)_SOURCES:%.c=%.o) $$($(1)_GEN_SOURCES:%.c=%.o)) +$(1)_OBJS += $$(filter %.o,$$($(1)_SOURCES:%.cc=%.o) $$($(1)_GEN_SOURCES:%.c=%.o)) +$(1)_OBJS += $$(filter %.o,$$($(1)_SOURCES:%.cxx=%.o) $$($(1)_GEN_SOURCES:%.c=%.o)) +$(1)_OBJS += $$(filter %.o,$$($(1)_SOURCES:%.S=%.o) $$($(1)_GEN_SOURCES:%.c=%.o)) $(1)_OBJS += $$($(1)_EMBEDTARFILES:%=%_tarfile.o) $(1)_OBJS := $$(sort $$($(1)_OBJS)) @@ -197,30 +203,60 @@ USER_OBJS += $$($(1)_OBJS) USER_SOURCES += $$($(1)_SOURCES) USER_EMBEDTARFILES += $$($(1)_EMBEDTARFILES) -$(2)/$(1): $(USER_LIB_DIR)/timestamp +$(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 -#@sed -n -e 's/^LOAD \(.*\)$$$$/ \1 \\/p' $(USER_OBJS_DIR)/$(1).exe.map >>$(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 #-Wl,-Map,$(USER_OBJS_DIR)/$(1).exe.map # FIXME: Why the map file was commented out? endef +# Rules for other output formats (can be specified by OUTPUT_FORMATS) +%.bin: % + @$(QUIET_CMD_ECHO) " OBJCOPY $@" + $(Q) $(OBJCOPY) --output-target=binary -S $< $@ +%.hex: % + @$(QUIET_CMD_ECHO) " OBJCOPY $@" + $(Q) $(OBJCOPY) --output-target=ihex -S $< $@ + +%.srec: % + @$(QUIET_CMD_ECHO) " OBJCOPY $@" + $(Q) $(OBJCOPY) --output-target=srec -S $< $@ # Syntax: $(call LIBRARY_template,) define LIBRARY_template -$(1)_OBJS += $$(filter %.o,$$($(1)_SOURCES:%.c=%.o)) -$(1)_OBJS += $$(filter %.o,$$($(1)_SOURCES:%.cc=%.o)) -$(1)_OBJS += $$(filter %.o,$$($(1)_SOURCES:%.cxx=%.o)) -$(1)_OBJS += $$(filter %.o,$$($(1)_SOURCES:%.S=%.o)) +USER_IDLS += $$($(1)_SERVER_IDL) $$($(1)_CLIENT_IDL) $$($(1)_IDL) +$(1)_GEN_SOURCES += $$(filter %.c,$$($(1)_SERVER_IDL:%.idl=%-skels.c)) +$(1)_GEN_SOURCES += $$(filter %.c,$$($(1)_SERVER_IDL:%.idl=%-common.c)) +$(1)_GEN_SOURCES += $$(filter %.c,$$($(1)_CLIENT_IDL:%.idl=%-stubs.c)) +$(1)_GEN_SOURCES += $$(filter %.c,$$($(1)_CLIENT_IDL:%.idl=%-common.c)) +$(1)_GEN_SOURCES += $$(filter %.c,$$($(1)_IDL:%.idl=%.c)) +USER_GEN_SOURCES += $$($(1)_GEN_SOURCES) + +$(1)_OBJS += $$(filter %.o,$$($(1)_SOURCES:%.c=%.o) $$($(1)_GEN_SOURCES:%.c=%.o)) +$(1)_OBJS += $$(filter %.o,$$($(1)_SOURCES:%.cc=%.o) $$($(1)_GEN_SOURCES:%.c=%.o)) +$(1)_OBJS += $$(filter %.o,$$($(1)_SOURCES:%.cxx=%.o) $$($(1)_GEN_SOURCES:%.c=%.o)) +$(1)_OBJS += $$(filter %.o,$$($(1)_SOURCES:%.S=%.o) $$($(1)_GEN_SOURCES:%.c=%.o)) $(1)_OBJS += $$($(1)_EMBEDTARFILES:%=%_tarfile.o) $(1)_OBJS := $$(sort $$($(1)_OBJS)) @@ -234,14 +270,23 @@ $(USER_LIB_DIR)/lib$(1).a: $$($(1)_OBJS) @touch $(USER_LIB_DIR)/timestamp endef - +$(USER_LIB_DIR)/timestamp: + $(Q)touch $@ # Syntax: $(call SOLIB_template,) define SOLIB_template -$(1)_OBJSLO += $$(filter %.lo,$$($(1)_SOURCES:%.c=%.lo)) -$(1)_OBJSLO += $$(filter %.lo,$$($(1)_SOURCES:%.cc=%.lo)) -$(1)_OBJSLO += $$(filter %.lo,$$($(1)_SOURCES:%.cxx=%.lo)) -$(1)_OBJSLO += $$(filter %.lo,$$($(1)_SOURCES:%.S=%.lo)) +USER_IDLS += $$($(1)_SERVER_IDL) $$($(1)_CLIENT_IDL) $$($(1)_IDL) +$(1)_GEN_SOURCES += $$(filter %.c,$$($(1)_SERVER_IDL:%.idl=%-skels.c)) +$(1)_GEN_SOURCES += $$(filter %.c,$$($(1)_SERVER_IDL:%.idl=%-common.c)) +$(1)_GEN_SOURCES += $$(filter %.c,$$($(1)_CLIENT_IDL:%.idl=%-stubs.c)) +$(1)_GEN_SOURCES += $$(filter %.c,$$($(1)_CLIENT_IDL:%.idl=%-common.c)) +$(1)_GEN_SOURCES += $$(filter %.c,$$($(1)_IDL:%.idl=%.c)) +SOLIB_GEN_SOURCES += $$($(1)_GEN_SOURCES) + +$(1)_OBJSLO += $$(filter %.lo,$$($(1)_SOURCES:%.c=%.lo) $$($(1)_GEN_SOURCES:%.c=%.lo)) +$(1)_OBJSLO += $$(filter %.lo,$$($(1)_SOURCES:%.cc=%.lo) $$($(1)_GEN_SOURCES:%.c=%.lo)) +$(1)_OBJSLO += $$(filter %.lo,$$($(1)_SOURCES:%.cxx=%.lo) $$($(1)_GEN_SOURCES:%.c=%.lo)) +$(1)_OBJSLO += $$(filter %.lo,$$($(1)_SOURCES:%.S=%.lo) $$($(1)_GEN_SOURCES:%.c=%.lo)) $(1)_OBJS += $$($(1)_EMBEDTARFILES:%=%_tarfile.o) $(1)_OBJSLO := $$(sort $$($(1)_OBJSLO)) @@ -256,21 +301,12 @@ 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) - -binary-pass-local: $(bin_PROGRAMS:%=$(USER_BIN_DIR)/%) $(utils_PROGRAMS:%=$(USER_UTILS_DIR)/% $(test_PROGRAMS:%=$(USER_TESTS_DIR)/%) +library-pass-local: $(lib_LIBRARIES:%=$(USER_LIB_DIR)/lib%.a) $(shared_LIBRARIES:%=$(USER_LIB_DIR)/lib%.so) -# Special rules for CMETRIC generated headers +binary-pass-local: $(bin_PROGRAMS:%=$(USER_BIN_DIR)/%) $(utils_PROGRAMS:%=$(USER_UTILS_DIR)/%) $(test_PROGRAMS:%=$(USER_TESTS_DIR)/%) \ + $(foreach of,$(OUTPUT_FORMATS),$(bin_PROGRAMS:%=$(USER_BIN_DIR)/%.$(of)) $(test_PROGRAMS:%=$(USER_TESTS_DIR)/%.$(of))) -$(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 @@ -284,6 +320,17 @@ $(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=%)))) + + -include $(USER_OBJS_DIR)/*.d endif @@ -291,7 +338,7 @@ endif #===================================================================== -$(eval $(call omk_pass_template, include-pass,$(USER_OBJS_DIR),,$(include_HEADERS)$(nobase_include_HEADERS)$(renamed_include_HEADERS)$(config_include_HEADERS)$(LOCAL_CONFIG_H))) +$(eval $(call omk_pass_template, include-pass,$(USER_OBJS_DIR),USER_RULE_TEMPLATES=y,$(include_HEADERS)$(nobase_include_HEADERS)$(renamed_include_HEADERS)$(config_include_HEADERS)$(LOCAL_CONFIG_H))) $(eval $(call omk_pass_template, library-pass,$(USER_OBJS_DIR),USER_RULE_TEMPLATES=y,$(lib_LIBRARIES)$(shared_LIBRARIES))) $(eval $(call omk_pass_template, binary-pass, $(USER_OBJS_DIR),USER_RULE_TEMPLATES=y,$(bin_PROGRAMS)$(utils_PROGRAMS)$(test_PROGRAMS))) @@ -311,6 +358,7 @@ ifdef USER_RULE_TEMPLATES # User-space static libraries and applications object files USER_SOURCES := $(sort $(USER_SOURCES)) +USER_GEN_SOURCES := $(sort $(USER_GEN_SOURCES)) #$(warning USER_SOURCES = $(USER_SOURCES)) @@ -322,6 +370,8 @@ $(foreach src,$(filter %.cxx,$(USER_SOURCES)),$(eval $(call COMPILE_cc_o_templat $(foreach src,$(filter %.S,$(USER_SOURCES)),$(eval $(call COMPILE_S_o_template,$(SOURCES_DIR)/$(src),$(src:%.S=%.o),))) +$(foreach src,$(filter %.c,$(USER_GEN_SOURCES)),$(eval $(call COMPILE_c_o_template,$(src),$(src:%.c=%.o),))) + # User-space shared libraries object files SOLIB_SOURCES := $(sort $(SOLIB_SOURCES)) @@ -341,13 +391,22 @@ $(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 + +include-pass-submakes: extra-rules-subdirs + +# We must go to EXTRA_RULES_SUBDIRS before going to any other +# 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