]> rtime.felk.cvut.cz Git - omk.git/blobdiff - snippets/base
Added support for pass hooks in Makefile.omk
[omk.git] / snippets / base
index 121112cb3e1aa33654abf23f58c2dcd24e1fc2d5..b20f19d217178525225ea6da3fe971205c2d7520 100644 (file)
@@ -20,6 +20,11 @@ ifndef SOURCES_DIR
 SOURCES_DIR := $(shell ( pwd -L ) )
 endif
 
+# If we are not called by OMK leaf Makefile...
+ifndef MAKERULES_DIR
+MAKERULES_DIR := $(abspath $(dir $(filter %Makefile.rules,$(MAKEFILE_LIST))))
+endif
+
 .PHONY: all default check-make-ver omkize
 
 ifdef W
@@ -40,6 +45,17 @@ all:
        @$(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)" > $(MAKERULES_DIR)/_canttest; echo "$(1)"; exit 1 )
+endef
+else
+define canttest
+       echo "$(1)"
+endef
+endif
+
 #=========================
 # Include the config file
 
@@ -55,6 +71,8 @@ $(warning Please, run "make default-config" first)
 endif
 endif
 
+-include $(MAKERULES_DIR)/config.target
+
 ifneq ($(wildcard $(CONFIG_FILE)),)
 include $(CONFIG_FILE)
 CONFIG_FILE_OK = y
@@ -88,6 +106,9 @@ override RELATIVE_PREFIX := $(RELATIVE_PREFIX:/%=%)
 #vpath %.cc $(SOURCES_DIR)
 #vpath %.cxx $(SOURCES_DIR)
 
+# Define srcdir for Automake compatibility
+srcdir = $(SOURCES_DIR)
+
 # Defines for quiet compilation
 ifdef V
   ifeq ("$(origin V)", "command line")
@@ -150,23 +171,51 @@ export USE_LEAF_MAKEFILES
 SUBDIR_MAKEFILE=$(MAKERULES_DIR)/Makefile.rules
 SOURCESDIR_MAKEFILE=$(MAKERULES_DIR)/Makefile.rules
 else
-SUBDIR_MAKEFILE=$(SOURCES_DIR)/$(dir)/Makefile
+SUBDIR_MAKEFILE=$(SOURCES_DIR)/$(3)/Makefile
 SOURCESDIR_MAKEFILE=$(SOURCES_DIR)/Makefile
 endif
 
-# Syntax: $(call omk_pass_template,<pass name>,<build dir>,[<local make flags>],[<local condition>])
+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: $(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) $(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
+
+# Usage: $(call omk_pass_template,<pass name>,<build dir>,[<local make flags>],[<local enable condition>])
 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_PREFIX)$(dir) -C $(2)/$(dir) \
-               -f $(SUBDIR_MAKEFILE) $$@ || exit 1 ;) true
-ifneq ($(4),)
-       @echo "make[omk]: $$@ 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) $$(@:%=%-local)
+.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)$($(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
 
@@ -196,9 +245,9 @@ omkize:
           echo "Makefile is not OMK leaf makefile!" >&2; exit 1; \
        fi
        $(Q)for i in `find -L . -name Makefile.omk` ; do \
-          i=`dirname $${i}`; \
-          if [ x"$$i" != x"." ]; then \
-             rm -f $${i}/Makefile; \
-             cp Makefile $${i}/Makefile; \
+          d=`dirname $${i}`; \
+          if ! test -f "$${d}/Makefile.rules" && ( ! test -f "$${d}/Makefile" || ! cmp --silent Makefile "$${d}/Makefile" ); then \
+             rm -f "$${d}/Makefile"; \
+             cp -v Makefile "$${d}/Makefile"; \
           fi \
        done