Kbuild: add LDFLAGS_STANDALONE
[oweals/u-boot.git] / examples / standalone / Makefile
1 # SPDX-License-Identifier: GPL-2.0+
2 #
3 # (C) Copyright 2000-2006
4 # Wolfgang Denk, DENX Software Engineering, wd@denx.de.
5
6 extra-y        := hello_world
7 extra-$(CONFIG_SMC91111)           += smc91111_eeprom
8 extra-$(CONFIG_SMC911X)            += smc911x_eeprom
9 extra-$(CONFIG_SPI_FLASH_ATMEL)    += atmel_df_pow2
10 extra-$(CONFIG_PPC)                += sched
11
12 #
13 # Some versions of make do not handle trailing white spaces properly;
14 # leading to build failures. The problem was found with GNU Make 3.80.
15 # Using 'strip' as a workaround for the problem.
16 #
17 ELF := $(strip $(extra-y))
18
19 extra-y += $(addsuffix .srec,$(extra-y)) $(addsuffix .bin,$(extra-y))
20 clean-files  := *.srec *.bin
21
22 COBJS   := $(ELF:=.o)
23
24 LIB     = $(obj)/libstubs.o
25
26 LIBOBJS-$(CONFIG_PPC) += ppc_longjmp.o ppc_setjmp.o
27 LIBOBJS-y += stubs.o
28
29 .SECONDARY: $(call objectify,$(COBJS))
30 targets += $(patsubst $(obj)/%,%,$(LIB)) $(COBJS) $(LIBOBJS-y)
31
32 LIBOBJS := $(addprefix $(obj)/,$(LIBOBJS-y))
33 ELF     := $(addprefix $(obj)/,$(ELF))
34
35 # For PowerPC there's no need to compile standalone applications as a
36 # relocatable executable.  The relocation data is not needed, and
37 # also causes the entry point of the standalone application to be
38 # inconsistent.
39 ifeq ($(CONFIG_PPC),y)
40 PLATFORM_CPPFLAGS := $(filter-out $(RELFLAGS),$(PLATFORM_CPPFLAGS))
41 endif
42
43 # We don't want gcc reordering functions if possible.  This ensures that an
44 # application's entry point will be the first function in the application's
45 # source file.
46 ccflags-y += $(call cc-option,-fno-toplevel-reorder)
47
48 LDFLAGS_STANDALONE      += -Ttext $(CONFIG_STANDALONE_LOAD_ADDR)
49
50 #########################################################################
51
52 quiet_cmd_link_lib = LD      $@
53       cmd_link_lib = $(LD) $(ld_flags) -r -o $@ $(filter $(LIBOBJS), $^)
54
55 $(LIB): $(LIBOBJS) FORCE
56         $(call if_changed,link_lib)
57
58 quiet_cmd_link_elf = LD      $@
59       cmd_link_elf = $(LD) $(LDFLAGS) $(LDFLAGS_STANDALONE) -g  \
60                      -o $@ -e $(SYM_PREFIX)$(@F) $< $(LIB) $(PLATFORM_LIBGCC)
61
62 $(ELF): $(obj)/%: $(obj)/%.o $(LIB) FORCE
63         $(call if_changed,link_elf)
64
65 $(obj)/%.srec: OBJCOPYFLAGS := -O srec
66 $(obj)/%.srec: $(obj)/% FORCE
67         $(call if_changed,objcopy)
68
69 $(obj)/%.bin: OBJCOPYFLAGS := -O binary
70 $(obj)/%.bin: $(obj)/% FORCE
71         $(call if_changed,objcopy)
72
73 # some files can only build in ARM or THUMB2, not THUMB1
74
75 ifdef CONFIG_SYS_THUMB_BUILD
76 ifndef CONFIG_HAS_THUMB2
77
78 CFLAGS_stubs.o := -marm
79
80 endif
81 endif