# Makefile.rules - OCERA make framework common project rules -*- makefile -*- #OMK@base # # (C) Copyright 2003 by Pavel Pisa - OCERA team member # (C) Copyright 2006 by Michal Sojka - Czech Technical University, FEE, DCE # # Version for system-less builds. #OMK@sysless # # #OMK@base # input variables # V .. if set to 1, full command text is shown else short form is used # SUBDIRS .. list of subdirectories intended for make from actual directory # default_CONFIG .. list of default config assignments CONFIG_XXX=y/n ... # LOCAL_CONFIG_H .. name of local config.h file generated from values #OMK@config_h # of options defined in the current directory # config_include_HEADERS .. names of global config files (possibly # with subdirectories) # xxx_DEFINES .. list of config directives to be included in # config header file of the name /xxx.h # LN_HEADERS .. if defined, header files are symbolicaly linked instead of copied. #OMK@include # #OMK@sysless # bin_PROGRAMS .. list of the require binary programs # include_HEADERS .. list of the user-space public header files # lib_LIBRARIES .. list of the user-space libraries # lib_LDSCRIPTS .. list of LD scripts that should be copied to the lib direcotry # lib_obj_SOURCES .. list of source files which should be compiled and # the produced object file placed to the lib directory (e.g. crt0.S) # shared_LIBRARIES .. list of the user-space shared libraries # nobase_include_HEADERS .. public headers copied even with directory part # renamed_include_HEADERS .. public headers copied to the different target name (xxx.h->yyy.h) # utils_PROGRAMS .. list of the development utility programs (compiled for host computer, this might change in future) # xxx_SOURCES .. list of specific target sources # xxx_LIBS .. list of specific target libraries # INCLUDES .. additional include directories and defines for user-space # lib_LOADLIBES .. list of libraries linked to each executable # link_VARIANTS .. list of ld script suffixes (after hypen `-') that # should be used for linking (e.g. ram flash). If this is not # specified, then the value of DEFAULT_LD_SCRIPT_VARIANT from config.target is used. # PREFIX_DIR .. Prefix to directories in _compiled and _build. Used in config.omk. # local_EVALUATE .. Makefile hook, which is executed at the end of #OMK@localeval # the Makefile.rules. Used only for dirty hacks. #OMK@sysless-setup BUILD_DIR_NAME = _build$(addprefix /,$(PREFIX_DIR)) COMPILED_DIR_NAME = _compiled$(addprefix /,$(PREFIX_DIR)) LOCAL_BUILD_DIR=$(MAKERULES_DIR)/$(BUILD_DIR_NAME)/$(RELATIVE_DIR) #$(warning LOCAL_BUILD_DIR = $(LOCAL_BUILD_DIR)) #===================================================================== # Common utility rules link_VARIANTS ?= $(DEFAULT_LD_SCRIPT_VARIANT) #===================================================================== # Include correct rules for just running pass USER_COMPILED_DIR_NAME=$(MAKERULES_DIR)/$(COMPILED_DIR_NAME) USER_INCLUDE_DIR = $(USER_COMPILED_DIR_NAME)/include USER_LIB_DIR = $(USER_COMPILED_DIR_NAME)/lib USER_UTILS_DIR = $(USER_COMPILED_DIR_NAME)/bin-utils USER_BIN_DIR = $(USER_COMPILED_DIR_NAME)/bin USER_OBJS_DIR = $(LOCAL_BUILD_DIR) # Local Variables: # mode:makefile # End: #OMK@base # We need to ensure definition of sources directory first ifndef SOURCES_DIR SOURCES_DIR := $(shell ( pwd -L ) ) endif .PHONY: all default check-make-ver all: check-make-ver default #========================= # Include the config file ifneq ($(CONFIG_FILE_OK),y) ifndef CONFIG_FILE CONFIG_FILE := $(MAKERULES_DIR)/config.omk endif ifneq ($(wildcard $(CONFIG_FILE)-default),) -include $(CONFIG_FILE)-default else $(warning Please, run "make default-config" first) endif ifneq ($(wildcard $(CONFIG_FILE)),) include $(CONFIG_FILE) CONFIG_FILE_OK = y endif endif #$(CONFIG_FILE_OK) export SOURCES_DIR MAKERULES_DIR RELATIVE_DIR export CONFIG_FILE OMK_SERIALIZE_INCLUDED OMK_VERBOSE OMK_SILENT # OMK_SERIALIZE_INCLUDED has to be exported to submakes because passes # must to be serialized only in the toplevel make. ifndef RELATIVE_DIR RELATIVE_DIR := $(SOURCES_DIR:$(MAKERULES_DIR)%=%) endif override RELATIVE_DIR := $(RELATIVE_DIR:/%=%) override RELATIVE_DIR := $(RELATIVE_DIR:\\%=%) #$(warning RELATIVE_DIR $(RELATIVE_DIR)) override BACK2TOP_DIR := $(shell echo $(RELATIVE_DIR)/ | sed -e 's_//_/_g' -e 's_/\./_/_g' -e 's_^\./__g' -e 's_\([^/][^/]*\)_.._g' -e 's_/$$__') #$(warning BACK2TOP_DIR $(BACK2TOP_DIR)) #$(warning SOURCES_DIR = $(SOURCES_DIR)) #$(warning MAKERULES_DIR = $(MAKERULES_DIR)) #$(warning RELATIVE_DIR = $(RELATIVE_DIR)) #vpath %.c $(SOURCES_DIR) #vpath %.cc $(SOURCES_DIR) #vpath %.cxx $(SOURCES_DIR) VPATH = $(SOURCES_DIR) srcdir = $(SOURCES_DIR) # Defines for quiet compilation ifdef V ifeq ("$(origin V)", "command line") OMK_VERBOSE = $(V) endif endif ifndef OMK_VERBOSE OMK_VERBOSE = 0 endif ifeq ($(OMK_VERBOSE),1) Q = else Q = @ endif ifneq ($(findstring s,$(MAKEFLAGS)),) QUIET_CMD_ECHO = true OMK_SILENT = 1 else QUIET_CMD_ECHO = echo endif # =================================================================== # We have set up all important variables, so we can check and include # real OCERA style Makefile.omk now ifndef OMK_INCLUDED include $(SOURCES_DIR)/Makefile.omk OMK_INCLUDED := 1 endif check-make-ver: @GOOD_MAKE_VERSION=`echo $(MAKE_VERSION) | sed -n -e 's/^[4-9]\..*\|^3\.9[0-9].*\|^3\.8[1-9].*/y/p'` ; \ if [ x$$GOOD_MAKE_VERSION != xy ] ; then \ echo "Your make program version is too old and does not support OMK system." ; \ echo "Please update to make program 3.81beta1 or newer." ; exit 1 ; \ fi distclean dist-clean: @$(QUIET_CMD_ECHO) " RM $(COMPILED_DIR_NAME) $(BUILD_DIR_NAME)" @rm -fr $(MAKERULES_DIR)/$(COMPILED_DIR_NAME) $(MAKERULES_DIR)/$(BUILD_DIR_NAME) # Common OMK templates # ==================== # Syntax: $(call mkdir,) define mkdir_def [ -d $(1) ] || mkdir -p $(1) || exit 1 endef # Syntax: $(call omk_pass_template,,,[],[],[]) define omk_pass_template .PHNOY: $(1) $(1)-local $(1): +@$(foreach dir,$(SUBDIRS),$(call mkdir_def,$(2)/$(dir)) ; \ $(MAKE) SOURCES_DIR=$(SOURCES_DIR)/$(dir) --no-print-directory \ RELATIVE_DIR=$(RELATIVE_DIR)/$(dir) -C $(2)/$(dir) \ -f $(SOURCES_DIR)/$(dir)/Makefile $$@ || exit 1 ;) $(5) +@if [ $(4) ] || [ -z "$(subst ",\",$(4))" ]; then \ echo " MAKE $$@ in $(RELATIVE_DIR)"; \ $(call mkdir_def,$(2)); \ $(MAKE) --no-print-directory -C $(2) \ -f $(SOURCES_DIR)/Makefile $(3) $$(@:%=%-local); \ fi endef # ======================= # DEFAULT CONFIG PASS default-config: @echo "# Start of OMK config file" > "$(CONFIG_FILE)-default" @echo "# This file should not be altered manually" >> "$(CONFIG_FILE)-default" @echo "# Overrides should be stored in file $(notdir $(CONFIG_FILE))" >> "$(CONFIG_FILE)-default" @echo >> "$(CONFIG_FILE)-default" @$(MAKE) --no-print-directory -C $(MAKERULES_DIR) \ RELATIVE_DIR="" SOURCES_DIR=$(MAKERULES_DIR) \ -f $(MAKERULES_DIR)/Makefile default-config-pass $(eval $(call omk_pass_template,default-config-pass,$$(LOCAL_BUILD_DIR))) default-config-pass-local: # @echo Default config for $(RELATIVE_DIR) @echo "# Config for $(RELATIVE_DIR)" >> "$(CONFIG_FILE)-default" @$(foreach x, $(default_CONFIG), echo $(x) | \ sed -e 's/^.*=x$$/#\0/' >> "$(CONFIG_FILE)-default" ; ) #OMK@gcc # Rules for compilation of C, C++ and assembler sources using GNU # toolchain. # Interface to other rules: # Input variables: # LIB_DIR - directory where compiled libraries are stored # OBJS_DIR - directory where intermediate files (.o, .map, ...) are stored # INCLUDE_DIR - where includes can be found # from config.omk or Makefile.omk # CROSS_COMPILE - # TARGET_ARCH, DEBUG, OPTIMIZE, DEFS - forms CFLAGS # from base: SOURCES_DIR # from Makefile.omk: lib_LOADLIBES # Output variables: # SOURCES - all the source files that needs to be compiled (except for shared library sources) # SOLIB_SOURCES - all the source files that needs to be compiled for a shared library # Templates: # COMPILER_DEFS_template - definitions that should be defined before # the following templates can be used. The input variables needs to be # defined before evaluating this template # COMPILE_c_o_template, COMPILE_cc_o_template, COMPILE_S_o_template - # templates that create rules for compilation of sources # CMETRIC_o_h_template - FIXME # PROGRAM_template, LIBRARY_template, SOLIB_template - templates that # create rules for compilation of a program, library and shared # library. The rules can use rules produced by COMPILE_xxx_template. define COMPILER_DEFS_template CC = $(CROSS_COMPILE)gcc LINK = $(CROSS_COMPILE)ld AR = $(CROSS_COMPILE)ar OBJCOPY = $(CROSS_COMPILE)objcopy NM = $(CROSS_COMPILE)nm CFLAGS += $(TARGET_ARCH) $(DEBUG) $(OPTIMIZE) CFLAGS += -Wall CFLAGS += -I$(SOURCES_DIR) CFLAGS += -I$(INCLUDE_DIR) LOADLIBES += -L$(LIB_DIR) LOADLIBES += $(lib_LOADLIBES:%=-l%) -include $(OBJS_DIR)/*.d #%.lo: %.c # $(CC) -o $@ $(LCFLAGS) -c $< c_o_COMPILE = $$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) \ $(CPPFLAGS) $(AM_CFLAGS) $$(CFLAGS) cc_o_COMPILE = $$(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) \ $(CPPFLAGS) $(AM_CFLAGS) $$(CFLAGS) S_o_COMPILE = $$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) \ $(CPPFLAGS) $(AM_CFLAGS) $$(CFLAGS) $(ASFLAGS) # Check GCC version for user build ifndef CC_MAJOR_VERSION CC_MAJOR_VERSION = $$(shell $$(CC) -dumpversion | sed -e 's/\([^.]\)\..*/\1/') endif # Prepare suitable define for dependency building ifeq ($$(CC_MAJOR_VERSION),2) CC_DEPFLAGS = -Wp,-MD,"$$@.d.tmp" else CC_DEPFLAGS = -MT $$@ -MD -MP -MF "$$@.d.tmp" endif # lib_obj_SOURCES handling $(LIB_DIR)/%.o: %.o @cp $$(CP_FLAGS) $$< $$@ endef # COMPILER_DEFS_template # Syntax: $(call COMPILE_c_o_template,,,) define COMPILE_c_o_template $(2): $(1) $(LOCAL_CONFIG_H) $$(GEN_HEADERS) @$(QUIET_CMD_ECHO) " CC $$@" $(Q) if $$(c_o_COMPILE) $$(CC_DEPFLAGS) $(3) -o $$@ -c $$< ; \ then mv -f "$$@.d.tmp" "$$@.d" ; \ else rm -f "$$@.d.tmp" ; exit 1; \ fi endef # Syntax: $(call COMPILE_cc_o_template,,,) define COMPILE_cc_o_template $(2): $(1) $(LOCAL_CONFIG_H) $$(GEN_HEADERS) @$(QUIET_CMD_ECHO) " CXX $$@" $(Q) if $$(cc_o_COMPILE) $$(CC_DEPFLAGS) $(3) -o $$@ -c $$< ; \ then mv -f "$$@.d.tmp" "$$@.d" ; \ else rm -f "$$@.d.tmp" ; exit 1; \ fi endef # Syntax: $(call COMPILE_S_o_template,,,) define COMPILE_S_o_template $(2): $(1) $(LOCAL_CONFIG_H) $$(GEN_HEADERS) @$(QUIET_CMD_ECHO) " AS $$@" $(Q) if $$(S_o_COMPILE) -D__ASSEMBLY__ $$(CC_DEPFLAGS) $(3) -o $$@ -c $$< ; \ then if [ -e "$$@.d.tmp" ] ; then mv -f "$$@.d.tmp" "$$@.d" ; fi ; \ else rm -f "$$@.d.tmp" ; exit 1; \ 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 >>$$@ endef # 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)) $(1)_OBJS += $$(filter %.o,$(1)_SOURCES) $(1)_OBJS := $$(sort $$($(1)_OBJS)) SOURCES += $$($(1)_SOURCES) ifneq ($(LD_SCRIPT),) $(1)$(3:%=-%)_LDFLAGS = -Wl,-T,$(LD_SCRIPT).ld$(3:%=-%) endif $(2)/$(1)$(3:%=-%): $$($(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)$(3:%=-%)_LDFLAGS) -Wl,-Map,$(1)$(3:%=-%).map \ $$($(1)_OBJS) $$(LOADLIBES) $$($(1)_MOREOBJS) $$($(1)_LIBS:%=-l%) \ -o $$@ @echo "$(2)/$(1)$(3:%=-%): \\" >$(OBJS_DIR)/$(1)$(3:%=-%).exe.d @if [ -n "$(LD_SCRIPT)" ]; then \ echo " $(LIB_DIR)/$(LD_SCRIPT).ld$(3:%=-%) \\" >>$(OBJS_DIR)/$(1)$(3:%=-%).exe.d; fi @sed -n -e 's/^LOAD \(.*\)$$$$/ \1 \\/p' $(OBJS_DIR)/$(1)$(3:%=-%).map >>$(OBJS_DIR)/$(1)$(3:%=-%).exe.d @echo >>$(OBJS_DIR)/$(1).exe.d 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)) $(1)_OBJS := $$(sort $$($(1)_OBJS)) SOURCES += $$($(1)_SOURCES) $(LIB_DIR)/lib$(1).a: $$($(1)_OBJS) @$(QUIET_CMD_ECHO) " AR $$@" $(Q) $(AR) rcs $$@ $$^ endef # 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)) $(1)_OBJSLO := $$(sort $$($(1)_OBJSLO)) SOLIB_OBJS += $$($(1)_OBJSLO) SOLIB_SOURCES += $$($(1)_SOURCES) $(LIB_DIR)/lib$(1).so: $$($(1)_OBJSLO) @$(QUIET_CMD_ECHO) " LINK $$@" $(Q) $(LD) --shared --soname=lib$(1).so -o $$@ $$^ endef # lib_obj_SOURCES handling lib_OBJS = $(addsuffix .o,$(basename $(lib_obj_SOURCES))) SOURCES += $(filter-out %.o,$(lib_obj_SOURCES)) #$(warning lib_OBJS = $(lib_OBJS)) # # Syntax: $(call LIBOBJ_template,) # define LIBOBJ_template # $(LIB_DIR)/$(1): $(1) # @cp $(CP_FLAGS) $$< $$@ # endef # Local Variables: # mode:makefile # End: #OMK@config_h # Syntax: $(call BUILD_CONFIG_H_template,,,) define BUILD_CONFIG_H_template $(1) : $(wildcard $(CONFIG_FILE)) $(wildcard $(CONFIG_FILE)-default) @$(QUIET_CMD_ECHO) " CONFGEN $$@ in `pwd`" @if [ ! -d `dirname $(1).tmp` ] ; then \ mkdir `dirname $(1).tmp` ; fi @echo "/* Automatically generated from */" > "$(1).tmp" @echo "/* config file: $$< */" >> "$(1).tmp" @echo "#ifndef $(3)" >> "$(1).tmp" @echo "#define $(3)" >> "$(1).tmp" @( $(foreach x, $(shell echo '$($(2))' | sed -e 's/\<\([^ =]*\)\(=[^ ]\+\|\)\>/\1/g' ), \ echo '$(x).$($(x))' ; ) echo ; ) | \ sed -e '/^[^.]*\.n$$$$/d' -e '/^[^.]*\.$$$$/d' -e 's/^\([^.]*\)\.[ym]$$$$/\1.1/' | \ sed -n -e 's/^\([^.]*\)\.\(.*\)$$$$/#define \1 \2/p' \ >> "$(1).tmp" @echo "#endif /*$(3)*/" >> "$(1).tmp" @if cmp --quiet "$(1).tmp" "$(1)" ; then \ echo rm "$(1).tmp" ; \ else mv "$(1).tmp" "$(1)" ; \ echo Updated configuration "$(1)" ; fi endef ifdef LOCAL_CONFIG_H CFLAGS += -I. $(eval $(call BUILD_CONFIG_H_template,$(LOCAL_CONFIG_H),default_CONFIG,_LOCAL_CONFIG_H) ) endif # Special rules for configuration exported headers #FIXME: The directory for headers should not be specified here. $(foreach confh,$(config_include_HEADERS),$(eval $(call BUILD_CONFIG_H_template,$(addprefix $(USER_INCLUDE_DIR)/,$(confh)),$(basename $(notdir $(confh)))_DEFINES,\ _$(basename $(notdir $(confh)))_H \ ))) # Add some hooks to standard passes include-pass-local: $(addprefix $(USER_INCLUDE_DIR)/,$(config_include_HEADERS)) clean-local: clean-local-config-h clean-local-config-h: @$(foreach confh,$(addprefix $(USER_INCLUDE_DIR)/,$(config_include_HEADERS)),\ if [ -e $(confh) ] ; then touch -t 200001010101 $(confh) ; fi ; \ ) # Local Variables: # mode:makefile # End: ifeq ($(OMK_VERBOSE),1) #OMK@include CPHEADER_FLAGS += -v LNHEADER_FLAGS += -v endif ifndef LN_HEADERS define cp_cmd cp $(CPHEADER_FLAGS) $(1) $(2) endef else define cp_cmd ln -sf $(LNHEADER_FLAGS) $(1) $(2) endef endif # TODO: Check modification date of changed header files. If it is # newer that in source dir, show a warning. # Syntax: $(call include-pass-template,,) define include-pass-template @$(foreach f, $($(2)_HEADERS), cmp --quiet $(SOURCES_DIR)/$(f) $(1)/$(notdir $(f)) \ || $(call cp_cmd,$(SOURCES_DIR)/$(f),$(1)/$(notdir $(f))) || exit 1 ; ) @$(foreach f, $(nobase_$(2)_HEADERS), cmp --quiet $(SOURCES_DIR)/$(f) $(1)/$(f) \ || ( mkdir -p $(1)/$(dir $(f)) && $(call cp_cmd,$(SOURCES_DIR)/$(f),$(1)/$(f)) ) || exit 1 ; ) @$(foreach f, $(renamed_$(2)_HEADERS), \ srcfname=`echo '$(f)' | sed -e 's/^\(.*\)->.*$$/\1/'` ; destfname=`echo '$(f)' | sed -e 's/^.*->\(.*\)$$/\1/'` ; \ cmp --quiet $(SOURCES_DIR)/$${srcfname} $(1)/$${destfname} \ || ( mkdir -p `dirname $(1)/$${destfname}` && $(call cp_cmd,$(SOURCES_DIR)/$${srcfname},$(1)/$${destfname}) ) || exit 1 ; ) endef # Local Variables: # mode:makefile # End: #OMK@sysless # Some support to serialize some targets for parallel make ifneq ($(OMK_SERIALIZE_INCLUDED),y) include-pass: $(check-dir) library-pass: include-pass binary-pass utils-pass: library-pass OMK_SERIALIZE_INCLUDED = y endif ifeq ($(wildcard $(MAKERULES_DIR)/config.target),$(MAKERULES_DIR)/config.target) $(error Please, rename $(MAKERULES_DIR)/config.target to config.omk!) endif # ------------------------------------- # Rules for compilation for target ifdef TARGET_RULE_TEMPLATES LDFLAGS += -nostartfiles # FIXME: These are not used. What they are good for? LIB_CPPFLAGS += $(CPPFLAGS) LIB_CFLAGS += $(CFLAGS) SOLIB_PICFLAGS += -shared -fpic CFLAGS += -DOMK_FOR_TARGET INCLUDE_DIR := $(USER_INCLUDE_DIR) LIB_DIR := $(USER_LIB_DIR) OBJS_DIR := $(USER_OBJS_DIR) $(eval $(COMPILER_DEFS_template)) # 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)/%) # Generate rules for compilation of programs and libraries $(foreach prog,$(bin_PROGRAMS),$(foreach link,$(link_VARIANTS),$(eval $(call PROGRAM_template,$(prog),$(USER_BIN_DIR),$(link))))) $(foreach lib,$(lib_LIBRARIES),$(eval $(call LIBRARY_template,$(lib)))) #$(foreach src,$(lib_obj_SOURCES),$(eval $(call LIBOBJ_template,$(addsuffix .o,$(basename $(src)))))) # FIXME: This can't work LIBOBJ_template is not defined $(foreach lib,$(shared_LIBRARIES),$(eval $(call SOLIB_template,$(lib)))) # User-space static libraries and applications object files SOURCES := $(sort $(SOURCES)) #$(warning SOURCES = $(SOURCES)) # User-space shared libraries object files SOLIB_SOURCES := $(sort $(SOLIB_SOURCES)) #$(warning SOLIB_SOURCES = $(SOLIB_SOURCES)) # The above generated rules produced $(SOURCES) and $(SOLIB_SOURCES) # variables. Now generate rules for compilation of theese sources $(foreach src,$(filter %.c,$(SOURCES)),$(eval $(call COMPILE_c_o_template,$(SOURCES_DIR)/$(src),$(src:%.c=%.o),))) $(foreach src,$(filter %.cc,$(SOURCES)),$(eval $(call COMPILE_cc_o_template,$(SOURCES_DIR)/$(src),$(src:%.cc=%.o),))) $(foreach src,$(filter %.cxx,$(SOURCES)),$(eval $(call COMPILE_cc_o_template,$(SOURCES_DIR)/$(src),$(src:%.cxx=%.o),))) $(foreach src,$(filter %.S,$(SOURCES)),$(eval $(call COMPILE_S_o_template,$(SOURCES_DIR)/$(src),$(src:%.S=%.o),))) $(foreach src,$(filter %.c,$(SOLIB_SOURCES)),$(eval $(call COMPILE_c_o_template,$(SOURCES_DIR)/$(src),$(src:%.c=%.lo),$(SOLIB_PICFLAGS)))) $(foreach src,$(filter %.cc,$(SOLIB_SOURCES)),$(eval $(call COMPILE_cc_o_template,$(SOURCES_DIR)/$(src),$(src:%.cc=%.lo),$(SOLIB_PICFLAGS)))) $(foreach src,$(filter %.cxx,$(SOLIB_SOURCES)),$(eval $(call COMPILE_cc_o_template,$(SOURCES_DIR)/$(src),$(src:%.cxx=%.lo),$(SOLIB_PICFLAGS)))) $(foreach src,$(filter %.S,$(SOLIB_SOURCES)),$(eval $(call COMPILE_S_o_template,$(SOURCES_DIR)/$(src),$(src:%.S=%.lo),$(SOLIB_PICFLAGS)))) library-pass-local: $(addprefix $(USER_INCLUDE_DIR)/,$(cmetric_include_HEADERS)) \ $(lib_LIBRARIES:%=$(LIB_DIR)/lib%.a) $(shared_LIBRARIES:%=$(LIB_DIR)/lib%.so) \ $(addprefix $(LIB_DIR)/,$(lib_OBJS)) binary-pass-local: $(foreach link,$(link_VARIANTS),$(bin_PROGRAMS:%=$(USER_BIN_DIR)/%-$(link)) \ $(foreach of,$(OUTPUT_FORMATS),$(bin_PROGRAMS:%=$(USER_BIN_DIR)/%-$(link).$(of)))) endif # TARGET_RULE_TEMPLATES # ------------------------------------- # Rules for compilation utilities for host (user space) ifdef HOST_RULE_TEMPLATES CROSS_COMPILE = TARGET_ARCH = SOLIB_PICFLAGS += -shared -fpic # For host compilation, we don't use a specfic ld script LD_SCRIPT = # TODO: It is probably better to use different directories for host # includes, libraries and objects INCLUDE_DIR := $(USER_INCLUDE_DIR) LIB_DIR := $(USER_LIB_DIR) OBJS_DIR := $(USER_OBJS_DIR) $(eval $(COMPILER_DEFS_template)) #User-space static libraries and applications object files #SOURCES := $(sort $(SOURCES)) #$(warning SOURCES = $(SOURCES)) # Generate rules for compilation of utility programs $(foreach prog,$(utils_PROGRAMS),$(eval $(call PROGRAM_template,$(prog),$(USER_UTILS_DIR),))) # The above generated rule produced $(SOURCES) variable. Now generate # rules for compilation of theese sources $(foreach src,$(filter %.c,$(SOURCES)),$(eval $(call COMPILE_c_o_template,$(SOURCES_DIR)/$(src),$(src:%.c=%.o),))) $(foreach src,$(filter %.cc,$(SOURCES)),$(eval $(call COMPILE_cc_o_template,$(SOURCES_DIR)/$(src),$(src:%.cc=%.o),))) $(foreach src,$(filter %.cxx,$(SOURCES)),$(eval $(call COMPILE_cc_o_template,$(SOURCES_DIR)/$(src),$(src:%.cxx=%.o),))) $(foreach src,$(filter %.S,$(SOURCES)),$(eval $(call COMPILE_S_o_template,$(SOURCES_DIR)/$(src),$(src:%.S=%.o),))) utils-pass-local: $(utils_PROGRAMS:%=$(USER_UTILS_DIR)/%) endif # HOST_RULE_TEMPLATES #===================================================================== # Automatic loading of compiled program by issuing "make load" ifneq ($(OUTPUT_FORMATS),) # Select a file extension (e.g. .bin) for "make load" command to load. LOAD_EXTENSION = .$(firstword $(OUTPUT_FORMATS)) endif # Syntax: $(call LOAD_PROGRAM_template,,,) # Used to load program to the target hardware define LOAD_PROGRAM_template .PHONY: load-$(1)$(3:%=-%) load-$(1)$(3:%=-%): $(2)/$(1)$(3:%=-%)$(LOAD_EXTENSION) @$(QUIET_CMD_ECHO) " LOAD $$<" @if [ -z "$$(LOAD_CMD$(3:%=-%))" ]; then echo "No command for loading applications to '$(3)' is specified."; exit 1; fi $(Q) $$(LOAD_CMD$(3:%=-%)) $$< endef # Syntax: $(call LOAD__RUN_VARIANT_template,) # Used to load and/or run non-default variant of the default program define LOAD_RUN_VARIANT_template .PHONY: load-$(1) run-$(1) load-$(1): load-$(firstword $(bin_PROGRAMS))-$(1) run-$(1): @$(QUIET_CMD_ECHO) " RUN $(1)" @if [ -z "$(RUN_CMD-$(1))" ]; then echo "No command for running '$(1)' variant is specified."; exit 1; fi $(Q) $(RUN_CMD-$(1)) endef $(foreach link,$(link_VARIANTS),$(foreach prog,$(bin_PROGRAMS),$(eval $(call LOAD_PROGRAM_template,$(prog),$(USER_BIN_DIR),$(link))))) $(foreach link,$(link_VARIANTS),$(eval $(call LOAD_RUN_VARIANT_template,$(link)))) .PHONY: load run load: $(addprefix load-,$(firstword $(bin_PROGRAMS))-$(firstword $(link_VARIANTS))) run: run-$(firstword $(link_VARIANTS)) #===================================================================== # Generate pass rules from generic templates OTHER_PASSES = dep clean install $(eval $(call omk_pass_template, include-pass, $(LOCAL_BUILD_DIR),,-n "$(include_HEADERS)$(nobase_include_HEADERS)$(renamed_include_HEADERS)$(lib_LDSCRIPTS)")) $(eval $(call omk_pass_template, library-pass, $(LOCAL_BUILD_DIR),TARGET_RULE_TEMPLATES=y, -n "$(lib_LIBRARIES)$(shared_LIBRARIES)$(lib_OBJS)")) $(eval $(call omk_pass_template, binary-pass, $(LOCAL_BUILD_DIR),TARGET_RULE_TEMPLATES=y, -n "$(bin_PROGRAMS)")) $(eval $(call omk_pass_template, utils-pass, $(LOCAL_BUILD_DIR),HOST_RULE_TEMPLATES=y,-n "$(utils_PROGRAMS)")) $(eval $(call omk_pass_template,$(OTHER_PASSES),$(LOCAL_BUILD_DIR))) dep-local: install-local: include-pass-local: $(call include-pass-template,$(USER_INCLUDE_DIR),include) @$(foreach f, $(lib_LDSCRIPTS), cmp --quiet $(SOURCES_DIR)/$(f) $(USER_LIB_DIR)/$(notdir $(f)) \ || $(call cp_cmd,$(SOURCES_DIR)/$(f),$(USER_LIB_DIR)/$(notdir $(f))) || exit 1 ; ) .PHONY: clean-custom clean-local: clean-custom @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)/%) check-dir: @$(call mkdir_def,$(USER_INCLUDE_DIR)) @$(call mkdir_def,$(USER_LIB_DIR)) @$(call mkdir_def,$(USER_BIN_DIR)) @$(call mkdir_def,$(USER_UTILS_DIR)) # Create directories only for the first time ifndef CHECK_DIR_DONE check-dir = check-dir CHECK_DIR_DONE = y endif export CHECK_DIR_DONE # Which passes to pass default: $(check-dir) include-pass library-pass binary-pass utils-pass ETAGS = etags -R -f $(MAKERULES_DIR)/TAGS .PHONY: TAGS TAGS: $(ETAGS) $(MAKERULES_DIR)/app $(ETAGS) -a $(MAKERULES_DIR)/arch/$(ARCH)/generic $(ETAGS) -a $(MAKERULES_DIR)/arch/$(ARCH)/mach-$(MACH) $(ETAGS) -a $(MAKERULES_DIR)/board/$(BOARD) $(ETAGS) -a $(MAKERULES_DIR)/libs4c # Local Variables: # mode:makefile # End: #OMK@localeval ifneq ($(local_EVALUATE),) #$(warning $(local_EVALUATE)) $(eval $(local_EVALUATE)) endif # Local Variables: # mode:makefile # End: