# 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 by Michal Sojka - Czech Technical University, FEE, DCE
+# (C) Copyright 2006, 2007, 2008, 2009, 2010, 2011 by Michal Sojka - Czech Technical University, FEE, DCE
#
# Homepage: http://rtime.felk.cvut.cz/omk/
-# Version: 0.2-27-g254fd61
+# Version: 0.2-97-g532aeb1
#
# The OMK build system is distributed under the GNU General Public
# License. See file COPYING for details.
# 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.
+# TARGET_STDSTARTFILES .. if left unset or set to `n', startup file provided
+# by compiler is supressed
# 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
MAKERULES_DIR := $(abspath $(dir $(filter %Makefile.rules,$(MAKEFILE_LIST))))
endif
+# The $(SED4OMK) command for BSD based systems requires -E option to allow
+# extended regular expressions
+
+SED4OMK ?= sed
+ifneq ($(shell ( echo A | $(SED4OMK) -n -e 's/A\|B/y/p' )),y)
+ SED4OMK := $(SED4OMK) -E
+ ifneq ($(shell ( echo A | $(SED4OMK) -n -e 's/A\|B/y/p' )),y)
+ SED4OMK := gsed
+ endif
+ ifneq ($(shell ( echo A | $(SED4OMK) -n -e 's/A\|B/y/p' )),y)
+ SED4OMK := gsed -E
+ endif
+ ifneq ($(shell ( echo A | $(SED4OMK) -n -e 's/A\|B/y/p' )),y)
+ $(error No SED program suitable for OMK found)
+ endif
+endif
+
# OUTPUT_DIR is the place where _compiled, _build and possible other
# files/directories are created. By default is the same as
# $(MAKERULES_DIR).
@$(MAKE) -C $(MAKERULES_DIR) OMK_SERIALIZE_INCLUDED=n SOURCES_DIR=$(MAKERULES_DIR) RELATIVE_DIR="" $(MAKECMDGOALS) W=0
endif
-ifdef OMK_TESTSROOT
-# Usage: $(call canttest,<error message>)
-define canttest
- ( echo "$(1)" > $(OUTPUT_DIR)/_canttest; echo "$(1)"; exit 1 )
-endef
-else
-define canttest
- echo "$(1)"
-endef
-endif
+# omk-get-var target allows external scripts/programs to determine the
+# values of OMK variables such as RELATIVE_DIR etc.
+.PHONY: omk-get-var
+omk-get-var:
+ @$(foreach var,$(VAR),echo $(var)=$($(var));)
#=========================
# Include the config file
CONFIG_FILES ?= $(wildcard $(CONFIG_FILE)-default) $(wildcard $(OUTPUT_DIR)/config.target) $(wildcard $(CONFIG_FILE))
-export SOURCES_DIR MAKERULES_DIR RELATIVE_DIR INVOCATION_DIR
+export SED4OMK SOURCES_DIR MAKERULES_DIR RELATIVE_DIR INVOCATION_DIR
export CONFIG_FILE CONFIG_FILES 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.
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_/$$__')
+#override BACK2TOP_DIR := $(shell echo $(RELATIVE_DIR)/ | $(SED4OMK) -e 's_//_/_g' -e 's_/\./_/_g' -e 's_^\./__g' -e 's_\([^/][^/]*\)_.._g' -e 's_/$$__')
#$(warning BACK2TOP_DIR = "$(BACK2TOP_DIR)")
#$(warning SOURCES_DIR = "$(SOURCES_DIR)")
@echo 'Use "make V=1" to see the verbose compile lines.'
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'` ; \
+ @GOOD_MAKE_VERSION=`echo $(MAKE_VERSION) | $(SED4OMK) -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 "Your make program version ($(MAKE_VERSION)) is too old and does not support OMK system." ; \
echo "Please update to make program 3.81beta1 or newer." ; exit 1 ; \
fi
$(pass)-$(3)-subdir: MAKEOVERRIDES:=$(filter-out SUBDIRS=%,$(MAKEOVERRIDES))
$(pass)-$(3)-subdir:
@$(call mkdir_def,$(2)/$(3))
- +@$(MAKE) SOURCES_DIR=$(SOURCES_DIR)/$(3) $(NO_PRINT_DIRECTORY) \
+ +@$(MAKE) --no-builtin-rules SOURCES_DIR=$(SOURCES_DIR)/$(3) $(NO_PRINT_DIRECTORY) \
RELATIVE_DIR=$(RELATIVE_PREFIX)$(3) -C $(2)/$(3) \
-f $(SUBDIR_MAKEFILE) $(pass)-submakes
# In subdirectories we can call submakes directly since passes are
$(pass):
# Submakes have to be called this way and not as dependecies for pass
# serialization to work
- +@$(MAKE) SOURCES_DIR=$(SOURCES_DIR) $(NO_PRINT_DIRECTORY) \
+ +@$(MAKE) --no-builtin-rules SOURCES_DIR=$(SOURCES_DIR) $(NO_PRINT_DIRECTORY) \
RELATIVE_DIR=$(RELATIVE_DIR) \
-f $(SOURCESDIR_MAKEFILE) $(pass)-submakes
$(pass)-submakes:
$(pass)-this-dir: $(foreach subdir,$(SUBDIRS),$(pass)-$(subdir)-subdir)
+@echo "make[omk]: $(pass) in $(RELATIVE_DIR)"
@$(call mkdir_def,$(2))
- +@$(MAKE) $(NO_PRINT_DIRECTORY) SOURCES_DIR=$(SOURCES_DIR) RELATIVE_DIR=$(RELATIVE_DIR) -C $(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)
$(pass)-local: $($(pass)_HOOKS)
endif
# @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" ; )
+ $(SED4OMK) -e 's/^[^=]*=x$$/#\0/' >> "$(CONFIG_FILE)-default" ; )
omkize:
# 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)
# 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; }\
- | sed -n 's/^ *0*\(0[0-9A-Fa-f]*\) *A *_cmetric2cond_\([A-Za-z_0-9]*\) */#define \2 0x\1/p' \
+ | $(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; }\
- | sed -n 's/^ *0*\(0[0-9A-Fa-f]*\) *A *_cmetric2def_\([A-Za-z_0-9]*\) */#define \2 0x\1/p' \
+ | $(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; }\
- | sed -n 's/^ *0*\(0\|[1-9][0-9]*\) *A *_cmetric2defdec_\([A-Za-z_0-9]*\) */#define \2 \1/p' \
+ | $(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
@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|tr '&' '\134' >>$(OBJS_DIR)/$(1)$(3:%=-%).exe.d
+ @$(SED4OMK) -n -e 's|^LOAD \(.*\)$$$$| \1 \&|p' $(OBJS_DIR)/$(1)$(3:%=-%).map|tr '&' '\134' >>$(OBJS_DIR)/$(1)$(3:%=-%).exe.d
@echo >>$(OBJS_DIR)/$(1).exe.d
endef
define cp_cmd
if ! cmp --quiet $(1) $(2); then \
echo " CP $(1:$(OUTPUT_DIR)/%=%) -> $(2:$(OUTPUT_DIR)/%=%)"; \
- install -C -D $(CPHEADER_FLAGS) $(1) $(2) || exit 1; \
+ install -D $(CPHEADER_FLAGS) $(1) $(2) || exit 1; \
fi
endef
else
# Rules for compilation for target
ifdef TARGET_RULE_TEMPLATES
+ifeq ($(TARGET_STDSTARTFILES),)
+TARGET_STDSTARTFILES=n
+endif
+
+ifneq ($(TARGET_STDSTARTFILES),y)
LDFLAGS += -nostartfiles
+ifneq ($(TARGET_STDSTARTFILES),n)
+LDFLAGS += $(TARGET_STDSTARTFILES)
+endif
+endif
- # FIXME: These are not used. What they are good for?
+# FIXME: These are not used. What they are good for?
LIB_CPPFLAGS += $(CPPFLAGS)
LIB_CFLAGS += $(CFLAGS)
endif # HOST_RULE_TEMPLATES
-# Checks for OMK tester
-ifdef OMK_TESTSROOT
-default-config-pass-check include-pass-check:
-library-pass-check binary-pass-check:
- @[ -x "$(shell which $(CC))" ] || $(call canttest,Cannot find compiler: $(CC))
-endif
-
#=====================================================================
# Automatic loading of compiled program by issuing "make load"
$(if $(DOXYGEN),@echo "/** @file */" >> "$(2).tmp")
@echo "#ifndef $(4)" >> "$(2).tmp"
@echo "#define $(4)" >> "$(2).tmp"
- @( $(foreach x, $(shell echo '$($(3))' | tr 'x\t ' 'x\n\n' | sed -e 's/^\([^ =]*\)\(=[^ ]\+\|\)$$/\1/' ), \
+ @( $(foreach x, $(shell echo '$($(3))' | tr 'x\t ' 'x\n\n' | $(SED4OMK) -e 's/^\([^ =]*\)\(=[^ ]\+\|\)$$/\1/' ), \
echo '$(x).$($(x))' ; ) echo ; ) | \
- sed -e '/^[^.]*\.n$$$$/d' -e '/^[^.]*\.$$$$/d' -e 's/^\([^.]*\)\.[ym]$$$$/\1.1/' | \
- sed -n -e 's/^\([^.]*\)\.\(.*\)$$$$/#define \1 \2/p' \
+ $(SED4OMK) -e '/^[^.]*\.n$$$$/d' -e '/^[^.]*\.$$$$/d' -e 's/^\([^.]*\)\.[ym]$$$$/\1.1/' | \
+ $(SED4OMK) -n -e 's/^\([^.]*\)\.\(.*\)$$$$/#define \1 \2/p' \
>> "$(2).tmp"
@echo "#endif /*$(4)*/" >> "$(2).tmp"
@touch "$$@"
@mv "$(SOURCES_LIST).tmp2" "$(SOURCES_LIST)"
@echo "$(SOURCES_LIST): \\" > "$(SOURCES_LIST_D).tmp2"
@cat "$(SOURCES_LIST_D).tmp"|grep -v "$(SOURCES_LIST_D).tmp"|sort|uniq|\
- sed -e 's/$$/\\/' >> "$(SOURCES_LIST_D).tmp2"
+ $(SED4OMK) -e 's/$$/\\/' >> "$(SOURCES_LIST_D).tmp2"
@rm "$(SOURCES_LIST_D).tmp"
@mv "$(SOURCES_LIST_D).tmp2" "$(SOURCES_LIST_D)"
endif
echo "$(addsuffix /,$(RELATIVE_DIR:$(SOURCES_LIST_DIR)/%=%))$(h)" >> "$(SOURCES_LIST).tmp";)
@$(foreach ch,$(config_include_HEADERS), \
echo "$(USER_INCLUDE_DIR:$(OUTPUT_DIR)/$(addsuffix /,$(SOURCES_LIST_DIR))%=%)/$(ch)" >> "$(SOURCES_LIST).tmp";)
- @$(foreach h,$(renamed_include_HEADERS),echo '$(h)'|sed -e 's|\(.*\)->.*|$(addsuffix /,$(RELATIVE_DIR:$(SOURCES_LIST_DIR)/%=%))\1|' >> "$(SOURCES_LIST).tmp";)
+ @$(foreach h,$(renamed_include_HEADERS),echo '$(h)'|$(SED4OMK) -e 's|\(.*\)->.*|$(addsuffix /,$(RELATIVE_DIR:$(SOURCES_LIST_DIR)/%=%))\1|' >> "$(SOURCES_LIST).tmp";)
@$(foreach bin,$(lib_LIBRARIES) $(shared_LIBRARIES) $(bin_PROGRAMS) $(test_PROGRAMS) $(utils_PROGRAMS) \
$(kernel_LIBRARIES) $(rtlinux_LIBRARIES) $(kernel_MODULES),\
$(foreach src,$(filter-out %.o,$($(bin)_SOURCES)),echo "$(addsuffix /,$(RELATIVE_DIR:$(SOURCES_LIST_DIR)/%=%))$(src)" >> "$(SOURCES_LIST).tmp";))
ifeq ($(MAKECMDGOALS),do-tags)
.PHONY: do-tags
-do-tags: $(shell sed -e '/^\#/d' $(SOURCES_LIST))
+do-tags: $(shell $(SED4OMK) -e '/^\#/d' $(SOURCES_LIST))
@$(QUIET_CMD_ECHO) " TAGS $(SOURCES_LIST_FN)"
$(Q)$(TAGS_CMD) $^
endif
cscope: $(SOURCES_LIST)
@$(QUIET_CMD_ECHO) " CSCOPE < $(SOURCES_LIST_FN)"
- $(Q)sed -e '/^#/d' $(SOURCES_LIST) > cscope.files
+ $(Q)$(SED4OMK) -e '/^#/d' $(SOURCES_LIST) > cscope.files
$(Q)cscope -b -icscope.files
#FIXME: see doc to -i in cscope(1)
#OMK:localeval.omk@Makefile.rules.sysless