# Makefile.rules - OCERA make framework common project rules -*- makefile-gmake -*- # # (C) Copyright 2003, 2006, 2007, 2008, 2009 by Pavel Pisa - OCERA team member # (C) Copyright 2009, 2010, 2011, 2013, 2015, 2016, 2017, 2019 by Pavel Pisa - PiKRON.com # (C) Copyright 2006, 2007, 2008, 2009, 2010, 2011, 2013, 2015 by Michal Sojka - Czech Technical University, FEE, DCE # # Homepage: http://rtime.felk.cvut.cz/omk/ # Version: @git-describe@ # # 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 ... # If we are not called by OMK leaf Makefile... ifndef MAKERULES_DIR MAKERULES_DIR := $(abspath $(dir $(filter %Makefile.rules,$(MAKEFILE_LIST)))) endif # The $(SED4OMK) command for BSD based systems requires -E option to allow # extended regular expressions SED4OMK ?= sed ifneq ($(shell ( echo A | $(SED4OMK) -n -e 's/A\|B/y/p' )),y) SED4OMK := $(SED4OMK) -E ifneq ($(shell ( echo A | $(SED4OMK) -n -e 's/A\|B/y/p' )),y) SED4OMK := gsed endif ifneq ($(shell ( echo A | $(SED4OMK) -n -e 's/A\|B/y/p' )),y) SED4OMK := gsed -E endif ifneq ($(shell ( echo A | $(SED4OMK) -n -e 's/A\|B/y/p' )),y) $(error No SED program suitable for OMK found) endif 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 # We need to ensure definition of sources directory first ifndef SOURCES_DIR # Only shell built-in pwd understands -L SOURCES_DIR := $(shell ( pwd -L ) ) INVOCATION_DIR := $(SOURCES_DIR:$(OUTPUT_DIR)%=%) INVOCATION_DIR := $(INVOCATION_DIR:/%=%) INVOCATION_DIR := $(INVOCATION_DIR:\\%=%) endif .PHONY: all default check-make-ver print-hints 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 print-hints 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 # omk-get-var target allows external scripts/programs to determine the # values of OMK variables such as RELATIVE_DIR etc. .PHONY: omk-get-var omk-get-var: @$(foreach var,$(VAR),echo $(var)=$($(var));) #========================= # Include the config file ifndef CONFIG_FILE CONFIG_FILE := $(OUTPUT_DIR)/config.omk endif $(CONFIG_FILE)-default: $(MAKE) default-config ifeq ($(MAKECMDGOALS),default-config) export DEFAULT_CONFIG_PASS=1 endif ifneq ($(DEFAULT_CONFIG_PASS),1) include $(CONFIG_FILE)-default endif -include $(OUTPUT_DIR)/config.target ifneq ($(wildcard $(CONFIG_FILE)),) -include $(CONFIG_FILE) endif CONFIG_FILES ?= $(wildcard $(CONFIG_FILE)-default) $(wildcard $(OUTPUT_DIR)/config.target) $(wildcard $(CONFIG_FILE)) export SED4OMK SOURCES_DIR MAKERULES_DIR RELATIVE_DIR INVOCATION_DIR 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:$(OUTPUT_DIR)%=%) endif #$(warning === RELATIVE_DIR = "$(RELATIVE_DIR)" ===) override RELATIVE_DIR := $(RELATIVE_DIR:/%=%) override RELATIVE_DIR := $(RELATIVE_DIR:\\%=%) #$(warning RELATIVE_DIR = "$(RELATIVE_DIR)") #override BACK2TOP_DIR := $(shell echo $(RELATIVE_DIR)/ | $(SED4OMK) -e 's_//_/_g' -e 's_/\./_/_g' -e 's_^\./__g' -e 's_\([^/][^/]*\)_.._g' -e 's_/$$__') #$(warning BACK2TOP_DIR = "$(BACK2TOP_DIR)") #$(warning SOURCES_DIR = "$(SOURCES_DIR)") #$(warning MAKERULES_DIR = "$(OUTPUT_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) # Define srcdir for Automake compatibility srcdir = $(SOURCES_DIR) # Defines for quiet compilation ifdef V ifeq ("$(origin V)", "command line") OMK_VERBOSE = $(V) endif endif ifndef OMK_VERBOSE OMK_VERBOSE = 0 endif ifneq ($(OMK_VERBOSE),0) Q = else Q = @ endif ifneq ($(findstring s,$(MAKEFLAGS)),) QUIET_CMD_ECHO = true OMK_SILENT = 1 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) ifeq ($(AUTOMATIC_SUBDIRS),y) SUBDIRS?=$(ALL_OMK_SUBDIRS) endif OMK_INCLUDED := 1 endif print-hints: @echo 'Use "make V=1" to see the verbose compile lines.' check-make-ver: @GOOD_MAKE_VERSION=`echo $(MAKE_VERSION) | $(SED4OMK) -n -e 's/^[4-9]\..*\|^3\.9[0-9].*\|^3\.8[1-9].*/y/p'` ; \ if [ x$$GOOD_MAKE_VERSION != xy ] ; then \ echo "Your make program version ($(MAKE_VERSION)) is too old and does not support OMK system." ; \ echo "Please update to make program 3.81beta1 or newer." ; exit 1 ; \ fi distclean dist-clean: @$(QUIET_CMD_ECHO) " RM $(COMPILED_DIR_NAME) $(BUILD_DIR_NAME)" @rm -fr $(OUTPUT_DIR)/$(COMPILED_DIR_NAME) $(OUTPUT_DIR)/$(BUILD_DIR_NAME) # Common OMK templates # ==================== # Syntax: $(call mkdir,