Generic Makefile
June 16, 2020
Just thought I'd share my Makefile. This is a sort of build script that is run automatically when you run make
in the directory where it's located (usually along with your source code). It operates on the idea of "targets" -- you can make a release build, make a debug build, make a backup, make your directory clean, etc.
The below Makefile makes generous use of variables so you only have to set your executable name, header files, and source files once, and it will automagically do the Right Thing™. The following commands are available:
make
: Makes a release version (same as below)make release
: Makes a release version (i.e., with debugging information stripped)make debug
: Makes a version with debugging informationmake strict-release
: Release version with strict checksmake strict-debug
: Debug version with strict checksmake superstrict-release
: Release version with very strict checksmake superstrict-debug
: Debug version with very strict checksmake clean
: Removes executable, object files, core dumps, old versions of files, and debugging information
EXE = [insert executable name here]
HDR = [insert directory-local headers here]
SRC = [insert source files here]
CC = cc
RFLAGS = -std=c17 -Oz
DFLAGS = -std=c17 -O0 -gfull
# For GCC use the following instead
# DFLAGS = -std=c17 -Og -g3
SFLAGS = -W -Wall -Werror -Wno-unused-parameter -Wstrict-prototypes -Wmissing-prototypes -Wpointer-arith -Wreturn-type -Wcast-qual -Wswitch -Wshadow -Wcast-align -Wwrite-strings -Wmisleading-indentation
SSFLAGS = -Wunused-parameter -Wchar-subscripts -Winline -Wnested-externs -Wredundant-decls
all: release
release: $(SRC) $(HDR)
$(CC) $(RFLAGS) $(SRC) -o $(EXE)
strip $(EXE)
debug: $(SRC) $(HDR)
$(CC) $(DFLAGS) $(SRC) -o $(EXE)
strict-release: $(SRC) $(HDR)
$(CC) $(SFLAGS) $(RFLAGS) $(SRC) -o $(EXE)
strip $(EXE)
strict-debug: $(SRC) $(HDR)
$(CC) $(SFLAGS) $(DFLAGS) $(SRC) -o $(EXE)
superstrict-release: $(SRC) $(HDR)
$(CC) $(SFLAGS) $(SSFLAGS) $(RFLAGS) $(SRC) -o $(EXE)
strip $(EXE)
superstrict-debug: $(SRC) $(HDR)
$(CC) $(SFLAGS) $(SSFLAGS) $(DFLAGS) $(SRC) -o $(EXE)
clean:
rm -Rf core *.o *~ $(EXE) $(EXE).dSYM/
0 Comment(s)
Post a Comment