# (C) Copyright 2003 by Pavel Pisa - OCERA team member
# (C) Copyright 2006 by Michal Sojka - Czech Technical University, FEE, DCE
#
+# Homepage: http://rtime.felk.cvut.cz/omk/
+#
# The OMK build system is distributed under the GNU General Public
# License. See file COPYING for details.
#
# We need to ensure definition of sources directory first
ifndef SOURCES_DIR
+# Only shell built-in pwd understands -L
SOURCES_DIR := $(shell ( pwd -L ) )
endif
-.PHONY: all default check-make-ver
+# 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
ifeq ("$(origin W)", "command line")
@$(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
ifndef RELATIVE_DIR
RELATIVE_DIR := $(SOURCES_DIR:$(MAKERULES_DIR)%=%)
endif
+#$(warning === RELATIVE_DIR = "$(RELATIVE_DIR)" ===)
override RELATIVE_DIR := $(RELATIVE_DIR:/%=%)
override RELATIVE_DIR := $(RELATIVE_DIR:\\%=%)
-#$(warning RELATIVE_DIR $(RELATIVE_DIR))
+#$(warning RELATIVE_DIR = "$(RELATIVE_DIR)")
override BACK2TOP_DIR := $(shell echo $(RELATIVE_DIR)/ | sed -e 's_//_/_g' -e 's_/\./_/_g' -e 's_^\./__g' -e 's_\([^/][^/]*\)_.._g' -e 's_/$$__')
-#$(warning BACK2TOP_DIR $(BACK2TOP_DIR))
+#$(warning BACK2TOP_DIR = "$(BACK2TOP_DIR)")
+
+#$(warning SOURCES_DIR = "$(SOURCES_DIR)")
+#$(warning MAKERULES_DIR = "$(MAKERULES_DIR)")
+#$(warning RELATIVE_DIR = "$(RELATIVE_DIR)")
-#$(warning SOURCES_DIR = $(SOURCES_DIR))
-#$(warning MAKERULES_DIR = $(MAKERULES_DIR))
-#$(warning RELATIVE_DIR = $(RELATIVE_DIR))
+# We have to use RELATIVE_PREFIX because of mingw
+override RELATIVE_PREFIX := $(RELATIVE_DIR)/
+override RELATIVE_PREFIX := $(RELATIVE_PREFIX:/%=%)
#vpath %.c $(SOURCES_DIR)
#vpath %.cc $(SOURCES_DIR)
#vpath %.cxx $(SOURCES_DIR)
-VPATH = $(SOURCES_DIR)
+# Define srcdir for Automake compatibility
srcdir = $(SOURCES_DIR)
# Defines for quiet compilation
ifndef OMK_VERBOSE
OMK_VERBOSE = 0
endif
-ifeq ($(OMK_VERBOSE),1)
+ifneq ($(OMK_VERBOSE),0)
Q =
else
Q = @
QUIET_CMD_ECHO = echo
endif
+MAKEFILE_OMK=Makefile.omk
+# All subdirectories (even linked ones) containing Makefile.omk
+# Usage in Makefile.omk: SUBDIRS = $(ALL_OMK_SUBDIRS)
+ALL_OMK_SUBDIRS = $(patsubst %/$(MAKEFILE_OMK),%,$(patsubst $(SOURCES_DIR)/%,%,$(wildcard $(SOURCES_DIR)/*/$(MAKEFILE_OMK))))
+
# ===================================================================
# We have set up all important variables, so we can check and include
# real OCERA style Makefile.omk now
ifndef OMK_INCLUDED
-include $(SOURCES_DIR)/Makefile.omk
+include $(SOURCES_DIR)/$(MAKEFILE_OMK)
OMK_INCLUDED := 1
endif
NO_PRINT_DIRECTORY := --no-print-directory
endif
-# Syntax: $(call omk_pass_template,<pass name>,<build dir>,[<local make flags>],[<local condition>])
+ifeq ($(USE_LEAF_MAKEFILES),n)
+export USE_LEAF_MAKEFILES
+SUBDIR_MAKEFILE=$(MAKERULES_DIR)/Makefile.rules
+SOURCESDIR_MAKEFILE=$(MAKERULES_DIR)/Makefile.rules
+else
+SUBDIR_MAKEFILE=$(SOURCES_DIR)/$(3)/Makefile
+SOURCESDIR_MAKEFILE=$(SOURCES_DIR)/Makefile
+endif
+
+# 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)-submakes: $(1)-$(3)-subdir
+$(1)-$(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)-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
+.PHONY: $(1) $(1)-local $(1)-check $(1)-submakes
+$(foreach subdir,$(SUBDIRS),$(eval $(call omk_pass_subdir_template,$(1),$(2),$(subdir))))
$(1):
- +@$(foreach dir,$(SUBDIRS),$(call mkdir_def,$(2)/$(dir)); \
- $(MAKE) SOURCES_DIR=$(SOURCES_DIR)/$(dir) $(NO_PRINT_DIRECTORY) \
- RELATIVE_DIR=$(RELATIVE_DIR)/$(dir) -C $(2)/$(dir) \
- -f $(SOURCES_DIR)/$(dir)/Makefile $$@ || exit 1 ;) true
+# 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) $(1)-submakes
+$(1)-submakes:
+ @true # Do not emit "nothing to be done" messages
+
ifneq ($(4),)
- @echo "make[omk]: $$@ in $(RELATIVE_DIR)"; \
- $(call mkdir_def,$(2)); \
- $(MAKE) $(NO_PRINT_DIRECTORY) -C $(2) \
- -f $(SOURCES_DIR)/Makefile $(3) $$(@:%=%-local)
+$(1)-submakes: $(1)-this-dir
+$(1)-this-dir: $(foreach subdir,$(SUBDIRS),$(1)-$(subdir)-subdir)
+ +@echo "make[omk]: $(strip $(1)) 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)
endif
endef
default-config-pass-local:
# @echo Default config for $(RELATIVE_DIR)
@echo "# Config for $(RELATIVE_DIR)" >> "$(CONFIG_FILE)-default"
- @$(foreach x, $(default_CONFIG), echo $(x) | \
- sed -e 's/^.*=x$$/#\0/' >> "$(CONFIG_FILE)-default" ; )
+ @$(foreach x, $(default_CONFIG), echo '$(x)' | \
+ sed -e 's/^[^=]*=x$$/#\0/' >> "$(CONFIG_FILE)-default" ; )
+
+
+omkize:
+ $(Q)if ! grep -q MAKERULES_DIR Makefile; then \
+ echo "Makefile is not OMK leaf makefile!" >&2; exit 1; \
+ fi
+ $(Q)for i in `find -L . -name Makefile.omk` ; do \
+ 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