Slight makefile reorganization and cleanup.

* Centralize optimization strategies in Makefile.common. This required moving detection of $(PLATFORM), which makes sense if we work on the paradigm that Makefile.common is for generic compiler setup and Makefile.shared works with libraries and things closer to the engine and game code itself.
* New Makefile variables OPTOPT (Optimization Options) and CUSTOMOPT (Custom Optimizations). OPTOPT by default contains -march, -mtune, etc. Setting this variable from Make invocation will blank these. CUSTOMOPT (Custom Optimizations) works the same but in an additive fashion, overwriting nothing. Technically CUSTOMOPT could stand for (Custom Options) and include any additional parameters sent to both linker and compiler.
* Factor out literal names of the main executables.
* The build process now prints assembler (if NOASM=0) and linker settings in addition to compiler settings.

git-svn-id: https://svn.eduke32.com/eduke32@3096 1a8010ca-5511-0410-912e-c29ae57300e0
This commit is contained in:
hendricks266 2012-10-29 04:26:25 +00:00
parent a3fe057c0a
commit f51bdc2faa
5 changed files with 162 additions and 116 deletions

View file

@ -53,13 +53,9 @@ JAUDIOLIB=libjfaudiolib.a
ENETDIR=$(SRC)/enet
ENETLIB=libenet.a
EBACKTRACEDLL=ebacktrace1.dll
EBACKTRACEDLL_TARGET=
include $(EROOT)/Makefile.shared
ifneq (0,$(USE_LIBVPX))
ifeq ($(PLATFORM),WINDOWS)
LIBS+= -LWindows/lib
@ -72,6 +68,18 @@ ifneq (0,$(USE_LIBVPX))
endif
endif
EDUKE32 ?= eduke32$(EXESUFFIX)
MAPSTER32 ?= mapster32$(EXESUFFIX)
EDUKE32_TARGET:=$(EDUKE32)
ifneq ($(PLATFORM),WII)
MAPSTER32_TARGET:=$(MAPSTER32)
endif
EBACKTRACEDLL ?= ebacktrace1.dll
EBACKTRACEDLL_TARGET:=
ifeq ($(PLATFORM),WINDOWS)
OBJ=obj_win
EOBJ=eobj_win
@ -316,11 +324,6 @@ ifeq ($(PRETTY_OUTPUT),1)
endif
.PHONY: clean all engine $(EOBJ)/$(ENGINELIB) $(EOBJ)/$(EDITORLIB) $(JAUDIOLIBDIR)/$(JAUDIOLIB) $(ENETDIR)/$(ENETLIB)
EDUKE32_TARGET:=eduke32$(EXESUFFIX)
ifneq ($(PLATFORM),WII)
MAPSTER32_TARGET:=mapster32$(EXESUFFIX)
endif
# TARGETS
all: notice $(EDUKE32_TARGET) $(MAPSTER32_TARGET) $(EBACKTRACEDLL_TARGET)
@ -328,45 +331,46 @@ all: notice $(EDUKE32_TARGET) $(MAPSTER32_TARGET) $(EBACKTRACEDLL_TARGET)
all:
$(BUILD_FINISHED)
ifneq (,$(EDUKE32_TARGET))
@ls -l $(EDUKE32_TARGET)
@ls -l $(EDUKE32)
endif
ifneq (,$(MAPSTER32_TARGET))
@ls -l $(MAPSTER32_TARGET)
@ls -l $(MAPSTER32)
endif
notice:
$(BUILD_STARTED)
eduke32$(EXESUFFIX): $(GAMEOBJS) $(EOBJ)/$(ENGINELIB) $(JAUDIOLIBDIR)/$(JAUDIOLIB) $(ENETDIR)/$(ENETLIB) $(MISCGAMEDEPS)
$(EDUKE32): $(GAMEOBJS) $(EOBJ)/$(ENGINELIB) $(JAUDIOLIBDIR)/$(JAUDIOLIB) $(ENETDIR)/$(ENETLIB) $(MISCGAMEDEPS)
$(LINK_STATUS)
if $(CC) $(OURCONLYFLAGS) $(OURCFLAGS) -o $@ $^ $(OURLDFLAGS) $(GAMELDFLAGS) $(LIBS) $(STATICSTDCPP) $(STDCPPLIB); then $(LINK_OK); else $(LINK_FAILED); fi
ifeq (1,$(RELEASE))
ifeq (0,$(DEBUGANYWAY))
ifneq ($(PLATFORM),WII)
$(STRIP) $(EDUKE32_TARGET)
$(STRIP) $(EDUKE32)
endif
endif
endif
ifeq ($(PLATFORM),DARWIN)
cp -RPf "Apple/bundles/EDuke32.app" "./"
mkdir -p "EDuke32.app/Contents/MacOS"
cp -f "$(EDUKE32_TARGET)" "EDuke32.app/Contents/MacOS/"
cp -f "$(EDUKE32)" "EDuke32.app/Contents/MacOS/"
endif
mapster32$(EXESUFFIX): $(EDITOROBJS) $(EOBJ)/$(EDITORLIB) $(EOBJ)/$(ENGINELIB) $(JAUDIOLIBDIR)/$(JAUDIOLIB)
$(MAPSTER32): $(EDITOROBJS) $(EOBJ)/$(EDITORLIB) $(EOBJ)/$(ENGINELIB) $(JAUDIOLIBDIR)/$(JAUDIOLIB)
$(LINK_STATUS)
if $(CC) $(OURCONLYFLAGS) $(OURCFLAGS) -o $@ $^ $(OURLDFLAGS) $(EDITORLDFLAGS) $(LIBS) $(STATICSTDCPP) $(STDCPPLIB); then $(LINK_OK); else $(LINK_FAILED); fi
ifeq (1,$(RELEASE))
ifeq (0,$(DEBUGANYWAY))
ifneq ($(PLATFORM),WII)
$(STRIP) $(MAPSTER32_TARGET)
$(STRIP) $(MAPSTER32)
endif
endif
endif
ifeq ($(PLATFORM),DARWIN)
cp -RPf "Apple/bundles/Mapster32.app" "./"
mkdir -p "Mapster32.app/Contents/MacOS"
cp -f "$(MAPSTER32_TARGET)" "Mapster32.app/Contents/MacOS/"
cp -f "$(MAPSTER32)" "Mapster32.app/Contents/MacOS/"
endif
include Makefile.deps
@ -503,7 +507,7 @@ $(RSRC)/editor_banner.c: $(RSRC)/build.bmp
# PHONIES
clean:
-rm -f $(OBJ)/* eduke32$(EXESUFFIX) eduke32$(EXESUFFIX).memmap mapster32$(EXESUFFIX) mapster32$(EXESUFFIX).memmap core* duke3d_w32$(EXESUFFIX) && $(MAKE) -C $(JAUDIOLIBDIR) clean && $(MAKE) -C $(ENETDIR) clean
-rm -f $(OBJ)/* $(EDUKE32) $(EDUKE32).memmap $(MAPSTER32) $(MAPSTER32).memmap core* duke3d_w32$(EXESUFFIX) && $(MAKE) -C $(JAUDIOLIBDIR) clean && $(MAKE) -C $(ENETDIR) clean
ifeq ($(PLATFORM),DARWIN)
-rm -rf EDuke32.app Mapster32.app
endif

View file

@ -5,6 +5,67 @@
# Use colored output
PRETTY_OUTPUT ?= 1
# Tools
CC=gcc
CXX=g++
AS=nasm
AR=ar
RC=windres
RANLIB=ranlib
STRIP=strip
CLANG?=0
ifneq (0,$(CLANG))
CC=clang -std=gnu89
CXX=clang
# AR=llvm-ar
# RANLIB=llvm-ranlib
endif
# GCC version, for conditional selection of flags.
# This is easier than trying to squeeze it out of gcc --version:
GCC_MAJOR?=4
# Detect machine architecture
SYSARCH?=$(strip $(shell uname -m))
# Detect the platform if it wasn't explicitly given to us from
# the outside world. This allows cross-compilation by overriding
# CC and giving us PLATFORM specifically.
#
ifndef PLATFORM
uname=$(strip $(shell uname -s))
PLATFORM=UNKNOWN
ifeq ($(findstring Linux,$(uname)),Linux)
PLATFORM=LINUX
endif
ifeq ($(findstring BSD,$(uname)),BSD)
PLATFORM=BSD
endif
ifeq ($(findstring MINGW,$(uname)),MINGW)
PLATFORM=WINDOWS
endif
ifeq ($(findstring Darwin,$(uname)),Darwin)
PLATFORM=DARWIN
endif
ifeq ($(findstring BeOS,$(uname)),BeOS)
PLATFORM=BEOS
endif
ifeq ($(findstring skyos,$(uname)),skyos)
PLATFORM=SKYOS
endif
ifeq ($(findstring QNX,$(uname)),QNX)
PLATFORM=QNX
endif
ifeq ($(findstring SunOS,$(uname)),SunOS)
PLATFORM=SUNOS
endif
ifeq ($(findstring syllable,$(uname)),syllable)
PLATFORM=SYLLABLE
endif
endif
# Binary suffix override:
EXESUFFIX_OVERRIDE ?=
@ -34,6 +95,7 @@ BUILD32_ON_64 ?= 0
USE_LIBPNG ?= 1
USE_LIBVPX ?= 1
ifeq (0,$(USE_OPENGL))
POLYMER = 0
USE_LIBVPX = 0
@ -47,7 +109,6 @@ endif
# EFENCE - 1 = compile with Electric Fence for malloc() debugging
# OPTLEVEL - 0..3 = GCC optimization strategy
# LTO - 1 = enable link-time optimization, for GCC 4.5 and up
# CLANG - 1 = enable the Clang/LLVM compiler
#
RELEASE?=1
DEBUGANYWAY?=0
@ -58,7 +119,62 @@ OPTLEVEL?=2
PROFILER?=0
MUDFLAP?=0
LTO?=0
CLANG?=0
ifeq (4,$(GCC_MAJOR))
F_NO_STACK_PROTECTOR := -fno-stack-protector
# there are some link-time issues with stack protectors, so make it possible to override
F_STACK_PROTECTOR_ALL ?= -fstack-protector-all
ifeq (0,$(CLANG))
F_JUMP_TABLES := -fjump-tables
endif
M_TUNE_GENERIC := -mtune=generic
M_STACKREALIGN := -mstackrealign
W_STRICT_OVERFLOW := -Wstrict-overflow=1
endif
ifeq ($(PLATFORM),DARWIN)
DARWINVERSION?=$(strip $(shell uname -r | cut -d . -f 1))
ifeq (1,$(strip $(shell expr $(DARWINVERSION) \< 10)))
DARWIN9 ?= 1
endif
# BASECFLAGS += -fno-leading-underscore
ifeq (1,$(DARWIN9))
F_JUMP_TABLES :=
W_STRICT_OVERFLOW :=
endif
ifeq (1,$(BUILD32_ON_64))
BASECFLAGS += $(F_NO_STACK_PROTECTOR)
else
ifeq ($(findstring ppc,$(ARCH)),ppc)
BASECFLAGS += $(F_NO_STACK_PROTECTOR)
endif
endif
endif
ifndef OPTOPT
ifeq ($(PLATFORM), WII)
OPTOPT=
else
OPTOPTARCH=$(ARCH)
ifeq (,$(OPTOPTARCH))
OPTOPTARCH=$(SYSARCH)
endif
ifeq (i686,$(findstring i686, $(OPTOPTARCH)))
OPTOPT=-march=pentium3 $(M_TUNE_GENERIC) -mmmx
# -msse2 -mfpmath=sse,387 -malign-double $(M_STACKREALIGN)
else
OPTOPT=
endif
endif
ifneq (,$(CUSTOMOPT))
OPTOPT+= $(CUSTOMOPT)
endif
endif
ifneq (0,$(KRANDDEBUG))
RELEASE=0
@ -68,21 +184,6 @@ ifneq (0,$(PROFILER))
endif
# Tools
CC=gcc
CXX=g++
AS=nasm
AR=ar
RC=windres
RANLIB=ranlib
STRIP=strip
ifneq (0,$(CLANG))
CC=clang -std=gnu89
CXX=clang++
# AR=llvm-ar
# RANLIB=llvm-ranlib
endif
# compiler flags etc.
BASECONLYFLAGS=-Wimplicit
@ -177,13 +278,15 @@ CWARNS := -W -Wall -Wdeclaration-after-statement -Werror-implicit-function-decla
#-Wcast-qual -Wcast-align \
#-Waddress -Wlogical-op
BASECFLAGS=$(debug) $(CWARNS) \
BASECFLAGS=$(debug) $(OPTOPT) $(CWARNS) \
-funsigned-char -fno-strict-aliasing -DNO_GCC_BUILTINS -D_FORTIFY_SOURCE=2 \
$(F_JUMP_TABLES) $(W_NO_UNUSED_RESULT) $(ARCH)
ifneq (0,$(CLANG))
BASECFLAGS+= -Wno-unused-value -Wno-parentheses
endif
BASELDFLAGS+= $(OPTOPT)
# This should come from the environment:
ifdef EDUKE32_MY_DEVELOPER_ID
BASECFLAGS+= -DMY_DEVELOPER_ID=$(EDUKE32_MY_DEVELOPER_ID)

View file

@ -27,76 +27,13 @@ endif
SDL_FRAMEWORK = 0
# Detect machine architecture
SYSARCH?=$(strip $(shell uname -m))
# GCC version, for conditional selection of flags.
# This is easier than trying to squeeze it out of gcc --version:
GCC_MAJOR ?= 4
ifeq (4,$(GCC_MAJOR))
F_NO_STACK_PROTECTOR := -fno-stack-protector
# there are some link-time issues with stack protectors, so make it possible to override
F_STACK_PROTECTOR_ALL ?= -fstack-protector-all
ifeq (0,$(CLANG))
F_JUMP_TABLES := -fjump-tables
endif
M_TUNE_GENERIC := -mtune=generic
M_STACKREALIGN := -mstackrealign
L_SSP := -lssp
W_STRICT_OVERFLOW := -Wstrict-overflow=1
endif
ifndef ARCH
ifeq ($(PLATFORM), WII)
ARCH=
else
ifeq ($(findstring i686, $(shell uname -m)), i686)
ARCH=-march=pentium3 $(M_TUNE_GENERIC) -mmmx # -msse2 -mfpmath=sse,387 -malign-double $(M_STACKREALIGN)
else
ARCH=
endif
endif
endif
BUILDCFLAGS=$(ARCH)
BUILDLDFLAGS=$(ARCH)
# Detect the platform if it wasn't explicitly given to us from
# the outside world. This allows cross-compilation by overriding
# CC and giving us PLATFORM specifically.
#
ifndef PLATFORM
uname=$(strip $(shell uname -s))
PLATFORM=UNKNOWN
ifeq ($(findstring Linux,$(uname)),Linux)
PLATFORM=LINUX
endif
ifeq ($(findstring BSD,$(uname)),BSD)
PLATFORM=BSD
endif
ifeq ($(findstring MINGW,$(uname)),MINGW)
PLATFORM=WINDOWS
endif
ifeq ($(findstring Darwin,$(uname)),Darwin)
PLATFORM=DARWIN
endif
ifeq ($(findstring BeOS,$(uname)),BeOS)
PLATFORM=BEOS
endif
ifeq ($(findstring skyos,$(uname)),skyos)
PLATFORM=SKYOS
endif
ifeq ($(findstring QNX,$(uname)),QNX)
PLATFORM=QNX
endif
ifeq ($(findstring SunOS,$(uname)),SunOS)
PLATFORM=SUNOS
endif
ifeq ($(findstring syllable,$(uname)),syllable)
PLATFORM=SYLLABLE
endif
endif
ifeq ($(PLATFORM),LINUX)
STDCPPLIB=
else
@ -122,30 +59,19 @@ ifeq ($(PLATFORM),LINUX)
endif
endif
ifeq ($(PLATFORM),DARWIN)
DARWINVERSION?=$(strip $(shell uname -r | cut -d . -f 1))
ifeq (1,$(strip $(shell expr $(DARWINVERSION) \< 10)))
DARWIN9 ?= 1
endif
RENDERTYPE = SDL
STDCPPLIB = -lstdc++
BUILDCFLAGS += -DHAVE_INTTYPES #-fno-leading-underscore
BUILDCFLAGS += -DHAVE_INTTYPES
GTKCOMPAT32 = 0
SDL_FRAMEWORK = 1
ifeq (1,$(DARWIN9))
BUILDCFLAGS += -DDARWIN9
F_JUMP_TABLES :=
W_STRICT_OVERFLOW :=
endif
ifeq (1,$(BUILD32_ON_64))
BUILDCFLAGS += $(F_NO_STACK_PROTECTOR)
ARCH=-arch i386
else
ifeq ($(findstring ppc,$(ARCH)),ppc)
BUILDCFLAGS += $(F_NO_STACK_PROTECTOR)
endif
# ASM won't work on PowerPC or x86_64
override NOASM = 1
endif
@ -154,13 +80,14 @@ ifeq ($(PLATFORM),WINDOWS)
RENDERTYPE ?= WIN
BUILDCFLAGS+= -DHAVE_INTTYPES
EXESUFFIX=.exe
LIBS+= -lmingwex -lwinmm -L$(DXROOT)/lib -lwsock32 -lcomctl32 #-lshfolder
LIBS+= -lmingwex -lwinmm -L$(DXROOT)/lib -lwsock32 -lcomctl32
#-lshfolder
# STDCPPLIB=-lstdc++
endif
ifeq ($(PLATFORM),BSD)
RENDERTYPE=SDL
BUILDCFLAGS+= -DHAVE_INTTYPES
ifneq ($(findstring i386, $(shell uname -m)), i386)
ifneq ($(findstring i386, $(SYSARCH)), i386)
override NOASM=1
endif
STDCPPLIB=-lstdc++
@ -322,8 +249,16 @@ endif
ifeq ($(PRETTY_OUTPUT),1)
BUILD_STARTED = printf "\033[K\033[1;36mBuild started using \"$(CC) $(OURCFLAGS) $(OURCONLYFLAGS) $(OURCXXFLAGS)\"\033[0m\n"
BUILD_ECHOFLAGS = printf "\033[K\033[1;36mEnded compilation in this directory using \"$(CC) $(OURCFLAGS) $(OURCONLYFLAGS) $(OURCXXFLAGS)\"\033[0m\n"
BUILD_SETTINGS_COMPILER = \033[1;33mcompiler: \033[0;33m\"$(CC) $(OURCFLAGS) $(OURCONLYFLAGS) $(OURCXXFLAGS)\"
BUILD_SETTINGS_ASSEMBLER = \033[1;33massembler: \033[0;33m\"$(AS) $(OURASFLAGS)\"
BUILD_SETTINGS_LINKER = \033[1;33mlinker: \033[0;33m\"$(OURLDFLAGS) $(LIBS) $(STATICSTDCPP) $(STDCPPLIB)\"
ifeq (0,$(NOASM))
BUILD_SETTINGS = printf "$(BUILD_SETTINGS_COMPILER)\n$(BUILD_SETTINGS_ASSEMBLER)\n$(BUILD_SETTINGS_LINKER)\033[0m\n"
else
BUILD_SETTINGS = printf "$(BUILD_SETTINGS_COMPILER)\n$(BUILD_SETTINGS_LINKER)\033[0m\n"
endif
BUILD_STARTED = printf "\033[K\033[1;36mBuild started using:\033[0m\n"; $(BUILD_SETTINGS)
BUILD_ECHOFLAGS = printf "\033[K\033[1;36mEnded compilation in this directory using:\n$(BUILD_SETTINGS_COMPILER)\033[0m\n"
BUILD_FINISHED = printf "\033[K\033[1;36mBuild successful:\033[0m\n"
COMPILE_STATUS = printf "\033[K\033[0mBuilding object \033[1m$@\033[0m...\033[0m\r"
ONESTEP_STATUS = printf "\033[K\033[0mBuilding executable \033[1m$@\033[0m...\033[0m\r"

View file

@ -14,6 +14,8 @@ ifneq ($(RELEASE),0)
endif
OURCONLYFLAGS=$(BASECONLYFLAGS)
OURCXXFLAGS=$(BASECXXFLAGS)
OURLDFLAGS=$(BASELDFLAGS)
OURASFLAGS=$(BASEASFLAGS)
OBJECTS=$(OBJ)/callbacks.o \

View file

@ -25,6 +25,8 @@ ifneq ($(RELEASE),0)
endif
OURCONLYFLAGS=$(BASECONLYFLAGS)
OURCXXFLAGS=$(BASECXXFLAGS)
OURLDFLAGS=$(BASELDFLAGS)
OURASFLAGS=$(BASEASFLAGS)
ifeq ($(PLATFORM),DARWIN)
ifeq (1,$(SDL_FRAMEWORK))