]> rtime.felk.cvut.cz Git - omk.git/blobdiff - snippets/base
There has to be copy of all config headers for kernel build too.
[omk.git] / snippets / base
index f85f8d54700c76bb212961c884f68a5cddd1363f..5bb742486e37eb0defd5ca4275a4a779f8e9e6a7 100644 (file)
@@ -1,10 +1,14 @@
 #  Makefile.rules - OCERA make framework common project rules -*- makefile -*-
 #
 #  (C) Copyright 2003 by Pavel Pisa - OCERA team member
+#  (C) Copyright 2006 by Michal Sojka - Czech Technical University, FEE, DCE
 #
+# 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
 # SUBDIRS          .. list of subdirectories intended for make from actual directory
 # default_CONFIG   .. list of default config assignments CONFIG_XXX=y/n ...
 
@@ -15,7 +19,23 @@ endif
 
 .PHONY: all default check-make-ver
 
+ifdef W
+  ifeq ("$(origin W)", "command line")
+    OMK_WHOLE_TREE:=$(W)
+  endif
+endif
+ifndef OMK_WHOLE_TREE
+  OMK_WHOLE_TREE:=0
+endif
+
+ifneq ($(OMK_WHOLE_TREE),1)
 all: check-make-ver default
+       @echo "Compilation finished"
+else
+# Run make in the top-level directory
+all:
+       @$(MAKE) -C $(MAKERULES_DIR) OMK_SERIALIZE_INCLUDED=n SOURCES_DIR=$(MAKERULES_DIR) RELATIVE_DIR="" $(MAKECMDGOALS) W=0
+endif
 
 #=========================
 # Include the config file
@@ -27,8 +47,10 @@ endif
 ifneq ($(wildcard $(CONFIG_FILE)-default),)
 -include $(CONFIG_FILE)-default
 else
+ifneq ($(MAKECMDGOALS),default-config)
 $(warning Please, run "make default-config" first)
 endif
+endif
 
 ifneq ($(wildcard $(CONFIG_FILE)),)
 include $(CONFIG_FILE)
@@ -38,20 +60,26 @@ endif #$(CONFIG_FILE_OK)
 
 export SOURCES_DIR MAKERULES_DIR RELATIVE_DIR
 export CONFIG_FILE OMK_SERIALIZE_INCLUDED OMK_VERBOSE OMK_SILENT
-# FIXME: Is it correct to export OMK_SERIALIZE_INCLUDED to submakes???
+# 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)%=%)
 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)
@@ -79,18 +107,21 @@ ifneq ($(findstring s,$(MAKEFLAGS)),)
   OMK_SILENT = 1
 else
   QUIET_CMD_ECHO = echo
-  CP_FLAGS += -v
 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
 
-
 check-make-ver:
        @GOOD_MAKE_VERSION=`echo $(MAKE_VERSION) | sed -n -e 's/^[4-9]\..*\|^3\.9[0-9].*\|^3\.8[1-9].*/y/p'` ; \
        if [ x$$GOOD_MAKE_VERSION != xy ] ; then \
@@ -110,22 +141,24 @@ define mkdir_def
        [ -d $(1) ] || mkdir -p $(1) || exit 1
 endef
 
-# Syntax: $(call omk_pass_template,<pass name>,<build dir>,[<local make flags>],[<local condition>],[<subpass>])
+ifneq ($(V),2)
+NO_PRINT_DIRECTORY := --no-print-directory
+endif
+
+# Syntax: $(call omk_pass_template,<pass name>,<build dir>,[<local make flags>],[<local 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_DIR)/$(dir) -C $(2)/$(dir) \
-               -f $(SOURCES_DIR)/$(dir)/Makefile $$@ || exit 1 ;)
-       $(5)
-       @echo "  MAKE $$@ in $(RELATIVE_DIR)"
-       +@if [ $(4) ] || [ -z "$(subst ",\",$(4))" ]; then \
-           $(call mkdir_def,$(2)); \
-           $(MAKE) --no-print-directory -C $(2) \
-               -f $(SOURCES_DIR)/Makefile $(3) $$(@:%=%-local); \
-       fi
-
+       +@$(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 $(SOURCES_DIR)/$(dir)/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 $(SOURCES_DIR)/Makefile $(3) $$(@:%=%-local)
+endif
 endef
 
 # =======================
@@ -136,14 +169,15 @@ 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) \
+       @$(MAKE) $(NO_PRINT_DIRECTORY) -C $(MAKERULES_DIR) \
                RELATIVE_DIR="" SOURCES_DIR=$(MAKERULES_DIR) \
                -f $(MAKERULES_DIR)/Makefile default-config-pass
 
-$(eval $(call omk_pass_template,default-config-pass))
+$(eval $(call omk_pass_template,default-config-pass,$$(LOCAL_BUILD_DIR),,always))
 
 default-config-pass-local:
-       @echo Default config for $(RELATIVE_DIR)
+#      @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" ; )
+