-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
58 lines (47 loc) · 1.34 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
# c compiler configuration
CC := gcc
CVERSION := -std=gnu11
CWARNS := -Wall
CC_OPT := -O0
CINCLUDES :=
CLIBS :=
CDEFINES :=
# source, input resources, object and binary directories
SRC_DIR := src
RCS_DIR := resources
OBJ_DIR := obj
BIN_DIR := bin
# target name
TARGET_NAME := ifthisisnamedthiswayyouforgottoeditsomelineinthemakefile
# ###
# CONFIGURATION END
# combined cflags
CFLAGS := $(CVERSION) $(CWARNS) $(CC_OPT) $(CINCLUDES) $(CLIBS) $(CDEFINES)
# target and output resources position
TARGET := $(BIN_DIR)/$(TARGET_NAME)
RCS_BIN_DIR := $(BIN_DIR)/$(RCS_DIR)
# get source, object and header files
SRCS := $(shell find $(SRC_DIR)/ -name "*.c")
OBJS := $(patsubst $(SRC_DIR)/%.c,$(OBJ_DIR)/%.o,$(SRCS))
HEADERS := $(shell find $(SRC_DIR)/ -name "*.h")
# get input and output resource files
RCS_INP := $(shell find $(RCS_DIR)/ -type f)
RCS_OUTP := $(patsubst $(RCS_DIR)/%,$(RCS_BIN_DIR)/%,$(RCS_INP))
# completely build project
.PHONY: all
all: $(TARGET) $(RCS_OUTP)
# compile and link program
$(TARGET): $(OBJS)
@mkdir -p $(dir $@)
$(CC) -o $@ $^ $(CFLAGS)
$(OBJS): $(OBJ_DIR)/%.o: $(SRC_DIR)/%.c $(HEADERS)
@mkdir -p $(dir $@)
$(CC) -o $@ $< -c $(CFLAGS)
# copy resources
$(RCS_OUTP): $(RCS_BIN_DIR)/%: $(RCS_DIR)/%
@mkdir -p $(dir $@)
cp $< $@
# clean project build
.PHONY: clean
clean:
rm -rf $(OBJ_DIR) $(BIN_DIR)