Debian Codegraph @

src/GNUmakefile

raw ◀ ▶
3 Debian patches touch this file
1 #
2 # Trigger Rally GNUmakefile for Linux users
3 #
4
•5 PKG_CONFIG ?= pkg-config
6 SDL2_CFLAGS = $(shell ${PKG_CONFIG} --cflags sdl2)
7 SDL2_LIBS = $(shell ${PKG_CONFIG} --libs sdl2)
8 SDL2_IMAGE_CFLAGS = $(shell ${PKG_CONFIG} --cflags SDL2_image)
9 SDL2_IMAGE_LIBS = $(shell ${PKG_CONFIG} --libs SDL2_image)
10
11 # standard GNU and custom variables
12 DISTNAME := trigger-rally
13 DISTVER := 0.6.6.1
14 DISTDIR := $(DISTNAME)-$(DISTVER)
15 DISTARC := $(DISTDIR).tar.gz
16 TR_EXENAME := trigger-rally
17 TR_CFGNAME := trigger-rally.config.defs
18 TR_BINDIR := ../bin
19 TR_DATADIR := ../data
20 TR_DOCDIR := ../doc
21 TR_EXEFILE := $(TR_BINDIR)/$(TR_EXENAME)
22 TR_CFGFILE := $(TR_BINDIR)/$(TR_CFGNAME)
23 TR_DATAFILES := $(shell cd $(TR_DATADIR); find * -type f)
24 TR_DOCFILES := $(shell cd $(TR_DOCDIR); find * -type f)
25 PROJDIRS := PEngine PSim Trigger
26 SRCFILES := $(sort $(shell find $(PROJDIRS) -type f -name "*.cpp"))
27 OBJFILES := $(patsubst %.cpp, %.o, $(SRCFILES))
28 DEPFILES := $(patsubst %.cpp, %.d, $(SRCFILES))
29 WARNINGS ?= -Wall -Wextra -pedantic
30 OPTIMS ?= -march=native -mtune=native -Ofast
31 DMACROS := -DNDEBUG -DUNIX -DPACKAGE_VERSION=\"$(DISTVER)\"
32 INCDIRS := -I'./include'
33 CXXFLAGS += -std=c++11 $(WARNINGS) $(OPTIMS)
•34 CPPFLAGS += $(DMACROS) $(INCDIRS) $(SDL2_CFLAGS) $(SDL2_IMAGE_CFLAGS)
35 EXTRA_LIBS := $(SDL2_LIBS) $(SDL2_IMAGE_LIBS) -lSDL2main -lGL -lGLU -lGLEW -lSDL2 -lSDL2_image -lphysfs -lopenal -lalut -lpthread -ltinyxml2
36 LDFLAGS += $(EXTRA_LIBS)
37 INSTALL_PROGRAM := install --mode=0755
38 INSTALL_DATA := install --mode=0644
39
40 # standard GNU directories
41 prefix ?= /usr/local
42 exec_prefix ?= $(prefix)
43 bindir := $(exec_prefix)/games
44 datarootdir := $(prefix)/share
45 datadir := $(datarootdir)/games
46 docdir := $(datarootdir)/doc/$(DISTNAME)
47
48 #
49 # phony targets, whose names aren't names of resulting files
50 #
51 # NOTE that several "standard" targets are missing; here
52 # `all` is `build` because I always felt "all" was a bad name,
53 # while the others I had either no time or no incentive to implement
54 #
55 .PHONY: build printvars install uninstall installdirs dist clean
56
57 # builds the executable
58 build: printvars $(TR_EXEFILE)
59
60 #
61 # prints the variables that the user can change;
62 # if VAR is in the list, then the user can change it by running:
63 #
64 # VAR="new value" make [target]
65 #
66 # examples:
67 # OPTIMS="-O0 -g" make
68 # prefix="/usr" exec_prefix="/usr" make install
69 #
70 printvars:
71 @printf "\ncurrent values of user-set variables:\n"
72 @printf "\tDESTDIR ?= %s\n" "$(DESTDIR)"
73 @printf "\tprefix ?= %s\n" "$(prefix)"
74 @printf "\texec_prefix ?= %s\n" "$(exec_prefix)"
75 @printf "\tOPTIMS ?= %s\n" "$(OPTIMS)"
76 @printf "\tWARNINGS ?= %s\n" "$(WARNINGS)"
77 @printf "\n"
78 @printf "resulting values of build variables:\n"
79 @printf "\tCXXFLAGS += %s\n" "$(CXXFLAGS)"
80 @printf "\tCPPFLAGS += %s\n" "$(CPPFLAGS)"
81 @printf "\tLDFLAGS += %s\n" "$(LDFLAGS)"
82 @printf "\n"
83
84 # installs the software (executable, data files and documentation)
85 install: installdirs build
86 @printf "\ninstall [%s] begin\n" "$(DISTNAME)"
87 @$(INSTALL_PROGRAM) "$(TR_EXEFILE)" "$(DESTDIR)$(bindir)"
88 @$(INSTALL_DATA) "$(TR_CFGFILE)" "$(DESTDIR)$(bindir)"
89 @for file in $(TR_DATAFILES); do \
90 $(INSTALL_DATA) -D "$(TR_DATADIR)/$$file" "$(DESTDIR)$(datadir)/$(DISTNAME)/$$file"; \
91 done
92 @for file in $(TR_DOCFILES); do \
93 $(INSTALL_DATA) -D "$(TR_DOCDIR)/$$file" "$(DESTDIR)$(docdir)/$$file"; \
94 done
95 @printf "install [%s] end\n\n" "$(DISTNAME)"
96
97 # deletes the software (executable, data files and documentation)
98 uninstall:
99 -@$(RM) --verbose "$(DESTDIR)$(bindir)/$(TR_EXENAME)"
100 -@$(RM) --verbose "$(DESTDIR)$(bindir)/$(TR_CFGNAME)"
101 -@$(RM) --verbose --recursive "$(DESTDIR)$(datadir)/$(DISTNAME)"
102 -@$(RM) --verbose --recursive "$(DESTDIR)$(docdir)"
103
104 # creates the installation directories if they do not exist
105 installdirs:
106 @printf "\nmkdir\t[installation directories]\n"
107 @mkdir --mode=0755 --parents \
108 "$(DESTDIR)$(bindir)" \
109 "$(DESTDIR)$(datadir)/$(DISTNAME)" \
110 "$(DESTDIR)$(docdir)"
111
112 #
113 # creates a zipped tarball for redistribution
114 #
115 # NOTE that this fails if the directory we're in isn't named $(DISTDIR) however
116 # this is by design: it's meant to enforce directory naming consistency and
117 # awareness of the $(DISTVER) variable, which you must update for each release!
118 #
119 dist: clean
120 @printf "\ntar -> \"../../%s\"\n" "$(DISTARC)"
121 @cd ../..; \
122 tar --owner=root --group=root --create --file="$(DISTARC)" --auto-compress "$(DISTDIR)"
123 @printf "md5sum -> \"../../%s.md5\"\n\n" "$(DISTARC)"
124 @cd ../..; \
125 md5sum "$(DISTARC)" > "$(DISTARC).md5"
126
127 # links the object files into the executable, which it then strips
128 $(TR_EXEFILE): $(OBJFILES)
•129 $(CXX) -o $@ $(OBJFILES) $(LDFLAGS)
•130 #@printf "strip\t%s\n" $@
131 #@strip $@
132
133 #
134 # removes object files, dependency files, executable and
135 # backup files (such as "func.cpp~")
136 #
137 clean:
138 -@$(RM) --verbose \
139 $(OBJFILES) \
140 $(DEPFILES) \
141 $(TR_EXEFILE) \
142 $(shell find -type f -name "*~")
143
144 #
145 # includes dependency files; these files are needed to speed up
146 # the build process by excluding the compilation of object files
147 # which are already up-to-date
148 #
149 -include $(DEPFILES)
150
151 #
152 # compiles source files to object files
153 #
154 # GNUmakefile was added as a dependency in order to trigger a rebuild
155 # if this makefile is edited
156 #
157 %.o: %.cpp GNUmakefile
•158 $(CXX) $(CXXFLAGS) $(CPPFLAGS) -MMD -MP -c $< -o $@