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