forked from sdlpal/sdlpal
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Makefile
52 lines (39 loc) · 960 Bytes
/
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
NAME = sdlpal
INC_DIR += ./include
BUILD_DIR ?= ./build
OBJ_DIR ?= $(BUILD_DIR)/
BINARY ?= $(BUILD_DIR)/$(NAME)
.DEFAULT_GOAL = app
# Compilation flags
CC = gcc
CXX = g++
LD = g++
INCLUDES = $(addprefix -I, $(INC_DIR))
CFLAGS += -O2 -MMD -Wall $(INCLUDES) `sdl-config --cflags`
CXXFLAGS += $(CFLAGS)
# Files to be compiled
C_SRCS = $(shell find src/ -name "*.c")
CXX_SRCS = $(shell find src/ -name "*.cpp")
OBJS = $(C_SRCS:src/%.c=$(OBJ_DIR)/%.o) $(CXX_SRCS:src/%.cpp=$(OBJ_DIR)/%.o)
# Compilation patterns
$(OBJ_DIR)/%.o: src/%.c
@echo + CC $<
@mkdir -p $(dir $@)
@$(CC) $(CFLAGS) -c -o $@ $<
$(OBJ_DIR)/%.o: src/%.cpp
@echo + CXX $<
@mkdir -p $(dir $@)
@$(CXX) $(CXXFLAGS) -c -o $@ $<
# Depencies
-include $(OBJS:.o=.d)
# Some convenient rules
.PHONY: app clean
app: $(BINARY)
$(BINARY): $(OBJS)
@echo + LD $@
@$(LD) -O2 -o $@ $^ `sdl-config --libs`
run: app
ln -sf ../data $(BUILD_DIR)/
$(BINARY)
clean:
-rm -rf $(BUILD_DIR)