forked from OpenTTD/grfcodec
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
279 lines (225 loc) · 7.68 KB
/
Makefile
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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
# =========================================================
# Makefile for the GRF development tools
#
# Don't put any local configuration in here
# Change Makefile.local instead, it'll be
# preserved when updating the sources
# =========================================================
PACKAGE_NAME = grfcodec
-include Makefile.local
# Gnu compiler settings
SHELL ?= /bin/sh
CXX ?= g++
STRIP ?=
UPX ?=
AWK ?= awk
SRCZIP_FLAGS ?= -9
SRCZIP ?= gzip
LIBPNG_CONFIG?= libpng-config
# OS detection: Cygwin vs Linux
ISCYGWIN ?= $(shell [ ! -d /cygdrive/ ]; echo $$?)
MACHINE ?= $(shell $(CXX) -dumpmachine || echo '??' )
# OS dependent variables
EXE ?= $(shell ( [ \( $(ISCYGWIN) -eq 1 \) -o \( "$(MACHINE)" = "mingw32" \) ] ) && echo .exe)
GRFCODEC ?= grfcodec$(EXE)
GRFID ?= grfid$(EXE)
GRFSTRIP ?= grfstrip$(EXE)
NFORENUM ?= nforenum$(EXE)
ENDIAN_CHECK ?= endian_check$(EXE)
TYPESIZE ?= GCC32
# Somewhat automatic detection of the correct boost include folder
ifndef BOOST_INCLUDE
BOOST_INCLUDE=$(shell \
find /usr/include /usr/local/include /opt/local/include -maxdepth 1 -name 'boost-*' 2> /dev/null | sort -t - -k 2 | tail -n 1 )
ifeq ($(BOOST_INCLUDE),)
BOOST_INCLUDE=$(shell \
( [ -d /usr/include/boost/date_time ] && echo /usr/include ) || \
( [ -d /usr/local/include/boost/date_time ] && echo /usr/local/include ) || \
( [ -d /opt/local/include/boost/date_time ] && echo /opt/local/include ) )
endif
endif
ifeq ($(BOOST_INCLUDE),)
BOOST_ERROR = echo Error: Boost not found. Compilation will fail.
endif
ifndef V
V=0 # verbose build default off
endif
ifndef FLAGS
ifeq ($(ISCYGWIN),1)
FLAGS = -I $(BOOST_INCLUDE) -O2
else
FLAGS = -idirafter$(BOOST_INCLUDE) -O2
endif
FLAGS += -D$(TYPESIZE) -D_FORTIFY_SOURCE=2
FLAGS += -Wall -Wextra -Wno-format-nonliteral
ifeq ($(DEBUG),1)
FLAGS += -DDEBUG
endif
ifeq ($(MACHINE),mingw32)
FLAGS += -DMINGW
endif
# Sadly enough fmemopen is
ifneq ($(shell grep fmemopen /usr/include/stdio.h 2> /dev/null | wc -l | sed "s/ *//"),0)
ifndef NO_FMEMOPEN
FLAGS += -DWITH_FMEMOPEN
endif
endif
ifeq ($(shell uname),Darwin)
FLAGS += -isystem/opt/local/include
endif
# GCC 4.5.0 has an optimisation bug that influences GRFCodec.
# As such we disable optimisation when GCC 4.5.0 is detected.
# The issue has been fixed in GCC 4.5.1
ifneq ($(shell $(CXX) -v 2>&1 | grep "4\.5\.0" || true),)
FLAGS += -O0
endif
# Complication of png support in grfcodec
ifneq ($(shell $(LIBPNG_CONFIG) --version 2>/dev/null),)
WITH_PNG = 0
FLAGS += -DWITH_PNG $(shell $(LIBPNG_CONFIG) --cflags)
endif
endif
MY_CXXFLAGS ?= $(FLAGS) $(CXXFLAGS)
# =======================================================================
# setup verbose/non-verbose make process
# =======================================================================
# _E = prefix for the echo [TYPE] TARGET
# _C = prefix for the actual command(s)
# _I = indentation for sub-make
# _Q = number of 'q's for UPX
# _S = sub-makes silent?
ifeq (${V},1)
# verbose, set _C = nothing (print command), _E = comment (don't echo)
_C=
_E=@\#
_Q=-qq
_S=
else
# not verbose, _C = @ (suppress cmd line), _E = @echo (echo type&target)
_C=@
_E:=@echo ${_I}
_Q=-qqq
_S=-s
endif
# increase indentation level for sub-makes
_I := ${_I}" "
export _I
# standard compilation commands should be of the form
# target: prerequisites
# ${_E} [CMD] $@
# ${_C}${CMD} ...arguments...
#
# non-standard commands (those not invoked by make all/dos/win) should
# use the regular syntax (without the ${_E} line and without the ${_C} prefix)
# because they'll be only used for testing special conditions
#
# =======================================================================
# sources to be compiled and linked
GRFCODECSRC=grfcomm.cpp pcxfile.cpp sprites.cpp pcxsprit.cpp pngsprit.cpp \
info.cpp globals.cpp mapescapes.cpp error.cpp path.cpp readinfo.cpp \
file.cpp grfcodec.cpp
GRFIDSRC=grfid.cpp md5.cpp
GRFSTRIPSRC=grfstrip.cpp
NFORENUMSRC=IDs.cpp act0.cpp act123.cpp act123_classes.cpp act5.cpp act6.cpp \
act79D.cpp actB.cpp actF.cpp act14.cpp command.cpp data.cpp globals.cpp \
inject.cpp messages.cpp pseudo.cpp rangedint.cpp nforenum.cpp sanity.cpp \
strings.cpp utf8.cpp help.cpp message_mgr.cpp language_mgr.cpp \
mapescapes.cpp pseudo_seq.cpp
PALORDER = ttd_norm&ttw_norm&ttd_cand&ttw_cand&tt1_norm&tt1_mars&ttw_pb_pal1&ttw_pb_pal2
PAL_FILES = pals/$(subst &,.bcp pals/,$(PALORDER)).bcp
# default targets
all: $(GRFCODEC) $(GRFID) $(GRFSTRIP) $(NFORENUM)
remake:
$(_E) [CLEAN]
$(_C)$(MAKE) ${_S} clean
$(_E) [REBUILD]
$(_C)$(MAKE) src/version.h src/endian.h
$(_C)$(MAKE) ${_S} all
$(GRFCODEC): $(GRFCODECSRC:%.cpp=objs/%.o)
$(_E) [LD] $@
ifdef WITH_PNG
$(_C)$(CXX) -o $@ $(MY_CXXFLAGS) $^ $(LDOPT) $(shell $(LIBPNG_CONFIG) --ldflags)
else
$(_C)$(CXX) -o $@ $(MY_CXXFLAGS) $^ $(LDOPT)
endif
$(GRFID): $(GRFIDSRC:%.cpp=objs/%.o)
$(_E) [LD] $@
$(_C)$(CXX) -o $@ $(MY_CXXFLAGS) $^ $(LDOPT)
$(GRFSTRIP): $(GRFSTRIPSRC:%.cpp=objs/%.o)
$(_E) [LD] $@
$(_C)$(CXX) -o $@ $(MY_CXXFLAGS) $^ $(LDOPT)
$(NFORENUM): $(NFORENUMSRC:%.cpp=objs/%.o)
$(_E) [LD] $@
$(_C)$(CXX) -o $@ $(MY_CXXFLAGS) $^ $(LDOPT)
clean:
$(_C)rm -rf objs $(GRFCODEC) $(GRFID) $(GRFSTRIP) $(NFORENUM) bundle bundles grfcodec-* src/endian.h
mrproper: clean
$(_C)rm -f src/version.h
$(_C)touch -ct 9901010000 ttdpal.h # don't delete it, so we don't confuse version control, but force it to be remade
distclean: mrproper
$(_C)rm -rf Makefile.local
FORCE:
@$(BOOST_ERROR)
include version.def
src/version.h: FORCE
@echo // Autogenerated by make. Do not edit. Edit version.def or the Makefile instead. > [email protected]
@echo "#define VERSION \"$(VERSIONSTR)\"" >> [email protected]
@echo "#define YEARS \"2004-$(YEAR)\"" >> [email protected]
@(diff [email protected] $@ > /dev/null 2>&1 && rm -f [email protected]) || (rm -f $@ ; mv [email protected] $@)
objs/$(ENDIAN_CHECK): src/endian_check.cpp
$(_C) mkdir -p objs
$(_E) [LD] $@
$(_C)$(CXX) -o $@ $(MY_CXXFLAGS) src/endian_check.cpp $(LDOPT)
src/endian.h: objs/$(ENDIAN_CHECK)
$(_E) [ENDIAN] Determining endianness
$(_C)objs/$(ENDIAN_CHECK) $(ENDIAN_PARAMS) > src/endian.h || rm src/endian.h
FORCE:
%_r: FORCE
$(_E) [REBUILD] $(@:%_r=%)
$(_C)rm -f $(@:%_r=%)
$(_C)$(MAKE) ${_S} $(@:%_r=%)
ifneq ($(STRIP),)
$(_E) [STRIP] $(@:%_r=%)
$(_C)$(STRIP) $(@:%_r=%)
endif
ifneq ($(UPX),)
$(_E) [UPX] $(@:%_r=%)
$(_C)$(UPX) $(_Q) --best $(@:%_r=%)
endif
.NOTPARALLEL release: FORCE $(GRFCODEC)_r $(GRFID)_r $(GRFSTRIP)_r $(NFORENUM)_r
src/ttdpal.h: $(PAL_FILES:%=src/%) src/pal2c.pl
$(_E) [PERL] $@
$(_C)perl src/pal2c.pl $(PAL_FILES:%=src/%) > $@
# Gnu compiler rules
objs/%.o : src/%.cpp Makefile
$(_E) [CPP] $@
$(_C)$(CXX) -c -o $@ $(MY_CXXFLAGS) -MMD -MF [email protected] -MT $@ $<
% : objs/%.o Makefile
$(_E) [LD] $@
$(_C)$(CXX) -o $@ $(MY_CXXFLAGS) $^ $(LDOPT)
$(_C)$(CP_TO_EXE)
# same as above but optimized for size not speed
objs/%.os : src/%.cpp Makefile
$(_E) [CPP] $@
$(_C)$(CXX) -c -o $@ $(MY_CXXFLAGS) -Os -MMD -MF [email protected] -MT $@ $<
% :: objs/%.os Makefile
$(_E) [LD] $@
$(_C)$(CXX) -o $@ $(MY_CXXFLAGS) $^ $(LDOPT)
# On some installations a version.h exists in /usr/include. This one is then
# found by the dependency tracker and thus the dependencies do not contain
# a reference to version.h, so it isn't generated and compilation fails.
objs/grfcodec.o: src/version.h
objs/grfid.o: src/version.h
objs/grfstrip.o: src/version.h
objs/message_mgr.o: src/version.h
objs/messages.o: src/version.h
objs/%.o.d: src/%.cpp Makefile src/endian.h
$(_E) [CPP DEP] $@
$(_C)$(CXX) $(MY_CXXFLAGS) -DMAKEDEP -MM -MG src/$*.cpp -MF $@
ifndef NO_MAKEFILE_DEP
-include $(GRFCODECSRC:%.cpp=objs/%.o.d)
-include $(GRFIDSRC:%.cpp=objs/%.o.d)
-include $(GRFSTRIPSRC:%.cpp=objs/%.o.d)
-include $(NFORENUMSRC:%.cpp=objs/%.o.d)
endif
include Makefile.bundle