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
|
# =========================================================
# Makefile for GRFCodec
#
# Don't put any local configuration in here
# Change Makefile.local instead, it'll be
# preserved when updating the sources
# =========================================================
MAKEFILELOCAL=Makefile.local
# Order of the palettes compiled in
# (note, this must match the text in grfcodec.cpp and grftut.txt)
PALORDER = ttd_norm&ttw_norm&ttd_cand&ttw_cand&tt1_norm&tt1_mars&ttw_pb_pal1&ttw_pb_pal2
# Gnu compiler settings
SHELL = /bin/sh
CXX = g++
STRIP = strip
UPX = $(shell [ `which upx 2>/dev/null` ] && echo "upx")
AWK = awk
SRCZIP_FLAGS = -9
SRCZIP = gzip
# Default installation directories
INSTALL_DOCS_DIR := "$(DESTDIR)/usr/share/doc/grfcodec"
INSTALL_BINARY_DIR := "$(DESTDIR)/usr/bin"
INSTALL_MAN_DIR := "$(DESTDIR)/usr/share/man/man1"
# OS detection: Cygwin vs Linux
ISCYGWIN = $(shell [ ! -d /cygdrive/ ]; echo $$?)
MACHINE = $(shell $(CXX) -dumpmachine || echo '??' )
# Cygwin builds default to -mno-cygwin.
ifndef NOCYGWIN
NOCYGWIN = 1
endif
# OS dependent variables
EXE = $(shell ( [ \( $(ISCYGWIN) -eq 1 \) -o \( "$(MACHINE)" = "mingw32" \) ] ) && echo .exe)
GRFCODEC = grfcodec$(EXE)
GRFDIFF = grfdiff$(EXE)
GRFMERGE = grfmerge$(EXE)
GRFID = grfid$(EXE)
TYPESIZE = GCC32
FLAGS = -D$(TYPESIZE) -I. -idirafter$(BOOST_INCLUDE) -D_FORTIFY_SOURCE=2
FLAGS += -Wall -Wno-uninitialized -Wsign-compare -Wwrite-strings -Wpointer-arith -W -Wno-unused-parameter -Wformat=2 -Wredundant-decls
ifeq ($(DEBUG),1)
FLAGS += -DDEBUG
endif
ifeq ($(MACHINE),mingw32)
FLAGS += -DMINGW
endif
ifeq ($(ISCYGWIN),1)
ifeq ($(NOCYGWIN),1)
FLAGS += -DMINGW -mno-cygwin
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
-include ${MAKEFILELOCAL}
CXXFLAGS := $(FLAGS) $(CXXFLAGS)
# 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
# =======================================================================
# 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 info.cpp \
error.cpp getopt.cpp path.cpp readinfo.cpp file.cpp grfcodec.cpp
GRFDIFFSRC=grfcomm.cpp error.cpp sprites.cpp getopt.cpp grfdiff.cpp path.cpp
GRFMERGESRC=grfcomm.cpp error.cpp getopt.cpp grfmerge.cpp path.cpp
GRFIDSRC=grfid.cpp
PAL_FILES = pals/$(subst &,.bcp pals/,$(PALORDER)).bcp
# deafult targets
all: $(GRFCODEC) $(GRFDIFF) $(GRFMERGE) $(GRFID)
remake:
$(_E) [CLEAN]
$(_C)$(MAKE) ${_S} clean
$(_E) [REBUILD]
$(_C)$(MAKE) ${_S} all
${MAKEFILELOCAL}:
@/bin/sh -c "export PATH=\"/bin\" && \
echo ${MAKEFILELOCAL} did not exist, using defaults. Please edit it if compilation fails. && \
cp ${MAKEFILELOCAL}.sample $@"
$(GRFCODEC): $(GRFCODECSRC:%.cpp=objs/%.o)
$(_E) [LD] $@
$(_C)$(CXX) -o $@ $(CXXFLAGS) $^ $(LDOPT)
$(GRFDIFF): $(GRFDIFFSRC:%.cpp=objs/%.o) objs/grfmrg.o
$(_E) [LD] $@
$(_C)$(CXX) -o $@ $(CXXFLAGS) $^ $(LDOPT)
$(GRFMERGE): $(GRFMERGESRC:%.cpp=objs/%.o)
$(_E) [LD] $@
$(_C)$(CXX) -o $@ $(CXXFLAGS) $^ $(LDOPT)
$(GRFID): $(GRFIDSRC:%.cpp=objs/%.o)
$(_E) [LD] $@
$(_C)$(CXX) -o $@ $(CXXFLAGS) $^ $(LDOPT)
clean:
rm -rf objs $(GRFCODEC) $(GRFDIFF) $(GRFMERGE) $(GRFID) bundle bundles grfcodec-*
mrproper: clean
rm -f *.d src/version.h src/grfmrg.c
@touch -ct 9901010000 ttdpal.h # don't delete it, so we don't confuse svn, but force it to be remade
FORCE:
@$(BOOST_ERROR)
include version.def
src/version.h: FORCE
@echo // Autogenerated by make. Do not edit. Edit version.def or the Makefile instead. > $@.tmp
@echo "#define GRFCODECVER \"$(VERSIONSTR)\"" >> $@.tmp
@(diff $@.tmp $@ > /dev/null 2>&1 && rm -f $@.tmp) || (rm -f $@ ; mv $@.tmp $@ || true)
FORCE:
%_r: FORCE
$(_E) [REBUILD] $(@:%_r=%)
$(_C)rm -f $(@:%_r=%)
$(_C)$(MAKE) ${_S} $(@:%_r=%)
$(_E) [STRIP] $(@:%_r=%)
$(_C)$(STRIP) $(@:%_r=%)
ifneq ($(UPX),)
$(_E) [UPX] $(@:%_r=%)
$(_C)$(UPX) $(_Q) --best $(@:%_r=%)
endif
release: FORCE $(GRFCODEC)_r $(GRFDIFF)_r $(GRFMERGE)_r $(GRFID)_r
# make grfmerge.exe (as grfmrgc.bin) optimized for size instead of speed
objs/grfmrgc.bin: objs/grfmerge.os $(GRFMERGESRC:%.cpp=objs/%.os)
$(_C)rm -f $@
$(_E) [LD] $@
$(_C)$(CXX) -o $@ $(CXXFLAGS) -Os $^
$(_E) [STRIP] $@
$(_C)$(STRIP) $@
ifneq ($(UPX),)
$(_E) [UPX] $@
$(_C)$(UPX) $(_Q) --best $@
endif
src/grfmrg.cpp: objs/grfmrgc.bin src/grfmrgc.pl
$(_E) [PERL] $@
$(_C)perl -w src/grfmrgc.pl > $@
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 $@ $(CXXFLAGS) -MMD -MF $@.d -MT $@ $<
% : objs/%.o Makefile
$(_E) [LD] $@
$(_C)$(CXX) -o $@ $(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 $@ $(CXXFLAGS) -Os -MMD -MF $@.d -MT $@ $<
% :: objs/%.os Makefile
$(_E) [LD] $@
$(_C)$(CXX) -o $@ $(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/grfmerge.o: src/version.h
objs/grfmerge.os: src/version.h
objs/grfdiff.o: src/version.h
objs/grfidc.o: src/version.h
objs/%.o.d: src/%.cpp Makefile
$(_C)mkdir -p objs
$(_E) [CPP DEP] $@
$(_C)$(CXX) $(CXXFLAGS) -DMAKEDEP -MM -MG src/$*.cpp -MF $@
ifndef NO_MAKEFILE_DEP
-include $(GRFCODECSRC:%.cpp=objs/%.o.d)
-include $(GRFMERGESRC:%.cpp=objs/%.o.d)
-include $(GRFDIFFSRC:%.cpp=objs/%.o.d)
-include $(GRFIDSRC:%.cpp=objs/%.o.d)
-include $(GRFMERGESRC:%.cpp=objs/%.os.d)
-include $(GRFCODECSRC:%.cpp=objs/%.obj.d)
-include $(GRFMERGESRC:%.cpp=objs/%.obj.d)
-include $(GRFDIFFSRC:%.cpp=objs/%.obj.d)
-include $(GRFIDSRC:%.cpp=objs/%.obj.d)
endif
include Makefile.bundle
|