From 98facfbc0494a9d7a152b58ae8efb832600c11b3 Mon Sep 17 00:00:00 2001 From: Michal Sojka Date: Wed, 25 Jun 2008 12:35:00 +0000 Subject: [PATCH] Added EXTRA_RULES_SUBDIRS feature By setting this variable in Makefile.omk, it is possible to compile some part of the source tree using different rules. It is useful for compilation of host tools which are needed to compile the rest of project (e.g. IDL compilers). darcs-hash:20080625123539-f2ef6-40ef4157c7098be9d851bae6ccf972ca90e69d23.gz --- snippets/base | 43 ++++++++++++++----- snippets/config_h | 2 +- snippets/include | 4 +- snippets/linux | 32 +++++++------- snippets/qt | 2 +- snippets/sources-list | 4 +- tests/extra_rules_subdirs/Makefile | 14 ++++++ tests/extra_rules_subdirs/Makefile.omk | 3 ++ tests/extra_rules_subdirs/runtest | 9 ++++ tests/extra_rules_subdirs/subdir/Makefile | 14 ++++++ tests/extra_rules_subdirs/subdir/Makefile.omk | 2 + tests/extra_rules_subdirs/tools/Makefile | 14 ++++++ tests/extra_rules_subdirs/tools/Makefile.omk | 5 +++ tests/extra_rules_subdirs/tools/test.c | 9 ++++ 14 files changed, 125 insertions(+), 32 deletions(-) create mode 100644 tests/extra_rules_subdirs/Makefile create mode 100644 tests/extra_rules_subdirs/Makefile.omk create mode 100755 tests/extra_rules_subdirs/runtest create mode 100644 tests/extra_rules_subdirs/subdir/Makefile create mode 100644 tests/extra_rules_subdirs/subdir/Makefile.omk create mode 100644 tests/extra_rules_subdirs/tools/Makefile create mode 100644 tests/extra_rules_subdirs/tools/Makefile.omk create mode 100644 tests/extra_rules_subdirs/tools/test.c diff --git a/snippets/base b/snippets/base index c89cf4b..77a0d8d 100644 --- a/snippets/base +++ b/snippets/base @@ -25,6 +25,13 @@ ifndef MAKERULES_DIR MAKERULES_DIR := $(abspath $(dir $(filter %Makefile.rules,$(MAKEFILE_LIST)))) endif +# OUTPUT_DIR is the place where _compiled, _build and possible other +# files/directories are created. By default is the same as +# $(MAKERULES_DIR). +ifndef OUTPUT_DIR +OUTPUT_DIR := $(MAKERULES_DIR) +endif + .PHONY: all default check-make-ver omkize ifdef W @@ -48,7 +55,7 @@ endif ifdef OMK_TESTSROOT # Usage: $(call canttest,) define canttest - ( echo "$(1)" > $(MAKERULES_DIR)/_canttest; echo "$(1)"; exit 1 ) + ( echo "$(1)" > $(OUTPUT_DIR)/_canttest; echo "$(1)"; exit 1 ) endef else define canttest @@ -64,7 +71,7 @@ endif # variable related. ifneq ($(CONFIG_FILE_OK),y) ifndef CONFIG_FILE -CONFIG_FILE := $(MAKERULES_DIR)/config.omk +CONFIG_FILE := $(OUTPUT_DIR)/config.omk endif ifneq ($(wildcard $(CONFIG_FILE)-default),) -include $(CONFIG_FILE)-default @@ -74,7 +81,7 @@ $(warning Please, run "make default-config" first) endif endif --include $(MAKERULES_DIR)/config.target +-include $(OUTPUT_DIR)/config.target ifneq ($(wildcard $(CONFIG_FILE)),) -include $(CONFIG_FILE) @@ -83,7 +90,7 @@ endif endif #$(CONFIG_FILE_OK) -CONFIG_FILES ?= $(wildcard $(CONFIG_FILE)-default) $(wildcard $(MAKERULES_DIR)/config.target) $(wildcard $(CONFIG_FILE)) +CONFIG_FILES ?= $(wildcard $(CONFIG_FILE)-default) $(wildcard $(OUTPUT_DIR)/config.target) $(wildcard $(CONFIG_FILE)) export SOURCES_DIR MAKERULES_DIR RELATIVE_DIR @@ -92,7 +99,7 @@ export CONFIG_FILE CONFIG_FILES OMK_SERIALIZE_INCLUDED OMK_VERBOSE OMK_SILENT # must to be serialized only in the toplevel make. ifndef RELATIVE_DIR -RELATIVE_DIR := $(SOURCES_DIR:$(MAKERULES_DIR)%=%) +RELATIVE_DIR := $(SOURCES_DIR:$(OUTPUT_DIR)%=%) endif #$(warning === RELATIVE_DIR = "$(RELATIVE_DIR)" ===) override RELATIVE_DIR := $(RELATIVE_DIR:/%=%) @@ -102,7 +109,7 @@ override BACK2TOP_DIR := $(shell echo $(RELATIVE_DIR)/ | sed -e 's_//_/_g' -e 's #$(warning BACK2TOP_DIR = "$(BACK2TOP_DIR)") #$(warning SOURCES_DIR = "$(SOURCES_DIR)") -#$(warning MAKERULES_DIR = "$(MAKERULES_DIR)") +#$(warning MAKERULES_DIR = "$(OUTPUT_DIR)") #$(warning RELATIVE_DIR = "$(RELATIVE_DIR)") # We have to use RELATIVE_PREFIX because of mingw @@ -162,7 +169,7 @@ check-make-ver: 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) + @rm -fr $(OUTPUT_DIR)/$(COMPILED_DIR_NAME) $(OUTPUT_DIR)/$(BUILD_DIR_NAME) # Common OMK templates # ==================== @@ -205,6 +212,22 @@ ifdef OMK_TESTSROOT check-target = $(1:%=%-check) endif +# Call a pass in a subdirectory +# Usage: $(call extra_rules_subdir_template,) +define extra_rules_subdir_template +extra-rules-subdirs: extra-rules-$(1) +extra-rules-$(1): + +$(MAKE) OMK_SERIALIZE_INCLUDED=n MAKERULES_DIR=$(SOURCES_DIR)/$(1) OUTPUT_DIR=$(OUTPUT_DIR) \ + SOURCES_DIR=$(SOURCES_DIR)/$(1) RELATIVE_DIR=$(RELATIVE_PREFIX)$(1) -C $(SOURCES_DIR)/$(1) +endef + +$(warning $(SOURCES_DIR)) + +.PHONY: extra-rules-subdirs +extra-rules-subdirs: + +$(foreach subdir,$(EXTRA_RULES_SUBDIRS),$(eval $(call extra_rules_subdir_template,$(subdir)))) + # Usage: $(call omk_pass_template,,,[],[]) define omk_pass_template .PHONY: $(pass) $(pass)-local $(pass)-check $(pass)-submakes @@ -237,9 +260,9 @@ default-config: @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 + @$(MAKE) $(NO_PRINT_DIRECTORY) -C $(OUTPUT_DIR) \ + RELATIVE_DIR="" SOURCES_DIR=$(OUTPUT_DIR) \ + -f $(OUTPUT_DIR)/Makefile default-config-pass $(eval $(call omk_pass_template,default-config-pass,$$(LOCAL_BUILD_DIR),,always)) diff --git a/snippets/config_h b/snippets/config_h index 35cd3aa..0e25ad9 100644 --- a/snippets/config_h +++ b/snippets/config_h @@ -16,7 +16,7 @@ $(addprefix $(1)/,$(notdir $(addsuffix .stamp,$(2)))) : $(CONFIG_FILES) @if [ ! -d `dirname $(2).tmp` ] ; then \ mkdir -p `dirname $(2).tmp` ; fi @echo "/* Automatically generated from */" > "$(2).tmp" - @echo "/* config files: $$(^:$(MAKERULES_DIR)/%=%) */" >> "$(2).tmp" + @echo "/* config files: $$(^:$(OUTPUT_DIR)/%=%) */" >> "$(2).tmp" $(if $(DOXYGEN),@echo "/** @file */" >> "$(2).tmp") @echo "#ifndef $(4)" >> "$(2).tmp" @echo "#define $(4)" >> "$(2).tmp" diff --git a/snippets/include b/snippets/include index b30acfc..c219117 100644 --- a/snippets/include +++ b/snippets/include @@ -6,11 +6,11 @@ endif ifneq ($(LN_HEADERS),y) define cp_cmd -( echo " CP $(1:$(MAKERULES_DIR)/%=%) -> $(2:$(MAKERULES_DIR)/%=%)"; cp $(CPHEADER_FLAGS) $(1) $(2) ) +( echo " CP $(1:$(OUTPUT_DIR)/%=%) -> $(2:$(OUTPUT_DIR)/%=%)"; cp $(CPHEADER_FLAGS) $(1) $(2) ) endef else define cp_cmd -( echo " LN $(1:$(MAKERULES_DIR)/%=%) -> $(2:$(MAKERULES_DIR)/%=%)"; [ -f $(1) ] && ln -sf $(LNHEADER_FLAGS) $(1) $(2) ) +( echo " LN $(1:$(OUTPUT_DIR)/%=%) -> $(2:$(OUTPUT_DIR)/%=%)"; [ -f $(1) ] && ln -sf $(LNHEADER_FLAGS) $(1) $(2) ) endef endif diff --git a/snippets/linux b/snippets/linux index 432fbc1..b077e30 100644 --- a/snippets/linux +++ b/snippets/linux @@ -34,9 +34,9 @@ #LINUX_DIR := /home/cvs/ocera/ocera-build/kernel/linux #RTL_DIR := /home/cvs/ocera/ocera-build/kernel/rtlinux #CONFIG_RTLINUX = y -#OCERA_DIR := $(shell ( cd -L $(MAKERULES_DIR)/../../.. ; pwd -L ) ) +#OCERA_DIR := $(shell ( cd -L $(OUTPUT_DIR)/../../.. ; pwd -L ) ) --include $(MAKERULES_DIR)/OCERA_TOP_DIR +-include $(OUTPUT_DIR)/OCERA_TOP_DIR BUILD_DIR_NAME = _build COMPILED_DIR_NAME = _compiled @@ -69,17 +69,17 @@ ifneq ($(wildcard $(CONFIG_FILE)),) CONFIG_FILE_OK = y endif else # OCERA_DIR -KERN_INCLUDE_DIR := $(MAKERULES_DIR)/$(COMPILED_DIR_NAME)/include-kern -KERN_LIB_DIR := $(MAKERULES_DIR)/$(COMPILED_DIR_NAME)/lib-kern -KERN_MODULES_DIR := $(MAKERULES_DIR)/$(COMPILED_DIR_NAME)/modules -KERN_BUILD_DIR := $(MAKERULES_DIR)/$(BUILD_DIR_NAME)/kern -KERN_MODPOST_DIR := $(MAKERULES_DIR)/$(BUILD_DIR_NAME)/kern-modpost -USER_INCLUDE_DIR := $(MAKERULES_DIR)/$(COMPILED_DIR_NAME)/include -USER_LIB_DIR := $(MAKERULES_DIR)/$(COMPILED_DIR_NAME)/lib -USER_UTILS_DIR := $(MAKERULES_DIR)/$(COMPILED_DIR_NAME)/bin-utils -USER_TESTS_DIR := $(MAKERULES_DIR)/$(COMPILED_DIR_NAME)/bin-tests -USER_BIN_DIR := $(MAKERULES_DIR)/$(COMPILED_DIR_NAME)/bin -USER_BUILD_DIR := $(MAKERULES_DIR)/$(BUILD_DIR_NAME)/user +KERN_INCLUDE_DIR := $(OUTPUT_DIR)/$(COMPILED_DIR_NAME)/include-kern +KERN_LIB_DIR := $(OUTPUT_DIR)/$(COMPILED_DIR_NAME)/lib-kern +KERN_MODULES_DIR := $(OUTPUT_DIR)/$(COMPILED_DIR_NAME)/modules +KERN_BUILD_DIR := $(OUTPUT_DIR)/$(BUILD_DIR_NAME)/kern +KERN_MODPOST_DIR := $(OUTPUT_DIR)/$(BUILD_DIR_NAME)/kern-modpost +USER_INCLUDE_DIR := $(OUTPUT_DIR)/$(COMPILED_DIR_NAME)/include +USER_LIB_DIR := $(OUTPUT_DIR)/$(COMPILED_DIR_NAME)/lib +USER_UTILS_DIR := $(OUTPUT_DIR)/$(COMPILED_DIR_NAME)/bin-utils +USER_TESTS_DIR := $(OUTPUT_DIR)/$(COMPILED_DIR_NAME)/bin-tests +USER_BIN_DIR := $(OUTPUT_DIR)/$(COMPILED_DIR_NAME)/bin +USER_BUILD_DIR := $(OUTPUT_DIR)/$(BUILD_DIR_NAME)/user ifndef LINUX_VERSION LINUX_VERSION=$(shell uname -r) @@ -375,9 +375,9 @@ endif ifdef KERN_RULE_TEMPLATES -$(KERN_LIB_DIR)/kernel.mk: $(LINUX_DIR)/.config $(MAKERULES_DIR)/kernelcfg2mk +$(KERN_LIB_DIR)/kernel.mk: $(LINUX_DIR)/.config $(OUTPUT_DIR)/kernelcfg2mk @$(QUIET_CMD_ECHO) " KCFG2MK $$@" - $(Q) $(MAKERULES_DIR)/kernelcfg2mk $(LINUX_DIR) $(KERN_LIB_DIR) + $(Q) $(OUTPUT_DIR)/kernelcfg2mk $(LINUX_DIR) $(KERN_LIB_DIR) ifeq ($(CONFIG_RTLINUX),y) include $(RTL_DIR)/rtl.mk @@ -753,7 +753,7 @@ clean-local: clean-custom touch -t 200001010101 $(KERN_LIB_DIR)/kernel.mk ; \ fi -default: include-pass library-pass binary-pass +default: extra-rules-subdirs include-pass library-pass binary-pass ifndef OMIT_KERNEL_PASSES # Also make kernel passes if not disabled default: kernel-lib-pass kernel-pass diff --git a/snippets/qt b/snippets/qt index b554df4..c09b28a 100644 --- a/snippets/qt +++ b/snippets/qt @@ -8,7 +8,7 @@ ifneq ($(QT_SUBDIRS),) # Usage: $(call qt_makefile_template,) define qt_makefile_template $(SOURCES_DIR)/$(1)/Makefile: $(wildcard $(SOURCES_DIR)/$(1)/*.pro) - cd $(SOURCES_DIR)/$(1); $(QTDIR:%=%/bin/)qmake TOP_DIR=$(MAKERULES_DIR) \ + cd $(SOURCES_DIR)/$(1); $(QTDIR:%=%/bin/)qmake TOP_DIR=$(OUTPUT_DIR) \ RELATIVE_DIR=$(RELATIVE_PREFIX)$(1) $(QTDIR:%=QTDIR=%) CC=$(CC) \ CXX=$(CXX) LIBS+="-L$(USER_LIB_DIR)" INCLUDEPATH+="$(USER_INCLUDE_DIR)" endef diff --git a/snippets/sources-list b/snippets/sources-list index a9eb027..ff5cfaf 100644 --- a/snippets/sources-list +++ b/snippets/sources-list @@ -6,7 +6,7 @@ SOURCES_LIST_FN=sources.txt ifndef SOURCES_LIST SOURCES_LIST_DIR:=$(RELATIVE_DIR) -SOURCES_LIST:=$(MAKERULES_DIR)/$(SOURCES_LIST_DIR)/$(SOURCES_LIST_FN) +SOURCES_LIST:=$(OUTPUT_DIR)/$(SOURCES_LIST_DIR)/$(SOURCES_LIST_FN) export SOURCES_LIST SOURCES_LIST_DIR endif @@ -39,7 +39,7 @@ sources-list-pass-local: @$(foreach h,$(include_HEADERS) $(nobase_include_HEADERS) $(kernel_HEADERS),\ echo "$(RELATIVE_DIR:$(SOURCES_LIST_DIR)/%=%)/$(h)" >> "$(SOURCES_LIST).tmp";) @$(foreach ch,$(config_include_HEADERS), \ - echo "$(USER_INCLUDE_DIR:$(MAKERULES_DIR)/$(addsuffix /,$(SOURCES_LIST_DIR))%=%)/$(ch)" >> "$(SOURCES_LIST).tmp";) + echo "$(USER_INCLUDE_DIR:$(OUTPUT_DIR)/$(addsuffix /,$(SOURCES_LIST_DIR))%=%)/$(ch)" >> "$(SOURCES_LIST).tmp";) @$(foreach h,$(renamed_include_HEADERS),echo "$(RELATIVE_DIR:$(SOURCES_LIST_DIR)/%=%)/$(h)"|sed -e 's/\(.*\)->.*/\1/' >> "$(SOURCES_LIST).tmp";) @$(foreach bin,$(lib_LIBRARIES) $(shared_LIBRARIES) $(bin_PROGRAMS) $(test_PROGRAMS) $(utils_PROGRAMS) \ $(kernel_LIBRARIES) $(rtlinux_LIBRARIES) $(kernel_MODULES),\ diff --git a/tests/extra_rules_subdirs/Makefile b/tests/extra_rules_subdirs/Makefile new file mode 100644 index 0000000..b22a357 --- /dev/null +++ b/tests/extra_rules_subdirs/Makefile @@ -0,0 +1,14 @@ +# Generic directory or leaf node makefile for OCERA make framework + +ifndef MAKERULES_DIR +MAKERULES_DIR := $(shell ( old_pwd="" ; while [ ! -e Makefile.rules ] ; do if [ "$$old_pwd" = `pwd` ] ; then exit 1 ; else old_pwd=`pwd` ; cd -L .. 2>/dev/null ; fi ; done ; pwd ) ) +endif + +ifeq ($(MAKERULES_DIR),) +all : default +.DEFAULT:: + @echo -e "\nThe Makefile.rules has not been found in this or partent directory\n" +else +include $(MAKERULES_DIR)/Makefile.rules +endif + diff --git a/tests/extra_rules_subdirs/Makefile.omk b/tests/extra_rules_subdirs/Makefile.omk new file mode 100644 index 0000000..6f1fea0 --- /dev/null +++ b/tests/extra_rules_subdirs/Makefile.omk @@ -0,0 +1,3 @@ +SUBDIRS=subdir +EXTRA_RULES_SUBDIRS = tools + diff --git a/tests/extra_rules_subdirs/runtest b/tests/extra_rules_subdirs/runtest new file mode 100755 index 0000000..953ea3b --- /dev/null +++ b/tests/extra_rules_subdirs/runtest @@ -0,0 +1,9 @@ +#!/bin/sh + +source ../functions.sh + +touch default-config + +cp Makefile.rules tools/ +make -k + diff --git a/tests/extra_rules_subdirs/subdir/Makefile b/tests/extra_rules_subdirs/subdir/Makefile new file mode 100644 index 0000000..b22a357 --- /dev/null +++ b/tests/extra_rules_subdirs/subdir/Makefile @@ -0,0 +1,14 @@ +# Generic directory or leaf node makefile for OCERA make framework + +ifndef MAKERULES_DIR +MAKERULES_DIR := $(shell ( old_pwd="" ; while [ ! -e Makefile.rules ] ; do if [ "$$old_pwd" = `pwd` ] ; then exit 1 ; else old_pwd=`pwd` ; cd -L .. 2>/dev/null ; fi ; done ; pwd ) ) +endif + +ifeq ($(MAKERULES_DIR),) +all : default +.DEFAULT:: + @echo -e "\nThe Makefile.rules has not been found in this or partent directory\n" +else +include $(MAKERULES_DIR)/Makefile.rules +endif + diff --git a/tests/extra_rules_subdirs/subdir/Makefile.omk b/tests/extra_rules_subdirs/subdir/Makefile.omk new file mode 100644 index 0000000..cdf7e55 --- /dev/null +++ b/tests/extra_rules_subdirs/subdir/Makefile.omk @@ -0,0 +1,2 @@ + +$(info Main rules goal: $(MAKECMDGOALS)) diff --git a/tests/extra_rules_subdirs/tools/Makefile b/tests/extra_rules_subdirs/tools/Makefile new file mode 100644 index 0000000..b22a357 --- /dev/null +++ b/tests/extra_rules_subdirs/tools/Makefile @@ -0,0 +1,14 @@ +# Generic directory or leaf node makefile for OCERA make framework + +ifndef MAKERULES_DIR +MAKERULES_DIR := $(shell ( old_pwd="" ; while [ ! -e Makefile.rules ] ; do if [ "$$old_pwd" = `pwd` ] ; then exit 1 ; else old_pwd=`pwd` ; cd -L .. 2>/dev/null ; fi ; done ; pwd ) ) +endif + +ifeq ($(MAKERULES_DIR),) +all : default +.DEFAULT:: + @echo -e "\nThe Makefile.rules has not been found in this or partent directory\n" +else +include $(MAKERULES_DIR)/Makefile.rules +endif + diff --git a/tests/extra_rules_subdirs/tools/Makefile.omk b/tests/extra_rules_subdirs/tools/Makefile.omk new file mode 100644 index 0000000..0a29372 --- /dev/null +++ b/tests/extra_rules_subdirs/tools/Makefile.omk @@ -0,0 +1,5 @@ +$(warning Extra rules goal: $(MAKECMDGOALS)) + +bin_PROGRAMS = test + +test_SOURCES = test.c \ No newline at end of file diff --git a/tests/extra_rules_subdirs/tools/test.c b/tests/extra_rules_subdirs/tools/test.c new file mode 100644 index 0000000..f24b7bd --- /dev/null +++ b/tests/extra_rules_subdirs/tools/test.c @@ -0,0 +1,9 @@ +#include + +int main() +{ +#ifdef NUMBER + printf("NUMBER is %d\n", NUMBER); +#endif + return 0; +} -- 2.39.2