1# SPDX-License-Identifier: GPL-2.0+
2#
3# (C) Copyright 2000-2006
4# Wolfgang Denk, DENX Software Engineering, wd@denx.de.
5
6extra-y        := hello_world
7extra-$(CONFIG_SPI_FLASH_ATMEL)    += atmel_df_pow2
8extra-$(CONFIG_PPC)                += sched
9
10# 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
14#
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#
19ELF := $(strip $(extra-y))
20
21extra-y += $(addsuffix .srec,$(extra-y)) $(addsuffix .bin,$(extra-y))
22clean-files  := *.srec *.bin
23
24COBJS	:= $(ELF:=.o)
25
26LIB	= $(obj)/libstubs.o
27
28LIBOBJS-$(CONFIG_PPC) += ppc_longjmp.o ppc_setjmp.o
29LIBOBJS-y += stubs.o
30
31targets += $(patsubst $(obj)/%,%,$(LIB)) $(COBJS) $(LIBOBJS-y)
32
33LIBOBJS	:= $(addprefix $(obj)/,$(LIBOBJS-y))
34ELF	:= $(addprefix $(obj)/,$(ELF))
35
36# Disable LTO for these builds
37CFLAGS_REMOVE_hello_world.o := $(LTO_CFLAGS)
38CFLAGS_REMOVE_stubs.o := $(LTO_CFLAGS)
39
40# 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.
44ifeq ($(CONFIG_PPC),y)
45PLATFORM_CPPFLAGS := $(filter-out $(RELFLAGS),$(PLATFORM_CPPFLAGS))
46endif
47
48# 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.
51ccflags-y += $(call cc-option,-fno-toplevel-reorder)
52
53LDFLAGS_STANDALONE	+= -Ttext $(LOAD_ADDR)
54
55#########################################################################
56
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)
62
63quiet_cmd_link_elf = LD      $@
64      cmd_link_elf = $(LD) $(KBUILD_LDFLAGS) $(LDFLAGS_STANDALONE) -g  \
65		     -o $@ -e $(SYM_PREFIX)$(@F) $< $(LIB) $(PLATFORM_LIBGCC)
66
67$(ELF): $(obj)/%: $(obj)/%.o $(LIB) FORCE
68	$(call if_changed,link_elf)
69
70$(obj)/%.srec: OBJCOPYFLAGS += -O srec
71$(obj)/%.srec: $(obj)/% FORCE
72	$(call if_changed,objcopy)
73
74$(obj)/%.bin: OBJCOPYFLAGS += -O binary
75$(obj)/%.bin: $(obj)/% FORCE
76	$(call if_changed,objcopy)
77
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
87