[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 |
---|
[653] | 11 | ifdef RAMDISK |
---|
| 12 | DEFS+= -DUSE_RDK |
---|
| 13 | else |
---|
| 14 | DEFS+= -DUSE_BDV |
---|
| 15 | endif |
---|
[388] | 16 | DTS=platform_soclib.dts |
---|
[586] | 17 | $(info Make for $(PLATFORM_DIR), SocLib variant) |
---|
[388] | 18 | else |
---|
[653] | 19 | DEFS+= -DUSE_SPI |
---|
[388] | 20 | DTS=platform_fpga.dts |
---|
[586] | 21 | $(info Make for $(PLATFORM_DIR), FPGA variant) |
---|
[388] | 22 | endif |
---|
| 23 | endif |
---|
| 24 | endif |
---|
| 25 | |
---|
[653] | 26 | LD := mipsel-unknown-elf-ld |
---|
| 27 | CC := mipsel-unknown-elf-gcc |
---|
| 28 | AS := mipsel-unknown-elf-as |
---|
| 29 | DU := mipsel-unknown-elf-objdump |
---|
| 30 | RM := rm -rf |
---|
| 31 | ECHO := @echo |
---|
| 32 | MKDIR := mkdir |
---|
| 33 | DTC := dtc |
---|
| 34 | HEXDUMP := hexdump |
---|
[388] | 35 | DOXYGEN := doxygen |
---|
[293] | 36 | |
---|
| 37 | BUILD_DIR := build |
---|
| 38 | SRCS_DIR := src |
---|
| 39 | INCS_DIR := include |
---|
| 40 | |
---|
| 41 | # ============================================================================= |
---|
| 42 | # Include files paths |
---|
| 43 | # ============================================================================= |
---|
| 44 | |
---|
[653] | 45 | INCLUDE += -I. -I$(INCS_DIR) -I$(PLATFORM_DIR) |
---|
[293] | 46 | |
---|
| 47 | # ============================================================================= |
---|
| 48 | # Paths of sources in another directories |
---|
| 49 | # ============================================================================= |
---|
| 50 | |
---|
| 51 | VPATH += $(SRCS_DIR) |
---|
| 52 | VPATH += $(PLATFORM_DIR) |
---|
| 53 | |
---|
| 54 | # ============================================================================= |
---|
| 55 | # Object files |
---|
| 56 | # ============================================================================= |
---|
| 57 | |
---|
[586] | 58 | CFLAGS := -Wall \ |
---|
| 59 | -mno-gpopt \ |
---|
| 60 | -ffreestanding \ |
---|
| 61 | -fomit-frame-pointer \ |
---|
| 62 | -mips32 \ |
---|
[653] | 63 | -ggdb \ |
---|
[586] | 64 | -mlong-calls \ |
---|
| 65 | -Werror |
---|
[293] | 66 | |
---|
[653] | 67 | C_SRCS := reset_elf_loader.c \ |
---|
[586] | 68 | reset_ioc.c \ |
---|
| 69 | reset_utils.c \ |
---|
| 70 | reset_tty.c \ |
---|
| 71 | reset_exception.c |
---|
[406] | 72 | |
---|
[293] | 73 | ifndef SOCLIB |
---|
[406] | 74 | C_SRCS += sdcard.c spi.c |
---|
[293] | 75 | endif |
---|
| 76 | |
---|
[653] | 77 | S_SRCS := reset.S |
---|
[293] | 78 | |
---|
| 79 | OBJS := $(subst .c,.o, $(notdir $(C_SRCS))) |
---|
| 80 | OBJS += $(subst .S,.o, $(notdir $(S_SRCS))) |
---|
| 81 | OBJS := $(addprefix $(BUILD_DIR)/, $(OBJS)) |
---|
| 82 | |
---|
[586] | 83 | TARGET := preloader.elf |
---|
[293] | 84 | |
---|
[653] | 85 | USE_DT ?= 1 |
---|
[293] | 86 | |
---|
| 87 | all: $(TARGET) |
---|
| 88 | |
---|
[587] | 89 | $(BUILD_DIR)/version.o: $(BUILD_DIR) $(OBJS) version version.sh |
---|
| 90 | $(ECHO) "[version.sh]" |
---|
| 91 | ./version.sh > $(BUILD_DIR)/version.c |
---|
| 92 | $(ECHO) "[ CC ] $(BUILD_DIR)/version.c" |
---|
| 93 | $(CC) $(DEFS) $(CFLAGS) $(INCLUDE) -c -o $@ $(BUILD_DIR)/version.c |
---|
| 94 | $(DU) -D $@ > $@.txt |
---|
[502] | 95 | |
---|
[587] | 96 | $(TARGET): $(BUILD_DIR) $(BUILD_DIR)/version.o $(OBJS) $(PLATFORM_DIR)/ldscript $(BUILD_DIR)/platform.ld |
---|
[388] | 97 | $(ECHO) "[ LD ] $@" |
---|
[587] | 98 | $(LD) -o $@ -T $(PLATFORM_DIR)/ldscript $(OBJS) $(BUILD_DIR)/version.o |
---|
[293] | 99 | $(DU) -D $@ > $@.txt |
---|
| 100 | |
---|
[425] | 101 | ifeq ($(USE_DT), 1) |
---|
[293] | 102 | $(BUILD_DIR)/platform.ld: $(BUILD_DIR)/platform.dtb |
---|
[388] | 103 | $(ECHO) "[ HEXDUMP ] $(notdir $<)" |
---|
[293] | 104 | $(HEXDUMP) -v -e '"BYTE(0x" 1/1 "%02X" ")\n"' $< > $@ |
---|
[425] | 105 | else |
---|
| 106 | $(BUILD_DIR)/platform.ld: |
---|
| 107 | $(ECHO) "[ TOUCH ] $(notdir $@)" |
---|
| 108 | touch $@ |
---|
| 109 | endif |
---|
[293] | 110 | |
---|
| 111 | $(BUILD_DIR)/platform.dtb: $(DTS) |
---|
[388] | 112 | $(ECHO) "[ DTC ] $(notdir $<)" |
---|
[390] | 113 | ${DTC} -O dtb -o $@ $< &> /dev/null |
---|
[293] | 114 | |
---|
| 115 | $(BUILD_DIR): |
---|
| 116 | $(MKDIR) $@ |
---|
| 117 | |
---|
[388] | 118 | doc: Doxyfile |
---|
| 119 | $(DOXYGEN) Doxyfile |
---|
| 120 | |
---|
[293] | 121 | clean: |
---|
| 122 | $(RM) $(TARGET).txt $(TARGET) *~ $(BUILD_DIR) |
---|
| 123 | |
---|
[388] | 124 | clean-doc: |
---|
| 125 | $(RM) doc |
---|
[293] | 126 | |
---|
[388] | 127 | distclean: clean clean-doc |
---|
| 128 | |
---|
[293] | 129 | # ============================================================================= |
---|
| 130 | # Implicit makefile rules |
---|
| 131 | |
---|
| 132 | $(BUILD_DIR)/%.o: %.c |
---|
[388] | 133 | $(ECHO) "[ CC ] $(notdir $<)" |
---|
[293] | 134 | $(CC) $(DEFS) $(CFLAGS) $(INCLUDE) -c -o $@ $< |
---|
| 135 | $(DU) -D $@ > $@.txt |
---|
| 136 | |
---|
| 137 | $(BUILD_DIR)/%.o: %.S |
---|
[388] | 138 | $(ECHO) "[ AS ] $(notdir $<)" |
---|
[293] | 139 | $(CC) $(DEFS) ${INCLUDE} -g -mips32 -c -o $@ $< |
---|
| 140 | $(DU) -D $@ > $@.txt |
---|
| 141 | |
---|
[654] | 142 | .SILENT: |
---|