1 #*****************************************************************************
2 # Makefile Build System for Fawkes
4 # Created on Sun Sep 03 14:14:14 2006
5 # Copyright (C) 2006-2009 by Tim Niemueller, AllemaniACs RoboCup Team
7 #*****************************************************************************
9 # This program is free software; you can redistribute it and/or modify
10 # it under the terms of the GNU General Public License as published by
11 # the Free Software Foundation; either version 2 of the License, or
12 # (at your option) any later version.
14 #*****************************************************************************
16 # see http://make.paulandlesley.org/autodep.html
17 # see http://make.paulandlesley.org/rules.html
19 ifndef __buildsys_rules_mk_
20 __buildsys_rules_mk := 1
22 include $(abspath $(BUILDSYSDIR)/ext/gmsl)
24 MAKE_MIN_VERSION_MAJOR=3
25 MAKE_MIN_VERSION_MINOR=81
27 MAKE_VERSION_SPLITTED=$(call split,.,$(MAKE_VERSION))
28 MAKE_VERSION_MAJOR=$(word 1,$(MAKE_VERSION_SPLITTED))
29 MAKE_VERSION_MINOR=$(word 2,$(MAKE_VERSION_SPLITTED))
31 ifneq ($(call gte,$(MAKE_VERSION_MAJOR),$(MAKE_MIN_VERSION_MAJOR)),$(true))
34 ifeq ($(MAKE_VERSION_MAJOR),$(MAKE_MIN_VERSION_MAJOR))
35 ifneq ($(call gte,$(MAKE_VERSION_MINOR),$(MAKE_MIN_VERSION_MINOR)),$(true))
41 ifeq ($(MAKE_INSUFFICIENT),1)
42 $(error You need at least GNU Make version $(MAKE_MIN_VERSION_MAJOR).$(MAKE_MIN_VERSION_MINOR), but you have only $(MAKE_VERSION))
45 # indentation definitions, dash (-) is replaced with space
47 INDENT_PRINT := $(subst -, ,$(INDENT))
48 ifeq ($(MAKECMDGOALS),clean)
49 DISABLE_OBJS_all_WARNING = 1
50 ifeq ($(shell test -d qa; if [ "$$?" = "0" ]; then echo "yes"; fi),yes)
51 ifneq ($(findstring qa,$(SUBDIRS)),qa)
57 # If SOVER for lib was not set (SOVER_libname empty), set it to DEFAULT_SOVER
58 $(foreach L,$(LIBS_all:$(LIBDIR)/%.so=%) $(LIBS_gui:$(LIBDIR)/%.so=%),$(if $(SOVER_$(subst /,_,$L)),,$(eval SOVER_$(subst /,_,$L) = $(DEFAULT_SOVER))))
60 ifdef __buildsys_lua_mk_
61 # Lua libraries do not set an SOVER, it's not checked anyway
62 $(foreach L,$(LIBS_all:$(LIBDIR)/lua/%.so=%),$(if $L,$(eval NOSOVER_lua_$(subst /,_,$L)=1)))
66 -include $(DEPDIR)/*.d
68 # One to build 'em all
71 EXTRA_ALL = $(LIBS_gui) $(PLUGINS_gui) $(BINS_gui) $(TARGETS_gui)
73 all: presubdirs $(LIBS_all) $(PLUGINS_all) $(BINS_all) $(TARGETS_all) $(EXTRA_ALL) subdirs
74 gui: presubdirs $(LIBS_gui) $(PLUGINS_gui) $(BINS_gui) $(TARGETS_gui) subdirs
80 # Do not delete .o files to allow for incremental builds
81 .SECONDARY: $(OBJS_all)
82 # Whenever the Makefile is modified rebuild everything
83 $(OBJS_all): $(SRCDIR)/Makefile
86 ifneq ($(LIBS_all)$(PLUGINS_all)$(BINS_all)$(LIBS_gui)$(PLUGINS_gui)$(BINS_gui),)
87 ifneq ($(DISABLE_OBJS_all_WARNING),1)
88 $(warning OBJS_all is not set. This is probably a bug. If you intended this set DISABLE_OBJS_all_WARNING to 1 to get rid of this warning.)
95 clean: presubdirs subdirs
96 $(SILENTSYMB) echo -e "$(INDENT_PRINT)--> Cleaning up directory $(TBOLDGRAY)$(CURDIR)$(TNORMAL)"
97 $(SILENT) if [ "$(SRCDIR)/$(OBJDIR)" != "/" ]; then rm -rf "$(SRCDIR)/$(OBJDIR)" ; fi
98 $(SILENT) if [ -n "$(DEPDIR)" ]; then rm -rf "$(DEPDIR)" ; fi
99 $(SILENT)$(foreach B,$(BINS_all),rm -f $(B);)
100 $(SILENT)$(foreach L,$(LIBS_all),rm -f $(addsuffix *,$(L));)
101 $(SILENT)$(foreach P,$(PLUGINS_all),rm -f $(P);)
102 $(SILENT)$(foreach T,$(TARGETS_all),rm -rf $(T);)
103 $(SILENT)$(foreach B,$(BINS_gui),rm -f $(B);)
104 $(SILENT)$(foreach L,$(LIBS_gui),rm -f $(L);)
105 $(SILENT)$(foreach P,$(PLUGINS_gui),rm -f $(P);)
106 $(SILENT)$(foreach T,$(TARGETS_gui),rm -rf $(T);)
107 $(SILENT)$(foreach E,$(CLEAN_FILES),rm -rf $(E);)
109 ifeq (,$(findstring qa,$(SUBDIRS)))
111 qa: presubdirs subdirs
112 $(SILENT) if [ -d "$(subst /.objs,,$(realpath $(CURDIR)))/qa" ]; then \
113 echo -e "$(INDENT_PRINT)--> Building QA in $(subst $(realpath $(CURDIR)/$(BASEDIR))/,,$(subst /.objs,,$(realpath $(CURDIR)))/qa)"; \
114 $(MAKE) --no-print-directory --no-keep-going -C "$(subst /.objs,,$(CURDIR))/qa" \
115 SRCDIR="$(subst /.objs,,$(CURDIR))/qa" $(MFLAGS) INDENT="$(INDENT)$(INDENT_STRING)" \
116 OBJSSUBMAKE=0 || exit $$?; \
120 .PHONY: presubdirs $(PRESUBDIRS) subdirs $(SUBDIRS)
121 presubdirs: $(PRESUBDIRS)
124 ifneq ($(PRESUBDIRS)$(SUBDIRS),)
125 $(PRESUBDIRS) $(SUBDIRS):
126 $(SILENTSYMB) if [ ! -d "$(realpath $(SRCDIR)/$(@))" ]; then \
127 echo -e "$(INDENT_PRINT)---$(TRED)Directory $(TNORMAL)$(TBOLDRED)$@$(TNORMAL)$(TRED) does not exist, check [PRE]SUBDIRS variable$(TNORMAL) ---"; \
130 echo -e "$(INDENT_PRINT)--> Entering sub-directory $(TBOLDBLUE)$@$(TNORMAL) ---"; \
131 $(MAKE) --no-print-directory --no-keep-going -C "$(realpath $(SRCDIR)/$@)" \
132 $(MFLAGS) $(MAKECMDGOALS) INDENT="$(INDENT)$(INDENT_STRING)" \
133 SRCDIR="$(realpath $(SRCDIR)/$@)" OBJSSUBMAKE=0 || exit $$?; \
134 if [ "$(MAKECMDGOALS)" != "clean" ]; then \
135 echo -e "$(INDENT_PRINT)$(subst -, ,$(INDENT_STRING))<-- Leaving $@"; \
140 # Cancel built-in implicit rules, they suck
144 # NOTE: .. are replaced by __. This is needed to have objects that are in upper relative
145 # directories are build in .objs, another change is needed below in bin, lib and plugin targets,
148 $(SILENT) mkdir -p $(DEPDIR)
149 $(SILENT) mkdir -p $(@D)
150 $(SILENTSYMB) echo "$(INDENT_PRINT)--- Compiling $(subst $(SRCDIR)/,,$<) (C++)"
151 $(SILENT) mkdir -p $(dir $(subst ..,__,$@))
152 $(SILENT) $(CC) -MD -MF $(DEPFILE).td $(CFLAGS_BASE) $(CFLAGS) $(CFLAGS_$*) \
153 $(addprefix -I,$(INCS_$*)) $(addprefix -I,$(INCDIRS)) -c -o $(subst ..,__,$@) $<
154 $(SILENT)sed -e '/^[^:]*\//! s/^\([^:]\+\): \(.*\)$$/$(subst /,\/,$(@D))\/\1: \2/' < $(DEPFILE).td > $(DEPFILE).d; \
155 sed -e 's/#.*//' -e 's/^[^:]*: *//' -e 's/ *\\$$//' -e 's/^ *//' \
156 -e '/^$$/ d' -e 's/$$/ :/' < $(DEPFILE).td >> $(DEPFILE).d; \
160 $(SILENT) mkdir -p $(DEPDIR)
161 $(SILENT) mkdir -p $(@D)
162 $(SILENTSYMB) echo "$(INDENT_PRINT)--- Compiling $(subst $(SRCDIR)/,,$<) (C)"
163 $(SILENT) mkdir -p $(dir $(subst ..,__,$@))
164 $(SILENT) $(CC) -MD -MF $(DEPFILE).td $(CFLAGS_BASE) $(CFLAGS) $(CFLAGS_$*) \
165 $(addprefix -I,$(INCS_$*)) $(addprefix -I,$(INCDIRS)) -c -o $(subst ..,__,$@) $<
166 $(SILENT)sed -e '/^[^:]*\//! s/^\([^:]\+\): \(.*\)$$/$(subst /,\/,$(@D))\/\1: \2/' < $(DEPFILE).td > $(DEPFILE).d; \
167 sed -e 's/#.*//' -e 's/^[^:]*: *//' -e 's/ *\\$$//' -e 's/^ *//' \
168 -e '/^$$/ d' -e 's/$$/ :/' < $(DEPFILE).td >> $(DEPFILE).d; \
172 $(SILENTSYMB) echo "$(INDENT_PRINT)--- Running Qt moc on $(subst $(SRCDIR)/,,$<), creating $(subst ..,__,$@)"
173 $(SILENT) $(MOC) $(MOC_FLAGS) -p "../$(subst ..,__,$(@D))" $< -o $(subst ..,__,$@)
176 $(BINDIR)/%: $$(OBJS_$$*)
177 $(SILENT) mkdir -p $(@D)
178 $(SILENTSYMB) echo -e "$(INDENT_PRINT)=== Linking $(TBOLDGREEN)$*$(TNORMAL) ---"
179 $(SILENT) $(CC) -o $@ $(subst ..,__,$^) \
181 $(if $(call seq,$(origin LDFLAGS_$(subst /,_,$*)),undefined),$(LDFLAGS),$(LDFLAGS_$(subst /,_,$*))) \
182 $(addprefix -l,$(LIBS_$*)) $(addprefix -l,$(LIBS)) \
183 $(addprefix -L,$(LIBDIRS_$*)) $(addprefix -L,$(LIBDIRS))
185 $(LIBDIR)/%.so: $$(OBJS_$$(subst /,_,$$*))
186 $(SILENT) mkdir -p $(@D)
187 $(SILENTSYMB) echo -e "$(INDENT_PRINT)=== Linking lib $(TBOLDGREEN)$*$(TNORMAL) ---"
188 $(SILENT) $(CC) -o $@$(if $(NOSOVER_$(subst /,_,$*)),,.$(SOVER_$(subst /,_,$*))) $(subst ..,__,$^) \
189 $(if $(NOSOVER_$(subst /,_,$*)),,-Wl,-soname=$(@F).$(SOVER_$(subst /,_,$*))) \
190 $(LDFLAGS_BASE) $(LDFLAGS_SHARED) \
191 $(if $(call seq,$(origin LDFLAGS_$(subst /,_,$*)),undefined),$(LDFLAGS),$(LDFLAGS_$(subst /,_,$*))) \
192 $(addprefix -l,$(LIBS_$(subst /,_,$*))) $(addprefix -l,$(LIBS)) \
193 $(addprefix -L,$(LIBDIRS_$(subst /,_,$*))) $(addprefix -L,$(LIBDIRS))
194 $(if $(NOSOVER_$(subst /,_,$*)),, \
195 $(SILENT) ln -fs $(@F).$(SOVER_$(subst /,_,$*)) $@; \
196 ln -fs $(@F).$(SOVER_$(subst /,_,$*)) $@.$(firstword $(call split,.,$(SOVER_$(subst /,_,$*)))); \
199 ### Check if there are special additions
200 ifneq ($(realpath $(BUILDSYSDIR)/btypes/rules_$(BUILD_TYPE).mk),)
201 include $(BUILDSYSDIR)/btypes/rules_$(BUILD_TYPE).mk
204 endif # __buildsys_rules_mk_