[411] | 1 | # let the user have a default configuration (ie for PLATFORM_DIR and SOCLIB) |
---|
| 2 | -include ./build.mk |
---|
| 3 | |
---|
[388] | 4 | ifndef MAKECMDGOALS |
---|
| 5 | MAKECMDGOALS=none |
---|
| 6 | endif |
---|
[293] | 7 | |
---|
[388] | 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 | |
---|
[406] | 23 | ifeq ($(USE_DT), 0) |
---|
| 24 | DTS= |
---|
| 25 | endif |
---|
| 26 | |
---|
[293] | 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 |
---|
[388] | 36 | DOXYGEN := doxygen |
---|
[293] | 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 |
---|
[406] | 63 | |
---|
[293] | 64 | ifndef SOCLIB |
---|
[406] | 65 | C_SRCS += sdcard.c spi.c |
---|
[293] | 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 | |
---|
[406] | 76 | ifndef USE_DT |
---|
| 77 | USE_DT := 1 |
---|
| 78 | else |
---|
| 79 | USE_DT := $(USE_DT) |
---|
| 80 | endif |
---|
[293] | 81 | |
---|
| 82 | ifdef SYSCLK_FREQ |
---|
[406] | 83 | DEFS += -DSYSCLK_FREQ=$(SYSCLK_FREQ) |
---|
[293] | 84 | endif |
---|
| 85 | |
---|
| 86 | all: $(TARGET) |
---|
| 87 | |
---|
[368] | 88 | $(TARGET): $(BUILD_DIR) $(OBJS) $(PLATFORM_DIR)/ldscript $(BUILD_DIR)/platform.ld |
---|
[388] | 89 | $(ECHO) "[ LD ] $@" |
---|
[368] | 90 | $(LD) -o $@ -T $(PLATFORM_DIR)/ldscript $(OBJS) |
---|
[293] | 91 | $(DU) -D $@ > $@.txt |
---|
| 92 | |
---|
| 93 | $(BUILD_DIR)/platform.ld: $(BUILD_DIR)/platform.dtb |
---|
[388] | 94 | $(ECHO) "[ HEXDUMP ] $(notdir $<)" |
---|
[293] | 95 | $(HEXDUMP) -v -e '"BYTE(0x" 1/1 "%02X" ")\n"' $< > $@ |
---|
| 96 | |
---|
| 97 | $(BUILD_DIR)/platform.dtb: $(DTS) |
---|
[406] | 98 | ifeq ($(USE_DT), 1) |
---|
[388] | 99 | $(ECHO) "[ DTC ] $(notdir $<)" |
---|
[390] | 100 | ${DTC} -O dtb -o $@ $< &> /dev/null |
---|
[406] | 101 | else |
---|
| 102 | touch $@ |
---|
| 103 | endif |
---|
[293] | 104 | |
---|
| 105 | $(BUILD_DIR): |
---|
| 106 | $(MKDIR) $@ |
---|
| 107 | |
---|
[388] | 108 | doc: Doxyfile |
---|
| 109 | $(DOXYGEN) Doxyfile |
---|
| 110 | |
---|
[293] | 111 | clean: |
---|
| 112 | $(RM) $(TARGET).txt $(TARGET) *~ $(BUILD_DIR) |
---|
| 113 | |
---|
[388] | 114 | clean-doc: |
---|
| 115 | $(RM) doc |
---|
[293] | 116 | |
---|
[388] | 117 | distclean: clean clean-doc |
---|
| 118 | |
---|
[293] | 119 | # ============================================================================= |
---|
| 120 | # Implicit makefile rules |
---|
| 121 | |
---|
| 122 | $(BUILD_DIR)/%.o: %.c |
---|
[388] | 123 | $(ECHO) "[ CC ] $(notdir $<)" |
---|
[293] | 124 | $(CC) $(DEFS) $(CFLAGS) $(INCLUDE) -c -o $@ $< |
---|
| 125 | $(DU) -D $@ > $@.txt |
---|
| 126 | |
---|
| 127 | $(BUILD_DIR)/%.o: %.S |
---|
[388] | 128 | $(ECHO) "[ AS ] $(notdir $<)" |
---|
[293] | 129 | $(CC) $(DEFS) ${INCLUDE} -g -mips32 -c -o $@ $< |
---|
| 130 | $(DU) -D $@ > $@.txt |
---|
| 131 | |
---|
| 132 | .SILENT: |
---|