File: Makefile.dependencies

package info (click to toggle)
soundscaperenderer 0.6.1%2Bdfsg-2
  • links: PTS, VCS
  • area: main
  • in suites: trixie
  • size: 16,908 kB
  • sloc: cpp: 37,125; sh: 4,509; ansic: 762; makefile: 761; javascript: 593; python: 57
file content (62 lines) | stat: -rw-r--r-- 2,111 bytes parent folder | download | duplicates (6)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
# This Makefile automagically creates dependency files for .cpp source files.
# Rules for other file types can be added easily.
#
# In your primary Makefile, set a DEPENDENCIES variable containing your
# executable files (if they have according .cpp files) and additional object
# files and include Makefile.dependencies at the very end:
#
#   DEPENDENCIES = mysource1 mysource2 mysource3 myobject1.o
#   include Makefile.dependencies
#
# For further customization you can also set the variables DEPENDENCY_EXT,
# DEPENDENCY_DIR and NO_INCLUDE_DEPENDENCIES.
#
# To remove all temporary dependency files, run 'make clean'.
# You can still define your own rule for the target 'clean', if needed.

# Author: Matthias Geier, 2011, 2014

DEPENDENCY_EXT ?= dep
DEPENDENCY_DIR ?= .dep

BINARY_EXTENSIONS ?= "" .o

# don't include dependencies for those targets:
NO_INCLUDE_DEPENDENCIES += clean

DECORATED_DEPENDENCIES = $(DEPENDENCIES:%=$(DEPENDENCY_DIR)/%.$(DEPENDENCY_EXT))

DEPENDENCY_MESSAGE = @echo Dependency file \"$@\" updated

$(DEPENDENCY_DIR):
	mkdir -p $(DEPENDENCY_DIR)

$(subst "",,$(BINARY_EXTENSIONS:%=$(DEPENDENCY_DIR)/\%%.$(DEPENDENCY_EXT))): %.cpp | $(DEPENDENCY_DIR)
	$(RM) $@; $(CXX) -MM -MF $@ \
	    -MT "$(@:$(DEPENDENCY_DIR)/%.$(DEPENDENCY_EXT)=%) $@" \
	    $(CXXFLAGS) $(CPPFLAGS) $(TARGET_ARCH) $< > /dev/null
	$(DEPENDENCY_MESSAGE)

# other file types (e.g. *.c) could be added like this:

#$(DEPENDENCY_DIR)/%.o.$(DEPENDENCY_EXT): %.c | $(DEPENDENCY_DIR)
#	somehow generate dependency files ...

# filter additional dependency files from default rule:
%: %.cpp
	$(LINK.cpp) $< $(filter %.o, $^) $(LOADLIBES) $(LDLIBS) -o $@

# include dependency files generated in the previous step
ifeq (,$(findstring $(MAKECMDGOALS), $(NO_INCLUDE_DEPENDENCIES)))
-include $(DECORATED_DEPENDENCIES)
endif

# If a rule for 'clean' already exists, it is not overwritten here!
# This merely adds a dependency on the target 'clean.dependencies':
clean: clean.dependencies

clean.dependencies:
	$(RM) $(DECORATED_DEPENDENCIES)
	rmdir $(DEPENDENCY_DIR) 2> /dev/null || true

.PHONY: clean clean.dependencies