[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 |
---|
[586] | 13 | $(info Make for $(PLATFORM_DIR), SocLib variant) |
---|
[388] | 14 | else |
---|
| 15 | DTS=platform_fpga.dts |
---|
[586] | 16 | $(info Make for $(PLATFORM_DIR), FPGA variant) |
---|
[388] | 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 | |
---|
[586] | 53 | CFLAGS := -Wall \ |
---|
| 54 | -mno-gpopt \ |
---|
| 55 | -ffreestanding \ |
---|
| 56 | -fomit-frame-pointer \ |
---|
| 57 | -mips32 \ |
---|
| 58 | -ggdb \ |
---|
| 59 | -mlong-calls \ |
---|
| 60 | -Werror |
---|
[293] | 61 | |
---|
[586] | 62 | C_SRCS := reset_elf_loader.c \ |
---|
| 63 | reset_ioc.c \ |
---|
| 64 | reset_utils.c \ |
---|
| 65 | reset_tty.c \ |
---|
| 66 | reset_exception.c |
---|
[406] | 67 | |
---|
[293] | 68 | ifndef SOCLIB |
---|
[406] | 69 | C_SRCS += sdcard.c spi.c |
---|
[293] | 70 | endif |
---|
| 71 | |
---|
| 72 | S_SRCS := reset.S |
---|
| 73 | |
---|
| 74 | OBJS := $(subst .c,.o, $(notdir $(C_SRCS))) |
---|
| 75 | OBJS += $(subst .S,.o, $(notdir $(S_SRCS))) |
---|
| 76 | OBJS := $(addprefix $(BUILD_DIR)/, $(OBJS)) |
---|
| 77 | |
---|
[586] | 78 | TARGET := preloader.elf |
---|
[293] | 79 | |
---|
[425] | 80 | USE_DT ?= 1 |
---|
[293] | 81 | |
---|
| 82 | all: $(TARGET) |
---|
| 83 | |
---|
[586] | 84 | # $(BUILD_DIR)/version.o: $(BUILD_DIR) $(OBJS) version version.sh |
---|
| 85 | # $(ECHO) "[version.sh]" |
---|
| 86 | # ./version.sh > $(BUILD_DIR)/version.c |
---|
| 87 | # $(ECHO) "[ CC ] $(BUILD_DIR)/version.c" |
---|
| 88 | # $(CC) $(DEFS) $(CFLAGS) $(INCLUDE) -c -o $@ $(BUILD_DIR)/version.c |
---|
| 89 | # $(DU) -D $@ > $@.txt |
---|
[502] | 90 | |
---|
[586] | 91 | $(TARGET): $(BUILD_DIR) $(OBJS) $(PLATFORM_DIR)/ldscript $(BUILD_DIR)/platform.ld |
---|
[388] | 92 | $(ECHO) "[ LD ] $@" |
---|
[586] | 93 | $(LD) -o $@ -T $(PLATFORM_DIR)/ldscript $(OBJS) |
---|
[293] | 94 | $(DU) -D $@ > $@.txt |
---|
| 95 | |
---|
[425] | 96 | ifeq ($(USE_DT), 1) |
---|
[293] | 97 | $(BUILD_DIR)/platform.ld: $(BUILD_DIR)/platform.dtb |
---|
[388] | 98 | $(ECHO) "[ HEXDUMP ] $(notdir $<)" |
---|
[293] | 99 | $(HEXDUMP) -v -e '"BYTE(0x" 1/1 "%02X" ")\n"' $< > $@ |
---|
[425] | 100 | else |
---|
| 101 | $(BUILD_DIR)/platform.ld: |
---|
| 102 | $(ECHO) "[ TOUCH ] $(notdir $@)" |
---|
| 103 | touch $@ |
---|
| 104 | endif |
---|
[293] | 105 | |
---|
| 106 | $(BUILD_DIR)/platform.dtb: $(DTS) |
---|
[388] | 107 | $(ECHO) "[ DTC ] $(notdir $<)" |
---|
[390] | 108 | ${DTC} -O dtb -o $@ $< &> /dev/null |
---|
[293] | 109 | |
---|
| 110 | $(BUILD_DIR): |
---|
| 111 | $(MKDIR) $@ |
---|
| 112 | |
---|
[388] | 113 | doc: Doxyfile |
---|
| 114 | $(DOXYGEN) Doxyfile |
---|
| 115 | |
---|
[293] | 116 | clean: |
---|
| 117 | $(RM) $(TARGET).txt $(TARGET) *~ $(BUILD_DIR) |
---|
| 118 | |
---|
[388] | 119 | clean-doc: |
---|
| 120 | $(RM) doc |
---|
[293] | 121 | |
---|
[388] | 122 | distclean: clean clean-doc |
---|
| 123 | |
---|
[293] | 124 | # ============================================================================= |
---|
| 125 | # Implicit makefile rules |
---|
| 126 | |
---|
| 127 | $(BUILD_DIR)/%.o: %.c |
---|
[388] | 128 | $(ECHO) "[ CC ] $(notdir $<)" |
---|
[293] | 129 | $(CC) $(DEFS) $(CFLAGS) $(INCLUDE) -c -o $@ $< |
---|
| 130 | $(DU) -D $@ > $@.txt |
---|
| 131 | |
---|
| 132 | $(BUILD_DIR)/%.o: %.S |
---|
[388] | 133 | $(ECHO) "[ AS ] $(notdir $<)" |
---|
[293] | 134 | $(CC) $(DEFS) ${INCLUDE} -g -mips32 -c -o $@ $< |
---|
| 135 | $(DU) -D $@ > $@.txt |
---|
| 136 | |
---|
| 137 | .SILENT: |
---|