summaryrefslogtreecommitdiff
path: root/Makefile
diff options
context:
space:
mode:
Diffstat (limited to 'Makefile')
-rw-r--r--Makefile64
1 files changed, 64 insertions, 0 deletions
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)/#' >$@