1 | # let the user have a default configuration (ie for PLATFORM_DIR and SOCLIB) |
---|
2 | -include ./build.mk |
---|
3 | |
---|
4 | MAKECMDGOALS ?= none |
---|
5 | |
---|
6 | ifneq ($(MAKECMDGOALS),$(filter $(MAKECMDGOALS),clean distclean clean-doc doc)) |
---|
7 | ifndef PLATFORM_DIR |
---|
8 | $(error please define PLATFORM_DIR 'make PLATFORM_DIR=foo') |
---|
9 | else |
---|
10 | ifdef SOCLIB |
---|
11 | DEFS+= -DSOCLIB_IOC |
---|
12 | DTS=platform_soclib.dts |
---|
13 | $(info Make for $(PLATFORM_DIR), SocLib variant) |
---|
14 | else |
---|
15 | DTS=platform_fpga.dts |
---|
16 | $(info Make for $(PLATFORM_DIR), FPGA variant) |
---|
17 | endif |
---|
18 | endif |
---|
19 | endif |
---|
20 | |
---|
21 | LD := mipsel-unknown-elf-ld |
---|
22 | CC := mipsel-unknown-elf-gcc |
---|
23 | AS := mipsel-unknown-elf-as |
---|
24 | DU := mipsel-unknown-elf-objdump |
---|
25 | RM := rm -rf |
---|
26 | ECHO := echo |
---|
27 | MKDIR := mkdir |
---|
28 | DTC := dtc |
---|
29 | HEXDUMP := hexdump |
---|
30 | DOXYGEN := doxygen |
---|
31 | |
---|
32 | BUILD_DIR := build |
---|
33 | SRCS_DIR := src |
---|
34 | INCS_DIR := include |
---|
35 | |
---|
36 | # ============================================================================= |
---|
37 | # Include files paths |
---|
38 | # ============================================================================= |
---|
39 | |
---|
40 | INCLUDE += -I. -I$(INCS_DIR) -I$(PLATFORM_DIR) |
---|
41 | |
---|
42 | # ============================================================================= |
---|
43 | # Paths of sources in another directories |
---|
44 | # ============================================================================= |
---|
45 | |
---|
46 | VPATH += $(SRCS_DIR) |
---|
47 | VPATH += $(PLATFORM_DIR) |
---|
48 | |
---|
49 | # ============================================================================= |
---|
50 | # Object files |
---|
51 | # ============================================================================= |
---|
52 | |
---|
53 | CFLAGS := -Wall \ |
---|
54 | -mno-gpopt \ |
---|
55 | -ffreestanding \ |
---|
56 | -fomit-frame-pointer \ |
---|
57 | -mips32 \ |
---|
58 | -ggdb \ |
---|
59 | -mlong-calls \ |
---|
60 | -Werror |
---|
61 | |
---|
62 | C_SRCS := reset_elf_loader.c \ |
---|
63 | reset_ioc.c \ |
---|
64 | reset_utils.c \ |
---|
65 | reset_tty.c \ |
---|
66 | reset_exception.c |
---|
67 | |
---|
68 | ifndef SOCLIB |
---|
69 | C_SRCS += sdcard.c spi.c |
---|
70 | endif |
---|
71 | |
---|
72 | S_SRCS := reset.S |
---|
73 | |
---|
74 | OBJS := $(subst .c,.o, $(notdir $(C_SRCS))) |
---|
75 | OBJS += $(subst .S,.o, $(notdir $(S_SRCS))) |
---|
76 | OBJS := $(addprefix $(BUILD_DIR)/, $(OBJS)) |
---|
77 | |
---|
78 | TARGET := preloader.elf |
---|
79 | |
---|
80 | USE_DT ?= 1 |
---|
81 | |
---|
82 | all: $(TARGET) |
---|
83 | |
---|
84 | $(BUILD_DIR)/version.o: $(BUILD_DIR) $(OBJS) version version.sh |
---|
85 | $(ECHO) "[version.sh]" |
---|
86 | ./version.sh > $(BUILD_DIR)/version.c |
---|
87 | $(ECHO) "[ CC ] $(BUILD_DIR)/version.c" |
---|
88 | $(CC) $(DEFS) $(CFLAGS) $(INCLUDE) -c -o $@ $(BUILD_DIR)/version.c |
---|
89 | $(DU) -D $@ > $@.txt |
---|
90 | |
---|
91 | $(TARGET): $(BUILD_DIR) $(BUILD_DIR)/version.o $(OBJS) $(PLATFORM_DIR)/ldscript $(BUILD_DIR)/platform.ld |
---|
92 | $(ECHO) "[ LD ] $@" |
---|
93 | $(LD) -o $@ -T $(PLATFORM_DIR)/ldscript $(OBJS) $(BUILD_DIR)/version.o |
---|
94 | $(DU) -D $@ > $@.txt |
---|
95 | |
---|
96 | ifeq ($(USE_DT), 1) |
---|
97 | $(BUILD_DIR)/platform.ld: $(BUILD_DIR)/platform.dtb |
---|
98 | $(ECHO) "[ HEXDUMP ] $(notdir $<)" |
---|
99 | $(HEXDUMP) -v -e '"BYTE(0x" 1/1 "%02X" ")\n"' $< > $@ |
---|
100 | else |
---|
101 | $(BUILD_DIR)/platform.ld: |
---|
102 | $(ECHO) "[ TOUCH ] $(notdir $@)" |
---|
103 | touch $@ |
---|
104 | endif |
---|
105 | |
---|
106 | $(BUILD_DIR)/platform.dtb: $(DTS) |
---|
107 | $(ECHO) "[ DTC ] $(notdir $<)" |
---|
108 | ${DTC} -O dtb -o $@ $< &> /dev/null |
---|
109 | |
---|
110 | $(BUILD_DIR): |
---|
111 | $(MKDIR) $@ |
---|
112 | |
---|
113 | doc: Doxyfile |
---|
114 | $(DOXYGEN) Doxyfile |
---|
115 | |
---|
116 | clean: |
---|
117 | $(RM) $(TARGET).txt $(TARGET) *~ $(BUILD_DIR) |
---|
118 | |
---|
119 | clean-doc: |
---|
120 | $(RM) doc |
---|
121 | |
---|
122 | distclean: clean clean-doc |
---|
123 | |
---|
124 | # ============================================================================= |
---|
125 | # Implicit makefile rules |
---|
126 | |
---|
127 | $(BUILD_DIR)/%.o: %.c |
---|
128 | $(ECHO) "[ CC ] $(notdir $<)" |
---|
129 | $(CC) $(DEFS) $(CFLAGS) $(INCLUDE) -c -o $@ $< |
---|
130 | $(DU) -D $@ > $@.txt |
---|
131 | |
---|
132 | $(BUILD_DIR)/%.o: %.S |
---|
133 | $(ECHO) "[ AS ] $(notdir $<)" |
---|
134 | $(CC) $(DEFS) ${INCLUDE} -g -mips32 -c -o $@ $< |
---|
135 | $(DU) -D $@ > $@.txt |
---|
136 | |
---|
137 | .SILENT: |
---|