2012-10-28 13:52:55 -07:00
|
|
|
###################################################
|
|
|
|
#
|
|
|
|
# Makefile for MCServer
|
|
|
|
# Creator: tedik
|
|
|
|
#
|
|
|
|
###################################################
|
|
|
|
#
|
|
|
|
# Info:
|
|
|
|
# This makefile is gnu-make spacific, other make systems needn't understand it
|
|
|
|
# This makefile generates include-file dependencies into *.d files in each build and then reuses these dependencies in the following builds
|
|
|
|
#
|
|
|
|
# Usage:
|
|
|
|
# To make a release build, call "make release=1"
|
|
|
|
# To make a debug build, call "make"
|
2013-08-15 00:20:50 -07:00
|
|
|
# To make a 32-bit build on 64-bit OS, pass the addm32=1 flag
|
|
|
|
# To build with clang, you need to add disableasm=1 flag
|
2012-10-28 13:52:55 -07:00
|
|
|
#
|
|
|
|
###################################################
|
|
|
|
|
|
|
|
#
|
|
|
|
# Macros
|
|
|
|
#
|
|
|
|
|
2013-09-10 12:38:06 -07:00
|
|
|
# allow user to override compiler
|
|
|
|
# if no compiler is specified make specifies cc
|
|
|
|
ifeq ($(CC),cc)
|
2012-10-28 13:52:55 -07:00
|
|
|
CC = /usr/bin/g++
|
2013-09-10 12:38:06 -07:00
|
|
|
endif
|
2012-10-28 13:52:55 -07:00
|
|
|
|
|
|
|
all: MCServer/MCServer
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
###################################################
|
|
|
|
# Set the variables used for compiling, based on the build mode requested:
|
|
|
|
# CC_OPTIONS ... options for the C code compiler
|
|
|
|
# CXX_OPTIONS ... options for the C++ code compiler
|
|
|
|
# LNK_OPTIONS ... options for the linker
|
2013-04-07 14:15:10 -07:00
|
|
|
# LNK_LIBS ... libraries to link in
|
|
|
|
# -- according to http://stackoverflow.com/questions/6183899/undefined-reference-to-dlopen, libs must come after all sources
|
2012-10-28 13:52:55 -07:00
|
|
|
# BUILDDIR ... folder where the intermediate object files are built
|
|
|
|
|
|
|
|
ifeq ($(release),1)
|
|
|
|
################
|
|
|
|
# release build - fastest run-time, no gdb support
|
|
|
|
################
|
2013-11-13 11:41:05 -08:00
|
|
|
|
2013-12-03 12:40:58 -08:00
|
|
|
CC_OPTIONS = -O3 -DNDEBUG -DLUA_USE_DLOPEN
|
|
|
|
CXX_OPTIONS = -O3 -DNDEBUG -DLUA_USE_DLOPEN
|
2013-11-26 23:19:12 -08:00
|
|
|
LNK_OPTIONS = -pthread -O3
|
|
|
|
|
2012-10-28 13:52:55 -07:00
|
|
|
BUILDDIR = build/release/
|
|
|
|
|
|
|
|
else
|
|
|
|
ifeq ($(profile),1)
|
|
|
|
################
|
|
|
|
# profile build - a release build with symbols and profiling engine built in
|
|
|
|
################
|
2013-11-13 11:41:05 -08:00
|
|
|
|
2013-12-03 12:40:58 -08:00
|
|
|
CC_OPTIONS = -g -ggdb -O3 -pg -DNDEBUG -DLUA_USE_DLOPEN
|
|
|
|
CXX_OPTIONS = -g -ggdb -O3 -pg -DNDEBUG -DLUA_USE_DLOPEN
|
2013-11-26 23:19:12 -08:00
|
|
|
LNK_OPTIONS = -pthread -ggdb -O3 -pg
|
2013-11-26 14:37:44 -08:00
|
|
|
|
2012-10-28 13:52:55 -07:00
|
|
|
BUILDDIR = build/profile/
|
|
|
|
|
|
|
|
else
|
|
|
|
################
|
|
|
|
# debug build - fully traceable by gdb in C++ code, slowest
|
2013-11-24 10:44:22 -08:00
|
|
|
# Since C code is used only for supporting libraries (zlib, lua), it is still Ofast-optimized
|
2012-10-28 13:52:55 -07:00
|
|
|
################
|
2013-11-13 11:41:05 -08:00
|
|
|
|
2013-12-03 12:40:58 -08:00
|
|
|
CC_OPTIONS = -ggdb -g -D_DEBUG -O3 -DLUA_USE_DLOPEN
|
|
|
|
CXX_OPTIONS = -ggdb -g -D_DEBUG -O1 -DLUA_USE_DLOPEN
|
2013-11-27 08:57:28 -08:00
|
|
|
LNK_OPTIONS = -pthread -g -ggdb -O1
|
2013-11-27 09:18:40 -08:00
|
|
|
|
2012-10-28 13:52:55 -07:00
|
|
|
BUILDDIR = build/debug/
|
2013-11-27 09:18:40 -08:00
|
|
|
|
2012-10-28 13:52:55 -07:00
|
|
|
endif
|
|
|
|
endif
|
|
|
|
|
2013-11-16 09:49:14 -08:00
|
|
|
##################################################
|
|
|
|
# Always be warning.
|
|
|
|
|
|
|
|
CXX_OPTIONS += -Wall
|
2012-10-28 13:52:55 -07:00
|
|
|
|
2013-09-10 12:59:24 -07:00
|
|
|
###################################################
|
2013-09-10 13:17:13 -07:00
|
|
|
# Fix Crypto++ warnings in clang
|
|
|
|
|
2013-12-14 06:47:29 -08:00
|
|
|
ifeq ($(shell $(CXX) --version 2>&1 | grep -i -c "clang"),1)
|
2013-11-27 09:18:40 -08:00
|
|
|
CC_OPTIONS += -DCRYPTOPP_DISABLE_ASM
|
|
|
|
CXX_OPTIONS += -DCRYPTOPP_DISABLE_ASM
|
2013-09-10 12:59:24 -07:00
|
|
|
endif
|
2013-09-10 13:17:13 -07:00
|
|
|
|
2012-10-28 13:52:55 -07:00
|
|
|
|
2013-08-11 23:29:02 -07:00
|
|
|
###################################################
|
|
|
|
# Set the link libraries based on the OS
|
|
|
|
# Linux uses libdl
|
|
|
|
# FreeBSD uses libltdl
|
|
|
|
# TODO: other OSs?
|
|
|
|
|
|
|
|
UNAME := $(shell uname -s)
|
|
|
|
ifeq ($(UNAME),Linux)
|
2013-11-13 11:36:04 -08:00
|
|
|
LNK_LIBS = -lstdc++ -ldl -lm
|
2013-08-11 23:29:02 -07:00
|
|
|
else
|
|
|
|
LNK_LIBS = -lstdc++ -lltdl
|
|
|
|
endif
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2013-12-03 12:40:58 -08:00
|
|
|
###################################################
|
|
|
|
# Export all symbols from the executable, so that LuaRocks may bind to Lua routines:
|
|
|
|
LNK_OPTIONS += -rdynamic
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2013-08-15 00:20:50 -07:00
|
|
|
###################################################
|
2013-04-10 00:42:39 -07:00
|
|
|
# 32-bit build override in 64-bit build environments
|
2013-08-15 00:20:50 -07:00
|
|
|
|
2013-04-10 00:42:39 -07:00
|
|
|
ifeq ($(addm32),1)
|
|
|
|
CC_OPTIONS += -m32
|
|
|
|
CXX_OPTIONS += -m32
|
|
|
|
LNK_OPTIONS += -m32
|
|
|
|
endif
|
|
|
|
|
2012-10-28 13:52:55 -07:00
|
|
|
|
|
|
|
|
2013-08-15 00:20:50 -07:00
|
|
|
|
|
|
|
|
|
|
|
|
2012-10-28 13:52:55 -07:00
|
|
|
###################################################
|
|
|
|
# INCLUDE directories for MCServer
|
|
|
|
|
2013-11-27 09:18:40 -08:00
|
|
|
INCLUDE = -Isrc\
|
2013-11-26 14:37:44 -08:00
|
|
|
-Ilib\
|
2013-11-27 00:17:25 -08:00
|
|
|
-Ilib/jsoncpp/include
|
2012-11-08 11:09:35 -08:00
|
|
|
|
|
|
|
|
2012-10-28 13:52:55 -07:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
###################################################
|
|
|
|
# Build MCServer
|
2012-11-08 11:09:35 -08:00
|
|
|
|
2013-11-24 06:57:44 -08:00
|
|
|
SOURCES := $(shell find src lib '(' -name '*.cpp' -o -name '*.c' ')')
|
2012-10-28 13:52:55 -07:00
|
|
|
SOURCES := $(filter-out %minigzip.c %lua.c %tolua.c %toluabind.c %LeakFinder.cpp %StackWalker.cpp %example.c,$(SOURCES))
|
|
|
|
OBJECTS := $(patsubst %.c,$(BUILDDIR)%.o,$(SOURCES))
|
|
|
|
OBJECTS := $(patsubst %.cpp,$(BUILDDIR)%.o,$(OBJECTS))
|
|
|
|
|
|
|
|
-include $(patsubst %.o,%.d,$(OBJECTS))
|
|
|
|
|
|
|
|
MCServer/MCServer : $(OBJECTS)
|
2013-04-07 14:15:10 -07:00
|
|
|
$(CC) $(LNK_OPTIONS) $(OBJECTS) $(LNK_LIBS) -o MCServer/MCServer
|
2012-10-28 13:52:55 -07:00
|
|
|
|
|
|
|
clean :
|
|
|
|
rm -rf $(BUILDDIR) MCServer/MCServer
|
|
|
|
|
|
|
|
install : MCServer
|
|
|
|
cp MCServer MCServer
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
###################################################
|
|
|
|
# Build the parts of MCServer
|
|
|
|
#
|
|
|
|
# options used:
|
|
|
|
# -x c ... compile as C code
|
|
|
|
# -c ... compile but do not link
|
|
|
|
# -MM ... generate a list of includes
|
|
|
|
|
|
|
|
$(BUILDDIR)%.o: %.c
|
|
|
|
@mkdir -p $(dir $@)
|
|
|
|
$(CC) $(CC_OPTIONS) -x c -c $(INCLUDE) $< -o $@
|
|
|
|
@$(CC) $(CC_OPTIONS) -x c -MM $(INCLUDE) $< > $(patsubst %.o,%.d,$@)
|
|
|
|
@mv -f $(patsubst %.o,%.d,$@) $(patsubst %.o,%.d,$@).tmp
|
|
|
|
@sed -e "s|.*:|$(BUILDDIR)$*.o:|" < $(patsubst %.o,%.d,$@).tmp > $(patsubst %.o,%.d,$@)
|
|
|
|
@sed -e 's/.*://' -e 's/\\$$//' < $(patsubst %.o,%.d,$@).tmp | fmt -1 | sed -e 's/^ *//' -e 's/$$/:/' >> $(patsubst %.o,%.d,$@)
|
|
|
|
@rm -f $(patsubst %.o,%.d,$@).tmp
|
|
|
|
|
|
|
|
$(BUILDDIR)%.o: %.cpp
|
|
|
|
@mkdir -p $(dir $@)
|
|
|
|
$(CC) $(CXX_OPTIONS) -c $(INCLUDE) $< -o $@
|
|
|
|
@$(CC) $(CXX_OPTIONS) -MM $(INCLUDE) $< > $(patsubst %.o,%.d,$@)
|
|
|
|
@mv -f $(patsubst %.o,%.d,$@) $(patsubst %.o,%.d,$@).tmp
|
|
|
|
@sed -e "s|.*:|$(BUILDDIR)$*.o:|" < $(patsubst %.o,%.d,$@).tmp > $(patsubst %.o,%.d,$@)
|
|
|
|
@sed -e 's/.*://' -e 's/\\$$//' < $(patsubst %.o,%.d,$@).tmp | fmt -1 | sed -e 's/^ *//' -e 's/$$/:/' >> $(patsubst %.o,%.d,$@)
|
|
|
|
@rm -f $(patsubst %.o,%.d,$@).tmp
|