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