-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMakefile
97 lines (81 loc) · 2.61 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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
# Modify these if you need
COMPILER := clang
CFLAGS := --std=c99 -Wall -Wextra -O3 # Change CFLAGS to C++ flags
# Name of the final executable
TARGET := Raquet
INCLUDES := -Iinclude/ -Iinclude/Raquet
# Build and Source directories.
BUILD_DIR := bin
SRC_DIR := src
ifeq ($(OS), Windows_NT)
LIBS := -Lwinclude/lib/ -lSDL2 -lSDL2_mixer -lm -lSDL2main -mwindows
PLATFORM := win
INSULT := "Windows Dev? I am so sorry."
EXTENSION := .exe
else
LIBS := -lSDL2 -lSDL2_mixer -lSDL2main -lm
PLATFORM := nix
INSULT := "*Nix Dev? How's your waifu wallpaper holding up?"
EXTENSION := .x86_64
endif
# Recursive wildcard function
rwildcard=$(foreach d,$(wildcard $(1:=/*)),$(call rwildcard,$d,$2) $(filter $(subst *,%,$2),$d))
# Find all source files recursively
SRCS_C := $(call rwildcard, $(SRC_DIR), *.c)
# Find C++ files
SRCS_CPP := $(call rwildcard, $(SRC_DIR), *.cpp)
# Round up everything
SRCS := $(SRCS_C) $(SRCS_CPP)
# Create object file paths maintaining directory structure
OBJS := $(patsubst $(SRC_DIR)/%.c,$(BUILD_DIR)/%.o,$(SRCS_C)) \
$(patsubst $(SRC_DIR)/%.cpp,$(BUILD_DIR)/%.o,$(SRCS_CPP))
all: announce $(BUILD_DIR)/ $(TARGET)$(EXTENSION)
# Bash command hell
$(TARGET)$(EXTENSION): $(OBJS)
@mkdir -p $(BUILD_DIR)/$(PLATFORM)
@echo $(INSULT)
ifeq ($(OS), Windows_NT)
@echo
@echo "Adding icon to executable"
@windres winclude/program.rc -o $(BUILD_DIR)/program.o
@echo
@echo "Compiling the final program"
@$(COMPILER) -o $(BUILD_DIR)/$(PLATFORM)/$(TARGET)$(EXTENSION) $^ $(BUILD_DIR)/program.o $(LIBS)
@echo
@echo "Copying DLL Files"
@cp -r winclude/$(BUILD_DIR)/* $(BUILD_DIR)/$(PLATFORM)
else
@echo
@echo "Compiling the final program"
@$(COMPILER) -o $(BUILD_DIR)/$(PLATFORM)/$(TARGET)$(EXTENSION) $^ $(LIBS)
endif
@echo
@echo "Copying assets"
@cp -r assets/ $(BUILD_DIR)/$(PLATFORM)
@echo
@echo "Running $(TARGET)"
@./$(BUILD_DIR)/$(PLATFORM)/$(TARGET)$(EXTENSION)
$(BUILD_DIR)/:
@echo "No build directory, creating one now"
@mkdir -p $(BUILD_DIR)
# Rule for building object files
$(BUILD_DIR)/%.o: $(SRC_DIR)/%.c
@mkdir -p $(dir $@) # Create the directory structure in BUILD_DIR
@$(COMPILER) $(CFLAGS) -c $< $(INCLUDES) -o $@
@echo "CC $<"
# Rule for building C++ object files
$(BUILD_DIR)/%.o: $(SRC_DIR)/%.cpp
@mkdir -p $(dir $@) # Create the directory structure in BUILD_DIR
@$(COMPILER) $(CFLAGS) -c $< $(INCLUDES) -o $@
@echo "CC $<"
announce:
@echo
@echo "Starting compilation"
@echo
clean: delete all announce
delete:
@echo
@echo "Deleting all build files"
@rm -rf $(BUILD_DIR)/
.PHONY: all clean delete announce
.NOTPARALLEL: announce clean delete $(BUILD_DIR)/ all