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
@$(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
endif
endif
+-include $(MAKERULES_DIR)/config.target
+
ifneq ($(wildcard $(CONFIG_FILE)),)
include $(CONFIG_FILE)
CONFIG_FILE_OK = y
#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")
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
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