From: Michal Sojka Date: Thu, 15 Jun 2006 11:57:00 +0000 (+0000) Subject: Added sysless rules. X-Git-Tag: v0.1~218 X-Git-Url: http://rtime.felk.cvut.cz/gitweb/omk.git/commitdiff_plain/8971b3422b74369ff65af186a03588e67d920f82?ds=sidebyside Added sysless rules. darcs-hash:20060615115724-f2ef6-fa29b8ccd50b66c6e8b95ad56937e921fb304769.gz --- diff --git a/Makefile.dollar-test b/Makefile.dollar-test new file mode 100644 index 0000000..73615af --- /dev/null +++ b/Makefile.dollar-test @@ -0,0 +1,27 @@ +VAR = first + +define asdf +A = hodnota-$(1)-$(VAR)-$$(VAR) +B := hodnota-$(1)-$(VAR)-$$(VAR) +C=A +$(VAR): + @echo $(A) $$(A) + @echo $(B) $$(B) + @echo $$($$(C)) + @echo $(VAR) $$(VAR) + @echo $$@ +endef + +VAR = second + +A=noneA +B=noneB + +$(eval $(call asdf,123)) + +VAR = third + +# Local Variables: +# mode: makefile +# compile-command: "make -f Makefile.dollar-test" +# End: \ No newline at end of file diff --git a/rulesdef.py b/rulesdef.py new file mode 100755 index 0000000..9abcbc0 --- /dev/null +++ b/rulesdef.py @@ -0,0 +1,5 @@ +#!/usr/bin/env python + +rules = { + 'sysless': [ 'base', 'gcc', 'sysless', 'localeval' ] + } diff --git a/snippets/base b/snippets/base new file mode 100644 index 0000000..25d312a --- /dev/null +++ b/snippets/base @@ -0,0 +1,154 @@ +# Makefile.rules - OCERA make framework common project rules -*- makefile -*- +# +# (C) Copyright 2003 by Pavel Pisa - OCERA team member +# +# 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_EVALUATE .. commands to be evaluated at the end of the Makefile + +# 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 + +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 + +ifeq ($(wildcard $(MAKERULES_DIR)/config.target),$(MAKERULES_DIR)/config.target) +$(error Please, rename $(MAKERULES_DIR)/config.target to config.omk!) +endif + +BUILD_DIR_NAME = _build$(addprefix /,$(PREFIX_DIR)) +COMPILED_DIR_NAME = _compiled$(addprefix /,$(PREFIX_DIR)) +ifndef GROUP_DIR_NAME +GROUP_DIR_NAME = nogroup +endif + + +export SOURCES_DIR MAKERULES_DIR RELATIVE_DIR +export CONFIG_FILE OMK_SERIALIZE_INCLUDED OMK_VERBOSE OMK_SILENT + +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)) + +LOCAL_BUILD_DIR=$(MAKERULES_DIR)/$(BUILD_DIR_NAME)/$(RELATIVE_DIR) +#$(warning LOCAL_BUILD_DIR = $(LOCAL_BUILD_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 + CP_FLAGS += -v +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) + +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 + +# 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,$(LOCAL_BUILD_DIR)/$(dir)) ; \ + $(MAKE) SOURCES_DIR=$(SOURCES_DIR)/$(dir) \ + RELATIVE_DIR=$(RELATIVE_DIR)/$(dir) -C $(LOCAL_BUILD_DIR)/$(dir) \ + -f $(SOURCES_DIR)/$(dir)/Makefile $$@ || exit 1 ;) + +@$(call mkdir_def,$(LOCAL_BUILD_DIR)) + @$(MAKE) --no-print-directory -C $(LOCAL_BUILD_DIR) \ + -f $(SOURCES_DIR)/Makefile $(2) $$(@:%=%-local) +endef + +# ======================= +# DEFAULT CONFIG PASS + +$(eval $(call omk_pass_template,default-config-pass)) +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" ; ) diff --git a/snippets/gcc b/snippets/gcc new file mode 100644 index 0000000..2ca8326 --- /dev/null +++ b/snippets/gcc @@ -0,0 +1,226 @@ + +# 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) -DOMK_FOR_TARGET + +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) + +# Shortcuts for use in this template +_LNK_VAR := $(addprefix -,$(3)) +_TARGET := $(1)$$(_LNK_VAR) + +ifneq ($(LD_SCRIPT),) +$$(_TARGET)_LDFLAGS = -Wl,-T,$(LD_SCRIPT).ld$$(_LNK_VAR) +endif + +$(2)/$$(_TARGET): $$($(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) $$($$(_TARGET)_LDFLAGS) -Wl,-Map,$$(_TARGET).map \ + $$($(1)_OBJS) $$(LOADLIBES) $$($(1)_MOREOBJS) $$($(1)_LIBS:%=-l%) \ + -o $$@ + @echo "$(2)/$$(_TARGET): \\" >$(OBJS_DIR)/$$(_TARGET).exe.d + @if [ -n "$(LD_SCRIPT)" ]; then \ + echo " $(LIB_DIR)/$(LD_SCRIPT).ld$$(_LNK_VAR) \\" >>$(OBJS_DIR)/$$(_TARGET).exe.d; fi + @sed -n -e 's/^LOAD \(.*\)$$$$/ \1 \\/p' $(OBJS_DIR)/$$(_TARGET).map >>$(OBJS_DIR)/$$(_TARGET).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: diff --git a/snippets/localeval b/snippets/localeval new file mode 100644 index 0000000..9cf7e5e --- /dev/null +++ b/snippets/localeval @@ -0,0 +1,11 @@ +# local_EVALUATE .. Makefile hook, which is executed at the end of +# the Makefile.rules. Used only for dirty hacks. + +ifneq ($(local_EVALUATE),) +#$(warning $(local_EVALUATE)) +$(eval $(local_EVALUATE)) +endif + +# Local Variables: +# mode:makefile +# End: diff --git a/snippets/sysless b/snippets/sysless new file mode 100644 index 0000000..3abb2b8 --- /dev/null +++ b/snippets/sysless @@ -0,0 +1,276 @@ +# 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) - does not work yet +# 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. + +# 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 + +#===================================================================== +# Common utility rules + +ifdef LOCAL_CONFIG_H + +$(LOCAL_CONFIG_H) : $(wildcard $(CONFIG_FILE)) $(wildcard $(CONFIG_FILE)-default) + @echo LOCAL_CONFIG_H=`pwd`/$(LOCAL_CONFIG_H) + @echo "/* Automatically generated from */" > "$(LOCAL_CONFIG_H).tmp" + @echo "/* config file : $< */" >> "$(LOCAL_CONFIG_H).tmp" + @echo "#ifndef _LOCAL_CONFIG_H" >> "$(LOCAL_CONFIG_H).tmp" + @echo "#define _LOCAL_CONFIG_H" >> "$(LOCAL_CONFIG_H).tmp" + @( $(foreach x, $(shell echo $(default_CONFIG) | sed -e 's/\<\([^ ]*\)=[^ ]\>/\1/g' ), \ + echo $(x).$($(x)) ; ) echo ; ) | \ + sed -n -e 's/^\(.*\)\.[ym]$$/#define \1 1/p' \ + >> "$(LOCAL_CONFIG_H).tmp" + @echo "#endif /*_LOCAL_CONFIG_H*/" >> "$(LOCAL_CONFIG_H).tmp" + @if cmp --quiet "$(LOCAL_CONFIG_H).tmp" "$(LOCAL_CONFIG_H)" ; then \ + echo rm "$(LOCAL_CONFIG_H).tmp" ; \ + else mv "$(LOCAL_CONFIG_H).tmp" "$(LOCAL_CONFIG_H)" ; \ + echo Updated configuration "$(LOCAL_CONFIG_H)" ; fi + +endif + +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) + + +# ------------------------------------- +# 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 + +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)))) + +$(warning $(lib_LIBRARIES)) + +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)$(addprefix -,$(3)) +load-$(1)$(addprefix -,$(3)): $(2)/$(1)$(addprefix -,$(3))$(LOAD_EXTENSION) + @$(QUIET_CMD_ECHO) " LOAD $$<" + @if [ -z "$$(LOAD_CMD$(addprefix -,$(3)))" ]; then echo "No command for loading applications to '$(3)' is specified."; exit 1; fi + $(Q) $$(LOAD_CMD$(addprefix -,$(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 +TARGET_PASSES = library-pass binary-pass +OTHER_PASSES = dep clean install check-dir include-pass + +$(eval $(call omk_pass_template,$(TARGET_PASSES),TARGET_RULE_TEMPLATES=y)) +$(eval $(call omk_pass_template, utils-pass,HOST_RULE_TEMPLATES=y)) + +$(eval $(call omk_pass_template,$(OTHER_PASSES),)) + + +dep-local: + +check-dir-local: + @$(call mkdir_def,$(USER_OBJS_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)) + +install-local: + +# TODO: Check modification date of changed header files. If it is +# newer that in source dir, show a warning. +include-pass-local: + @$(call mkdir_def,$(USER_INCLUDE_DIR)) + @$(foreach f, $(include_HEADERS), cmp --quiet $(SOURCES_DIR)/$(f) $(USER_INCLUDE_DIR)/$(notdir $(f)) \ + || cp $(CP_FLAGS) $(SOURCES_DIR)/$(f) $(USER_INCLUDE_DIR)/$(notdir $(f)) || exit 1 ; ) + @$(foreach f, $(nobase_include_HEADERS), cmp --quiet $(SOURCES_DIR)/$(f) $(USER_INCLUDE_DIR)/$(f) \ + || ( mkdir -p $(USER_INCLUDE_DIR)/$(dir $(f)) && cp $(CP_FLAGS) $(SOURCES_DIR)/$(f) $(USER_INCLUDE_DIR)/$(f) ) || exit 1 ; ) + @$(foreach f, $(renamed_include_HEADERS), \ + srcfname=`echo '$(f)' | sed -e 's/^\(.*\)->.*$$/\1/'` ; destfname=`echo '$(f)' | sed -e 's/^.*->\(.*\)$$/\1/'` ; \ + cmp --quiet $(SOURCES_DIR)/$${srcfname} $(USER_INCLUDE_DIR)/$${destfname} \ + || ( mkdir -p `dirname $(USER_INCLUDE_DIR)/$${destfname}` && cp $(CP_FLAGS) $(SOURCES_DIR)/$${srcfname} $(USER_INCLUDE_DIR)/$${destfname} ) || exit 1 ; ) + @$(foreach f, $(lib_LDSCRIPTS), cmp --quiet $(SOURCES_DIR)/$(f) $(USER_LIB_DIR)/$(notdir $(f)) \ + || cp $(CP_FLAGS) $(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)/%) + +# 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: