-
Notifications
You must be signed in to change notification settings - Fork 1
/
gen.mk
39 lines (31 loc) · 1.31 KB
/
gen.mk
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
# subset of Makefile used to generate headers on demand
-include $(OBJS:.o=.d)
SHELL := bash
# collects NAME(...) macros into a sorted list of NAME__ITEM(...) in .gen/name_list.h
# NAME can optionally be followed by more uppercase letters: NAME_MORE_WORDS(...)
# which adds NAME_MORE_WORDS__ITEM(...) to the list
# The list will be sorted on everything after the first '('
.gen/%_list.h.new: NAME=$(shell echo $(notdir $*) | tr a-z A-Z)
.gen/%_list.h.new: $(SRC)
@mkdir -p $(dir $@)
sed -E -n -e 's/^ *'"$(NAME)"'(_[A-Z][A-Z_]*)?\((.*)\).*/'"$(NAME)\1__ITEM"'( \2 )/p' $(SRC) | sed -e 's/,/ , /g' | LC_ALL=C sort -u -k 2,2 > $@
# store the current git commit
.gen/git_log.h.new: LOG = $(shell git log -1 --oneline)
.gen/git_log.h.new: $(SRC)
@mkdir -p $(dir $@)
@if git diff-index --quiet HEAD --; then \
echo "#define GIT_LOG \"$(LOG)\"" > $@; \
else \
echo "#define GIT_LOG \"$(LOG) [DIRTY]\"" > $@; \
fi
.gen/%-local.h.new: %.c startle/bin/makeheaders
@mkdir -p $(dir $@)
startle/bin/makeheaders -local $<:$@
.gen/%.h.new: %.c startle/bin/makeheaders
@mkdir -p $(dir $@)
startle/bin/makeheaders $<:$@
.gen/%.h: .gen/%.h.new $(SRC)
@cmp -s $< $@ || cp $< $@
startle/bin/makeheaders: startle/makeheaders/makeheaders.c
@mkdir -p startle/bin
$(CC) -O -w startle/makeheaders/makeheaders.c -o startle/bin/makeheaders