1# 2# Main Makefile, intended for use on Linux/X11 and compatible platforms 3# using GNU Make. 4# 5# It should guess the paths to the game dependencies on its own, except for 6# Boost which is assumed to be installed to the default locations. If you have 7# installed Boost to a non-standard location, you will need to override CXXFLAGS 8# and LDFLAGS with any applicable -I and -L arguments. 9# 10# The main options are: 11# 12# CCACHE The ccache binary that should be used when USE_CCACHE is 13# enabled (see below). Defaults to 'ccache'. 14# CXX C++ compiler comand line. 15# CXXFLAGS Additional C++ compiler options. 16# OPTIMIZE If set to 'yes' (default), builds with compiler 17# optimizations enabled (-O2). You may alternatively use 18# CXXFLAGS to set your own optimization options. 19# LDFLAGS Additional linker options. 20# USE_CCACHE If set to 'yes' (default), builds using the CCACHE binary 21# to run the compiler. If ccache is not installed (i.e. 22# found in PATH), this option has no effect. 23# 24 25OPTIMIZE=no 26CCACHE?=ccache 27USE_CCACHE?=$(shell which $(CCACHE) 2>&1 > /dev/null && echo yes) 28ifneq ($(USE_CCACHE),yes) 29CCACHE= 30endif 31 32ifeq ($(OPTIMIZE),yes) 33BASE_CXXFLAGS += -O2 34endif 35 36# Initial compiler options, used before CXXFLAGS and CPPFLAGS. 37BASE_CXXFLAGS += -fno-inline-functions -fthreadsafe-statics -Wnon-virtual-dtor -Wformat -Wswitch -Wno-narrowing 38 39# Compiler include options, used after CXXFLAGS and CPPFLAGS. 40INC := $(shell pkg-config --cflags x11 sdl glu glew SDL_image libpng zlib) 41 42# Linker library options. 43LIBS := $(shell pkg-config --libs x11 ) -lSDLmain \ 44 $(shell pkg-config --libs sdl glu glew SDL_image libpng zlib) -lSDL_ttf -lSDL_mixer 45 46include Makefile.common 47 48%.o : src/%.cpp 49 $(CCACHE) $(CXX) \ 50 $(BASE_CXXFLAGS) $(CXXFLAGS) $(CPPFLAGS) $(INC) -DIMPLEMENT_SAVE_PNG \ 51 -c $< 52 $(CXX) $(BASE_CXXFLAGS) $(CXXFLAGS) $(CPPFLAGS) $(INC) -DIMPLEMENT_SAVE_PNG -MM $< > $*.d 53 @mv -f $*.d $*.d.tmp 54 @sed -e 's|.*:|$*.o:|' < $*.d.tmp > $*.d 55 @sed -e 's/.*://' -e 's/\\$$//' < $*.d.tmp | fmt -1 | \ 56 sed -e 's/^ *//' -e 's/$$/:/' >> $*.d 57 @rm -f $*.d.tmp 58 59game: $(objects) 60 $(CCACHE) $(CXX) \ 61 $(BASE_CXXFLAGS) $(LDFLAGS) $(CXXFLAGS) $(CPPFLAGS) $(INC) \ 62 $(objects) -o game \ 63 $(LIBS) -lboost_regex -lboost_system -lpthread -fthreadsafe-statics 64 65# pull in dependency info for *existing* .o files 66-include $(objects:.o=.d) 67 68server: $(server_objects) 69 $(CCACHE) $(CXX) \ 70 $(BASE_CXXFLAGS) $(LDFLAGS) $(CXXFLAGS) $(CPPFLAGS) \ 71 $(server_objects) -o server \ 72 $(LIBS) -lboost_regex -lboost_system -lboost_thread -lboost_iostreams 73 74clean: 75 rm -f *.o *.d game 76 77assets: 78 ./game --utility=compile_levels 79 ./game --utility=compile_objects 80