summaryrefslogtreecommitdiff
path: root/Makefile
diff options
context:
space:
mode:
authorAleksey Veresov <aleksey@veresov.pro>2021-02-18 13:50:05 +0300
committerAleksey Veresov <aleksey@veresov.pro>2021-02-18 13:50:05 +0300
commit2d74b68ac770601ef9e4d621752f9229c56cb2f3 (patch)
tree26d67e680f978a830f587d68c2ff1b4c44e7b67b /Makefile
downloadtakethis-2d74b68ac770601ef9e4d621752f9229c56cb2f3.tar
takethis-2d74b68ac770601ef9e4d621752f9229c56cb2f3.tar.xz
takethis-2d74b68ac770601ef9e4d621752f9229c56cb2f3.zip
Initial commit.
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)/#' >$@