Make GET_SAVED_SP lowercase.
[linux-2.6/linux-mips.git] / scripts / Makefile.lib
blob398114524818c22b5a19e4a9bb0da1c075159f8a
1 # ===========================================================================
2 # kbuild: Generic definitions
3 # ===========================================================================
5 # Standard vars
7 comma   := ,
8 empty   :=
9 space   := $(empty) $(empty)
11 # Backward compatibility - to be removed...
12 extra-y += $(EXTRA_TARGETS)
13 # Figure out what we need to build from the various variables
14 # ===========================================================================
16 # When an object is listed to be built compiled-in and modular,
17 # only build the compiled-in version
19 obj-m := $(filter-out $(obj-y),$(obj-m))
21 # Libraries are always collected in one lib file.
22 # Filter out objects already built-in
24 lib-y := $(filter-out $(obj-y), $(sort $(lib-y) $(lib-m)))
27 # Handle objects in subdirs
28 # ---------------------------------------------------------------------------
29 # o if we encounter foo/ in $(obj-y), replace it by foo/built-in.o
30 #   and add the directory to the list of dirs to descend into: $(subdir-y)
31 # o if we encounter foo/ in $(obj-m), remove it from $(obj-m) 
32 #   and add the directory to the list of dirs to descend into: $(subdir-m)
34 __subdir-y      := $(patsubst %/,%,$(filter %/, $(obj-y)))
35 subdir-y        += $(__subdir-y)
36 __subdir-m      := $(patsubst %/,%,$(filter %/, $(obj-m)))
37 subdir-m        += $(__subdir-m)
38 obj-y           := $(patsubst %/, %/built-in.o, $(obj-y))
39 obj-m           := $(filter-out %/, $(obj-m))
41 # Subdirectories we need to descend into
43 subdir-ym       := $(sort $(subdir-y) $(subdir-m))
45 # if $(foo-objs) exists, foo.o is a composite object 
46 multi-used-y := $(sort $(foreach m,$(obj-y), $(if $(strip $($(m:.o=-objs)) $($(m:.o=-y))), $(m))))
47 multi-used-m := $(sort $(foreach m,$(obj-m), $(if $(strip $($(m:.o=-objs)) $($(m:.o=-y))), $(m))))
48 multi-used   := $(multi-used-y) $(multi-used-m)
49 single-used-m := $(sort $(filter-out $(multi-used-m),$(obj-m)))
51 # Build list of the parts of our composite objects, our composite
52 # objects depend on those (obviously)
53 multi-objs-y := $(foreach m, $(multi-used-y), $($(m:.o=-objs)) $($(m:.o=-y)))
54 multi-objs-m := $(foreach m, $(multi-used-m), $($(m:.o=-objs)) $($(m:.o=-y)))
55 multi-objs   := $(multi-objs-y) $(multi-objs-m)
57 # $(subdir-obj-y) is the list of objects in $(obj-y) which do not live
58 # in the local directory
59 subdir-obj-y := $(foreach o,$(obj-y),$(if $(filter-out $(o),$(notdir $(o))),$(o)))
61 # Replace multi-part objects by their individual parts, look at local dir only
62 real-objs-y := $(foreach m, $(filter-out $(subdir-obj-y), $(obj-y)), $(if $(strip $($(m:.o=-objs)) $($(m:.o=-y))),$($(m:.o=-objs)) $($(m:.o=-y)),$(m))) $(extra-y)
63 real-objs-m := $(foreach m, $(obj-m), $(if $(strip $($(m:.o=-objs)) $($(m:.o=-y))),$($(m:.o=-objs)) $($(m:.o=-y)),$(m)))
65 # C code
66 # Executables compiled from a single .c file
67 host-csingle    := $(foreach m,$(host-progs),$(if $($(m)-objs),,$(m)))
69 # C executables linked based on several .o files
70 host-cmulti     := $(foreach m,$(host-progs),\
71                    $(if $($(m)-cxxobjs),,$(if $($(m)-objs),$(m))))
73 # Object (.o) files compiled from .c files
74 host-cobjs      := $(sort $(foreach m,$(host-progs),$($(m)-objs)))
76 # C++ code
77 # C++ executables compiled from at least on .cc file
78 # and zero or more .c files
79 host-cxxmulti   := $(foreach m,$(host-progs),$(if $($(m)-cxxobjs),$(m)))
81 # C++ Object (.o) files compiled from .cc files
82 host-cxxobjs    := $(sort $(foreach m,$(host-cxxmulti),$($(m)-cxxobjs)))
84 # Shared libaries (only .c supported)
85 # Shared libraries (.so) - all .so files referenced in "xxx-objs"
86 host-cshlib     := $(sort $(filter %.so, $(host-cobjs)))
87 # Remove .so files from "xxx-objs"
88 host-cobjs      := $(filter-out %.so,$(host-cobjs))
90 #Object (.o) files used by the shared libaries
91 host-cshobjs    := $(sort $(foreach m,$(host-cshlib),$($(m:.so=-objs))))
93 # Add subdir path
95 extra-y         := $(addprefix $(obj)/,$(extra-y))
96 always          := $(addprefix $(obj)/,$(always))
97 targets         := $(addprefix $(obj)/,$(targets))
98 obj-y           := $(addprefix $(obj)/,$(obj-y))
99 obj-m           := $(addprefix $(obj)/,$(obj-m))
100 lib-y           := $(addprefix $(obj)/,$(lib-y))
101 subdir-obj-y    := $(addprefix $(obj)/,$(subdir-obj-y))
102 real-objs-y     := $(addprefix $(obj)/,$(real-objs-y))
103 real-objs-m     := $(addprefix $(obj)/,$(real-objs-m))
104 single-used-m   := $(addprefix $(obj)/,$(single-used-m))
105 multi-used-y    := $(addprefix $(obj)/,$(multi-used-y))
106 multi-used-m    := $(addprefix $(obj)/,$(multi-used-m))
107 multi-objs-y    := $(addprefix $(obj)/,$(multi-objs-y))
108 multi-objs-m    := $(addprefix $(obj)/,$(multi-objs-m))
109 subdir-ym       := $(addprefix $(obj)/,$(subdir-ym))
110 host-progs      := $(addprefix $(obj)/,$(host-progs))
111 host-csingle    := $(addprefix $(obj)/,$(host-csingle))
112 host-cmulti     := $(addprefix $(obj)/,$(host-cmulti))
113 host-cobjs      := $(addprefix $(obj)/,$(host-cobjs))
114 host-cxxmulti   := $(addprefix $(obj)/,$(host-cxxmulti))
115 host-cxxobjs    := $(addprefix $(obj)/,$(host-cxxobjs))
116 host-cshlib     := $(addprefix $(obj)/,$(host-cshlib))
117 host-cshobjs    := $(addprefix $(obj)/,$(host-cshobjs))
119 # The temporary file to save gcc -MD generated dependencies must not
120 # contain a comma
121 depfile = $(subst $(comma),_,$(@D)/.$(@F).d)
123 # These flags are needed for modversions and compiling, so we define them here
124 # already
125 # $(modname_flags) #defines KBUILD_MODNAME as the name of the module it will 
126 # end up in (or would, if it gets compiled in)
127 # Note: It's possible that one object gets potentially linked into more
128 #       than one module. In that case KBUILD_MODNAME will be set to foo_bar,
129 #       where foo and bar are the name of the modules.
130 basename_flags = -DKBUILD_BASENAME=$(subst $(comma),_,$(subst -,_,$(*F)))
131 modname_flags  = $(if $(filter 1,$(words $(modname))),-DKBUILD_MODNAME=$(subst $(comma),_,$(subst -,_,$(modname))))
132 c_flags        = -Wp,-MD,$(depfile) $(CFLAGS) $(NOSTDINC_FLAGS) \
133                  $(modkern_cflags) $(EXTRA_CFLAGS) $(CFLAGS_$(*F).o) \
134                  $(basename_flags) $(modname_flags)
135 a_flags        = -Wp,-MD,$(depfile) $(AFLAGS) $(NOSTDINC_FLAGS)\
136                  $(modkern_aflags) $(EXTRA_AFLAGS) $(AFLAGS_$(*F).o)
137 hostc_flags    = -Wp,-MD,$(depfile) $(HOSTCFLAGS) $(HOST_EXTRACFLAGS)\
138                  $(HOSTCFLAGS_$(*F).o)
139 hostcxx_flags  = -Wp,-MD,$(depfile) $(HOSTCXXFLAGS) $(HOST_EXTRACXXFLAGS)\
140                  $(HOSTCXXFLAGS_$(*F).o)
141 ld_flags       = $(LDFLAGS) $(EXTRA_LDFLAGS)
143 # Finds the multi-part object the current object will be linked into
144 modname-multi = $(sort $(foreach m,$(multi-used),\
145                 $(if $(filter $(subst $(obj)/,,$*.o), $($(m:.o=-objs)) $($(m:.o=-y))),$(m:.o=))))
147 # Shipped files
148 # ===========================================================================
150 quiet_cmd_shipped = SHIPPED $@
151 cmd_shipped = cat $< > $@
153 $(obj)/%:: $(src)/%_shipped
154         $(call cmd,shipped)
156 # Commands useful for building a boot image
157 # ===========================================================================
159 #       Use as following:
161 #       target: source(s) FORCE
162 #               $(if_changed,ld/objcopy/gzip)
164 #       and add target to EXTRA_TARGETS so that we know we have to
165 #       read in the saved command line
167 # Linking
168 # ---------------------------------------------------------------------------
170 quiet_cmd_ld = LD      $@
171 cmd_ld = $(LD) $(LDFLAGS) $(EXTRA_LDFLAGS) $(LDFLAGS_$(@F)) \
172                $(filter-out FORCE,$^) -o $@ 
174 # Objcopy
175 # ---------------------------------------------------------------------------
177 quiet_cmd_objcopy = OBJCOPY $@
178 cmd_objcopy = $(OBJCOPY) $(OBJCOPYFLAGS) $(OBJCOPYFLAGS_$(@F)) $< $@
180 # Gzip
181 # ---------------------------------------------------------------------------
183 quiet_cmd_gzip = GZIP    $@
184 cmd_gzip = gzip -f -9 < $< > $@
186 # ===========================================================================
187 # Generic stuff
188 # ===========================================================================
190 # function to only execute the passed command if necessary
191 # >'< substitution is for echo to work, >$< substitution to preserve $ when reloading .cmd file
192 # note: when using inline perl scripts [perl -e '...$$t=1;...'] in $(cmd_xxx) double $$ your perl vars
194 if_changed = $(if $(strip $? \
195                           $(filter-out $(cmd_$(1)),$(cmd_$@))\
196                           $(filter-out $(cmd_$@),$(cmd_$(1)))),\
197         @set -e; \
198         $(if $($(quiet)cmd_$(1)),echo '  $(subst ','\'',$($(quiet)cmd_$(1)))';) \
199         $(cmd_$(1)); \
200         echo 'cmd_$@ := $(subst $$,$$$$,$(subst ','\'',$(cmd_$(1))))' > $(@D)/.$(@F).cmd)
203 # execute the command and also postprocess generated .d dependencies
204 # file
206 if_changed_dep = $(if $(strip $? $(filter-out FORCE $(wildcard $^),$^)\
207                           $(filter-out $(cmd_$(1)),$(cmd_$@))\
208                           $(filter-out $(cmd_$@),$(cmd_$(1)))),\
209         @set -e; \
210         $(if $($(quiet)cmd_$(1)),echo '  $(subst ','\'',$($(quiet)cmd_$(1)))';) \
211         $(cmd_$(1)); \
212         scripts/fixdep $(depfile) $@ '$(subst $$,$$$$,$(subst ','\'',$(cmd_$(1))))' > $(@D)/.$(@F).tmp; \
213         rm -f $(depfile); \
214         mv -f $(@D)/.$(@F).tmp $(@D)/.$(@F).cmd)
216 # Usage: $(call if_changed_rule,foo)
217 # will check if $(cmd_foo) changed, or any of the prequisites changed,
218 # and if so will execute $(rule_foo)
220 if_changed_rule = $(if $(strip $? \
221                                $(filter-out $(cmd_$(1)),$(cmd_$@))\
222                                $(filter-out $(cmd_$@),$(cmd_$(1)))),\
223                         @set -e; \
224                         $(rule_$(1)))
226 # If quiet is set, only print short version of command
228 cmd = @$(if $($(quiet)cmd_$(1)),echo '  $($(quiet)cmd_$(1))' &&) $(cmd_$(1))
230 #       $(call descend,<dir>,<target>)
231 #       Recursively call a sub-make in <dir> with target <target> 
232 # Usage is deprecated, because make do not see this as an invocation of make.
233 descend =$(Q)$(MAKE) -f scripts/Makefile.build obj=$(1) $(2)
235 # Shorthand for $(Q)$(MAKE) -f scripts/Makefile.build obj=
236 # Usage:
237 # $(Q)$(MAKE) $(build)=dir
238 build := -f scripts/Makefile.build obj