-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
50 lines (38 loc) · 1.24 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
BIN_DIR := bin
SRC_DIR := src
AS = nasm
BINS := $(BIN_DIR)/xlink
OBJS := $(patsubst $(SRC_DIR)/%.c,$(BIN_DIR)/%.o,$(filter-out \
$(patsubst $(BIN_DIR)/%,$(SRC_DIR)/%.c,$(BINS)),$(wildcard $(SRC_DIR)/*.c)))
ASMS := $(shell find $(SRC_DIR) -type f -name "*.asm")
MODS := $(patsubst $(SRC_DIR)/%.asm,$(BIN_DIR)/%.o,$(ASMS))
CFLAGS := -O2 -Wno-parenthesis -Wno-overlength-strings
ASFLAGS := -f obj
LIBS := -lm
all: $(BINS) $(OBJS) $(MODS)
guard=@mkdir -p $(@D)
$(BIN_DIR)/%.o: $(SRC_DIR)/%.c
$(guard)
$(CC) $(CFLAGS) -c -o $@ $<
$(BIN_DIR)/%.o: $(SRC_DIR)/%.asm
$(guard)
$(AS) $(ASFLAGS) -i $(dir $<) -o $@ $<
$(SRC_DIR)/stubs.h: $(MODS)
@echo '/* Generated file, do not commit */' > $@
@echo 'const xlink_file XLINK_STUB_MODULES[] = {' >> $@
@$(foreach s,$(patsubst $(BIN_DIR)/%.o,%,$^), \
$(eval SIZE = $(shell stat -c %s $(BIN_DIR)/$s.o)) \
echo ' { ' >> $@; \
echo ' "$s.o",' >> $@; \
echo ' $(SIZE), 0,' >> $@; \
echo ' (unsigned char[]) {' >> $@; \
xxd -i - < $(BIN_DIR)/$s.o | sed -e s'/^/ /' >> $@; \
echo ' }' >> $@; \
echo ' },' >> $@; \
)
@echo '};' >> $@; \
$(BIN_DIR)/%: $(SRC_DIR)/%.c $(SRC_DIR)/stubs.h $(OBJS)
$(guard)
$(CC) $(CFLAGS) $< $(OBJS) -o $@ $(LIBS)
clean:
rm -rf $(BIN_DIR) $(SRC_DIR)/stubs.h