RingRacers/src/Makefile
James R d5c08ac034 Backport 2021 SRB2 makefile overhaul
This is a squashed commit of the following commits from
upstream:

James R <justsomejames2@gmail.com> on 2021-05-01
Commit 44d217807f71d15bd7ca69dad226458e7060ccab
> Collect makefiles

James R <justsomejames2@gmail.com> on 2021-05-04
Commit f637e28d0c1877c44acd7b01f7130625d5ea4099
> Remove bin, objs and dep directories

James R <justsomejames2@gmail.com> on 2021-05-02
Commit b31056c7d977fe3c2a5e0637589fd9521f1f6c04
> Rewrite Makefile to be modular as well as more automated
>
> Some key points for programmers:
> - Source code files are mostly listed in a 'Sourcefile'.
>   So you no longer directly edit the object list. There
>   can be multiple Sourcefiles and they can even live in
>   subdirectories--the directory name will be prepended to
>   every filename in the list. Of course, the Makefile
>   still needs to be edited to read from each Sourcefile.
> - Different rules are no longer required for source code
>   files that live in subdirectories (such as sdl/ or
>   hardware/). Subdirectories Just Work so go ham!
>
> In addition to those points, another important change is
> that the bin directory is no longer divided into platform
> subdirectories (Linux64, Mingw, etc). Executables now go
> directly into bin. If you use DEBUGMODE or target 64-bit,
> then subdirectories for 'debug' and '64' will be made
> though.
>
> Oh by the way, I don't think make clean actually removed
> files before on Windows. It should now. I also fixed as
> many little inconsistencies like that as I noticed.
>
> And now just an overview of the technical aspects that
> shouldn't affect anyone who doesn't REALLY care about the
> Makefile...
>
> objs and dep directories have been moved to a make
> directory. Makefile.cfg and its variants have been moved
> out of their various subdirectories to src/Makefile.d
> make distclean removes the bin and make directories
> entirely, but make clean and cleandep still only affect
> the current build target.
>
> When I say automation, I mean that a lot of copy pasting
> in the Makefile has been reduced.

James R <justsomejames2@gmail.com> on 2021-05-04
Commit 53d1cbe8264196e46911c86bc4be13d44aa35dfe
> Appveyor: update executable directory

James R <justsomejames2@gmail.com> on 2021-05-04
Commit 888073d64d1885cae0ad8b5d54bfec31e9793e0a
> Fix make clean printing header

James R <justsomejames2@gmail.com> on 2021-05-04
Commit 3d7205d4942d1e1b2627fdf5acf9d9c82437a97b
> Fix minor errors with Windows ECHO, DEL, MD
>
> - Quotes were not removed by ECHO.
> - DEL would print an error on nonexistent file.
> - MD would do this plus return a nonzero exit code.

James R <justsomejames2@gmail.com> on 2021-05-05
Commit f9813844e7f0dfa6229062b1ebd83e4e8150c120
> Update CMakeLists.txt to use Sourcefiles
>
> This establishes (near) parity of source code file lists
> between the Makefile and CMakeLists.txt
>
> To make that change I messed around CMakeLists.txt a bit.
> It now uses target_sources and target_compile_definitions.
> I also removed some MSVC stuff since we don't actually
> care about MSVC--it made things easier.
>
> CMake minimum version 3.0 -> 3.13 for target_sources.

James R <justsomejames2@gmail.com> on 2021-05-05
Commit ec8b63d6759f0c124693ea6d5a521e8d82efd566
> Makefile: remove last of unused flags

James R <justsomejames2@gmail.com> on 2021-05-07
Commit c06817d0085ee77b0027917bca91a24e60c7deba
> Makefile: fix mingw/64 swapped with 32-bit

James R <justsomejames2@gmail.com> on 2021-05-07
Commit 9e7d80c2c44199126fa451c59fca0f98d23ad14d
> Makefile: suppress DEL error

James R <justsomejames2@gmail.com> on 2021-05-07
Commit 87afa7655a71539c7cbc7db12df18c4253187fbc
> CMake: fix ASM compile
>
> - target_sources from correct directory
> - enable_language must be used in add_executable directory

James R <justsomejames2@gmail.com> on 2021-05-08
Commit 210c9419e4bddd1fe8e9be7cb66de31119fa0d68
> Ignore -Wtrigraphs

