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