-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMakefile
64 lines (56 loc) · 2.27 KB
/
Makefile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
# This makefile compiles Projet Pasteque using GCC (or another compiler, if needed).
# Note that this makefile is barely optimized for incremental compilation.
# If you need incremental compilation, use CMake instead.
CC = gcc
# Add any options here
CFLAGS = -std=c11 -fPIC
# Enable multi threading
MAKEFLAGS = -j 4
OUT = build-make
INCLUDE_DIRS = include external/rgr/inc
INCLUDE_FLAGS = $(addprefix -I, $(INCLUDE_DIRS))
# Add any library here
LDLIBS = GameRGR2 ncursesw m
LDFLAGS += $(addprefix -l, $(LDLIBS))
LIBRARY_PATHS = external/rgr/lib
# This is for LD_LIBRARY_PATH. Add the : infix if we have multiple libraries.
LIBRARY_PATHS_ENV = external/rgr/lib
LIBRARY_PATHS_FLAGS = $(addprefix -L, $(LIBRARY_PATHS))
# Register all C files here
SRC_FILES = board.c game.c game_state.c panel.c colors.c scene.c ui.c highscore.c scenes/main_menu_scene.c scenes/crush_scene.c scenes/story_scene.c
OBJ_FILES = $(SRC_FILES:.c=.o)
OBJ_FILES_FP = $(addprefix $(OUT)/, $(OBJ_FILES))
# Full paths to the project includes
INCLUDE_FILES_FP = $(wildcard include/**/*.h) $(wildcard include/*.h) src/scenes/story_scene_text.h
all: build
.PHONY: make_build_dir
make_build_dir:
@mkdir -p $(OUT) && mkdir -p $(OUT)/scenes
# The default rule for all object files.
$(OUT)/%.o: src/%.c $(INCLUDE_FILES_FP) external/rgr/lib/libGameRGR2.so | make_build_dir
@echo "Compiling $<..."
@$(CC) $(CFLAGS) $(INCLUDE_FLAGS) $(LIBRARY_PATHS_FLAGS) -c $< -o $@ $(LDFLAGS)
$(OUT)/projet_pasteque: $(OBJ_FILES_FP)
@echo "Linking executable..."
@# It's necessary to have library flags at the end of the command for the linker to resolve
@# dependencies correctly. Weird behavior. But it works.
@$(CC) $(CFLAGS) $(INCLUDE_FLAGS) $(LIBRARY_PATHS_FLAGS) $^ -o $@ $(LDFLAGS)
external/rgr/lib/libGameRGR2.so:
@echo "Compiling library GameRGR2..."
@cd ./external/rgr && mkdir -p ./lib && $(MAKE) lib/libGameRGR2.so
.PHONY: build
build: $(OUT)/projet_pasteque
.PHONY: run
run: build
@export LD_LIBRARY_PATH="../$(LIBRARY_PATHS_ENV)";\
if [ $$TERM = "xterm-256color" ]; then\
# Setup the terminal for extended mouse support, if possible\
export TERMINFO=$(shell pwd)/terminfo/;\
export TERM="xterm-256color-mouse";\
fi;\
cd ./$(OUT);\
./projet_pasteque;\
cd ../
.PHONY: clean
clean:
@if [ -d "$(OUT)/" ]; then rm -r $(OUT)/*; fi;