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