-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathMakefile
76 lines (61 loc) · 1.72 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
Q ?= @
CC = arm-none-eabi-gcc
BUILD_DIR = output
NWLINK = npx --yes -- [email protected]
LINK_GC = 1
LTO = 1
define object_for
$(addprefix $(BUILD_DIR)/,$(addsuffix .o,$(basename $(1))))
endef
src = $(addprefix src/,\
main.c \
)
CFLAGS = -std=c99
CFLAGS += $(shell $(NWLINK) eadk-cflags)
CFLAGS += -Os -Wall
CFLAGS += -ggdb
LDFLAGS = -Wl,--relocatable
LDFLAGS += -nostartfiles
LDFLAGS += --specs=nano.specs
# LDFLAGS += --specs=nosys.specs # Alternatively, use full-fledged newlib
ifeq ($(LINK_GC),1)
CFLAGS += -fdata-sections -ffunction-sections
LDFLAGS += -Wl,-e,main -Wl,-u,eadk_app_name -Wl,-u,eadk_app_icon -Wl,-u,eadk_api_level
LDFLAGS += -Wl,--gc-sections
endif
ifeq ($(LTO),1)
CFLAGS += -flto -fno-fat-lto-objects
CFLAGS += -fwhole-program
CFLAGS += -fvisibility=internal
LDFLAGS += -flinker-output=nolto-rel
endif
.PHONY: build
build: $(BUILD_DIR)/app.nwa
.PHONY: check
check: $(BUILD_DIR)/app.bin
.PHONY: run
run: $(BUILD_DIR)/app.nwa src/input.txt
@echo "INSTALL $<"
$(Q) $(NWLINK) install-nwa --external-data src/input.txt $<
$(BUILD_DIR)/%.bin: $(BUILD_DIR)/%.nwa src/input.txt
@echo "BIN $@"
$(Q) $(NWLINK) nwa-bin --external-data src/input.txt $< $@
$(BUILD_DIR)/%.elf: $(BUILD_DIR)/%.nwa src/input.txt
@echo "ELF $@"
$(Q) $(NWLINK) nwa-elf --external-data src/input.txt $< $@
$(BUILD_DIR)/app.nwa: $(call object_for,$(src)) $(BUILD_DIR)/icon.o
@echo "LD $@"
$(Q) $(CC) $(CFLAGS) $(LDFLAGS) $^ -o $@
$(addprefix $(BUILD_DIR)/,%.o): %.c | $(BUILD_DIR)
@echo "CC $^"
$(Q) $(CC) $(CFLAGS) -c $^ -o $@
$(BUILD_DIR)/icon.o: src/icon.png
@echo "ICON $<"
$(Q) $(NWLINK) png-icon-o $< $@
.PRECIOUS: $(BUILD_DIR)
$(BUILD_DIR):
$(Q) mkdir -p $@/src
.PHONY: clean
clean:
@echo "CLEAN"
$(Q) rm -rf $(BUILD_DIR)