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