X-Git-Url: http://rtime.felk.cvut.cz/gitweb/omk.git/blobdiff_plain/769efdbe7ac6513bbfab091ddc30efa3f7fbc862..1a974f19f07e156a251ef5f9b4be4131dae1aca9:/snippets/base diff --git a/snippets/base b/snippets/base index 4c1306a..e7fb2e5 100644 --- a/snippets/base +++ b/snippets/base @@ -1,64 +1,127 @@ # 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 +# +# Homepage: http://rtime.felk.cvut.cz/omk/ +# +# 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 ... # 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 + +# OUTPUT_DIR is the place where _compiled, _build and possible other +# files/directories are created. By default is the same as +# $(MAKERULES_DIR). +ifndef OUTPUT_DIR +OUTPUT_DIR := $(MAKERULES_DIR) +endif + +.PHONY: all default check-make-ver omkize +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 + +ifdef OMK_TESTSROOT +# Usage: $(call canttest,) +define canttest + ( echo "$(1)" > $(OUTPUT_DIR)/_canttest; echo "$(1)"; exit 1 ) +endef +else +define canttest + echo "$(1)" +endef +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 +CONFIG_FILE := $(OUTPUT_DIR)/config.omk endif ifneq ($(wildcard $(CONFIG_FILE)-default),) -include $(CONFIG_FILE)-default else +ifneq ($(MAKECMDGOALS),default-config) $(warning Please, run "make default-config" first) endif +endif + +-include $(OUTPUT_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 $(OUTPUT_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. ifndef RELATIVE_DIR -RELATIVE_DIR := $(SOURCES_DIR:$(MAKERULES_DIR)%=%) +RELATIVE_DIR := $(SOURCES_DIR:$(OUTPUT_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 = "$(OUTPUT_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 @@ -70,7 +133,7 @@ endif ifndef OMK_VERBOSE OMK_VERBOSE = 0 endif -ifeq ($(OMK_VERBOSE),1) +ifneq ($(OMK_VERBOSE),0) Q = else Q = @ @@ -82,15 +145,22 @@ else 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) +ifeq ($(AUTOMATIC_SUBDIRS),y) +SUBDIRS?=$(ALL_OMK_SUBDIRS) +endif 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 \ @@ -100,7 +170,7 @@ check-make-ver: distclean dist-clean: @$(QUIET_CMD_ECHO) " RM $(COMPILED_DIR_NAME) $(BUILD_DIR_NAME)" - @rm -fr $(MAKERULES_DIR)/$(COMPILED_DIR_NAME) $(MAKERULES_DIR)/$(BUILD_DIR_NAME) + @rm -fr $(OUTPUT_DIR)/$(COMPILED_DIR_NAME) $(OUTPUT_DIR)/$(BUILD_DIR_NAME) # Common OMK templates # ==================== @@ -110,22 +180,75 @@ define mkdir_def [ -d $(1) ] || mkdir -p $(1) || exit 1 endef -# Syntax: $(call omk_pass_template,,,[],[],[]) +ifneq ($(OMK_VERBOSE),2) +NO_PRINT_DIRECTORY := --no-print-directory +endif + +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 + +pass = $(strip $(1)) + +# Call a pass in a subdirectory +# Usage: $(call omk_pass_subdir_template,,,) +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 + +# Call a pass in a subdirectory +# Usage: $(call extra_rules_subdir_template,) +define extra_rules_subdir_template +extra-rules-subdirs: extra-rules-$(1) +extra-rules-$(1): + +@$(MAKE) OMK_SERIALIZE_INCLUDED=n MAKERULES_DIR=$(SOURCES_DIR)/$(1) OUTPUT_DIR=$(OUTPUT_DIR) \ + SOURCES_DIR=$(SOURCES_DIR)/$(1) RELATIVE_DIR=$(RELATIVE_PREFIX)$(1) -C $(SOURCES_DIR)/$(1) +endef + +.PHONY: extra-rules-subdirs +extra-rules-subdirs: + +$(foreach subdir,$(EXTRA_RULES_SUBDIRS),$(eval $(call extra_rules_subdir_template,$(subdir)))) + +# Usage: $(call omk_pass_template,,,[],[]) 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) - +@if [ $(4) ] || [ -z "$(subst ",\",$(4))" ]; then \ - echo " MAKE $$@ in $(RELATIVE_DIR)"; \ - $(call mkdir_def,$(2)); \ - $(MAKE) --no-print-directory -C $(2) \ - -f $(SOURCES_DIR)/Makefile $(3) $$(@:%=%-local); \ - fi +.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 # ======================= @@ -136,14 +259,27 @@ 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) \ - RELATIVE_DIR="" SOURCES_DIR=$(MAKERULES_DIR) \ - -f $(MAKERULES_DIR)/Makefile default-config-pass + @$(MAKE) $(NO_PRINT_DIRECTORY) -C $(OUTPUT_DIR) \ + RELATIVE_DIR="" SOURCES_DIR=$(OUTPUT_DIR) \ + -f $(OUTPUT_DIR)/Makefile default-config-pass -$(eval $(call omk_pass_template,default-config-pass,$(MAKERULES_DIR)/$(BUILD_DIR_NAME))) +$(eval $(call omk_pass_template,default-config-pass,$$(LOCAL_BUILD_DIR),,always)) 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