-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
163 lines (123 loc) · 4.69 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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
PROJECT_NAME = tiny-kyoukai
BUILD_DIR = build
SOURCE_DIR = src
HEADER_DIR = $(SOURCE_DIR)/includes
#------------------------------------------------------------------------------
# SETUP
#------------------------------------------------------------------------------
CC = gcc
CFLAGS = -std=c11 -g
LDFLAGS = -g
LIBS = x11 gtk4 gtk4-x11
STATIC_LIBS =
INCLUDES = -I$(HEADER_DIR)
ifdef LIBS
LDLIBS = $(shell pkg-config --libs $(LIBS))
INCLUDES += $(shell pkg-config --cflags $(LIBS))
endif
ifdef STATIC_LIBS
LDLIBS += -Wl,-Bstatic $(shell pkg-config --libs $(STATIC_LIBS)) -Wl,-Bdynamic
INCLUDES += $(shell pkg-config --cflags $(STATIC_LIBS))
endif
SRC = $(shell find $(SOURCE_DIR)/ -type f -name '*.c') main.c
NOM = $(basename $(notdir $(SRC)))
OBJ = $(addprefix $(BUILD_DIR)/,$(addsuffix .o, $(NOM)))
DEP = $(addprefix $(BUILD_DIR)/,$(addsuffix .d, $(NOM)))
# Variables for GResources (GTK)
RES_DIR = ressources
RES_PREFIX = kyou
RCC = glib-compile-resources
RCC_OPTS = --c-name $(RES_PREFIX)
RES_SRC = $(shell find $(RES_DIR)/ -type f -name '*.gresource.xml')
RES_NOM = $(basename $(notdir $(RES_SRC)))
RES = $(addprefix $(SOURCE_DIR)/,$(addsuffix .c, $(RES_NOM)))
RES_INC = $(addprefix $(HEADER_DIR)/,$(addsuffix .h, $(RES_NOM)))
RES_OBJ = $(addprefix $(BUILD_DIR)/,$(addsuffix .o, $(RES_NOM)))
RES_DEP = $(addprefix $(BUILD_DIR)/,$(addsuffix .dep, $(RES_NOM)))
# Add GResources objects to general prerequisites
OBJ := $(RES_OBJ) $(OBJ)
DEP += $(addprefix $(BUILD_DIR)/,$(addsuffix .d, $(RES_NOM)))
# Note: '.d' and '.dep' are different, as CC -MMD would overwrite the resource
# dependencies generated by glib-compile-resources, and '.d' concerns the
# '.o' objects made from '.gresource.c', not deps for the latter.
#------------------------------------------------------------------------------
# MAIN BUILD RULES
#------------------------------------------------------------------------------
# Main rule
all: init build
# General build
build: $(PROJECT_NAME)
# Build all the .o files in src dir
$(BUILD_DIR)/%.o: $(SOURCE_DIR)/%.c Makefile
$(CC) $(CFLAGS) -MMD -MP -c $< $(INCLUDES) -o $(BUILD_DIR)/$(notdir $@)
# Build all the .o files in base dir
$(BUILD_DIR)/%.o: %.c Makefile
$(CC) $(CFLAGS) -MMD -MP -c $< $(INCLUDES) -o $(BUILD_DIR)/$(notdir $@)
# Main program
$(PROJECT_NAME): $(OBJ)
$(CC) $(LDFLAGS) $^ $(LDLIBS) -o $@
# Helloworld
kyoutest: $(BUILD_DIR)/helloworld.o
$(CC) $(LDFLAGS) $^ $(LDLIBS) -o $@
# Dependancies generated by GCC (for headers)
-include $(DEP)
#------------------------------------------------------------------------------
# GRESOURCES
#------------------------------------------------------------------------------
# Build all GResources from .gresource.xml files in res dir
$(SOURCE_DIR)/%.gresource.c: $(RES_DIR)/%.gresource.xml $(HEADER_DIR)/%.gresource.h Makefile
$(eval DEPFILE = $(BUILD_DIR)/$(subst xml,dep,$(notdir $<)))
printf "$(SOURCE_DIR)/$$(basename $<): " | sed 's/xml/c/g' > $(DEPFILE)
$(RCC) --generate-dependencies $< --sourcedir=$(RES_DIR) | tr "\n" " " >> $(DEPFILE)
$(RCC) $< --generate-source $(RCC_OPTS) --target=$@ --sourcedir=$(RES_DIR)
# Generate header files from .gresource.xml files in res dir
$(HEADER_DIR)/%.gresource.h: $(RES_DIR)/%.gresource.xml Makefile
$(RCC) $< --generate-header $(RCC_OPTS) --target=$@ --sourcedir=$(RES_DIR)
# Dependencies generated above
-include $(RES_DEP)
# Utility to pre-generate resource headers
pregen-res: $(RES_INC)
test-res:
@echo RCC: $(RCC)
@echo RCC_OPTS: $(RCC_OPTS)
@echo RES_DIR: $(RES_DIR)
@echo RES_SRC: $(RES_SRC)
@echo RES: $(RES)
@echo RES_OBJ: $(RES_OBJ)
@echo RES_DEP: $(RES_DEP)
@echo RES_INC: $(RES_INC)
# Keep intermediate C files ! (remove with 'clear')
.PRECIOUS: $(RES_INC) $(RES)
#------------------------------------------------------------------------------
# SILLY RULES
#------------------------------------------------------------------------------
always: SUSSYBAKA
@echo "Aloha :3"
SUSSYBAKA:
#------------------------------------------------------------------------------
# UTILITIES
#------------------------------------------------------------------------------
rebuild: clean build
init: clear
mkdir -p $(BUILD_DIR)
test:
@echo CC: $(CC)
@echo CFLAGS: $(CFLAGS)
@echo LDFLAGS: $(LDFLAGS)
@echo LIBS: $(LIBS)
@echo LDLIBS: $(LDLIBS)
@echo SOURCE_DIR: $(SOURCE_DIR)
@echo HEADER_DIR: $(HEADER_DIR)
@echo OBJ: $(OBJ)
@echo SRC: $(SRC)
@echo DEP: $(DEP)
@echo INCLUDES: $(INCLUDES)
run: $(PROJECT_NAME)
./$(PROJECT_NAME)
clean:
@rm -if $(OBJ) $(DEP) $(RES) $(RES_DEP)
# @rm -rif *.o *.gch
# @rm -rif $(BUILD_DIR)/*.o $(BUILD_DIR)/*.gch
clear: clean
@rm -if $(PROJECT_NAME) $(RES_INC)
.PHONY: always init SUSSYBAKA test test-res clear clean run pregen-res