blob: 9b57f1c0c66ce21746c5b545fd9f1fa4a2c5f4ae [file] [log] [blame]
Tom Rini10e47792018-05-06 17:58:06 -04001# SPDX-License-Identifier: GPL-2.0+
wdenk717b5aa2002-04-27 11:09:31 +00002#
Marian Balakowiczd62379d2006-09-01 19:49:50 +02003# (C) Copyright 2000-2006
wdenk717b5aa2002-04-27 11:09:31 +00004# Wolfgang Denk, DENX Software Engineering, wd@denx.de.
wdenk717b5aa2002-04-27 11:09:31 +00005
Masahiro Yamada6b05dae2014-02-04 17:24:12 +09006extra-y := hello_world
Masahiro Yamada6b05dae2014-02-04 17:24:12 +09007extra-$(CONFIG_SPI_FLASH_ATMEL) += atmel_df_pow2
Masahiro Yamada6b05dae2014-02-04 17:24:12 +09008extra-$(CONFIG_PPC) += sched
Mike Frysinger0f4964a2009-07-23 16:37:03 -04009
Heinrich Schuchardtceb24982025-01-27 08:18:46 +010010# Environment variable loadaddr is set from CONFIG_SYS_LOAD_ADDR.
11# Run the examples 4 MiB above this address.
12LOAD_ADDR:=${shell printf 0x%X $$(( $(CONFIG_SYS_LOAD_ADDR) + 0x400000 ))}
13
Sanjeev Premi68db2352009-11-09 22:43:00 +053014#
15# Some versions of make do not handle trailing white spaces properly;
16# leading to build failures. The problem was found with GNU Make 3.80.
17# Using 'strip' as a workaround for the problem.
18#
Masahiro Yamada6b05dae2014-02-04 17:24:12 +090019ELF := $(strip $(extra-y))
Sanjeev Premi68db2352009-11-09 22:43:00 +053020
Masahiro Yamada6b05dae2014-02-04 17:24:12 +090021extra-y += $(addsuffix .srec,$(extra-y)) $(addsuffix .bin,$(extra-y))
Masahiro Yamada580a5f12014-09-05 01:56:52 +090022clean-files := *.srec *.bin
Masahiro Yamada6b05dae2014-02-04 17:24:12 +090023
Mike Frysinger659c60d2009-09-04 19:54:45 -040024COBJS := $(ELF:=.o)
wdenkabda5ca2003-05-31 18:35:21 +000025
Masahiro Yamada59f15f22014-02-04 17:24:24 +090026LIB = $(obj)/libstubs.o
wdenkbd1575f2003-10-14 19:43:55 +000027
Masahiro Yamada020a1f22014-02-24 11:12:19 +090028LIBOBJS-$(CONFIG_PPC) += ppc_longjmp.o ppc_setjmp.o
Masahiro Yamada020a1f22014-02-24 11:12:19 +090029LIBOBJS-y += stubs.o
Marian Balakowiczd62379d2006-09-01 19:49:50 +020030
Masahiro Yamada020a1f22014-02-24 11:12:19 +090031targets += $(patsubst $(obj)/%,%,$(LIB)) $(COBJS) $(LIBOBJS-y)
Masahiro Yamada0d68fb12014-02-04 17:24:28 +090032
Masahiro Yamada020a1f22014-02-24 11:12:19 +090033LIBOBJS := $(addprefix $(obj)/,$(LIBOBJS-y))
Masahiro Yamada59f15f22014-02-04 17:24:24 +090034ELF := $(addprefix $(obj)/,$(ELF))
wdenk717b5aa2002-04-27 11:09:31 +000035
Tom Rinif7003562023-03-09 11:22:09 -050036# Disable LTO for these builds
37CFLAGS_REMOVE_hello_world.o := $(LTO_CFLAGS)
38CFLAGS_REMOVE_stubs.o := $(LTO_CFLAGS)
39
Peter Tyser29764ee2010-06-15 21:48:25 +020040# For PowerPC there's no need to compile standalone applications as a
41# relocatable executable. The relocation data is not needed, and
42# also causes the entry point of the standalone application to be
43# inconsistent.
Masahiro Yamada958fe8f2014-03-05 16:59:40 +090044ifeq ($(CONFIG_PPC),y)
45PLATFORM_CPPFLAGS := $(filter-out $(RELFLAGS),$(PLATFORM_CPPFLAGS))
Peter Tyser29764ee2010-06-15 21:48:25 +020046endif
47
Peter Tyser4bbc0822010-09-12 17:38:49 -050048# We don't want gcc reordering functions if possible. This ensures that an
49# application's entry point will be the first function in the application's
50# source file.
Masahiro Yamada0d68fb12014-02-04 17:24:28 +090051ccflags-y += $(call cc-option,-fno-toplevel-reorder)
wdenk717b5aa2002-04-27 11:09:31 +000052
Heinrich Schuchardtceb24982025-01-27 08:18:46 +010053LDFLAGS_STANDALONE += -Ttext $(LOAD_ADDR)
Daniel Schwierzeck9dc13da2018-09-23 19:15:15 +020054
wdenk717b5aa2002-04-27 11:09:31 +000055#########################################################################
Masahiro Yamada0d68fb12014-02-04 17:24:28 +090056
57quiet_cmd_link_lib = LD $@
58 cmd_link_lib = $(LD) $(ld_flags) -r -o $@ $(filter $(LIBOBJS), $^)
59
60$(LIB): $(LIBOBJS) FORCE
61 $(call if_changed,link_lib)
wdenk717b5aa2002-04-27 11:09:31 +000062
Masahiro Yamada020a1f22014-02-24 11:12:19 +090063quiet_cmd_link_elf = LD $@
Tom Rini5d4ecf22020-03-27 11:46:27 -040064 cmd_link_elf = $(LD) $(KBUILD_LDFLAGS) $(LDFLAGS_STANDALONE) -g \
Alexey Brodkin80bf4162014-05-16 12:54:17 +040065 -o $@ -e $(SYM_PREFIX)$(@F) $< $(LIB) $(PLATFORM_LIBGCC)
Masahiro Yamada020a1f22014-02-24 11:12:19 +090066
67$(ELF): $(obj)/%: $(obj)/%.o $(LIB) FORCE
68 $(call if_changed,link_elf)
Wolfgang Denk29be6222006-10-24 13:55:18 +020069
Daniel Schwierzeck81a06442018-09-23 19:15:16 +020070$(obj)/%.srec: OBJCOPYFLAGS += -O srec
Masahiro Yamada734c3ef2014-02-24 11:12:14 +090071$(obj)/%.srec: $(obj)/% FORCE
72 $(call if_changed,objcopy)
wdenk717b5aa2002-04-27 11:09:31 +000073
Daniel Schwierzeck81a06442018-09-23 19:15:16 +020074$(obj)/%.bin: OBJCOPYFLAGS += -O binary
Masahiro Yamada734c3ef2014-02-24 11:12:14 +090075$(obj)/%.bin: $(obj)/% FORCE
76 $(call if_changed,objcopy)
Albert ARIBAUDa3823222015-10-23 18:06:40 +020077
78# some files can only build in ARM or THUMB2, not THUMB1
79
80ifdef CONFIG_SYS_THUMB_BUILD
81ifndef CONFIG_HAS_THUMB2
82
83CFLAGS_stubs.o := -marm
84
85endif
86endif