-
Notifications
You must be signed in to change notification settings - Fork 11
/
Makefile
120 lines (78 loc) · 3.7 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
#
# Makefile for plo (structured)
#
# Copyright 2020-2022 Phoenix Systems
#
# %LICENSE%
#
SIL ?= @
MAKEFLAGS += --no-print-directory
VERSION="1.21 rev: $(shell git rev-parse --short HEAD)"
KERNEL=1
include ../phoenix-rtos-build/Makefile.common
LDGEN ?= $(CC)
CFLAGS += -I.
CPPFLAGS += -DVERSION=\"$(VERSION)\"
OBJS :=
# hal Makefile needs to be included first as it adds cmds and devices definitions
include hal/$(TARGET_SUFF)/Makefile
include lib/Makefile
include devices/Makefile
include phfs/Makefile
include cmds/Makefile
# use explicit plo script dir, legacy value by default
PLO_SCRIPT_DIR ?= $(BUILD_DIR)
OBJS += $(addprefix $(PREFIX_O), _startc.o plo.o syspage.o)
# add optional per-project customizations - all WEAK symbols can be overridden
OBJS += $(addprefix $(PREFIX_O)/custom/, $(patsubst $(PROJECT_PATH)/%.c, %.o, $(wildcard $(PROJECT_PATH)/plo*.c)))
$(PREFIX_O)/custom/%.o: $(PROJECT_PATH)/%.c
@mkdir -p $(@D)
@printf "CC %-24s\n" "$<"
$(SIL)$(CC) -c $(CFLAGS) "$(abspath $<)" -o "$@"
$(SIL)$(CC) -M -MD -MP -MF $(PREFIX_O)/custom/$*.c.d -MT "$@" $(CFLAGS) $<
# incremental build quick-fix, WARN: assuming the sources are in c
DEPS := $(patsubst %.o, %.c.d, $(OBJS))
-include $(DEPS)
.PHONY: all base ram clean
.PRECIOUS: $(BUILD_DIR)%/.
all: base ram
base: $(PREFIX_PROG_STRIPPED)plo-$(TARGET_FAMILY)-$(TARGET_SUBFAMILY).elf $(PREFIX_PROG_STRIPPED)plo-$(TARGET_FAMILY)-$(TARGET_SUBFAMILY).img
ram: $(PREFIX_PROG_STRIPPED)plo-ram-$(TARGET_FAMILY)-$(TARGET_SUBFAMILY).elf $(PREFIX_PROG_STRIPPED)plo-ram-$(TARGET_FAMILY)-$(TARGET_SUBFAMILY).img
$(PLO_SCRIPT_DIR)/script.plo $(PLO_SCRIPT_DIR)/script-ram.plo: | $(PLO_SCRIPT_DIR)/.
@echo "TOUCH $(@F)"
$(SIL)touch $@
$(PREFIX_O)/script.o.plo: $(PREFIX_O)cmds/cmd.o $(PLO_SCRIPT_DIR)/script.plo | $(PREFIX_O)/.
@echo "EMBED script.plo"
$(SIL)$(OBJCOPY) --update-section .data=$(PLO_SCRIPT_DIR)/script.plo $(PREFIX_O)cmds/cmd.o --add-symbol script=.data:0 $@
$(PREFIX_O)/script-ram.o.plo: $(PREFIX_O)cmds/cmd.o $(PLO_SCRIPT_DIR)/script-ram.plo | $(PREFIX_O)/.
@echo "EMBED script-ram.plo"
$(SIL)$(OBJCOPY) --update-section .data=$(PLO_SCRIPT_DIR)/script-ram.plo $(PREFIX_O)cmds/cmd.o --add-symbol script=.data:0 $@
$(PREFIX_PROG)plo-$(TARGET_FAMILY)-$(TARGET_SUBFAMILY).elf: $(PREFIX_O)/$(TARGET_FAMILY)-$(TARGET_SUBFAMILY).ld $(OBJS) $(PREFIX_O)/script.o.plo | $(PREFIX_PROG)/.
@echo "LD $(@F)"
$(SIL)$(LD) $(CFLAGS) $(LDFLAGS) -Wl,-Map=$<.map -o $@ -Wl,-T,$^ -nostdlib -lgcc
$(PREFIX_PROG)plo-ram-$(TARGET_FAMILY)-$(TARGET_SUBFAMILY).elf: $(PREFIX_O)/$(TARGET_FAMILY)-$(TARGET_SUBFAMILY)-ram.ld $(OBJS) $(PREFIX_O)/script-ram.o.plo | $(PREFIX_PROG)/.
@echo "LD $(@F)"
$(SIL)$(LD) $(CFLAGS) $(LDFLAGS) -Wl,-Map=$<.map -o $@ -Wl,-T,$^ -nostdlib -lgcc
$(PREFIX_PROG_STRIPPED)%.hex: $(PREFIX_PROG_STRIPPED)%.elf
@echo "HEX $(@F)"
$(SIL)$(OBJCOPY) -O ihex $< $@
$(PREFIX_PROG_STRIPPED)%.img: $(PREFIX_PROG_STRIPPED)%.elf
@echo "BIN $(@F)"
$(SIL)$(OBJCOPY) -O binary $< $@
-include $(PREFIX_O)/$(TARGET_FAMILY)-$(TARGET_SUBFAMILY)*ld.d
$(PREFIX_O)/$(TARGET_FAMILY)-$(TARGET_SUBFAMILY).ld: | $(PREFIX_O)/.
@echo "GEN $(@F)"
$(SIL)$(LDGEN) $(LDSFLAGS) -MP -MF $@.d -MMD -D__LINKER__ -undef -xc -E -P ld/$(TARGET_FAMILY)-$(TARGET_SUBFAMILY).ldt > $@
$(SIL)$(SED) -i.tmp -e 's`.*\.o[ \t]*:`$@:`' $@.d && rm $@.d.tmp
$(PREFIX_O)/$(TARGET_FAMILY)-$(TARGET_SUBFAMILY)-%.ld: | $(PREFIX_O)/.
@echo "GEN $(@F)"
$(SIL)$(LDGEN) $(LDSFLAGS) -MP -MF $@.d -MMD -D__LINKER__ -D$* -undef -xc -E -P ld/$(TARGET_FAMILY)-$(TARGET_SUBFAMILY).ldt > $@
$(SIL)$(SED) -i.tmp -e 's`.*\.o[ \t]*:`$@:`' $@.d && rm $@.d.tmp
%/.:
@echo "MKDIR $(@D)"
$(SIL)mkdir -p "$(@D)"
clean:
@echo "rm -rf $(BUILD_DIR)"
ifneq ($(filter clean,$(MAKECMDGOALS)),)
$(shell rm -rf $(BUILD_DIR))
endif