James R <justsomejames2@gmail.com> on 2021-06-16
Commit 3a044e71cc7cf6c80d9836189511c1a58c108370
> Disable EXE disassembly and compression by default
>
> NOOBJDUMP=1 and NOUPX=1 have been removed. Make 'dump'
> target to disassemble. UPX=upx to compress executable.
>
> Setting UPX used to cause it to fail. That has been fixed.

James R <justsomejames2@gmail.com> on 2021-06-16
Commit c142b3241ddb8f1ea9b5090d20dffa43a17129ab
> Makefile: alert full path of final executable
>
> With added textual contrast.

James R <justsomejames2@gmail.com> on 2021-06-16
Commit b04c79d8a7ba4ae8f888ab94d394b6714699e107
> Say 'at'

James R <justsomejames2@gmail.com> on 2021-06-21
Commit 2d7a8c3c571bcc5335437e9db074c75af00408ce
> Makefile: use shell commands to read in Sourcefile
>
> File function is not supported < Make 4.2.

James R <justsomejames2@gmail.com> on 2021-06-21
Commit d5146945a69ebf30e6fc1fbb64558e456e0b7459
> Makefile: don't automatically set WINDOWSHELL unless PATH matches Windows norms
>
> This is for MSYS2, which requires unix shell commands.

James R <justsomejames2@gmail.com> on 2021-06-22
Commit 5f4d7e3c5b013afe03ae2a441c82ad79bae7c66c
> Makefile: fail if old build directories exist
>
> After a checkout from before revision, old directories
> such as bin/Linux64 only remain if untracked files exist
> within. This may be confusing to the user. They may even
> use an outdated executable if it is one of those untracked
> files.

James R <justsomejames2@gmail.com> on 2021-06-22
Commit c3ad5de912fccfdd64c510f5684883afceaa7d36
> Makefile: let variables be defined on Make line
>
> If a variable is defined as in 'make CC=gcc-10', then that
> definition overrides anything other definition in the
> Makefile.

James R <justsomejames2@gmail.com> on 2021-06-22
Commit ed85e994a46ace07cf022b38a9abac1698a8667e
> Remove misplaced parentheses

James R <justsomejames2@gmail.com> on 2021-06-29
Commit c1ecfa306f6a0b168d4f6cbc3224ebebd4deec51
> Makefile: 'dep' not 'deps'

James R <justsomejames2@gmail.com> on 2021-06-29
Commit 6c03f9b5b3590e01773f05bc1c31cc67a2d88fc2
> fuck

James R <justsomejames2@gmail.com> on 2021-06-29
Commit abdf5c101cbe80657f210c0b90800e2c4c6f0c05
> Makefile: report SHELL

James R <justsomejames2@gmail.com> on 2021-06-29
Commit 22ab611daa17bd23225f3afeeba39147c0d0fe17
> Makefile: do not automatically set WINDOWSHELL
>
> According to this answer--
> https://stackoverflow.com/a/45952425
> --Make will always prefer a unix shell, even on Windows,
> if one can be found in Path. So we can't check PATH to
> determine if it's a Windows shell... this is just too much
> bother.

James R <justsomejames2@gmail.com> on 2021-06-29
Commit f79e0ee540564fcec5da7c0dc4006906492a7f30
> Appveyor: remove 64-bit target

James R <justsomejames2@gmail.com> on 2021-06-29
Commit faee657572f23cd6f8b68c077873e01c4278414e
> Appveyor: update for new Makefile

James R <justsomejames2@gmail.com> on 2021-06-29
Commit 44b82dea58612e6f07830647e2b08555f54a7caa
> Appveyor: remove redundant CFLAGS
>
> Also changed -Wno-error=implicit-fallthrough to
> -Wno-implicit-fallthrough. For some reason Appveyor's
> version of GCC is triggering these warnings despite the
> comments, so just shut it up.

James R <justsomejames2@gmail.com> on 2021-06-29
Commit db919accd22350c087c1fd0e5122d8e490e2f171
> Appveyor: suppress real time file names

James R <justsomejames2@gmail.com> on 2021-07-12
Commit 58fa44e8dc0444eecbe701f31872fad9fa563a6a
> CMP0115

SteelT <steeltitanium1@gmail.com> on 2021-07-16
Commit 71f905f95bd4fe62dbca87208cf71b7309f12de1
> Fix gme support being effectively disabled
>
> I found this easier than trying to adjust the makefile, as it uses the same thing to automatically generate the various NO* compile options.

