This repository has been archived by the owner on Sep 16, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
75 lines (58 loc) · 1.52 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
65
66
67
68
69
70
71
72
73
74
75
rwildcard = $(foreach d,$(wildcard $(1:=/*)),$(call rwildcard,$d,$2) $(filter $(subst *,%,$2),$d))
# Dirs
BIN_DIR := bin
SRC_DIR := src
OBJ_DIR := obj
LIB_DIR := lib
# C Stuff
override CFLAGS := -Wall -Wextra -I$(SRC_DIR) -I$(LIB_DIR) -std=c17 -g
# Sources
SOURCES := $(call rwildcard, $(SRC_DIR), *.c)
HEADERS := $(call rwildcard, $(SRC_DIR), *.h)
# Outputs
OBJECTS := $(patsubst $(SRC_DIR)/%.c, $(OBJ_DIR)/%.o, $(SOURCES))
ifeq ($(OS),Windows_NT)
OUTPUT_BIN := $(BIN_DIR)/magik.exe
else
OUTPUT_BIN := $(BIN_DIR)/magik
endif
# TomlC99
TOMLC99 := tomlc99
TOMLC99_DIR := $(LIB_DIR)/$(TOMLC99)
TOMLC99_OBJ_DIR := $(OBJ_DIR)/$(TOMLC99)
TOMLC99_SOURCES := $(TOMLC99_DIR)/toml.c
TOMLC99_OBJECTS := $(patsubst $(TOMLC99_DIR)/%.c, $(TOMLC99_OBJ_DIR)/%.o, $(TOMLC99_SOURCES))
OBJECTS += $(TOMLC99_OBJECTS)
# Rules
.PHONY : all
all : dirs $(OUTPUT_BIN)
$(OUTPUT_BIN) : $(OBJECTS)
$(CC) $^ -o $@
$(OBJ_DIR)/%.o : $(SRC_DIR)/%.c $(HEADERS)
@mkdir -p $(dir $@)
$(CC) $(CFLAGS) -c $< -o $@
$(TOMLC99_OBJ_DIR)/%.o : $(TOMLC99_DIR)/%.c
@mkdir -p $(dir $@)
$(CC) $(CFLAGS) -c $< -o $@
.PHONY : dirs
dirs : $(BIN_DIR) $(OBJ_DIR) $(TOMLC99_OBJ_DIR)
$(BIN_DIR) $(OBJ_DIR) $(TOMLC99_OBJ_DIR) :
@mkdir -p $@
.PHONY : run
run : all
$(OUTPUT_BIN)
.PHONY : docs
docs :
doxygen
.PHONY : gen-cflags
gen-cflags :
rm -f compile_flags.txt
echo $(CFLAGS) | tr " " "\n" > compile_flags.txt
.PHONY : full-clean
full-clean : clean clean-docs
.PHONY : clean
clean :
rm -rf $(BIN_DIR) $(OBJ_DIR) magik_build
.PHONY : clean-docs
clean-docs :
rm -rf html latex