Merge ../linux-2.6
[pandora-kernel.git] / scripts / Makefile.lib
1 # Backward compatibility - to be removed...
2 extra-y += $(EXTRA_TARGETS)
3 # Figure out what we need to build from the various variables
4 # ===========================================================================
5
6 # When an object is listed to be built compiled-in and modular,
7 # only build the compiled-in version
8
9 obj-m := $(filter-out $(obj-y),$(obj-m))
10
11 # Libraries are always collected in one lib file.
12 # Filter out objects already built-in
13
14 lib-y := $(filter-out $(obj-y), $(sort $(lib-y) $(lib-m)))
15
16
17 # Handle objects in subdirs
18 # ---------------------------------------------------------------------------
19 # o if we encounter foo/ in $(obj-y), replace it by foo/built-in.o
20 #   and add the directory to the list of dirs to descend into: $(subdir-y)
21 # o if we encounter foo/ in $(obj-m), remove it from $(obj-m) 
22 #   and add the directory to the list of dirs to descend into: $(subdir-m)
23
24 __subdir-y      := $(patsubst %/,%,$(filter %/, $(obj-y)))
25 subdir-y        += $(__subdir-y)
26 __subdir-m      := $(patsubst %/,%,$(filter %/, $(obj-m)))
27 subdir-m        += $(__subdir-m)
28 obj-y           := $(patsubst %/, %/built-in.o, $(obj-y))
29 obj-m           := $(filter-out %/, $(obj-m))
30
31 # Subdirectories we need to descend into
32
33 subdir-ym       := $(sort $(subdir-y) $(subdir-m))
34
35 # if $(foo-objs) exists, foo.o is a composite object 
36 multi-used-y := $(sort $(foreach m,$(obj-y), $(if $(strip $($(m:.o=-objs)) $($(m:.o=-y))), $(m))))
37 multi-used-m := $(sort $(foreach m,$(obj-m), $(if $(strip $($(m:.o=-objs)) $($(m:.o=-y))), $(m))))
38 multi-used   := $(multi-used-y) $(multi-used-m)
39 single-used-m := $(sort $(filter-out $(multi-used-m),$(obj-m)))
40
41 # Build list of the parts of our composite objects, our composite
42 # objects depend on those (obviously)
43 multi-objs-y := $(foreach m, $(multi-used-y), $($(m:.o=-objs)) $($(m:.o=-y)))
44 multi-objs-m := $(foreach m, $(multi-used-m), $($(m:.o=-objs)) $($(m:.o=-y)))
45 multi-objs   := $(multi-objs-y) $(multi-objs-m)
46
47 # $(subdir-obj-y) is the list of objects in $(obj-y) which do not live
48 # in the local directory
49 subdir-obj-y := $(foreach o,$(obj-y),$(if $(filter-out $(o),$(notdir $(o))),$(o)))
50
51 # $(obj-dirs) is a list of directories that contain object files
52 obj-dirs := $(dir $(multi-objs) $(subdir-obj-y))
53
54 # Replace multi-part objects by their individual parts, look at local dir only
55 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)
56 real-objs-m := $(foreach m, $(obj-m), $(if $(strip $($(m:.o=-objs)) $($(m:.o=-y))),$($(m:.o=-objs)) $($(m:.o=-y)),$(m)))
57
58 # Add subdir path
59
60 extra-y         := $(addprefix $(obj)/,$(extra-y))
61 always          := $(addprefix $(obj)/,$(always))
62 targets         := $(addprefix $(obj)/,$(targets))
63 obj-y           := $(addprefix $(obj)/,$(obj-y))
64 obj-m           := $(addprefix $(obj)/,$(obj-m))
65 lib-y           := $(addprefix $(obj)/,$(lib-y))
66 subdir-obj-y    := $(addprefix $(obj)/,$(subdir-obj-y))
67 real-objs-y     := $(addprefix $(obj)/,$(real-objs-y))
68 real-objs-m     := $(addprefix $(obj)/,$(real-objs-m))
69 single-used-m   := $(addprefix $(obj)/,$(single-used-m))
70 multi-used-y    := $(addprefix $(obj)/,$(multi-used-y))
71 multi-used-m    := $(addprefix $(obj)/,$(multi-used-m))
72 multi-objs-y    := $(addprefix $(obj)/,$(multi-objs-y))
73 multi-objs-m    := $(addprefix $(obj)/,$(multi-objs-m))
74 subdir-ym       := $(addprefix $(obj)/,$(subdir-ym))
75 obj-dirs        := $(addprefix $(obj)/,$(obj-dirs))
76
77 # These flags are needed for modversions and compiling, so we define them here
78 # already
79 # $(modname_flags) #defines KBUILD_MODNAME as the name of the module it will 
80 # end up in (or would, if it gets compiled in)
81 # Note: It's possible that one object gets potentially linked into more
82 #       than one module. In that case KBUILD_MODNAME will be set to foo_bar,
83 #       where foo and bar are the name of the modules.
84 name-fix = $(subst $(comma),_,$(subst -,_,$1))
85 basename_flags = -D"KBUILD_BASENAME=KBUILD_STR($(call name-fix,$(*F)))"
86 modname_flags  = $(if $(filter 1,$(words $(modname))),\
87                  -D"KBUILD_MODNAME=KBUILD_STR($(call name-fix,$(modname)))")
88
89 _c_flags       = $(CFLAGS) $(EXTRA_CFLAGS) $(CFLAGS_$(*F).o)
90 _a_flags       = $(AFLAGS) $(EXTRA_AFLAGS) $(AFLAGS_$(*F).o)
91 _cpp_flags     = $(CPPFLAGS) $(EXTRA_CPPFLAGS) $(CPPFLAGS_$(@F))
92
93 # If building the kernel in a separate objtree expand all occurrences
94 # of -Idir to -I$(srctree)/dir except for absolute paths (starting with '/').
95
96 ifeq ($(KBUILD_SRC),)
97 __c_flags       = $(_c_flags)
98 __a_flags       = $(_a_flags)
99 __cpp_flags     = $(_cpp_flags)
100 else
101
102 # Prefix -I with $(srctree) if it is not an absolute path
103 addtree = $(if $(filter-out -I/%,$(1)),$(patsubst -I%,-I$(srctree)/%,$(1))) $(1)
104 # Find all -I options and call addtree
105 flags = $(foreach o,$($(1)),$(if $(filter -I%,$(o)),$(call addtree,$(o)),$(o)))
106
107 # -I$(obj) locates generated .h files
108 # $(call addtree,-I$(obj)) locates .h files in srctree, from generated .c files
109 #   and locates generated .h files
110 # FIXME: Replace both with specific CFLAGS* statements in the makefiles
111 __c_flags       = $(call addtree,-I$(obj)) $(call flags,_c_flags)
112 __a_flags       =                          $(call flags,_a_flags)
113 __cpp_flags     =                          $(call flags,_cpp_flags)
114 endif
115
116 c_flags        = -Wp,-MD,$(depfile) $(NOSTDINC_FLAGS) $(CPPFLAGS) \
117                  $(__c_flags) $(modkern_cflags) \
118                  -D"KBUILD_STR(s)=\#s" $(basename_flags) $(modname_flags)
119
120 a_flags        = -Wp,-MD,$(depfile) $(NOSTDINC_FLAGS) $(CPPFLAGS) \
121                  $(__a_flags) $(modkern_aflags)
122
123 cpp_flags      = -Wp,-MD,$(depfile) $(NOSTDINC_FLAGS) $(__cpp_flags)
124
125 ld_flags       = $(LDFLAGS) $(EXTRA_LDFLAGS)
126
127 # Finds the multi-part object the current object will be linked into
128 modname-multi = $(sort $(foreach m,$(multi-used),\
129                 $(if $(filter $(subst $(obj)/,,$*.o), $($(m:.o=-objs)) $($(m:.o=-y))),$(m:.o=))))
130
131 # Shipped files
132 # ===========================================================================
133
134 quiet_cmd_shipped = SHIPPED $@
135 cmd_shipped = cat $< > $@
136
137 $(obj)/%:: $(src)/%_shipped
138         $(call cmd,shipped)
139
140 # Commands useful for building a boot image
141 # ===========================================================================
142
143 #       Use as following:
144 #
145 #       target: source(s) FORCE
146 #               $(if_changed,ld/objcopy/gzip)
147 #
148 #       and add target to EXTRA_TARGETS so that we know we have to
149 #       read in the saved command line
150
151 # Linking
152 # ---------------------------------------------------------------------------
153
154 quiet_cmd_ld = LD      $@
155 cmd_ld = $(LD) $(LDFLAGS) $(EXTRA_LDFLAGS) $(LDFLAGS_$(@F)) \
156                $(filter-out FORCE,$^) -o $@ 
157
158 # Objcopy
159 # ---------------------------------------------------------------------------
160
161 quiet_cmd_objcopy = OBJCOPY $@
162 cmd_objcopy = $(OBJCOPY) $(OBJCOPYFLAGS) $(OBJCOPYFLAGS_$(@F)) $< $@
163
164 # Gzip
165 # ---------------------------------------------------------------------------
166
167 quiet_cmd_gzip = GZIP    $@
168 cmd_gzip = gzip -f -9 < $< > $@
169
170