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