-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
164 lines (111 loc) · 4.46 KB
/
Copy pathMakefile
File metadata and controls
164 lines (111 loc) · 4.46 KB
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
rwildcard = $(foreach d,$(wildcard $(1:=/*)),$(call rwildcard,$d,$2) $(filter $(subst *,%,$2),$d))
C_DYN_DIR := .c-dyn-split
SRCDIR := src
OUTDIR := out
BUILDIR := build
CFLAGS += -Wall
HOST_CFLAGS := ${CFLAGS}
DYN_CFLAGS := ${CFLAGS}
all_src := $(call rwildcard,${SRCDIR},*.c)
dyn_src := $(call rwildcard,${SRCDIR},*.dyn.c)
generated_dyn_headers := $(call rwildcard,${SRCDIR},*.dyn.gen.h)
dyn_sofiles = $(dyn_src:${SRCDIR}/%.c=${OUTDIR}/%.so)
dyn_objfiles = $(dyn_src:${SRCDIR}/%.c=${BUILDIR}/%.o)
dyn_deps := $(dyn_objfiles:%.o=%.d)
dyn_headerfiles := $(dyn_src:%.dyn.c=%.dyn.gen.h)
unified_src := ${all_src}
unified_objfiles := ${unified_src:${SRCDIR}/%.c=${BUILDIR}/%.o}
unified_deps := $(unified_objfiles:%.o=%.d)
host_src := ${filter-out $(dyn_src),${all_src}}
host_objfiles = $(host_src:${SRCDIR}/%.c=${BUILDIR}/%.o)
host_deps := $(host_objfiles:%.o=%.d)
host_executable := ${OUTDIR}/main.host
default: split
info:
@echo
@echo all: ${all_src}
@echo host: ${host_src}
@echo dyn: ${dyn_src}
@echo dyn so: ${dyn_sofiles}
@echo dyn deps: ${dyn_deps}
@echo
@date
@date +%s
u: unified
unified: HOST_CFLAGS := ${HOST_CFLAGS} -MMD -MP
unified: DYN_CFLAGS := ${DYN_CFLAGS} -MMD -MP -fPIC
unified: unified_executable
@echo
@echo unified_src
@echo ${unified_src}
@echo unified_objfiles
@echo ${unified_objfiles}
@echo
${unified_objfiles}: ${dyn_headerfiles}
${OUTDIR}/main.unified: ${unified_objfiles} ${C_DYN_DIR}/dynamic_registry.o
@mkdir -p $(OUTDIR)
cc -o ${host_executable} $^
unified_executable: ${OUTDIR}/main.unified
split: HOST_CFLAGS := ${HOST_CFLAGS} -MMD -MP -g -D_DYN_SPLIT_BUILD
split: DYN_CFLAGS := ${DYN_CFLAGS} -MMD -MP -fPIC -g -D_DYN_SPLIT_BUILD
split: ${dyn_sofiles} ${host_executable}
build_sofiles: ${dyn_sofiles}
${host_executable}: ${host_objfiles} ${C_DYN_DIR}/dynamic_registry.o
@mkdir -p $(@D)
cc -o ${host_executable} $^ -rdynamic
${host_objfiles}: ${BUILDIR}/%.o: ${SRCDIR}/%.c
@mkdir -p $(@D)
cc -o ${@} -c $< ${HOST_CFLAGS}
${C_DYN_DIR}/dynamic_registry.o: CFLAGS+=-fPIC -g -D_DYN_SPLIT_BUILD -DDYNCSPLIT_LOG_HIDE_DEBUG
${dyn_sofiles}: ${OUTDIR}/%.so: ${BUILDIR}/%.o
@mkdir -p $(@D)
cc -o ${@} $^ -shared -rdynamic
${dyn_objfiles}: ${BUILDIR}/%.dyn.o: ${SRCDIR}/%.dyn.gen.h
self_guard = $(shell echo "${<:$(SRCDIR)/%.c=%.c}" | sed -e 's#\([\/_\.-]\)#_#g' | sed -e 's#\(.*\)#\U\1#g')
${dyn_objfiles}: ${BUILDIR}/%.o: ${SRCDIR}/%.c
@mkdir -p $(@D)
cc -o ${@} -c $< ${DYN_CFLAGS} -D$(self_guard)
@mv ${@:%.o=%.d} ${@:%.o=%.t}
awk -f ./${C_DYN_DIR}/awkrecipe ${@:%.o=%.t} > ${@:%.o=%.d}
@rm ${@:%.o=%.t}
%.dyn.gen.h: %.dyn.c ${C_DYN_DIR}/gen/node_modules/tree-sitter/index.js
bun run ./${C_DYN_DIR}/gen/scan.js `realpath $<`
bunpath := $(shell which bun)
bunpath := $(if $(bunpath),$(bunpath),trigger_bun_install)
${C_DYN_DIR}/gen/node_modules/tree-sitter/index.js: $(bunpath)
cd ${C_DYN_DIR}/gen && bun i
$(bunpath):
curl -fsSL https://bun.sh/install | bash
-include $(dyn_deps)
-include $(host_deps)
-include $(unified_deps)
${C_DYN_DIR}/downloads/latest.tar.gz:
mkdir -p ${C_DYN_DIR}/downloads
curl https://codeload.github.com/badrpas/c-dyn-split/tar.gz/master > ${C_DYN_DIR}/downloads/latest.tar.gz
init: ${C_DYN_DIR}/downloads/latest.tar.gz .gitignore rtmuxer.yaml gdbrc
cd ${C_DYN_DIR} && tar -xzf ./downloads/latest.tar.gz --strip=2 c-dyn-split-master/internals
cd ${C_DYN_DIR} && tar -xzf ./downloads/latest.tar.gz --strip=1 c-dyn-split-master/readme.md
update_self: ${C_DYN_DIR}/downloads/latest.tar.gz
tar -xzf ./${C_DYN_DIR}/downloads/latest.tar.gz --strip=1 c-dyn-split-master/Makefile
touch Makefile
.gitignore: ${C_DYN_DIR}/downloads/latest.tar.gz
tar -xzf ./${C_DYN_DIR}/downloads/latest.tar.gz --strip=2 c-dyn-split-master/internals/.gitignore
touch $@
rtmuxer.yaml: ${C_DYN_DIR}/downloads/latest.tar.gz
tar -xzf ./${C_DYN_DIR}/downloads/latest.tar.gz --strip=1 c-dyn-split-master/rtmuxer.yaml
touch $@
gdbrc: ${C_DYN_DIR}/downloads/latest.tar.gz
tar -xzf ./${C_DYN_DIR}/downloads/latest.tar.gz --strip=1 c-dyn-split-master/gdbrc
touch $@
ifeq ($(wildcard ${SRCDIR}/main.c),)
init: example_basic
example_basic: ${C_DYN_DIR}/downloads/latest.tar.gz
mkdir -p ${SRCDIR}
cd ${SRCDIR} && tar -xzf ${ARCHIVE} --strip=3 c-dyn-split-master/examples/basic
else
example_basic:
@echo ${SRCDIR}/main.c exists. Skipping example init.
endif
example_basic: ARCHIVE = ${shell realpath ${C_DYN_DIR}/downloads/latest.tar.gz}
clean:
rm -rf ${BUILDIR} ${OUTDIR} ${generated_dyn_headers} ${C_DYN_DIR}/dynamic_registry.o ${C_DYN_DIR}/downloads