# Makefile.rules - OCERA make framework common project rules -*- makefile -*- # # (C) Copyright 2003 by Pavel Pisa - OCERA team member # # input variables # V .. if set to 1, full command text is shown else short form is used # SUBDIRS .. list of subdirectories intended for make from actual directory # default_CONFIG .. list of default config assignments CONFIG_XXX=y/n ... # local_EVALUATE .. commands to be evaluated at the end of the Makefile BUILD_DIR_NAME = _build COMPILED_DIR_NAME = _compiled ifndef GROUP_DIR_NAME GROUP_DIR_NAME = nogroup endif # We need to ensure definition of sources directory first ifndef SOURCES_DIR SOURCES_DIR := $(shell ( pwd -L ) ) endif .PHONY: all default check-make-ver all: check-make-ver default #========================= # Include the config file # First, include for which target we are compiling -include $(MAKERULES_DIR)/config.target ifeq ($(wildcard $(MAKERULES_DIR)/config.target),) $(warning You may want to create $(MAKERULES_DIR)/config.target) endif ifndef CONFIG_FILE CONFIG_FILE := $(MAKERULES_DIR)/config.omk endif ifneq ($(wildcard $(CONFIG_FILE)-default),) -include $(CONFIG_FILE)-default else $(warning Please, run "make default-config" first) endif ifneq ($(wildcard $(CONFIG_FILE)),) include $(CONFIG_FILE) CONFIG_FILE_OK = y endif export SOURCES_DIR MAKERULES_DIR RELATIVE_DIR export CONFIG_FILE OMK_SERIALIZE_INCLUDED OMK_VERBOSE OMK_SILENT ifndef RELATIVE_DIR RELATIVE_DIR := $(SOURCES_DIR:$(MAKERULES_DIR)%=%) endif override RELATIVE_DIR := $(RELATIVE_DIR:/%=%) override 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 SOURCES_DIR = $(SOURCES_DIR)) #$(warning MAKERULES_DIR = $(MAKERULES_DIR)) #$(warning RELATIVE_DIR = $(RELATIVE_DIR)) LOCAL_BUILD_DIR=$(MAKERULES_DIR)/$(BUILD_DIR_NAME)/$(RELATIVE_DIR) #$(warning LOCAL_BUILD_DIR = $(LOCAL_BUILD_DIR)) #vpath %.c $(SOURCES_DIR) #vpath %.cc $(SOURCES_DIR) #vpath %.cxx $(SOURCES_DIR) VPATH = $(SOURCES_DIR) 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 ifeq ($(OMK_VERBOSE),1) Q = else Q = @ endif ifneq ($(findstring s,$(MAKEFLAGS)),) QUIET_CMD_ECHO = true OMK_SILENT = 1 else QUIET_CMD_ECHO = echo CP_FLAGS += -v endif # =================================================================== # 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 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 \ echo "Your make program version is too old and does not support OMK system." ; \ echo "Please update to make program 3.81beta1 or newer." ; exit 1 ; \ fi default-config: @echo "# Start of OMK config file" > "$(CONFIG_FILE)-default" @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 # Common OMK templates # ==================== # Syntax: $(call mkdir,,) define mkdir_def [ -d $(1) ] || mkdir -p $(1) || exit 1 endef # Syntax: $(call omk_pass_template,,) define omk_pass_template .PHNOY: $(1) $(1)-local $(1): +@$(foreach dir,$(SUBDIRS),$(call mkdir_def,$(LOCAL_BUILD_DIR)/$(dir)) ; \ $(MAKE) SOURCES_DIR=$(SOURCES_DIR)/$(dir) \ RELATIVE_DIR=$(RELATIVE_DIR)/$(dir) -C $(LOCAL_BUILD_DIR)/$(dir) \ -f $(SOURCES_DIR)/$(dir)/Makefile $$@ || exit 1 ;) +@$(call mkdir_def,$(LOCAL_BUILD_DIR)) @$(MAKE) --no-print-directory -C $(LOCAL_BUILD_DIR) \ -f $(SOURCES_DIR)/Makefile $(2) $$(@:%=%-local) endef # ======================= # DEFAULT CONFIG PASS $(eval $(call omk_pass_template,default-config-pass)) 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" ; ) # ======================= # TODO: Put rules specific to C language to a separate file #include $(MAKERULES_DIR)/Makefile.rules.c-lang include $(MAKERULES_DIR)/Makefile.rules.h8300-boot ifneq ($(local_EVALUATE),) #$(warning $(local_EVALUATE)) $(eval $(local_EVALUATE)) endif