Makefile
changeset 3900 2c84ed52709d
parent 3866 b13553406a0a
child 3901 88d50f8030ce
equal deleted inserted replaced
3899:5ba7f20a14ca 3900:2c84ed52709d
    26 # clean: remove intermediate build files
    26 # clean: remove intermediate build files
    27 # mrproper: remove intermediate files and makefile configuration
    27 # mrproper: remove intermediate files and makefile configuration
    28 # upgradeconf: add new options to old Makefile.config
    28 # upgradeconf: add new options to old Makefile.config
    29 # osx: OS X application
    29 # osx: OS X application
    30 # release: used by OSX to make a dmg file ready to release
    30 # release: used by OSX to make a dmg file ready to release
       
    31 # unittest: compile and link ./yapf/unittest/unittest - test for some yapf related classes, and run it
    31 
    32 
    32 # Options:
    33 # Options:
    33 #
    34 #
    34 # Summary of OS choice defines
    35 # Summary of OS choice defines
    35 # WIN32: building on Windows
    36 # WIN32: building on Windows
   250 # Set output executable names
   251 # Set output executable names
   251 TTD=openttd$(EXE)
   252 TTD=openttd$(EXE)
   252 ENDIAN_CHECK=endian_check$(EXE)
   253 ENDIAN_CHECK=endian_check$(EXE)
   253 STRGEN=strgen/strgen$(EXE)
   254 STRGEN=strgen/strgen$(EXE)
   254 OSXAPP="OpenTTD.app"
   255 OSXAPP="OpenTTD.app"
       
   256 UNITTEST=unit_test$(EXE)
   255 
   257 
   256 ifdef RELEASE
   258 ifdef RELEASE
   257 REV:=$(RELEASE)
   259 REV:=$(RELEASE)
   258 else
   260 else
   259 REV := $(shell if test -d .svn; then svnversion . | awk '{ print "r"$$0 }'; fi)
   261 REV := $(shell if test -d .svn; then svnversion . | awk '{ print "r"$$0 }'; fi)
       
   262 endif
       
   263 
       
   264 # define flag to use for -lrt (some OSes overwrites this later for compatibility)
       
   265 ifndef LRT
       
   266 ifndef MORPHOS
       
   267 LRT:= -lrt
       
   268 endif
   260 endif
   269 endif
   261 
   270 
   262 # MorphOS needs builddate
   271 # MorphOS needs builddate
   263 BUILDDATE=`date +%d.%m.%y`
   272 BUILDDATE=`date +%d.%m.%y`
   264 
   273 
   265 # Check if there is a windres override
   274 # Check if there is a windres override
   266 ifndef WINDRES
   275 ifndef WINDRES
   267 WINDRES = windres
   276 WINDRES = windres
   268 endif
   277 endif
   269 
   278 
       
   279 # Check that CXX is defined. If not, then it's g++
       
   280 ifndef CXX
       
   281 CXX = g++
       
   282 endif
       
   283 
       
   284 # Check if CXX_HOST is defined. If not, it is CXX
       
   285 ifndef CXX_HOST
       
   286 CXX_HOST = $(CXX)
       
   287 endif
       
   288 
       
   289 # Check if we have a new target
       
   290 ifdef CXX_TARGET
       
   291 CXX = $(CXX_TARGET)
       
   292 endif
       
   293 
   270 # Check if CC_HOST is defined. If not, it is CC
   294 # Check if CC_HOST is defined. If not, it is CC
   271 ifndef CC_HOST
   295 ifndef CC_HOST
   272 CC_HOST = $(CC)
   296 CC_HOST = $(CC)
   273 endif
   297 endif
   274 ifndef CFLAGS_HOST
   298 ifndef CFLAGS_HOST
   283 CC_VERSION = $(shell $(CC) -dumpversion | cut -c 1,3)
   307 CC_VERSION = $(shell $(CC) -dumpversion | cut -c 1,3)
   284 
   308 
   285 # GNU make can only test for (in)equality
   309 # GNU make can only test for (in)equality
   286 # this is a workaround to test for >=
   310 # this is a workaround to test for >=
   287 ifeq ($(shell expr $(CC_VERSION) \>= 29), 1)
   311 ifeq ($(shell expr $(CC_VERSION) \>= 29), 1)
   288   CFLAGS += -O -Wall -Wno-multichar -Wsign-compare -Wstrict-prototypes -Wundef
   312   CFLAGS += -O -Wall -Wno-multichar -Wsign-compare -Wundef
       
   313   CC_CFLAGS += -Wstrict-prototypes
   289   CFLAGS += -Wwrite-strings -Wpointer-arith
   314   CFLAGS += -Wwrite-strings -Wpointer-arith
   290 endif
   315 endif
   291 ifeq ($(shell expr $(CC_VERSION) \>= 30), 1)
   316 ifeq ($(shell expr $(CC_VERSION) \>= 30), 1)
   292   CFLAGS += -W -Wno-unused-parameter
   317   CFLAGS += -W -Wno-unused-parameter
   293 endif
   318 endif
   294 ifeq ($(shell expr $(CC_VERSION) \>= 34), 1)
   319 ifeq ($(shell expr $(CC_VERSION) \>= 34), 1)
   295   CFLAGS += -Wdeclaration-after-statement -Wold-style-definition
   320   CC_CFLAGS += -Wdeclaration-after-statement -Wold-style-definition
   296 endif
   321 endif
   297 
   322 
   298 ifdef DEBUG
   323 ifdef DEBUG
   299   ifeq ($(shell expr $(DEBUG) \>= 1), 1)
   324   ifeq ($(shell expr $(DEBUG) \>= 1), 1)
   300     CFLAGS += -g -D_DEBUG
   325     CFLAGS += -g -D_DEBUG
   321 ifndef DEBUG
   346 ifndef DEBUG
   322 ifndef PROFILE
   347 ifndef PROFILE
   323 # Release mode
   348 # Release mode
   324 ifndef MORPHOS
   349 ifndef MORPHOS
   325 ifndef IRIX
   350 ifndef IRIX
       
   351 ifdef OSX
       
   352 # it appears that OSX can't handle automated stripping when mixing C and C++
       
   353 # we will do it manually in the target OSX_STRIP
       
   354 OSX_STRIP:=OSX_STRIP
       
   355 else
   326 # automatical strip breaks under morphos
   356 # automatical strip breaks under morphos
   327 BASECFLAGS += -s
   357 CC_CFLAGS += -s
   328 LDFLAGS += -s
   358 LDFLAGS += -s
       
   359 endif
   329 endif
   360 endif
   330 endif
   361 endif
   331 endif
   362 endif
   332 
   363 
   333 ifdef OSX
   364 ifdef OSX
   361 LDFLAGS += -mwin32
   392 LDFLAGS += -mwin32
   362 endif
   393 endif
   363 ifdef MINGW
   394 ifdef MINGW
   364 BASECFLAGS += -mno-cygwin
   395 BASECFLAGS += -mno-cygwin
   365 LDFLAGS += -mno-cygwin
   396 LDFLAGS += -mno-cygwin
       
   397 # -lrt fails with MINGW, so we disable it
       
   398 LRT:=
   366 endif
   399 endif
   367 endif
   400 endif
   368 
   401 
   369 CFLAGS += $(BASECFLAGS)
   402 CFLAGS += $(BASECFLAGS)
   370 
   403 
   386 endif
   419 endif
   387 endif
   420 endif
   388 
   421 
   389 ifdef MORPHOS
   422 ifdef MORPHOS
   390 # -Wstrict-prototypes generates much noise because of system headers
   423 # -Wstrict-prototypes generates much noise because of system headers
   391 CFLAGS += -Wno-strict-prototypes
   424 # and it also uses 4-byte bools in the C++ ABI, so C bools need to be that size as well for YAPF to work
       
   425 CFLAGS += -Wno-strict-prototypes -DFOUR_BYTE_BOOL
   392 endif
   426 endif
   393 
   427 
   394 ifdef SUNOS
   428 ifdef SUNOS
   395 CDEFS += -DSUNOS
   429 CDEFS += -DSUNOS
   396 ifdef WITH_NETWORK
   430 ifdef WITH_NETWORK
   446 else
   480 else
   447 LIBS += $(shell $(LIBPNG_CONFIG)  --L_opts $(PNGCONFIG_FLAGS))
   481 LIBS += $(shell $(LIBPNG_CONFIG)  --L_opts $(PNGCONFIG_FLAGS))
   448 endif
   482 endif
   449 endif
   483 endif
   450 
   484 
       
   485 # use std C++ lib:
       
   486 LIBS += -lstdc++
       
   487 ifndef MINGW
       
   488 	LIBS += -lc
       
   489 endif
       
   490 
   451 # iconv is enabled defaultly on OSX >= 10.3
   491 # iconv is enabled defaultly on OSX >= 10.3
   452 ifdef OSX
   492 ifdef OSX
   453 	ifndef JAGUAR
   493 	ifndef JAGUAR
   454 		WITH_ICONV=1
   494 		WITH_ICONV=1
   455 		LIBS += -liconv
   495 		LIBS += -liconv
   483 
   523 
   484 # OSX specific setup
   524 # OSX specific setup
   485 ifdef OSX
   525 ifdef OSX
   486 	# set the endian flag for OSX, that can't fail
   526 	# set the endian flag for OSX, that can't fail
   487 	ENDIAN_FORCE:=PREPROCESSOR
   527 	ENDIAN_FORCE:=PREPROCESSOR
       
   528 
       
   529 	# -lrt fails on OSX, so we disable it
       
   530 	LRT:=
   488 
   531 
   489 	ifndef DEDICATED
   532 	ifndef DEDICATED
   490 		LIBS += -framework QuickTime
   533 		LIBS += -framework QuickTime
   491 	endif
   534 	endif
   492 
   535 
   698 SRCS += window.c
   741 SRCS += window.c
   699 SRCS += music/null_m.c
   742 SRCS += music/null_m.c
   700 SRCS += sound/null_s.c
   743 SRCS += sound/null_s.c
   701 SRCS += video/dedicated_v.c
   744 SRCS += video/dedicated_v.c
   702 SRCS += video/null_v.c
   745 SRCS += video/null_v.c
       
   746 SRCS += yapf/follow_track.cpp
       
   747 SRCS += yapf/yapf_common.cpp
       
   748 SRCS += yapf/yapf_rail.cpp
       
   749 SRCS += yapf/yapf_road.cpp
       
   750 SRCS += yapf/yapf_ship.cpp
   703 
   751 
   704 # AI related files
   752 # AI related files
   705 SRCS += ai/ai.c
   753 SRCS += ai/ai.c
   706 SRCS += ai/default/default.c
   754 SRCS += ai/default/default.c
   707 SRCS += ai/trolly/build.c
   755 SRCS += ai/trolly/build.c
   784 # needs to be before all
   832 # needs to be before all
   785 OSX:=OSX
   833 OSX:=OSX
   786 endif
   834 endif
   787 
   835 
   788 
   836 
   789 all: endian_target.h endian_host.h $(UPDATECONFIG) $(LANGS) $(TTD) $(OSX)
   837 all: endian_target.h endian_host.h $(UPDATECONFIG) $(LANGS) $(TTD) $(OSX) $(UNITTEST)
   790 
   838 
   791 ifdef OSX
   839 ifdef OSX
   792 -include os/macosx/Makefile
   840 -include os/macosx/Makefile
   793 endif
   841 endif
   794 
   842 
   822 
   870 
   823 lang/%.lng: lang/%.txt $(STRGEN) lang/english.txt
   871 lang/%.lng: lang/%.txt $(STRGEN) lang/english.txt
   824 	@echo '===> Compiling language $(*F)'
   872 	@echo '===> Compiling language $(*F)'
   825 	$(Q)$(STRGEN) $(STRGEN_FLAGS) $< $(LANG_ERRORS) || rm -f $@
   873 	$(Q)$(STRGEN) $(STRGEN_FLAGS) $< $(LANG_ERRORS) || rm -f $@
   826 
   874 
       
   875 # stupid KUDr doesn't know how to setup unittest dependencies (so rm,cp,rm)
       
   876 # please don't blame him and repair it:
       
   877 unittest: endian_host.h $(UPDATECONFIG) $(UNITTEST) rununittest
       
   878 $(UNITTEST): yapf/unittest/unittest.cpp
       
   879 	@echo '===> Compiling and Linking $@'
       
   880 	$(Q)rm -f $(UNITTEST)
       
   881 	$(Q)$(CXX_HOST) $(CFLAGS_HOST) $(CDEFS) $< $(LIBS) $(LRT) -o $@
       
   882 
       
   883 .PHONY: unittest
       
   884 
       
   885 rununittest:
       
   886 	@echo '===> Starting unittest'
       
   887 	$(Q)./$(UNITTEST)
       
   888 .PHONY: rununittest
       
   889 
   827 ifdef MORPHOS
   890 ifdef MORPHOS
       
   891 
   828 release: all
   892 release: all
   829 	$(Q)rm -fr "/t/openttd-$(RELEASE)-morphos.lha"
   893 	$(Q)rm -fr "/t/openttd-$(RELEASE)-morphos.lha"
   830 	$(Q)mkdir -p "/t/"
   894 	$(Q)mkdir -p "/t/"
   831 	$(Q)mkdir -p "/t/openttd-$(RELEASE)-morphos"
   895 	$(Q)mkdir -p "/t/openttd-$(RELEASE)-morphos"
   832 	$(Q)mkdir -p "/t/openttd-$(RELEASE)-morphos/docs"
   896 	$(Q)mkdir -p "/t/openttd-$(RELEASE)-morphos/docs"
   875 
   939 
   876 
   940 
   877 clean:
   941 clean:
   878 	@echo '===> Cleaning up'
   942 	@echo '===> Cleaning up'
   879 # endian.h is out-dated and no longer in use, so it can be removed soon
   943 # endian.h is out-dated and no longer in use, so it can be removed soon
   880 	$(Q)rm -rf .deps *~ $(TTD) $(STRGEN) core table/strings.h $(LANGS) $(OBJS) $(OSX_MIDI_PLAYER_FILE) endian.h endian_host.h endian_target.h $(ENDIAN_CHECK) .OSX
   944 	$(Q)rm -rf .deps *~ $(TTD) $(STRGEN) core table/strings.h $(LANGS) $(OBJS) $(OSX_MIDI_PLAYER_FILE) endian.h endian_host.h endian_target.h $(ENDIAN_CHECK) .OSX $(UNITTEST)
   881 
   945 
   882 mrproper: clean
   946 mrproper: clean
   883 	$(Q)rm -rf $(MAKE_CONFIG)
   947 	$(Q)rm -rf $(MAKE_CONFIG)
   884 
   948 
   885 ifndef OSX
   949 ifndef OSX
   961 
  1025 
   962 depend:
  1026 depend:
   963 	@true # The include handles this automagically
  1027 	@true # The include handles this automagically
   964 
  1028 
   965 # Introduce the dependencies
  1029 # Introduce the dependencies
   966 ifeq ($(findstring $(MAKECMDGOALS), clean info depend mrproper upgradeconf $(MAKE_CONFIG)),)
  1030 ifeq ($(findstring $(MAKECMDGOALS), clean info depend mrproper upgradeconf unittest $(MAKE_CONFIG)),)
   967 -include $(DEPS)
  1031 -include $(DEPS)
   968 endif
  1032 endif
   969 
  1033 
   970 # Silence stale header dependency errors
  1034 # Silence stale header dependency errors
   971 %.h:
  1035 %.h:
   986 
  1050 
   987 ifndef NATIVE_OSX
  1051 ifndef NATIVE_OSX
   988 # OSX uses os/macosx/Makefile to compile files
  1052 # OSX uses os/macosx/Makefile to compile files
   989 %.o: %.c $(MAKE_CONFIG)
  1053 %.o: %.c $(MAKE_CONFIG)
   990 	@echo '===> Compiling $<'
  1054 	@echo '===> Compiling $<'
   991 	$(Q)$(CC) $(CFLAGS) $(CDEFS) -c -o $@ $<
  1055 	$(Q)$(CC) $(CC_CFLAGS) $(CFLAGS) $(CDEFS) -c -o $@ $<
   992 
  1056 
   993 %.o: %.cpp  $(MAKE_CONFIG)
  1057 %.o: %.cpp  $(MAKE_CONFIG)
   994 	@echo '===> Compiling $<'
  1058 	@echo '===> Compiling $<'
   995 	$(Q)$(CXX) $(CFLAGS) $(CDEFS) -c -o $@ $<
  1059 	$(Q)$(CXX) $(CFLAGS) $(CDEFS) -c -o $@ $<
   996 
  1060 
   997 %.o: %.m  $(MAKE_CONFIG)
  1061 %.o: %.m  $(MAKE_CONFIG)
   998 	@echo '===> Compiling $<'
  1062 	@echo '===> Compiling $<'
   999 	$(Q)$(CC) $(CFLAGS) $(CDEFS) -c -o $@ $<
  1063 	$(Q)$(CC) $(CC_CFLAGS) $(CFLAGS) $(CDEFS) -c -o $@ $<
  1000 endif
  1064 endif
  1001 
  1065 
  1002 %.o: %.rc
  1066 %.o: %.rc
  1003 	@echo '===> Compiling resource $<'
  1067 	@echo '===> Compiling resource $<'
  1004 	$(Q)$(WINDRES) -o $@ $<
  1068 	$(Q)$(WINDRES) -o $@ $<