blob: 4a34813804f634741c7f9896b8c6572de8a69750 [file] [log] [blame]
Tom Rini83d290c2018-05-06 17:58:06 -04001# SPDX-License-Identifier: GPL-2.0+
wdenk717b5aa2002-04-27 11:09:31 +00002#
Marian Balakowiczf9328632006-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 Yamada4a20df32014-02-04 17:24:12 +09006extra-y := hello_world
7extra-$(CONFIG_SMC91111) += smc91111_eeprom
Masahiro Yamada4a20df32014-02-04 17:24:12 +09008extra-$(CONFIG_SPI_FLASH_ATMEL) += atmel_df_pow2
Masahiro Yamada4a20df32014-02-04 17:24:12 +09009extra-$(CONFIG_PPC) += sched
Mike Frysinger65f6f072009-07-23 16:37:03 -040010
Marek Vasut81486932020-03-15 17:39:01 +010011ifndef CONFIG_DM_ETH
12extra-$(CONFIG_SMC911X) += smc911x_eeprom
13endif
14
Sanjeev Premi604f7ce2009-11-09 22:43:00 +053015#
16# Some versions of make do not handle trailing white spaces properly;
17# leading to build failures. The problem was found with GNU Make 3.80.
18# Using 'strip' as a workaround for the problem.
19#
Masahiro Yamada4a20df32014-02-04 17:24:12 +090020ELF := $(strip $(extra-y))
Sanjeev Premi604f7ce2009-11-09 22:43:00 +053021
Masahiro Yamada4a20df32014-02-04 17:24:12 +090022extra-y += $(addsuffix .srec,$(extra-y)) $(addsuffix .bin,$(extra-y))
Masahiro Yamada8e714432014-09-05 01:56:52 +090023clean-files := *.srec *.bin
Masahiro Yamada4a20df32014-02-04 17:24:12 +090024
Mike Frysinger557555f2009-09-04 19:54:45 -040025COBJS := $(ELF:=.o)
wdenk717b5aa2002-04-27 11:09:31 +000026
Masahiro Yamada9e414032014-02-04 17:24:24 +090027LIB = $(obj)/libstubs.o
Mike Frysinger557555f2009-09-04 19:54:45 -040028
Masahiro Yamada04a34c92014-02-24 11:12:19 +090029LIBOBJS-$(CONFIG_PPC) += ppc_longjmp.o ppc_setjmp.o
Masahiro Yamada04a34c92014-02-24 11:12:19 +090030LIBOBJS-y += stubs.o
Marian Balakowiczf9328632006-09-01 19:49:50 +020031
Masahiro Yamada04a34c92014-02-24 11:12:19 +090032targets += $(patsubst $(obj)/%,%,$(LIB)) $(COBJS) $(LIBOBJS-y)
Masahiro Yamada6825a952014-02-04 17:24:28 +090033
Masahiro Yamada04a34c92014-02-24 11:12:19 +090034LIBOBJS := $(addprefix $(obj)/,$(LIBOBJS-y))
Masahiro Yamada9e414032014-02-04 17:24:24 +090035ELF := $(addprefix $(obj)/,$(ELF))
wdenk717b5aa2002-04-27 11:09:31 +000036
Peter Tyser620bbba2010-06-15 21:48:25 +020037# For PowerPC there's no need to compile standalone applications as a
38# relocatable executable. The relocation data is not needed, and
39# also causes the entry point of the standalone application to be
40# inconsistent.
Masahiro Yamada026f9cf2014-03-05 16:59:40 +090041ifeq ($(CONFIG_PPC),y)
42PLATFORM_CPPFLAGS := $(filter-out $(RELFLAGS),$(PLATFORM_CPPFLAGS))
Peter Tyser620bbba2010-06-15 21:48:25 +020043endif
44
Peter Tyserc91d4562010-09-12 17:38:49 -050045# We don't want gcc reordering functions if possible. This ensures that an
46# application's entry point will be the first function in the application's
47# source file.
Masahiro Yamada6825a952014-02-04 17:24:28 +090048ccflags-y += $(call cc-option,-fno-toplevel-reorder)
wdenk717b5aa2002-04-27 11:09:31 +000049
Daniel Schwierzeck1d3b97c2018-09-23 19:15:15 +020050LDFLAGS_STANDALONE += -Ttext $(CONFIG_STANDALONE_LOAD_ADDR)
51
wdenk717b5aa2002-04-27 11:09:31 +000052#########################################################################
Masahiro Yamada6825a952014-02-04 17:24:28 +090053
54quiet_cmd_link_lib = LD $@
55 cmd_link_lib = $(LD) $(ld_flags) -r -o $@ $(filter $(LIBOBJS), $^)
56
57$(LIB): $(LIBOBJS) FORCE
58 $(call if_changed,link_lib)
wdenk717b5aa2002-04-27 11:09:31 +000059
Masahiro Yamada04a34c92014-02-24 11:12:19 +090060quiet_cmd_link_elf = LD $@
Tom Rini587e4a42020-03-27 11:46:27 -040061 cmd_link_elf = $(LD) $(KBUILD_LDFLAGS) $(LDFLAGS_STANDALONE) -g \
Alexey Brodkine75e73d2014-05-16 12:54:17 +040062 -o $@ -e $(SYM_PREFIX)$(@F) $< $(LIB) $(PLATFORM_LIBGCC)
Masahiro Yamada04a34c92014-02-24 11:12:19 +090063
64$(ELF): $(obj)/%: $(obj)/%.o $(LIB) FORCE
65 $(call if_changed,link_elf)
Wolfgang Denk96582982006-10-24 13:55:18 +020066
Daniel Schwierzeckd3a9ba72018-09-23 19:15:16 +020067$(obj)/%.srec: OBJCOPYFLAGS += -O srec
Masahiro Yamadaf9c235f2014-02-24 11:12:14 +090068$(obj)/%.srec: $(obj)/% FORCE
69 $(call if_changed,objcopy)
wdenk717b5aa2002-04-27 11:09:31 +000070
Daniel Schwierzeckd3a9ba72018-09-23 19:15:16 +020071$(obj)/%.bin: OBJCOPYFLAGS += -O binary
Masahiro Yamadaf9c235f2014-02-24 11:12:14 +090072$(obj)/%.bin: $(obj)/% FORCE
73 $(call if_changed,objcopy)
Albert ARIBAUD62e92072015-10-23 18:06:40 +020074
75# some files can only build in ARM or THUMB2, not THUMB1
76
77ifdef CONFIG_SYS_THUMB_BUILD
78ifndef CONFIG_HAS_THUMB2
79
80CFLAGS_stubs.o := -marm
81
82endif
83endif