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