2007-01-02 19:19:48 +00:00
# Auto-generated file -- DO NOT EDIT
CC_HOST = !!CC_HOST!!
CXX_HOST = !!CXX_HOST!!
CC_BUILD = !!CC_BUILD!!
2007-01-10 18:56:51 +00:00
CXX_BUILD = !!CXX_BUILD!!
2007-01-02 19:19:48 +00:00
WINDRES = !!WINDRES!!
STRIP = !!STRIP!!
CC_CFLAGS = !!CC_CFLAGS!!
CFLAGS = !!CFLAGS!!
CFLAGS_BUILD = !!CFLAGS_BUILD!!
LIBS = !!LIBS!!
LDFLAGS = !!LDFLAGS!!
BIN_DIR = !!BIN_DIR!!
LANG_DIR = !!LANG_DIR!!
SRC_OBJS_DIR = !!SRC_OBJS_DIR!!
LANG_OBJS_DIR = !!LANG_OBJS_DIR!!
SRC_DIR = !!SRC_DIR!!
MEDIA_DIR = !!MEDIA_DIR!!
TTD = !!TTD!!
STRGEN = !!STRGEN!!
ENDIAN_CHECK = !!ENDIAN_CHECK!!
ENDIAN_FORCE = !!ENDIAN_FORCE!!
OS = !!OS!!
STAGE = !!STAGE!!
MAKEDEPEND = !!MAKEDEPEND!!
CFLAGS_MAKEDEP = !!CFLAGS_MAKEDEP!!
SORT = !!SORT!!
2007-01-05 15:01:51 +00:00
REVISION = !!REVISION!!
2007-02-19 19:59:19 +00:00
AWK = !!AWK!!
2007-04-21 13:19:43 +00:00
GCC295 = !!GCC295!!
2007-01-02 19:19:48 +00:00
CONFIG_CACHE_COMPILER = $( SRC_OBJS_DIR) /!!CONFIG_CACHE_COMPILER!!
CONFIG_CACHE_LINKER = $( SRC_OBJS_DIR) /!!CONFIG_CACHE_LINKER!!
CONFIG_CACHE_ENDIAN = $( SRC_OBJS_DIR) /!!CONFIG_CACHE_ENDIAN!!
CONFIG_CACHE_SOURCE = $( SRC_OBJS_DIR) /!!CONFIG_CACHE_SOURCE!!
CONFIG_CACHE_VERSION = $( SRC_OBJS_DIR) /!!CONFIG_CACHE_VERSION!!
OBJS_C := !!OBJS_C!!
OBJS_CPP := !!OBJS_CPP!!
2007-02-05 21:16:56 +00:00
OBJS_MM := !!OBJS_MM!!
2007-01-02 19:19:48 +00:00
OBJS_RC := !!OBJS_RC!!
2007-02-05 21:16:56 +00:00
OBJS := $( OBJS_C) $( OBJS_CPP) $( OBJS_MM) $( OBJS_RC)
2007-01-02 19:19:48 +00:00
SRCS := !!SRCS!!
# All C-files depend on those 3 files
FILE_DEP := $( CONFIG_CACHE_COMPILER) $( LANG_OBJS_DIR) /table/strings.h endian_target.h
# Create all dirs and subdirs
RES := $( shell mkdir -p $( BIN_DIR) $( sort $( dir $( OBJS) ) ) )
# Make sure endian_target.h is reasable as if it was in the src/ dir
CFLAGS += -I $( SRC_OBJS_DIR) -I $( LANG_OBJS_DIR)
ENDIAN_TARGETS := endian_target.h $( ENDIAN_CHECK)
2007-04-21 13:19:43 +00:00
# This 'sed' basicly just removes 'const' from the line if it is a 2+D array
# For more information, please check:
# http://maillist.openttd.org/pipermail/devs/2007-April/000284.html
# http://maillist.openttd.org/pipermail/devs/2007-February/000248.html
GCC295_FIX = sed -r 's/^(\t*)(.*)( const )([A-Za-z0-9_ ]+(\[.*\]){2,})(( = \{)|(;))(.*)$$/\1\2 \4\6\8\9/g'
# This 'sed' removes the 3rd '4' in the # lines of the -E output of
# gcc 2.95.3 and lower, as it should indicate that it is a C-linkage, but the
# compiler can't handle that information (just don't ask). So we remove it
# and then it compiles happily and without bitching :)
2007-07-14 20:40:11 +00:00
# Furthermore gcc 2.95 has some trouble with protected and private when
# accessing the protected/private stuff of the enclosing class (or the
# super class of the enclosing class).
GCC295_FIX_2 = sed -e 's|\(^\# [0-9][0-9]* "[^"]*"[ 0-9]*\) 4$$|\1|g;s|private:|public:|g;s|protected:|public:|g'
2007-04-21 13:19:43 +00:00
2007-01-02 19:19:48 +00:00
# Check if we want to show what we are doing
i f d e f V E R B O S E
Q =
E = @true
e l s e
Q = @
E = @echo
e n d i f
# Our default target
2007-01-11 18:26:53 +00:00
all : $( BIN_DIR ) /$( TTD )
2007-01-02 19:19:48 +00:00
# This are 2 rules that are pointing back to STRGEN stuff.
# There is not really a need to have them here, but in case
# some weirdo wants to run 'make' in the 'src' dir and expects
# the languages to be recompiled, this catches that case and
# takes care of it nicely.
$(LANG_OBJS_DIR)/$(STRGEN) :
$( MAKE) -C $( LANG_OBJS_DIR) $( STRGEN)
$(LANG_OBJS_DIR)/table/strings.h : $( LANG_DIR ) /english .txt $( LANG_OBJS_DIR ) /$( STRGEN )
$( MAKE) -C $( LANG_OBJS_DIR) table/strings.h
# Make the revision number
i f d e f R E V I S I O N
REV := $( REVISION)
2007-10-21 20:14:15 +00:00
REV_NR := $( shell echo $( REVISION) | sed "s/[^0-9]//g" )
2007-01-02 19:19:48 +00:00
e l s e
# Are we a SVN dir?
i f e q ( $( shell if test -d $ ( SRC_DIR ) /.svn ; then echo 1; fi ) , 1 )
# Find if the local source if modified
REV_MODIFIED := $( shell svnversion $( SRC_DIR) | sed -n 's/.*\(M\).*/\1/p' )
# Find the revision like: rXXXX-branch
2007-02-19 19:59:19 +00:00
REV := $( shell LC_ALL = C svn info $( SRC_DIR) | $( AWK) '/^URL:.*branch/ { split($$2, a, "/"); BRANCH="-"a[5] } /^Last Changed Rev:/ { REV="r"$$4"$(REV_MODIFIED)" } END { print REV BRANCH }' )
2007-10-21 14:59:05 +00:00
REV_NR := $( shell LC_ALL = C svn info $( SRC_DIR) | $( AWK) '/^Last Changed Rev:/ { print $$4 }' )
2007-06-07 00:25:49 +00:00
e l s e
# Are we a git dir?
i f e q ( $( shell if test -d $ ( SRC_DIR ) /../.git ; then echo 1; fi ) , 1 )
2007-09-23 10:26:20 +00:00
# Find the revision like: gXXXXM-branch
2007-11-18 22:37:44 +00:00
REV := g$( shell if head = ` LC_ALL = C git rev-parse --verify HEAD 2>/dev/null` ; then echo " $$ head " | cut -c1-8; fi ) $( shell if cd " $( SRC_DIR) /.. " && git diff-index HEAD src | read dummy; then echo M; fi ) $( shell git branch| grep '[*]' | sed 's/\* /-/;s/^-master$$//' )
2007-11-18 20:38:24 +00:00
REV_NR := $( shell LC_ALL = C cd " $( SRC_DIR) /.. " && git log --pretty= format:%s src | grep -m 1 "^(svn r[0-9]*)" | sed "s/.*(svn r\([0-9]*\)).*/\1/" )
2007-09-23 10:26:20 +00:00
e l s e
# Are we a hg (Mercurial) dir?
i f e q ( $( shell if test -d $ ( SRC_DIR ) /../.hg ; then echo 1; fi ) , 1 )
# Find the revision like: hXXXXM-branch
2007-10-21 17:19:18 +00:00
REV := h$( shell if head = ` LC_ALL = C hg tip 2>/dev/null` ; then echo " $$ head " | head -n 1 | cut -c19-26; fi ) $( shell if hg status $( SRC_DIR) | grep -v '^?' | read dummy; then echo M; fi ) $( shell hg branch | sed 's/^/-/;s/^-default$$//' )
2007-11-18 20:38:24 +00:00
REV_NR := $( shell LC_ALL = C hg log -k "svn" -l 1 --template "{desc}\n" $( SRC_DIR) | grep -m 1 "^(svn r[0-9]*)" | sed "s/.*(svn r\([0-9]*\)).*/\1/" )
2007-09-23 10:26:20 +00:00
e n d i f
2007-06-07 00:25:49 +00:00
e n d i f
2007-01-02 19:19:48 +00:00
e n d i f
e n d i f
2007-06-07 00:25:49 +00:00
2007-01-02 19:19:48 +00:00
# Make sure we have something in REV
i f e q ( $( REV ) , )
REV := norev000
2007-10-21 14:59:05 +00:00
REV_NR := 0
2007-01-02 19:19:48 +00:00
e n d i f
# This helps to recompile if flags change
RES := $( shell if [ " `cat $( CONFIG_CACHE_COMPILER) 2>/dev/null` " != " $( CC_CFLAGS) $( CFLAGS) " ] ; then echo " $( CC_CFLAGS) $( CFLAGS) " > $( CONFIG_CACHE_COMPILER) ; fi )
RES := $( shell if [ " `cat $( CONFIG_CACHE_LINKER) 2>/dev/null` " != " $( LDFLAGS) $( LIBS) " ] ; then echo " $( LDFLAGS) $( LIBS) " > $( CONFIG_CACHE_LINKER) ; fi )
RES := $( shell if [ " `cat $( CONFIG_CACHE_ENDIAN) 2>/dev/null` " != " $( ENDIAN_FORCE) " ] ; then echo " $( ENDIAN_FORCE) " > $( CONFIG_CACHE_ENDIAN) ; fi )
# If there is a change in the source-file-list, make sure we recheck the deps
RES := $( shell if [ " `cat $( CONFIG_CACHE_SOURCE) 2>/dev/null` " != " $( SRCS) " ] ; then echo " $( SRCS) " > $( CONFIG_CACHE_SOURCE) ; fi )
2007-01-10 18:56:51 +00:00
# If there is a change in the revision, make sure we recompile rev.cpp
2007-01-02 19:19:48 +00:00
RES := $( shell if [ " `cat $( CONFIG_CACHE_VERSION) 2>/dev/null` " != " $( REV) " ] ; then echo " $( REV) " > $( CONFIG_CACHE_VERSION) ; fi )
i f n d e f M A K E D E P E N D
# The slow, but always correct, dep-check
DEP_MASK := %.d
DEPS := $( OBJS:%.o= %.d)
# Only include the deps if we are compiling everything
i f e q ( $( filter $ ( ENDIAN_TARGETS ) %.o clean mrproper , $ ( MAKECMDGOALS ) ) , )
- i n c l u d e $( DEPS )
e l s e
# In case we want to compile a single target, include the .d file for it
i f n e q ( $( filter %.o , $ ( MAKECMDGOALS ) ) , )
SINGLE_DEP := $( filter %.o, $( MAKECMDGOALS) )
-include $(SINGLE_DEP : %.o =%.d )
e n d i f
e n d i f
# Find the deps via GCC. Rarely wrong, but a bit slow
$(OBJS_C : %.o =%.d ): %.d : $( SRC_DIR ) /%.c $( FILE_DEP )
$( E) '$(STAGE) DEP $(<:$(SRC_DIR)/%.c=%.c)'
$( Q) $( CC_HOST) $( CC_CFLAGS) $( CFLAGS) -MM $< | sed 's#^$(@F:%.d=%.o):#$@ $(@:%.d=%.o):#' > $@
$(OBJS_CPP : %.o =%.d ): %.d : $( SRC_DIR ) /%.cpp $( FILE_DEP )
$( E) '$(STAGE) DEP $(<:$(SRC_DIR)/%.cpp=%.cpp)'
$( Q) $( CXX_HOST) $( CFLAGS) -MM $< | sed 's#^$(@F:%.d=%.o):#$@ $(@:%.d=%.o):#' > $@
2007-02-05 21:16:56 +00:00
$(OBJS_MM : %.o =%.d ): %.d : $( SRC_DIR ) /%.mm $( FILE_DEP )
$( E) '$(STAGE) DEP $(<:$(SRC_DIR)/%.mm=%.mm)'
$( Q) $( CC_HOST) $( CFLAGS) -MM $< | sed 's#^$(@F:%.d=%.o):#$@ $(@:%.d=%.o):#' > $@
2007-01-02 19:19:48 +00:00
2007-01-02 20:19:25 +00:00
$(OBJS_RC : %.o =%.d ): %.d : $( SRC_DIR ) /%.rc $( FILE_DEP )
2007-02-05 21:16:56 +00:00
$( E) '$(STAGE) DEP $(<:$(SRC_DIR)/%.mm=%.mm)'
2007-01-02 20:19:25 +00:00
$( Q) touch $@
2007-01-02 19:19:48 +00:00
e l s e
# The much faster, but can be wrong, dep-check
DEP_MASK :=
DEPS := Makefile.dep
# Only include the deps if we are not cleaning
i f e q ( $( filter $ ( ENDIAN_TARGETS ) depend clean mrproper , $ ( MAKECMDGOALS ) ) , )
- i n c l u d e M a k e f i l e . d e p
e n d i f
# Make sure that only 'make depend' ALWAYS triggers a recheck
i f e q ( $( filter depend , $ ( MAKECMDGOALS ) ) , )
Makefile.dep : $( FILE_DEP ) $( SRCS :%=$ ( SRC_DIR ) /%) $( CONFIG_CACHE_SOURCE )
e l s e
Makefile.dep : FORCE
e n d i f
$( E) '$(STAGE) DEP CHECK (all files)'
$( Q) rm -f Makefile.dep.tmp
$( Q) touch Makefile.dep.tmp
# Calculate the deps via makedepend
$( Q) $( MAKEDEPEND) -f$( SRC_OBJS_DIR) /Makefile.dep.tmp -o.o -Y -v -- $( CFLAGS_MAKEDEP) -- $( SRCS:%= $( SRC_DIR) /%) 2>/dev/null
# Convert x:/... paths to /x/... for mingw
i f e q ( $( OS ) , M I N G W )
2007-02-22 00:33:39 +00:00
@cat Makefile.dep.tmp | sed 's@\([a-zA-Z]\):\/@\/\1\/@g' > Makefile.dep.tmp.mingw
2007-01-02 19:19:48 +00:00
@cp Makefile.dep.tmp.mingw Makefile.dep.tmp
@rm -f Makefile.dep.tmp.mingw
e n d i f
# Remove all comments and includes that don't start with $(SRC_DIR)
# Remove $(SRC_DIR) from object-file-name
2007-02-19 19:59:19 +00:00
@$( AWK) ' \
2007-01-02 19:19:48 +00:00
/^# DO NOT/ { print $$ 0 ; next} \
/^#/ { next} \
/:/ { \
left = NF - 1; \
for ( n = 2; n <= NF; n++) { \
if ( match( $$ n, " ^ $( SRC_DIR) " ) = = 0) { \
$$ n = "" ; \
left--; \
} \
} \
gsub( " $( SRC_DIR) / " , "" , $$ 1) ; \
if ( left > 0) { \
print $$ 0; \
$$ 1 = "Makefile.dep:" ; \
print $$ 0; \
} \
next \
} \
{ \
print $$ 0 \
} \
' < Makefile.dep.tmp | sed ' s/ */ /g; s/ $$ //' | $( SORT) > Makefile.dep
$( Q) rm -f Makefile.dep.tmp Makefile.dep.tmp.bak
e n d i f
2007-01-13 18:44:38 +00:00
# Avoid problems with deps if a .h/.hpp file is deleted without the deps
2007-01-02 19:19:48 +00:00
# being updated. Now the Makefile continues, the deps are recreated
# and all will be fine.
2007-01-13 18:44:38 +00:00
%.h %.hpp :
2007-01-02 19:19:48 +00:00
@true
# Compile all the files according to the targets
$(OBJS_C) : %.o : $( SRC_DIR ) /%.c $( DEP_MASK ) $( FILE_DEP )
$( E) '$(STAGE) Compiling $(<:$(SRC_DIR)/%.c=%.c)'
$( Q) $( CC_HOST) $( CC_CFLAGS) $( CFLAGS) -c -o $@ $<
$(OBJS_CPP) : %.o : $( SRC_DIR ) /%.cpp $( DEP_MASK ) $( FILE_DEP )
$( E) '$(STAGE) Compiling $(<:$(SRC_DIR)/%.cpp=%.cpp)'
2007-04-21 13:19:43 +00:00
i f e q ( $( GCC 295) , 1 )
$( Q) $( CXX_HOST) -E $( CFLAGS) $< | $( GCC295_FIX) | $( GCC295_FIX_2) | $( CXX_HOST) $( CFLAGS) -c -o $@ -x c++ -
e l s e
2007-01-02 19:19:48 +00:00
$( Q) $( CXX_HOST) $( CFLAGS) -c -o $@ $<
2007-04-21 13:19:43 +00:00
e n d i f
2007-01-02 19:19:48 +00:00
2007-02-05 21:16:56 +00:00
$(OBJS_MM) : %.o : $( SRC_DIR ) /%.mm $( DEP_MASK ) $( FILE_DEP )
$( E) '$(STAGE) Compiling $(<:$(SRC_DIR)/%.mm=%.mm)'
$( Q) $( CC_HOST) $( CFLAGS) -c -o $@ $<
2007-01-02 19:19:48 +00:00
$(OBJS_RC) : %.o : $( SRC_DIR ) /%.rc $( FILE_DEP )
$( E) '$(STAGE) Compiling resource $(<:$(SRC_DIR)/%.rc=%.rc)'
$( Q) $( WINDRES) -o $@ -I $( MEDIA_DIR) $<
2007-01-11 18:26:53 +00:00
$(BIN_DIR)/$(TTD) : $( TTD )
$( Q) cp $< $@
2007-09-12 07:11:48 +00:00
$(TTD) : $( OBJS ) $( CONFIG_CACHE_LINKER )
2007-01-02 19:19:48 +00:00
$( E) '$(STAGE) Linking $@'
2007-02-11 16:28:00 +00:00
i f e q ( $( OS ) , P S P )
2007-02-19 21:18:39 +00:00
# Because of a bug in the PSP GCC tools, linking via CXX results
# in total chaos and more problems then you can handle. So we need
# CC to link OpenTTD for PSP
2007-09-12 07:11:48 +00:00
$( Q) $( CC_HOST) $( LDFLAGS) $( OBJS) $( LIBS) -o $@
2007-02-11 16:28:00 +00:00
e l s e
2007-09-12 07:11:48 +00:00
$( Q) $( CXX_HOST) $( LDFLAGS) $( OBJS) $( LIBS) -o $@
2007-02-11 16:28:00 +00:00
e n d i f
2007-01-02 19:19:48 +00:00
i f d e f S T R I P
$( Q) $( STRIP) $@
e n d i f
# The targets to compile the endian-code
endian_target.h : $( ENDIAN_CHECK ) $( CONFIG_CACHE_ENDIAN )
$( E) '$(STAGE) Testing endianness for target'
$( Q) ./$( ENDIAN_CHECK) $( ENDIAN_FORCE) > $@
2007-01-10 18:56:51 +00:00
$(ENDIAN_CHECK) : $( SRC_DIR ) /endian_check .cpp
2007-01-02 19:19:48 +00:00
$( E) '$(STAGE) Compiling and Linking $@'
2007-01-10 18:56:51 +00:00
$( Q) $( CXX_BUILD) $( CFLAGS_BUILD) $< -o $@
2007-01-02 19:19:48 +00:00
# Revision files
2007-09-12 07:11:48 +00:00
$(SRC_DIR)/rev.cpp : $( CONFIG_CACHE_VERSION ) $( SRC_DIR ) /rev .cpp .in
2007-10-21 14:59:05 +00:00
$( Q) cat $( SRC_DIR) /rev.cpp.in | sed " s#@@REVISION@@# $( REV_NR) #g;s#@@VERSION@@# $( REV) #g;s#@@DATE@@#`date +%d.%m.%y`#g " > $( SRC_DIR) /rev.cpp
2007-01-02 19:19:48 +00:00
2007-09-12 07:11:48 +00:00
$(SRC_DIR)/ottdres.rc : $( CONFIG_CACHE_VERSION ) $( SRC_DIR ) /ottdres .rc .in
2007-10-21 14:59:05 +00:00
$( Q) cat $( SRC_DIR) /ottdres.rc.in | sed " s#@@REVISION@@# $( REV_NR) #g;s#@@VERSION@@# $( REV) #g;s#@@DATE@@#`date +%d.%m.%y`#g " > $( SRC_DIR) /ottdres.rc
2007-01-02 19:19:48 +00:00
FORCE :
depend : $( DEPS )
clean :
$( E) '$(STAGE) Cleaning up object files'
2007-09-12 07:11:48 +00:00
$( Q) rm -f $( DEPS) $( OBJS) $( TTD) $( TTD:%= $( BIN_DIR) /%) $( CONFIG_CACHE_COMPILER) $( CONFIG_CACHE_LINKER) $( CONFIG_CACHE_ENDIAN) $( CONFIG_CACHE_SOURCE) $( ENDIAN_TARGETS)
2007-01-02 19:19:48 +00:00
mrproper : clean
2007-09-12 07:11:48 +00:00
$( Q) rm -f $( SRC_DIR) /rev.cpp $( SRC_DIR) /ottdres.rc
2007-01-02 19:19:48 +00:00
%.o :
2007-02-10 00:22:32 +00:00
@echo '$(STAGE) No such source-file: $(@:%.o=%).[c|cpp|mm|rc]'
2007-01-02 19:19:48 +00:00
.PHONY : all mrproper depend clean FORCE