From 2d74b68ac770601ef9e4d621752f9229c56cb2f3 Mon Sep 17 00:00:00 2001 From: Aleksey Veresov Date: Thu, 18 Feb 2021 13:50:05 +0300 Subject: Initial commit. --- Makefile | 64 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 64 insertions(+) create mode 100644 Makefile (limited to 'Makefile') diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..ede3445 --- /dev/null +++ b/Makefile @@ -0,0 +1,64 @@ +# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # +# Compilation Options +# Debug mode [yes/no] (allowing to debug the library via gdb): +DEBUG ?= no +# Specify your favourite C compiler here: +COMPILE ?= gcc + + +# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # +# Preparations +# Compile as ANSI C code: +CFLAGS = -xc -ansi -Wall +# Debug and optimisation (as well as -static for valgrind) are not compatible: +ifeq '$(DEBUG)' 'yes' +CFLAGS += -g -O0 +else +CFLAGS += -O3 +endif +# Use SDL: +LFLAGS = -lSDL2 + +# Directories definitions: +BUILD = build +SRCDIR = src +# Game itself: +GAME = takethis +# Determing needed object files: +MODULES = $(foreach x,$(notdir $(wildcard $(SRCDIR)/*.c)),$(x:.c=)) +HEADERS = $(wildcard $(SRCDIR)/*.h) +SRC = $(foreach i,$(MODULES:=.c),$(SRCDIR)/$(i)) +OBJ = $(foreach i,$(MODULES:=.o),$(BUILD)/$(i)) +# Dependency file: +DEPS = deps.mk + + +# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # +# Targets +.PHONY: all clean + +all: $(BUILD) $(GAME) + +clean: + rm -f $(GAME) $(OBJ) $(DEPS) + + +# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # +# Compilation +-include $(DEPS) + +# Packing object files into library: +$(GAME): $(OBJ) + $(COMPILE) $(LFLAGS) $^ -o $@ + +# Compile object files from corresponding source: +$(BUILD)/%.o: $(SRCDIR)/%.c + $(COMPILE) $(CFLAGS) -c $< -o $@ + +# Create build directories, if no such: +$(BUILD): + mkdir -p $@ + +# Generate dependency file, adding corresponding build prefixes: +$(DEPS): $(SRC) $(HEADERS) + $(COMPILE) $(SRC) -MM | sed '/^ /!s#^#$(BUILD)/#' >$@ -- cgit v1.2.3