]> rtime.felk.cvut.cz Git - omk.git/blobdiff - snippets/base
omkbuild.py: Makefile.rules are constructed by replacing include directives in snippets
[omk.git] / snippets / base
index bc9622be6bd2419b8618c57da4095b8954428196..e7fb2e51c9c3821a05387cc1b79da524e5cf68a1 100644 (file)
@@ -8,6 +8,7 @@
 # The OMK build system is distributed under the GNU General Public
 # License.  See file COPYING for details.
 #
+#
 # input variables
 # V                .. if set to 1, full command text is shown else short form is used
 # W                .. whole tree - if set to 1, make is always called from the top-level directory
@@ -25,6 +26,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 +56,7 @@ endif
 ifdef OMK_TESTSROOT
 # Usage: $(call canttest,<error message>)
 define canttest
-       ( echo "$(1)" > $(MAKERULES_DIR)/_canttest; echo "$(1)"; exit 1 )
+       ( echo "$(1)" > $(OUTPUT_DIR)/_canttest; echo "$(1)"; exit 1 )
 endef
 else
 define canttest
@@ -59,9 +67,12 @@ endif
 #=========================
 # Include the config file
 
+# FIXME: I think CONFIG_FILE_OK variable is useless. We have three
+# config files and it is not clearly defined to which file is this
+# 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
@@ -71,21 +82,25 @@ $(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)
+-include $(CONFIG_FILE)
 CONFIG_FILE_OK = y
 endif
 endif #$(CONFIG_FILE_OK)
 
+
+CONFIG_FILES ?= $(wildcard $(CONFIG_FILE)-default) $(wildcard $(OUTPUT_DIR)/config.target) $(wildcard $(CONFIG_FILE))
+
+
 export SOURCES_DIR MAKERULES_DIR RELATIVE_DIR
-export CONFIG_FILE OMK_SERIALIZE_INCLUDED OMK_VERBOSE OMK_SILENT
+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.
 
 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:/%=%)
@@ -95,7 +110,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
@@ -140,6 +155,9 @@ ALL_OMK_SUBDIRS = $(patsubst %/$(MAKEFILE_OMK),%,$(patsubst $(SOURCES_DIR)/%,%,$
 # real OCERA style Makefile.omk now
 ifndef OMK_INCLUDED
 include $(SOURCES_DIR)/$(MAKEFILE_OMK)
+ifeq ($(AUTOMATIC_SUBDIRS),y)
+SUBDIRS?=$(ALL_OMK_SUBDIRS)
+endif
 OMK_INCLUDED := 1
 endif
 
@@ -152,7 +170,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
 # ====================
@@ -162,7 +180,7 @@ define mkdir_def
        [ -d $(1) ] || mkdir -p $(1) || exit 1
 endef
 
-ifneq ($(V),2)
+ifneq ($(OMK_VERBOSE),2)
 NO_PRINT_DIRECTORY := --no-print-directory
 endif
 
@@ -175,35 +193,61 @@ SUBDIR_MAKEFILE=$(SOURCES_DIR)/$(3)/Makefile
 SOURCESDIR_MAKEFILE=$(SOURCES_DIR)/Makefile
 endif
 
+pass = $(strip $(1))
+
 # Call a pass in a subdirectory
 # Usage: $(call omk_pass_subdir_template,<pass name>,<build dir>,<subdir>)
 define omk_pass_subdir_template
-.PHONY: $(1)-$(3)-subdir
-$(1): $(1)-$(3)-subdir
-$(1)-$(3)-subdir:
+.PHONY: $(pass)-$(3)-subdir
+$(pass)-submakes: $(pass)-$(3)-subdir
+$(pass)-$(3)-subdir:
        @$(call mkdir_def,$(2)/$(3))
        +@$(MAKE) SOURCES_DIR=$(SOURCES_DIR)/$(3) $(NO_PRINT_DIRECTORY) \
                RELATIVE_DIR=$(RELATIVE_PREFIX)$(3) -C $(2)/$(3) \
-               -f $(SUBDIR_MAKEFILE) $(1)
+               -f $(SUBDIR_MAKEFILE) $(pass)-submakes
+# In subdirectories we can call submakes directly since passes are
+# already searialized on the toplevel make.
 endef
 
 ifdef OMK_TESTSROOT
 check-target = $(1:%=%-check)
 endif
 
+# Call a pass in a subdirectory
+# Usage: $(call extra_rules_subdir_template,<subdir>)
+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
+
+.PHONY: extra-rules-subdirs
+extra-rules-subdirs:
+
+$(foreach subdir,$(EXTRA_RULES_SUBDIRS),$(eval $(call extra_rules_subdir_template,$(subdir))))
+
 # Usage: $(call omk_pass_template,<pass name>,<build dir>,[<local make flags>],[<local enable condition>])
 define omk_pass_template
-.PHONY: $(1) $(addsuffix -local,$(1)) $(addsuffix -check,$(1))
-$(foreach subdir,$(SUBDIRS),$(eval $(call omk_pass_subdir_template,$(1),$(2),$(subdir))))
-$(1):
+.PHONY: $(pass) $(pass)-local $(pass)-check $(pass)-submakes
+$(foreach subdir,$(SUBDIRS),$(eval $(call omk_pass_subdir_template,$(pass),$(2),$(subdir))))
+$(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) \
+               RELATIVE_DIR=$(RELATIVE_DIR) \
+               -f $(SOURCESDIR_MAKEFILE) $(pass)-submakes
+$(pass)-submakes:
        @true                   # Do not emit "nothing to be done" messages
-ifneq ($(4),)
-$(1): $(1)-this-dir
-$(1)-this-dir: $(foreach subdir,$(SUBDIRS),$(1)-$(subdir)-subdir)
-       +@echo "make[omk]: $(strip $(1)) in $(RELATIVE_DIR)"
+
+ifneq ($(4)$($(pass)_HOOKS),)
+$(pass)-submakes: $(pass)-this-dir
+$(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) \
                -f $(SOURCESDIR_MAKEFILE) $(3) $(check-target) $(1:%=%-local)
+$(pass)-local: $($(pass)_HOOKS)
 endif
 endef
 
@@ -215,9 +259,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))