James R <justsomejames2@gmail.com> on 2021-08-14
Commit 824b1ab28cdddfd1c018454a9af14dabaab49fcd
> Makefile: use full stem in dependency generation
>
> Previously took only the filename, so the directory
> component was stripped. This broke dependencies for
> basically every file.

GoldenTails <milestailsprower101n2@gmail.com> on 2021-08-28
Commit 1a8ec7975c20e1d652cbbdb7a9e366192e41c05f
> Makefile: Improve gcc detection
>
> Wasn't working for me until I fixed it.
> Turns out gcc really doesn't like giving its name out.
> Most of the time it reads argv[0].
2021-11-25 03:56:23 -08:00

416 lines
9.2 KiB
Makefile

# GNU Makefile for SRB2
# the poly3 Makefile adapted over and over...
#
# Copyright 1998-2000 DooM Legacy Team.
# Copyright 2020-2021 James R.
# Copyright 2003-2021 Sonic Team Junior.
#
# This program is free software distributed under the
# terms of the GNU General Public License, version 2.
# See the 'LICENSE' file for more details.
#
# Special targets:
#
# clean - remove executables and objects for this build
# cleandep - remove dependency files for this build
# distclean - remove entire executable, object and
# dependency file directory structure.
# dump - disassemble executable
# info - print settings
#
# This Makefile can automatically detect the host system
# as well as the compiler version. If system or compiler
# version cannot be detected, you may need to set a flag
# manually.
#
# On Windows machines, 32-bit Windows is always targetted.
#
# Platform/system flags:
#
# LINUX=1, LINUX64=1
# MINGW=1, MINGW64=1 - Windows (MinGW toolchain)
# UNIX=1 - Generic Unix like system
# FREEBSD=1
# SDL=1 - Use SDL backend. SDL is the only backend though
# and thus, always enabled.
#
# A list of supported GCC versions can be found in
# Makefile.d/detect.mk -- search 'gcc_versions'.
#
# Feature flags:
#
# Safe to use online
# ------------------
# NO_IPV6=1 - Disable IPv6 address support.
# NOHW=1 - Disable OpenGL renderer.
# ZDEBUG=1 - Enable more detailed memory debugging
# HAVE_MINIUPNPC=1 - Enable automated port forwarding.
# Already enabled by default for 32-bit
# Windows.
# NOASM=1 - Disable hand optimized assembly code for the
# Software renderer.
# NOPNG=1 - Disable PNG graphics support. (TODO: double
# check netplay compatible.)
# NOCURL=1 - Disable libcurl--HTTP capability.
# NOGME=1 - Disable game music emu, retro VGM support.
# NOOPENMPT=1 - Disable module (tracker) music support.
# NOMIXER=1 - Disable SDL Mixer (audio playback).
# NOMIXERX=1 - Forgo SDL Mixer X--revert to standard SDL
# Mixer. Mixer X is the default for Windows
# builds.
# HAVE_MIXERX=1 - Enable SDL Mixer X. Outside of Windows
# builds, SDL Mixer X is not the default.
# NOTHREADS=1 - Disable multithreading.
#
# Netplay incompatible
# --------------------
# NONET=1 - Disable online capability.
# NOMD5=1 - Disable MD5 checksum (validation tool).
# NOPOSTPROCESSING=1 - ?
# MOBJCONSISTANCY=1 - ??
# PACKETDROP=1 - ??
# DEBUGMODE=1 - Enable various debugging capabilities.
# Also disables optimizations.
# NOZLIB=1 - Disable some compression capability. Implies
# NOPNG=1.
#
# Development flags:
#
# VALGRIND=1 - Enable Valgrind memory debugging support.
# PROFILEMODE=1 - Enable performance profiling (gprof).
#
# General flags for building:
#
# STATIC=1 - Use static linking.
# DISTCC=1
# CCACHE=1
# UPX= - UPX command to use for compressing final
# executable.
# WINDOWSHELL=1 - Use Windows commands.
# PREFIX= - Prefix to many commands, for cross compiling.
# YASM=1 - Use Yasm instead of NASM assembler.
# STABS=1 - ?
# ECHO=1 - Print out each command in the build process.
# NOECHOFILENAMES=1 - Don't print out each that is being
# worked on.
# SILENT=1 - Print absolutely nothing except errors.
# RELAXWARNINGS=1 - Use less compiler warnings/errors.
# ERRORMODE=1 - Treat most compiler warnings as errors.
# NOCASTALIGNWARN=1 - ?
# NOLDWARNING=1 - ?
# NOSDLMAIN=1 - ?
# SDLMAIN=1 - ?
#
# Library configuration flags:
# Everything here is an override.
#
# PNG_PKGCONFIG= - libpng-config command.
# PNG_CFLAGS=, PNG_LDFLAGS=
#
# CURLCONFIG= - curl-config command.
# CURL_CFLAGS=, CURL_LDFLAGS=
#
# VALGRIND_PKGCONFIG= - pkg-config package name.
# VALGRIND_CFLAGS=, VALGRIND_LDFLAGS=
#
# LIBGME_PKGCONFIG=, LIBGME_CFLAGS=, LIBGME_LDFLAGS=
# LIBOPENMPT_PKGCONFIG=
# LIBOPENMPT_CFLAGS=, LIBOPENMPT_LDFLAGS=
#
# ZLIB_PKGCONFIG=, ZLIB_CFLAGS=, ZLIB_LDFLAGS=
#
# SDL_PKGCONFIG=
# SDL_CONFIG= - sdl-config command.
# SDL_CFLAGS=, SDL_LDFLAGS=
clean_targets=cleandep clean distclean info
.PHONY : $(clean_targets) all
goals:=$(or $(MAKECMDGOALS),all)
cleanonly:=$(filter $(clean_targets),$(goals))
destructive:=$(filter-out info,$(cleanonly))
ifndef cleanonly
include Makefile.d/old.mk
endif
include Makefile.d/util.mk
ifdef PREFIX
CC:=$(PREFIX)-gcc
endif
OBJDUMP_OPTS?=--wide --source --line-numbers
OBJCOPY:=$(call Prefix,objcopy)
OBJDUMP:=$(call Prefix,objdump)
WINDRES:=$(call Prefix,windres)
ifdef YASM
NASM?=yasm
else
NASM?=nasm
endif
ifdef YASM
ifdef STABS
NASMOPTS?=-g stabs
else
NASMOPTS?=-g dwarf2
endif
else
NASMOPTS?=-g
endif
GZIP?=gzip
GZIP_OPTS?=-9 -f -n
ifdef WINDOWSHELL
GZIP_OPTS+=--rsyncable
endif
UPX_OPTS?=--best --preserve-build-id
ifndef ECHO
UPX_OPTS+=-qq
endif
include Makefile.d/detect.mk
# make would try to remove the implicitly made directories
.PRECIOUS : %/ comptime.c
sources:=
makedir:=../make
# -DCOMPVERSION: flag to use comptime.h
opts:=-DCOMPVERSION -g
libs:=
nasm_format:=
# This is a list of variables names, of which if defined,
# also defines the name as a macro to the compiler.
passthru_opts:=
include Makefile.d/platform.mk
include Makefile.d/features.mk
include Makefile.d/versions.mk
ifdef DEBUGMODE
makedir:=$(makedir)/debug
endif
depdir:=$(makedir)/deps
objdir:=$(makedir)/objs
# very sophisticated dependency
sources+=\
$(call List,Sourcefile)\
$(call List,blua/Sourcefile)\
depends:=$(basename $(filter %.c %.s,$(sources)))
objects:=$(basename $(filter %.c %.s %.nas,$(sources)))
depends:=$(depends:%=$(depdir)/%.d)
# comptime.o added directly to objects instead of thru
# sources because comptime.c includes comptime.h, but
# comptime.h may not exist yet. It's a headache so this is
# easier.
objects:=$(objects:=.o) comptime.o
# windows resource file
rc_file:=$(basename $(filter %.rc,$(sources)))
ifdef rc_file
objects+=$(rc_file:=.res)
endif
objects:=$(addprefix $(objdir)/,$(objects))
ifdef DEBUGMODE
bin:=../bin/debug
else
bin:=../bin
endif
# default EXENAME (usually set by platform)
EXENAME?=srb2
DBGNAME?=$(EXENAME).debug
exe:=$(bin)/$(EXENAME)
dbg:=$(bin)/$(DBGNAME)
build_done==== Build is done, look for \
$(<F) at $(abspath $(<D)) ===
all : $(exe)
$(call Echo,$(build_done))
ifndef VALGRIND
dump : $(dbg).txt
endif
ifdef STATIC
libs+=-static
endif
# build with profiling information
ifdef PROFILEMODE
opts+=-pg
libs+=-pg
endif
ifdef DEBUGMODE
debug_opts=-D_DEBUG
else # build a normal optimized version
debug_opts=-DNDEBUG
opts+=-O3
endif
# debug_opts also get passed to windres
opts+=$(debug_opts)
opts+=$(foreach v,$(passthru_opts),$(if $($(v)),-D$(v)))
opts+=$(WFLAGS) $(CPPFLAGS) $(CFLAGS)
libs+=$(LDFLAGS)
asflags:=$(ASFLAGS) -x assembler-with-cpp
cc=$(CC)
ifdef DISTCC
cc=distcc $(CC)
endif
ifdef CCACHE
cc=ccache $(CC)
endif
ifndef SILENT
# makefile will 'restart' when it finishes including the
# dependencies.
ifndef MAKE_RESTARTS
ifndef destructive
$(shell $(CC) -v)
define flags =
SHELL ..... $(SHELL)
CC ........ $(cc)
CFLAGS .... $(opts)
LDFLAGS ... $(libs)
endef
$(info $(flags))
endif
# don't generate dependency files if only cleaning
ifndef cleanonly
$(info Checking dependency files...)
include $(depends)
endif
endif
endif
LD:=$(CC)
cc:=$(cc) $(opts)
nasm=$(NASM) $(NASMOPTS) -f $(nasm_format)
ifdef UPX
upx=$(UPX) $(UPX_OPTS)
endif
windres=$(WINDRES) $(WINDRESFLAGS)\
$(debug_opts) --include-dir=win32 -O coff
%/ :
$(.)$(mkdir) $(call Windows_path,$@)
# this is needed so the target can be referenced in the
# prerequisites
.SECONDEXPANSION :
# 'UPX' is also recognized in the environment by upx
unexport UPX
# executable stripped of debugging symbols
$(exe) : $(dbg) | $$(@D)/
$(.)$(OBJCOPY) --strip-debug $< $@
$(.)-$(OBJCOPY) --add-gnu-debuglink=$< $@
ifdef UPX
$(call Echo,Compressing final executable...)
$(.)-$(upx) $@
endif
# original executable with debugging symbols
$(dbg) : $(objects) | $$(@D)/
$(call Echo,Linking $(@F)...)
$(.)$(LD) -o $@ $^ $(libs)
# disassembly of executable
$(dbg).txt : $(dbg)
$(call Echo,Dumping debugging info...)
$(.)$(OBJDUMP) $(OBJDUMP_OPTS) $< > $@
$(.)$(GZIP) $(GZIP_OPTS) $@
# '::' means run unconditionally
# this really updates comptime.h
comptime.c ::
ifdef WINDOWSHELL
$(.)..\comptime.bat .
else
$(.)../comptime.sh .
endif
# I wish I could make dependencies out of rc files :(
$(objdir)/win32/Srb2win.res : \
win32/afxres.h win32/resource.h
# dependency recipe template
# 1: source file suffix
# 2: extra flags to gcc
define _recipe =
$(depdir)/%.d : %.$(1) | $$$$(@D)/
ifndef WINDOWSHELL
ifdef Echo_name
@printf '%-20.20s\r' $$<
endif
endif
$(.)$(cc) -MM -MF $$@ -MT $(objdir)/$$*.o $(2) $$<
endef
$(eval $(call _recipe,c))
$(eval $(call _recipe,s,$(asflags)))
# compiling recipe template
# 1: target file suffix
# 2: source file suffix
# 3: compile command
define _recipe =
$(objdir)/%.$(1) : %.$(2) | $$$$(@D)/
$(call Echo_name,$$<)
$(.)$(3)
endef
$(eval $(call _recipe,o,c,$(cc) -c -o $$@ $$<))
$(eval $(call _recipe,o,nas,$(nasm) -o $$@ $$<))
$(eval $(call _recipe,o,s,$(cc) $(asflags) -c -o $$@ $$<))
$(eval $(call _recipe,res,rc,$(windres) -i $$< -o $$@))
_rm=$(.)$(rmrf) $(call Windows_path,$(1))
cleandep :
$(call _rm,$(depends) comptime.h)
clean :
$(call _rm,$(exe) $(dbg) $(dbg).txt $(objects))
distclean :
$(call _rm,../bin ../objs ../dep ../make comptime.h)
info:
ifdef WINDOWSHELL
@REM
else
@:
endif