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