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