]> rtime.felk.cvut.cz Git - omk.git/blob - snippets/base
Changes to vxWorks support. Still not fully functional.
[omk.git] / snippets / base
1 #  Makefile.rules - OCERA make framework common project rules -*- makefile -*-
2 #
3 #  (C) Copyright 2003 by Pavel Pisa - OCERA team member
4 #  (C) Copyright 2006 by Michal Sojka - Czech Technical University, FEE, DCE
5 #
6 #
7 # input variables
8 # V                .. if set to 1, full command text is shown else short form is used
9 # SUBDIRS          .. list of subdirectories intended for make from actual directory
10 # default_CONFIG   .. list of default config assignments CONFIG_XXX=y/n ...
11
12 # We need to ensure definition of sources directory first
13 ifndef SOURCES_DIR
14 SOURCES_DIR := $(shell ( pwd -L ) )
15 endif
16
17 .PHONY: all default check-make-ver
18
19 all: check-make-ver default
20         @echo "Compilation finished"
21
22 #=========================
23 # Include the config file
24
25 ifneq ($(CONFIG_FILE_OK),y)
26 ifndef CONFIG_FILE
27 CONFIG_FILE      := $(MAKERULES_DIR)/config.omk
28 endif
29 ifneq ($(wildcard $(CONFIG_FILE)-default),)
30 -include $(CONFIG_FILE)-default
31 else
32 ifneq ($(MAKECMDGOALS),default-config)
33 $(warning Please, run "make default-config" first)
34 endif
35 endif
36
37 ifneq ($(wildcard $(CONFIG_FILE)),)
38 include $(CONFIG_FILE)
39 CONFIG_FILE_OK = y
40 endif
41 endif #$(CONFIG_FILE_OK)
42
43 export SOURCES_DIR MAKERULES_DIR RELATIVE_DIR
44 export CONFIG_FILE OMK_SERIALIZE_INCLUDED OMK_VERBOSE OMK_SILENT
45 # OMK_SERIALIZE_INCLUDED has to be exported to submakes because passes
46 # must to be serialized only in the toplevel make.
47
48 ifndef RELATIVE_DIR
49 RELATIVE_DIR := $(SOURCES_DIR:$(MAKERULES_DIR)%=%)
50 endif
51 override RELATIVE_DIR := $(RELATIVE_DIR:/%=%)
52 override RELATIVE_DIR := $(RELATIVE_DIR:\\%=%)
53 #$(warning  RELATIVE_DIR $(RELATIVE_DIR))
54 override BACK2TOP_DIR := $(shell echo $(RELATIVE_DIR)/ | sed -e 's_//_/_g' -e 's_/\./_/_g' -e 's_^\./__g'  -e 's_\([^/][^/]*\)_.._g' -e 's_/$$__')
55 #$(warning  BACK2TOP_DIR $(BACK2TOP_DIR))
56
57 #$(warning SOURCES_DIR = $(SOURCES_DIR))
58 #$(warning MAKERULES_DIR = $(MAKERULES_DIR))
59 #$(warning RELATIVE_DIR = $(RELATIVE_DIR))
60
61 #vpath %.c $(SOURCES_DIR)
62 #vpath %.cc $(SOURCES_DIR)
63 #vpath %.cxx $(SOURCES_DIR)
64
65 VPATH = $(SOURCES_DIR)
66 srcdir = $(SOURCES_DIR)
67
68 # Defines for quiet compilation
69 ifdef V
70   ifeq ("$(origin V)", "command line")
71     OMK_VERBOSE = $(V)
72   endif
73 endif
74 ifndef OMK_VERBOSE
75   OMK_VERBOSE = 0
76 endif
77 ifeq ($(OMK_VERBOSE),1)
78   Q =
79 else
80   Q = @
81 endif
82 ifneq ($(findstring s,$(MAKEFLAGS)),)
83   QUIET_CMD_ECHO = true
84   OMK_SILENT = 1
85 else
86   QUIET_CMD_ECHO = echo
87 endif
88
89 # ===================================================================
90 # We have set up all important variables, so we can check and include
91 # real OCERA style Makefile.omk now
92 ifndef OMK_INCLUDED
93 include $(SOURCES_DIR)/Makefile.omk
94 OMK_INCLUDED := 1
95 endif
96
97
98 check-make-ver:
99         @GOOD_MAKE_VERSION=`echo $(MAKE_VERSION) | sed -n -e 's/^[4-9]\..*\|^3\.9[0-9].*\|^3\.8[1-9].*/y/p'` ; \
100         if [ x$$GOOD_MAKE_VERSION != xy ] ; then \
101                 echo "Your make program version is too old and does not support OMK system." ; \
102                 echo "Please update to make program 3.81beta1 or newer." ; exit 1 ; \
103         fi
104
105 distclean dist-clean:
106         @$(QUIET_CMD_ECHO) "  RM      $(COMPILED_DIR_NAME) $(BUILD_DIR_NAME)"
107         @rm -fr $(MAKERULES_DIR)/$(COMPILED_DIR_NAME)  $(MAKERULES_DIR)/$(BUILD_DIR_NAME)
108
109 # Common OMK templates
110 # ====================
111
112 # Syntax: $(call mkdir,<dir name>)
113 define mkdir_def
114         [ -d $(1) ] || mkdir -p $(1) || exit 1
115 endef
116
117 ifneq ($(V),2)
118 NO_PRINT_DIRECTORY := --no-print-directory
119 endif
120
121 # Syntax: $(call omk_pass_template,<pass name>,<build dir>,[<local make flags>],[<local condition>])
122 define omk_pass_template
123 .PHNOY: $(1) $(1)-local
124 $(1):
125         +@$(foreach dir,$(SUBDIRS),$(call mkdir_def,$(2)/$(dir)); \
126                 $(MAKE) SOURCES_DIR=$(SOURCES_DIR)/$(dir) $(NO_PRINT_DIRECTORY) \
127                 RELATIVE_DIR=$(RELATIVE_DIR)/$(dir) -C $(2)/$(dir) \
128                 -f $(SOURCES_DIR)/$(dir)/Makefile $$@ || exit 1 ;)
129 ifneq ($(4),)
130         @echo "make[omk]:$$@ in $(RELATIVE_DIR)"; \
131         $(call mkdir_def,$(2)); \
132         $(MAKE) $(NO_PRINT_DIRECTORY) -C $(2) \
133                 -f $(SOURCES_DIR)/Makefile $(3) $$(@:%=%-local)
134 endif
135 endef
136
137 # =======================
138 # DEFAULT CONFIG PASS
139
140 default-config:
141         @echo "# Start of OMK config file" > "$(CONFIG_FILE)-default"
142         @echo "# This file should not be altered manually" >> "$(CONFIG_FILE)-default"
143         @echo "# Overrides should be stored in file $(notdir $(CONFIG_FILE))" >> "$(CONFIG_FILE)-default"
144         @echo >> "$(CONFIG_FILE)-default"
145         @$(MAKE) $(NO_PRINT_DIRECTORY) -C $(MAKERULES_DIR) \
146                 RELATIVE_DIR="" SOURCES_DIR=$(MAKERULES_DIR) \
147                 -f $(MAKERULES_DIR)/Makefile default-config-pass
148
149 $(eval $(call omk_pass_template,default-config-pass,$$(LOCAL_BUILD_DIR),,always))
150
151 default-config-pass-local:
152 #       @echo Default config for $(RELATIVE_DIR)
153         @echo "# Config for $(RELATIVE_DIR)" >> "$(CONFIG_FILE)-default"
154         @$(foreach x, $(default_CONFIG), echo $(x) | \
155                 sed -e 's/^.*=x$$/#\0/' >> "$(CONFIG_FILE)-default" ; )