]> rtime.felk.cvut.cz Git - omk.git/blobdiff - snippets/base
Fixed error on inclusion of config.omk if it is broken symlink
[omk.git] / snippets / base
index a35d9fde589bd9a321d1c03f2099778377b84239..cc843da8c6ed69f941323b7d7e6ef509a99da0b5 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
@@ -54,6 +59,9 @@ 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
@@ -69,13 +77,17 @@ endif
 -include $(MAKERULES_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 $(MAKERULES_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.
 
@@ -101,6 +113,7 @@ 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
@@ -165,27 +178,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
 
+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 = $$(@:%=%-check)
+check-target = $(1:%=%-check)
 endif
 
-# Syntax: $(call omk_pass_template,<pass name(s)>,<build dir>,[<local make flags>],[<local condition>])
+# Usage: $(call omk_pass_template,<pass name>,<build dir>,[<local make flags>],[<local enable condition>])
 define omk_pass_template
-.PHNOY: $(1) $(addsuffix -local,$(1)) $(addsuffix -check,$(1))
-$(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) $(check-target) $$(@:%=%-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
 
@@ -215,9 +252,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