blob: 7789efab82ccbfb867cd83574abbbe3613fd6f6e [file] [log] [blame]
Masahiro Yamadace28d7a2013-10-17 17:34:47 +09001# our default target
2.PHONY: all
3all:
4
Masahiro Yamadabf4b3de2014-02-04 17:24:18 +09005include $(srctree)/scripts/Kbuild.include
Masahiro Yamadace28d7a2013-10-17 17:34:47 +09006include $(TOPDIR)/config.mk
7
Masahiro Yamada4a20df32014-02-04 17:24:12 +09008# variable LIB is used in examples/standalone/Makefile
9__LIB := $(obj)built-in.o
Masahiro Yamadace28d7a2013-10-17 17:34:47 +090010LIBGCC = $(obj)libgcc.o
11SRCS :=
Masahiro Yamadaad71fa92014-02-04 17:24:09 +090012subdir-y :=
13obj-dirs :=
Masahiro Yamadace28d7a2013-10-17 17:34:47 +090014
15include Makefile
16
Masahiro Yamadaad71fa92014-02-04 17:24:09 +090017# Do not include host rules unless needed
18ifneq ($(hostprogs-y)$(hostprogs-m),)
19include $(SRCTREE)/scripts/Makefile.host.tmp
20endif
21
Masahiro Yamadace28d7a2013-10-17 17:34:47 +090022# Going forward use the following
23obj-y := $(sort $(obj-y))
24extra-y := $(sort $(extra-y))
Masahiro Yamadaad71fa92014-02-04 17:24:09 +090025always := $(sort $(always))
Masahiro Yamadace28d7a2013-10-17 17:34:47 +090026lib-y := $(sort $(lib-y))
27
Masahiro Yamadaad71fa92014-02-04 17:24:09 +090028subdir-y += $(patsubst %/,%,$(filter %/, $(obj-y)))
Masahiro Yamadaac7e7352013-10-17 20:38:51 +090029obj-y := $(patsubst %/, %/built-in.o, $(obj-y))
30subdir-obj-y := $(filter %/built-in.o, $(obj-y))
31subdir-obj-y := $(addprefix $(obj),$(subdir-obj-y))
32
Masahiro Yamada3fdf5c82013-11-11 14:35:49 +090033SRCS += $(wildcard $(obj-y:.o=.c) $(obj-y:.o=.S) $(lib-y:.o=.c) \
34 $(lib-y:.o=.S) $(extra-y:.o=.c) $(extra-y:.o=.S))
35OBJS := $(addprefix $(obj),$(obj-y))
Masahiro Yamadace28d7a2013-10-17 17:34:47 +090036
Masahiro Yamadae5c53012013-11-11 14:35:54 +090037# $(obj-dirs) is a list of directories that contain object files
Masahiro Yamadaad71fa92014-02-04 17:24:09 +090038
39obj-dirs += $(dir $(OBJS))
Masahiro Yamadae5c53012013-11-11 14:35:54 +090040
41# Create directories for object files if directory does not exist
42# Needed when obj-y := dir/file.o syntax is used
43_dummy := $(foreach d,$(obj-dirs), $(shell [ -d $(d) ] || mkdir -p $(d)))
44
Masahiro Yamada3fdf5c82013-11-11 14:35:49 +090045LGOBJS := $(addprefix $(obj),$(sort $(lib-y)))
Masahiro Yamadace28d7a2013-10-17 17:34:47 +090046
Masahiro Yamada4a20df32014-02-04 17:24:12 +090047all: $(__LIB) $(addprefix $(obj),$(extra-y) $(always)) $(subdir-y)
Masahiro Yamadace28d7a2013-10-17 17:34:47 +090048
Masahiro Yamada4a20df32014-02-04 17:24:12 +090049$(__LIB): $(obj).depend $(OBJS)
Masahiro Yamadace28d7a2013-10-17 17:34:47 +090050 $(call cmd_link_o_target, $(OBJS))
51
52ifneq ($(strip $(lib-y)),)
53all: $(LIBGCC)
54
55$(LIBGCC): $(obj).depend $(LGOBJS)
56 $(call cmd_link_o_target, $(LGOBJS))
57endif
58
Masahiro Yamadaac7e7352013-10-17 20:38:51 +090059ifneq ($(subdir-obj-y),)
60# Descending
61$(subdir-obj-y): $(subdir-y)
Masahiro Yamadaad71fa92014-02-04 17:24:09 +090062endif
Masahiro Yamadaac7e7352013-10-17 20:38:51 +090063
Masahiro Yamadaad71fa92014-02-04 17:24:09 +090064ifneq ($(subdir-y),)
Masahiro Yamadaac7e7352013-10-17 20:38:51 +090065$(subdir-y): FORCE
66 $(MAKE) -C $@ -f $(TOPDIR)/scripts/Makefile.build
67endif
68
Masahiro Yamadace28d7a2013-10-17 17:34:47 +090069#########################################################################
70
Masahiro Yamada5651ccf2014-02-04 17:24:14 +090071# Allow boards to use custom optimize flags on a per dir/file basis
72ALL_AFLAGS = $(AFLAGS) $(AFLAGS_$(BCURDIR)/$(@F)) $(AFLAGS_$(BCURDIR))
73ALL_CFLAGS = $(CFLAGS) $(CFLAGS_$(BCURDIR)/$(@F)) $(CFLAGS_$(BCURDIR))
74EXTRA_CPPFLAGS = $(CPPFLAGS_$(BCURDIR)/$(@F)) $(CPPFLAGS_$(BCURDIR))
75ALL_CFLAGS += $(EXTRA_CPPFLAGS)
76
77# The _DEP version uses the $< file target (for dependency generation)
78# See rules.mk
79EXTRA_CPPFLAGS_DEP = $(CPPFLAGS_$(BCURDIR)/$(addsuffix .o,$(basename $<))) \
80 $(CPPFLAGS_$(BCURDIR))
81$(obj)%.s: %.S
82 $(CPP) $(ALL_AFLAGS) -o $@ $<
83$(obj)%.o: %.S
84 $(CC) $(ALL_AFLAGS) -o $@ $< -c
85$(obj)%.o: %.c
86ifneq ($(CHECKSRC),0)
87 $(CHECK) $(CHECKFLAGS) $(ALL_CFLAGS) $<
88endif
89 $(CC) $(ALL_CFLAGS) -o $@ $< -c
90$(obj)%.i: %.c
91 $(CPP) $(ALL_CFLAGS) -o $@ $< -c
92$(obj)%.s: %.c
93 $(CC) $(ALL_CFLAGS) -o $@ $< -c -S
94
95# If the list of objects to link is empty, just create an empty built-in.o
96cmd_link_o_target = $(if $(strip $1),\
97 $(LD) $(LDFLAGS) -r -o $@ $1,\
98 rm -f $@; $(AR) rcs $@ )
99
100#########################################################################
101
Masahiro Yamadace28d7a2013-10-17 17:34:47 +0900102# defines $(obj).depend target
103
104include $(TOPDIR)/rules.mk
105
106sinclude $(obj).depend
107
108#########################################################################
Masahiro Yamadaac7e7352013-10-17 20:38:51 +0900109
110.PHONY: FORCE