1# This file is used by Makefile and declares common build rules,
2# a list of common object files etc.
3#
4
5######################################################################
6# The default build target: just build the residualvm executable
7######################################################################
8
9all: $(EXECUTABLE) plugins
10
11
12######################################################################
13# Module settings
14######################################################################
15#ResidualVM: added 'math':
16
17PLUGINS :=
18MODULES := test devtools base $(MODULES)
19
20-include engines/engines.mk
21
22# After the game specific modules follow the shared modules
23MODULES += \
24	gui \
25	backends \
26	engines \
27	video \
28	image \
29	graphics \
30	audio \
31	math \
32	common \
33	po
34
35ifdef USE_MT32EMU
36MODULES += audio/softsynth/mt32
37endif
38
39######################################################################
40# The build rules follow - normally you should have no need to
41# touch whatever comes after here.
42######################################################################
43
44# Concat DEFINES and INCLUDES to form the CPPFLAGS
45CPPFLAGS := $(DEFINES) $(INCLUDES)
46
47# Include the build instructions for all modules
48-include $(addprefix $(srcdir)/, $(addsuffix /module.mk,$(MODULES)))
49
50# Depdir information
51DEPDIRS = $(addsuffix $(DEPDIR),$(MODULE_DIRS))
52DEPFILES =
53
54# Make base/version.o depend on all other object files. This way if anything is
55# changed, it causes version.cpp to be recompiled. This in turn ensures that
56# the build date in gScummVMBuildDate is correct.
57base/version.o: $(filter-out base/libbase.a,$(OBJS))
58
59ifdef USE_ELF_LOADER
60backends/plugins/elf/version.o: $(filter-out base/libbase.a,$(filter-out backends/libbackends.a,$(OBJS)))
61endif
62
63# Replace regular output with quiet messages
64ifneq ($(findstring $(MAKEFLAGS),s),s)
65ifneq ($(VERBOSE_BUILD),1)
66ifneq ($(VERBOSE_BUILD),yes)
67QUIET_CC      = @echo '   ' C '      ' $@;
68QUIET_CXX     = @echo '   ' C++ '    ' $@;
69QUIET_AS      = @echo '   ' AS '     ' $@;
70QUIET_NASM    = @echo '   ' NASM '   ' $@;
71QUIET_AR      = @echo '   ' AR '     ' $@;
72QUIET_RANLIB  = @echo '   ' RANLIB ' ' $@;
73QUIET_PLUGIN  = @echo '   ' PLUGIN ' ' $@;
74QUIET_LINK    = @echo '   ' LINK '   ' $@;
75QUIET_WINDRES = @echo '   ' WINDRES '' $@;
76QUIET         = @
77endif
78endif
79endif
80
81# The build rule for the ResidualVM executable
82$(EXECUTABLE): $(OBJS)
83	$(QUIET_LINK)$(LD) $(LDFLAGS) $(PRE_OBJS_FLAGS) $+ $(POST_OBJS_FLAGS) $(LIBS) -o $@
84
85distclean: clean clean-devtools
86	$(RM) config.h config.mk config.log engines/engines.mk engines/plugins_table.h
87
88clean:
89	$(RM_REC) $(DEPDIRS)
90	$(RM) $(OBJS) $(EXECUTABLE)
91
92
93#
94# The build rules for object files.
95#
96
97ifdef CXX_UPDATE_DEP_FLAG
98
99# Build rule for C++ files. Makes use of CXX_UPDATE_DEP_FLAG for advanced
100# dependency tracking.
101%.o: %.c
102	$(QUIET)$(MKDIR) $(*D)/$(DEPDIR)
103	$(QUIET_CC)$(CC) $(CXX_UPDATE_DEP_FLAG) $(CFLAGS) $(CPPFLAGS) -c $(<) -o $*.o
104%.o: %.cpp
105	$(QUIET)$(MKDIR) $(*D)/$(DEPDIR)
106	$(QUIET_CXX)$(CXX) $(CXX_UPDATE_DEP_FLAG) $(CXXFLAGS) $(CPPFLAGS) -c $(<) -o $*.o
107
108
109# Build rules for Objective-C and Objective-C++ files. Strictly speaking, this is for OS X only.
110%.o: %.mm
111	$(QUIET)$(MKDIR) $(*D)/$(DEPDIR)
112	$(QUIET_CXX)$(CXX) $(CXX_UPDATE_DEP_FLAG) $(CXXFLAGS) $(CPPFLAGS) -c $(<) -o $*.o
113
114%.o: %.m
115	$(QUIET)$(MKDIR) $(*D)/$(DEPDIR)
116	$(QUIET_CXX)$(CXX) $(CXX_UPDATE_DEP_FLAG) $(CPPFLAGS) $(OBJCFLAGS) -c $(<) -o $*.o
117
118# Build rule for assembler files with preprocessing
119%.o: %.S
120	$(QUIET)$(MKDIR) $(*D)/$(DEPDIR)
121	$(QUIET_AS)$(CXX) $(CXX_UPDATE_DEP_FLAG) $(ASFLAGS) -c $(<) -o $*.o
122
123else
124
125# Dumb compile rule, for C++ compilers that don't allow dependency tracking or
126# where it is broken (such as GCC 2.95).
127.cpp.o:
128	$(QUIET)$(MKDIR) $(*D)
129	$(QUIET_CXX)$(CXX) $(CXXFLAGS) $(CPPFLAGS) -c $(<) -o $*.o
130
131# Build rule for assembler files with preprocessing
132%.o: %.S
133	$(QUIET)$(MKDIR) $(*D)
134	$(QUIET_AS)$(CXX) $(ASFLAGS) -c $(<) -o $*.o
135
136endif
137
138# Build rule for assembler files
139%.o: %.s
140	$(QUIET)$(MKDIR) $(*D)
141	$(QUIET_AS)$(AS) $(ASFLAGS) $(<) -o $*.o
142
143ifdef USE_NASM
144# Build rule for NASM assembler files
145%.o: %.asm
146	$(QUIET)$(MKDIR) $(*D)
147	$(QUIET_NASM)$(NASM) $(NASMFLAGS) -o $*.o $(<)
148endif
149
150# Include the dependency tracking files.
151-include $(wildcard $(addsuffix /*.d,$(DEPDIRS)))
152
153# Mark *.d files and most *.mk files as PHONY. This stops make from trying to
154# recreate them (which it can't), and in particular from looking for potential
155# source files. This can save quite a bit of disk access time.
156.PHONY: $(wildcard $(addsuffix /*.d,$(DEPDIRS))) $(addprefix $(srcdir)/, $(addsuffix /module.mk,$(MODULES))) \
157	$(srcdir)/$(port_mk) $(srcdir)/rules.mk
158
159######################################################################
160# Get the current version information
161######################################################################
162
163# AmigaOS4's grep has a problem with "./" in pathnames, so use cat piped into grep.
164VERSION = $(shell cat "${srcdir}/base/internal_version.h" | grep SCUMMVM_VERSION | cut -d\" -f2)
165VER_MAJOR = $(shell echo $(VERSION) | cut -d. -f 1)
166VER_MINOR = $(shell echo $(VERSION) | cut -d. -f 2)
167VER_PATCH = $(shell echo $(VERSION) | cut -d. -f 3 | cut -c1)
168VER_EXTRA = $(shell echo $(VERSION) | cut -d. -f 3 | cut -c2-)
169
170ifdef AMIGAOS
171# Amiga needs date in specific format for the version cookie
172AMIGA_DATE = $(shell gdate '+%d.%m.%Y')
173base/version.o: CXXFLAGS:=$(CXXFLAGS) -DAMIGA_DATE=\"$(AMIGA_DATE)\"
174endif
175
176######################################################################
177# Get git's working copy information
178######################################################################
179
180ifneq ($(shell cd $(srcdir); git rev-parse --verify HEAD 1>/dev/null 2>&1 || echo "error"),error)
181GITROOT := $(srcdir)
182ifeq ($(origin VER_REV), undefined)
183# Are there uncommitted changes? (describe --dirty is only available since 1.6.6)
184VER_DIRTY := $(shell cd $(srcdir); git update-index --refresh --unmerged 1>/dev/null 2>&1; git diff-index --quiet HEAD || echo "-dirty")
185# Get the working copy base revision
186#ResidualVM: --always
187VER_REV := $(shell cd $(srcdir); git describe --always --long --match desc/\* | cut -d '-' -f 2-)$(VER_DIRTY)
188endif
189else
190GITROOT := git://github.com/residualvm/residualvm.git
191endif
192
193# Define the Subversion revision if available, either autodetected or
194# specified by the user, but only for base/version.cpp.
195ifneq ($(origin VER_REV), undefined)
196base/version.o: CXXFLAGS:=$(CXXFLAGS) -DSCUMMVM_REVISION=\"$(VER_REV)\"
197endif
198
199######################################################################
200# Distribution settings
201######################################################################
202
203ifeq ($(VER_EXTRA),git)
204ifeq ($(origin VER_REV), undefined)
205DISTVERSION = $(shell date '+%Y-%m-%d')
206else
207DISTVERSION = git$(VER_REV)
208endif
209else
210DISTVERSION = $(VERSION)
211endif
212
213DISTNAME := residualvm-$(DISTVERSION)
214DISTDIR := dist
215VERFILE := $(DISTDIR)/$(DISTNAME)/base/internal_version.h
216
217# TODO git via $(GITROOT)
218$(VERFILE): $(srcdir)/base/internal_version.h
219	@$(RM_REC) $(DISTDIR)
220	@$(MKDIR) $(DISTDIR)
221	svn export $(SVNROOT) $(DISTDIR)/$(DISTNAME)
222ifneq ($(origin VER_REV), undefined)
223	@# Use the current SVN revision as a default for the snapshot sources
224	@svn cat $(SVNROOT)/base/internal_version.h | sed -e \
225		"s/^#define SCUMMVM_REVISION$$/#define SCUMMVM_REVISION \"$(VER_REV)\"/g" \
226		> $(VERFILE)
227endif
228
229$(DISTDIR)/$(DISTNAME).tar.gz: $(VERFILE)
230	cd $(DISTDIR); tar zcf $(DISTNAME).tar.gz $(DISTNAME)
231
232$(DISTDIR)/$(DISTNAME).tar.bz2: $(VERFILE)
233	cd $(DISTDIR); tar jcf $(DISTNAME).tar.bz2 $(DISTNAME)
234
235$(DISTDIR)/$(DISTNAME).zip: $(VERFILE)
236	cd $(DISTDIR); zip -qr9 $(DISTNAME).zip $(DISTNAME)
237
238dist-src: \
239	$(DISTDIR)/$(DISTNAME).tar.gz \
240	$(DISTDIR)/$(DISTNAME).tar.bz2 \
241	$(DISTDIR)/$(DISTNAME).zip
242	@#RPM-src?
243	@#DEB-src?
244
245# Common files
246DIST_FILES_DOCS:=$(addprefix $(srcdir)/,AUTHORS COPYING COPYING.BSD COPYING.LGPL COPYING.FREEFONT COPYING.ISC COPYING.LUA COPYING.MIT COPYING.TINYGL COPYRIGHT KNOWN_BUGS NEWS README.md)
247
248# Themes files
249DIST_FILES_THEMES=modern.zip
250ifdef USE_TRANSLATION
251DIST_FILES_THEMES+=translations.dat
252endif
253DIST_FILES_THEMES:=$(addprefix $(srcdir)/gui/themes/,$(DIST_FILES_THEMES))
254
255# Networking files
256DIST_FILES_NETWORKING=
257ifdef USE_SDL_NET
258DIST_FILES_NETWORKING:=$(addprefix $(srcdir)/dists/networking/,wwwroot.zip)
259endif
260
261# Engine data files
262DIST_FILES_ENGINEDATA=
263ifdef ENABLE_GRIM
264DIST_FILES_ENGINEDATA+=residualvm-grim-patch.lab
265endif
266ifdef ENABLE_MONKEY4
267DIST_FILES_ENGINEDATA+=residualvm-emi-patch.m4b
268endif
269ifdef ENABLE_MYST3
270DIST_FILES_ENGINEDATA+=myst3.dat
271endif
272DIST_FILES_ENGINEDATA:=$(addprefix $(srcdir)/dists/engine-data/,$(DIST_FILES_ENGINEDATA))
273
274# ResidualVM specific
275# Shaders
276# DIST_FILES_SHADERS=
277DIST_FILES_SHADERS=
278ifdef USE_OPENGL_SHADERS
279ifdef ENABLE_GRIM
280DIST_FILES_SHADERS+=$(wildcard $(srcdir)/engines/grim/shaders/*)
281endif
282ifdef ENABLE_MYST3
283DIST_FILES_SHADERS+=$(wildcard $(srcdir)/engines/myst3/shaders/*)
284endif
285ifdef ENABLE_STARK
286DIST_FILES_SHADERS+=$(wildcard $(srcdir)/engines/stark/shaders/*)
287endif
288endif
289
290
291.PHONY: all clean distclean plugins dist-src
292