Caesar Wang | b400374 | 2016-10-12 08:10:12 +0800 | [diff] [blame] | 1 | # |
| 2 | # Copyright (c) 2016, ARM Limited and Contributors. All rights reserved. |
| 3 | # |
| 4 | # Redistribution and use in source and binary forms, with or without |
| 5 | # modification, are permitted provided that the following conditions are met: |
| 6 | # |
| 7 | # Redistributions of source code must retain the above copyright notice, this |
| 8 | # list of conditions and the following disclaimer. |
| 9 | # |
| 10 | # Redistributions in binary form must reproduce the above copyright notice, |
| 11 | # this list of conditions and the following disclaimer in the documentation |
| 12 | # and/or other materials provided with the distribution. |
| 13 | # |
| 14 | # Neither the name of ARM nor the names of its contributors may be used |
| 15 | # to endorse or promote products derived from this software without specific |
| 16 | # prior written permission. |
| 17 | # |
| 18 | # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
| 19 | # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
| 20 | # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
| 21 | # ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE |
| 22 | # LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
| 23 | # CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
| 24 | # SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
| 25 | # INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN |
| 26 | # CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
| 27 | # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
| 28 | # POSSIBILITY OF SUCH DAMAGE. |
| 29 | # |
| 30 | |
| 31 | # Cross Compile |
| 32 | M0_CROSS_COMPILE ?= arm-none-eabi- |
| 33 | |
| 34 | # Build architecture |
| 35 | ARCH := cortex-m0 |
| 36 | |
| 37 | # Build platform |
| 38 | PLAT_M0 ?= rk3399m0 |
| 39 | |
| 40 | ifeq (${V},0) |
| 41 | Q=@ |
Caesar Wang | b400374 | 2016-10-12 08:10:12 +0800 | [diff] [blame] | 42 | else |
| 43 | Q= |
| 44 | endif |
| 45 | export Q |
| 46 | |
Caesar Wang | b400374 | 2016-10-12 08:10:12 +0800 | [diff] [blame] | 47 | .SUFFIXES: |
| 48 | |
Xing Zheng | 93280b7 | 2016-10-26 21:25:26 +0800 | [diff] [blame] | 49 | INCLUDES += -Iinclude/ \ |
| 50 | -I../../include/shared/ |
Caesar Wang | b400374 | 2016-10-12 08:10:12 +0800 | [diff] [blame] | 51 | |
| 52 | # NOTE: Add C source files here |
| 53 | C_SOURCES := src/startup.c \ |
Xing Zheng | 93280b7 | 2016-10-26 21:25:26 +0800 | [diff] [blame] | 54 | src/main.c \ |
| 55 | src/suspend.c \ |
| 56 | src/dram.c |
Caesar Wang | b400374 | 2016-10-12 08:10:12 +0800 | [diff] [blame] | 57 | |
| 58 | # Flags definition |
| 59 | CFLAGS := -g |
| 60 | ASFLAGS := -g -Wa,--gdwarf-2 |
| 61 | |
| 62 | ASFLAGS += -mcpu=$(ARCH) -mthumb -Wall -ffunction-sections -O3 |
| 63 | CFLAGS += -mcpu=$(ARCH) -mthumb -Wall -ffunction-sections -O3 |
| 64 | |
Patrick Georgi | 5c979f1 | 2017-01-04 19:06:14 +0100 | [diff] [blame] | 65 | LDFLAGS := -mcpu=$(ARCH) -mthumb -g -nostartfiles -nostdlib -O3 |
Caesar Wang | b400374 | 2016-10-12 08:10:12 +0800 | [diff] [blame] | 66 | LDFLAGS += -Wl,--gc-sections -Wl,--build-id=none |
| 67 | |
| 68 | # Cross tool |
| 69 | CC := ${M0_CROSS_COMPILE}gcc |
| 70 | CPP := ${M0_CROSS_COMPILE}cpp |
| 71 | AS := ${M0_CROSS_COMPILE}gcc |
| 72 | AR := ${M0_CROSS_COMPILE}ar |
| 73 | LD := ${M0_CROSS_COMPILE}ld |
| 74 | OC := ${M0_CROSS_COMPILE}objcopy |
| 75 | OD := ${M0_CROSS_COMPILE}objdump |
| 76 | NM := ${M0_CROSS_COMPILE}nm |
| 77 | PP := ${M0_CROSS_COMPILE}gcc -E ${CFLAGS} |
| 78 | |
| 79 | # NOTE: The line continuation '\' is required in the next define otherwise we |
| 80 | # end up with a line-feed characer at the end of the last c filename. |
| 81 | # Also bare this issue in mind if extending the list of supported filetypes. |
| 82 | define SOURCES_TO_OBJS |
| 83 | $(notdir $(patsubst %.c,%.o,$(filter %.c,$(1)))) \ |
| 84 | $(notdir $(patsubst %.S,%.o,$(filter %.S,$(1)))) |
| 85 | endef |
| 86 | |
Caesar Wang | b400374 | 2016-10-12 08:10:12 +0800 | [diff] [blame] | 87 | SOURCES := $(C_SOURCES) |
Julius Werner | 705aeeb | 2016-10-31 19:18:47 -0700 | [diff] [blame] | 88 | OBJS := $(addprefix $(BUILD)/,$(call SOURCES_TO_OBJS,$(SOURCES))) |
Xing Zheng | 93280b7 | 2016-10-26 21:25:26 +0800 | [diff] [blame] | 89 | LINKERFILE := $(BUILD)/$(PLAT_M0).ld |
Julius Werner | 705aeeb | 2016-10-31 19:18:47 -0700 | [diff] [blame] | 90 | MAPFILE := $(BUILD)/$(PLAT_M0).map |
| 91 | ELF := $(BUILD)/$(PLAT_M0).elf |
| 92 | BIN := $(BUILD)/$(PLAT_M0).bin |
Xing Zheng | 93280b7 | 2016-10-26 21:25:26 +0800 | [diff] [blame] | 93 | LINKERFILE_SRC := src/$(PLAT_M0).ld.S |
Caesar Wang | b400374 | 2016-10-12 08:10:12 +0800 | [diff] [blame] | 94 | |
| 95 | # Function definition related compilation |
| 96 | define MAKE_C |
| 97 | $(eval OBJ := $(1)/$(patsubst %.c,%.o,$(notdir $(2)))) |
Julius Werner | 844782d | 2016-11-03 12:25:48 -0700 | [diff] [blame] | 98 | -include $(patsubst %.o,%.d,$(OBJ)) |
Caesar Wang | b400374 | 2016-10-12 08:10:12 +0800 | [diff] [blame] | 99 | |
| 100 | $(OBJ) : $(2) |
| 101 | @echo " CC $$<" |
Julius Werner | 844782d | 2016-11-03 12:25:48 -0700 | [diff] [blame] | 102 | $$(Q)$$(CC) $$(CFLAGS) $$(INCLUDES) -MMD -MT $$@ -c $$< -o $$@ |
Caesar Wang | b400374 | 2016-10-12 08:10:12 +0800 | [diff] [blame] | 103 | endef |
| 104 | |
| 105 | define MAKE_S |
| 106 | $(eval OBJ := $(1)/$(patsubst %.S,%.o,$(notdir $(2)))) |
| 107 | |
| 108 | $(OBJ) : $(2) |
| 109 | @echo " AS $$<" |
| 110 | $$(Q)$$(AS) $$(ASFLAGS) -c $$< -o $$@ |
| 111 | endef |
| 112 | |
| 113 | define MAKE_OBJS |
| 114 | $(eval C_OBJS := $(filter %.c,$(2))) |
| 115 | $(eval REMAIN := $(filter-out %.c,$(2))) |
| 116 | $(eval $(foreach obj,$(C_OBJS),$(call MAKE_C,$(1),$(obj),$(3)))) |
| 117 | |
| 118 | $(eval S_OBJS := $(filter %.S,$(REMAIN))) |
| 119 | $(eval REMAIN := $(filter-out %.S,$(REMAIN))) |
| 120 | $(eval $(foreach obj,$(S_OBJS),$(call MAKE_S,$(1),$(obj),$(3)))) |
| 121 | |
| 122 | $(and $(REMAIN),$(error Unexpected source files present: $(REMAIN))) |
| 123 | endef |
| 124 | |
Xing Zheng | 93280b7 | 2016-10-26 21:25:26 +0800 | [diff] [blame] | 125 | .DEFAULT_GOAL := $(BIN) |
| 126 | |
| 127 | $(LINKERFILE): $(LINKERFILE_SRC) |
| 128 | $(CC) $(CFLAGS) $(INCLUDES) -P -E -D__LINKER__ -MMD -MF $@.d -MT $@ -o $@ $< |
| 129 | -include $(LINKERFILE).d |
Caesar Wang | b400374 | 2016-10-12 08:10:12 +0800 | [diff] [blame] | 130 | |
| 131 | $(ELF) : $(OBJS) $(LINKERFILE) |
| 132 | @echo " LD $@" |
| 133 | $(Q)$(CC) -o $@ $(LDFLAGS) -Wl,-Map=$(MAPFILE) -Wl,-T$(LINKERFILE) \ |
| 134 | $(OBJS) |
| 135 | |
| 136 | $(BIN) : $(ELF) |
| 137 | @echo " BIN $@" |
| 138 | $(Q)$(OC) -O binary $< $@ |
| 139 | |
Julius Werner | 705aeeb | 2016-10-31 19:18:47 -0700 | [diff] [blame] | 140 | $(eval $(call MAKE_OBJS,$(BUILD),$(SOURCES),$(1))) |