]> git.kernelconcepts.de Git - karo-tx-uboot.git/blob - scripts/Makefile.build
kbuild: change out-of-tree build
[karo-tx-uboot.git] / scripts / Makefile.build
1 # our default target
2 .PHONY: all
3 all:
4
5 ifeq ($(CONFIG_TPL_BUILD),y)
6   src := $(patsubst tpl/%,%,$(obj))
7 else
8   ifeq ($(CONFIG_SPL_BUILD),y)
9     src := $(patsubst spl/%,%,$(obj))
10   else
11     src := $(obj)
12   endif
13 endif
14
15 include $(srctree)/scripts/Kbuild.include
16 include $(srctree)/config.mk
17
18 # variable LIB is used in examples/standalone/Makefile
19 __LIB := $(obj)/built-in.o
20 LIBGCC = $(obj)/libgcc.o
21 SRCS :=
22 subdir-y :=
23 obj-dirs :=
24
25 kbuild-dir := $(if $(filter /%,$(src)),$(src),$(srctree)/$(src))
26 include $(kbuild-dir)/Makefile
27
28 # Do not include host rules unless needed
29 ifneq ($(hostprogs-y)$(hostprogs-m),)
30 include $(SRCTREE)/scripts/Makefile.host.tmp
31 endif
32
33 # Going forward use the following
34 obj-y := $(sort $(obj-y))
35 extra-y := $(sort $(extra-y))
36 always := $(sort $(always))
37 lib-y := $(sort $(lib-y))
38
39 subdir-y        += $(patsubst %/,%,$(filter %/, $(obj-y)))
40 obj-y           := $(patsubst %/, %/built-in.o, $(obj-y))
41 subdir-obj-y    := $(filter %/built-in.o, $(obj-y))
42 subdir-obj-y    := $(addprefix $(obj)/,$(subdir-obj-y))
43
44 SRCS    += $(obj-y:.o=.c) $(obj-y:.o=.S) $(lib-y:.o=.c) \
45         $(lib-y:.o=.S) $(extra-y:.o=.c) $(extra-y:.o=.S)
46
47 SRCS := $(addprefix $(if $(KBUILD_SRC),$(srctree)/$(src)/,$(src)/),$(SRCS))
48 SRCS := $(wildcard $(SRCS))
49
50 OBJS    := $(addprefix $(obj)/,$(obj-y))
51
52 # $(obj-dirs) is a list of directories that contain object files
53
54 obj-dirs += $(dir $(OBJS))
55
56 _dummy := $(shell [ -d $(obj) ] || mkdir -p $(obj))
57
58 # Create directories for object files if directory does not exist
59 # Needed when obj-y := dir/file.o syntax is used
60 _dummy := $(foreach d,$(obj-dirs), $(shell [ -d $(d) ] || mkdir -p $(d)))
61
62 LGOBJS := $(addprefix $(obj)/,$(sort $(lib-y)))
63
64 all: $(__LIB) $(addprefix $(obj)/,$(extra-y) $(always)) $(subdir-y)
65
66 $(__LIB):       $(obj)/.depend $(OBJS)
67         $(call cmd_link_o_target, $(OBJS))
68
69 ifneq ($(strip $(lib-y)),)
70 all: $(LIBGCC)
71
72 $(LIBGCC): $(obj)/.depend $(LGOBJS)
73         $(call cmd_link_o_target, $(LGOBJS))
74 endif
75
76 ifneq ($(subdir-obj-y),)
77 # Descending
78 $(subdir-obj-y): $(subdir-y)
79 endif
80
81 ifneq ($(subdir-y),)
82 $(subdir-y): FORCE
83         $(MAKE) $(build)=$(obj)/$@
84 endif
85
86 #########################################################################
87
88 # Allow boards to use custom optimize flags on a per dir/file basis
89 ALL_AFLAGS = $(AFLAGS) $(AFLAGS_$(BCURDIR)/$(@F)) $(AFLAGS_$(BCURDIR))
90 ALL_CFLAGS = $(CFLAGS) $(CFLAGS_$(BCURDIR)/$(@F)) $(CFLAGS_$(BCURDIR))
91 EXTRA_CPPFLAGS = $(CPPFLAGS_$(BCURDIR)/$(@F)) $(CPPFLAGS_$(BCURDIR))
92 ALL_CFLAGS += $(EXTRA_CPPFLAGS)
93
94 # The _DEP version uses the $< file target (for dependency generation)
95 # See rules.mk
96 EXTRA_CPPFLAGS_DEP = $(CPPFLAGS_$(BCURDIR)/$(addsuffix .o,$(basename $<))) \
97                 $(CPPFLAGS_$(BCURDIR))
98 $(obj)/%.s:     $(src)/%.S
99         $(CPP) $(ALL_AFLAGS) -o $@ $<
100 $(obj)/%.o:     $(src)/%.S
101         $(CC)  $(ALL_AFLAGS) -o $@ $< -c
102 $(obj)/%.o:     $(src)/%.c
103 ifneq ($(CHECKSRC),0)
104         $(CHECK) $(CHECKFLAGS) $(ALL_CFLAGS) $<
105 endif
106         $(CC)  $(ALL_CFLAGS) -o $@ $< -c
107 $(obj)/%.i:     $(src)/%.c
108         $(CPP) $(ALL_CFLAGS) -o $@ $< -c
109 $(obj)/%.s:     $(src)/%.c
110         $(CC)  $(ALL_CFLAGS) -o $@ $< -c -S
111
112 # If the list of objects to link is empty, just create an empty built-in.o
113 cmd_link_o_target = $(if $(strip $1),\
114                       $(LD) $(LDFLAGS) -r -o $@ $1,\
115                       rm -f $@; $(AR) rcs $@ )
116
117 #########################################################################
118
119 # defines $(obj)/.depend target
120
121 include $(TOPDIR)/rules.mk
122
123 sinclude $(obj)/.depend
124
125 #########################################################################
126
127 .PHONY: FORCE