blob: 90e173b83ee8f1750962890dfdad66927e2bb9ed [file] [log] [blame]
wdenk717b5aa2002-04-27 11:09:31 +00001#
Marian Balakowiczd62379d2006-09-01 19:49:50 +02002# (C) Copyright 2000-2006
wdenk717b5aa2002-04-27 11:09:31 +00003# Wolfgang Denk, DENX Software Engineering, wd@denx.de.
4#
Wolfgang Denkd79de1d2013-07-08 09:37:19 +02005# SPDX-License-Identifier: GPL-2.0+
wdenk717b5aa2002-04-27 11:09:31 +00006#
7
Masahiro Yamadaa6d77562014-02-04 17:24:23 +09008ifdef FTRACE
Masahiro Yamada0d68fb12014-02-04 17:24:28 +09009ccflags-y += -finstrument-functions -DFTRACE
Masahiro Yamadaa6d77562014-02-04 17:24:23 +090010endif
11
Masahiro Yamada6b05dae2014-02-04 17:24:12 +090012extra-y := hello_world
13extra-$(CONFIG_SMC91111) += smc91111_eeprom
14extra-$(CONFIG_SMC911X) += smc911x_eeprom
15extra-$(CONFIG_SPI_FLASH_ATMEL) += atmel_df_pow2
16extra-$(CONFIG_MPC5xxx) += interrupt
17extra-$(CONFIG_8xx) += test_burst timer
18extra-$(CONFIG_8260) += mem_to_mem_idma2intr
19extra-$(CONFIG_PPC) += sched
Mike Frysinger0f4964a2009-07-23 16:37:03 -040020
Sanjeev Premi68db2352009-11-09 22:43:00 +053021#
22# Some versions of make do not handle trailing white spaces properly;
23# leading to build failures. The problem was found with GNU Make 3.80.
24# Using 'strip' as a workaround for the problem.
25#
Masahiro Yamada6b05dae2014-02-04 17:24:12 +090026ELF := $(strip $(extra-y))
Sanjeev Premi68db2352009-11-09 22:43:00 +053027
Masahiro Yamada6b05dae2014-02-04 17:24:12 +090028extra-y += $(addsuffix .srec,$(extra-y)) $(addsuffix .bin,$(extra-y))
29clean-files := $(extra-) $(addsuffix .srec,$(extra-)) $(addsuffix .bin,$(extra-))
30
wdenke339a7a2005-05-07 19:06:32 +000031
Mike Frysinger659c60d2009-09-04 19:54:45 -040032COBJS := $(ELF:=.o)
wdenkabda5ca2003-05-31 18:35:21 +000033
Masahiro Yamada59f15f22014-02-04 17:24:24 +090034LIB = $(obj)/libstubs.o
wdenkbd1575f2003-10-14 19:43:55 +000035
Masahiro Yamada71db7542013-11-28 12:09:59 +090036LIBAOBJS-$(CONFIG_PPC) += ppc_longjmp.o ppc_setjmp.o
37LIBAOBJS-$(CONFIG_8xx) += test_burst_lib.o
38LIBAOBJS := $(LIBAOBJS-y)
wdenk717b5aa2002-04-27 11:09:31 +000039
Mike Frysinger659c60d2009-09-04 19:54:45 -040040LIBCOBJS = stubs.o
Marian Balakowiczd62379d2006-09-01 19:49:50 +020041
Masahiro Yamada0d68fb12014-02-04 17:24:28 +090042.SECONDARY: $(call objectify,$(COBJS))
43targets += $(patsubst $(obj)/%,%,$(LIB)) $(COBJS) $(LIBAOBJS) $(LIBCOBJS)
44
Masahiro Yamada59f15f22014-02-04 17:24:24 +090045LIBOBJS = $(addprefix $(obj)/,$(LIBAOBJS) $(LIBCOBJS))
Marian Balakowiczd62379d2006-09-01 19:49:50 +020046
Masahiro Yamada59f15f22014-02-04 17:24:24 +090047ELF := $(addprefix $(obj)/,$(ELF))
wdenk717b5aa2002-04-27 11:09:31 +000048
Tom Rinic98feda2013-09-10 09:51:44 -040049gcclibdir := $(shell dirname `$(CC) -print-libgcc-file-name`)
wdenk710e3502003-08-29 20:57:53 +000050
Peter Tyser29764ee2010-06-15 21:48:25 +020051# For PowerPC there's no need to compile standalone applications as a
52# relocatable executable. The relocation data is not needed, and
53# also causes the entry point of the standalone application to be
54# inconsistent.
55ifeq ($(ARCH),powerpc)
Masahiro Yamada0d68fb12014-02-04 17:24:28 +090056# FIX ME
57CPPFLAGS := $(filter-out $(RELFLAGS), $(CPPFLAGS))
Peter Tyser29764ee2010-06-15 21:48:25 +020058endif
59
Peter Tyser4bbc0822010-09-12 17:38:49 -050060# We don't want gcc reordering functions if possible. This ensures that an
61# application's entry point will be the first function in the application's
62# source file.
Masahiro Yamada0d68fb12014-02-04 17:24:28 +090063ccflags-y += $(call cc-option,-fno-toplevel-reorder)
wdenk717b5aa2002-04-27 11:09:31 +000064
65#########################################################################
Masahiro Yamada0d68fb12014-02-04 17:24:28 +090066
67quiet_cmd_link_lib = LD $@
68 cmd_link_lib = $(LD) $(ld_flags) -r -o $@ $(filter $(LIBOBJS), $^)
69
70$(LIB): $(LIBOBJS) FORCE
71 $(call if_changed,link_lib)
wdenk717b5aa2002-04-27 11:09:31 +000072
Wolfgang Denk29be6222006-10-24 13:55:18 +020073$(ELF):
Masahiro Yamada59f15f22014-02-04 17:24:24 +090074$(obj)/%: $(obj)/%.o $(LIB)
Marek Vasut3ee93d32012-03-06 00:44:22 +010075 $(LD) $(LDFLAGS) -g -Ttext $(CONFIG_STANDALONE_LOAD_ADDR) \
Mike Frysingera13ad8e2008-02-04 19:26:55 -050076 -o $@ -e $(SYM_PREFIX)$(notdir $(<:.o=)) $< $(LIB) \
Tom Rinic98feda2013-09-10 09:51:44 -040077 -L$(gcclibdir) -lgcc
Wolfgang Denk29be6222006-10-24 13:55:18 +020078
Masahiro Yamada59f15f22014-02-04 17:24:24 +090079$(obj)/%.srec: $(obj)/%
Marian Balakowiczd62379d2006-09-01 19:49:50 +020080 $(OBJCOPY) -O srec $< $@ 2>/dev/null
wdenk717b5aa2002-04-27 11:09:31 +000081
Masahiro Yamada59f15f22014-02-04 17:24:24 +090082$(obj)/%.bin: $(obj)/%
Marian Balakowiczd62379d2006-09-01 19:49:50 +020083 $(OBJCOPY) -O binary $< $@ 2>/dev/null