Back to home page

LXR

 
 

    


0001 # Backward compatibility
0002 asflags-y  += $(EXTRA_AFLAGS)
0003 ccflags-y  += $(EXTRA_CFLAGS)
0004 cppflags-y += $(EXTRA_CPPFLAGS)
0005 ldflags-y  += $(EXTRA_LDFLAGS)
0006 
0007 #
0008 # flags that take effect in sub directories
0009 export KBUILD_SUBDIR_ASFLAGS := $(KBUILD_SUBDIR_ASFLAGS) $(subdir-asflags-y)
0010 export KBUILD_SUBDIR_CCFLAGS := $(KBUILD_SUBDIR_CCFLAGS) $(subdir-ccflags-y)
0011 
0012 # Figure out what we need to build from the various variables
0013 # ===========================================================================
0014 
0015 # When an object is listed to be built compiled-in and modular,
0016 # only build the compiled-in version
0017 
0018 obj-m := $(filter-out $(obj-y),$(obj-m))
0019 
0020 # Libraries are always collected in one lib file.
0021 # Filter out objects already built-in
0022 
0023 lib-y := $(filter-out $(obj-y), $(sort $(lib-y) $(lib-m)))
0024 
0025 
0026 # Handle objects in subdirs
0027 # ---------------------------------------------------------------------------
0028 # o if we encounter foo/ in $(obj-y), replace it by foo/built-in.o
0029 #   and add the directory to the list of dirs to descend into: $(subdir-y)
0030 # o if we encounter foo/ in $(obj-m), remove it from $(obj-m)
0031 #   and add the directory to the list of dirs to descend into: $(subdir-m)
0032 
0033 # Determine modorder.
0034 # Unfortunately, we don't have information about ordering between -y
0035 # and -m subdirs.  Just put -y's first.
0036 modorder        := $(patsubst %/,%/modules.order, $(filter %/, $(obj-y)) $(obj-m:.o=.ko))
0037 
0038 __subdir-y      := $(patsubst %/,%,$(filter %/, $(obj-y)))
0039 subdir-y        += $(__subdir-y)
0040 __subdir-m      := $(patsubst %/,%,$(filter %/, $(obj-m)))
0041 subdir-m        += $(__subdir-m)
0042 obj-y           := $(patsubst %/, %/built-in.o, $(obj-y))
0043 obj-m           := $(filter-out %/, $(obj-m))
0044 
0045 # Subdirectories we need to descend into
0046 
0047 subdir-ym       := $(sort $(subdir-y) $(subdir-m))
0048 
0049 # if $(foo-objs) exists, foo.o is a composite object
0050 multi-used-y := $(sort $(foreach m,$(obj-y), $(if $(strip $($(m:.o=-objs)) $($(m:.o=-y))), $(m))))
0051 multi-used-m := $(sort $(foreach m,$(obj-m), $(if $(strip $($(m:.o=-objs)) $($(m:.o=-y)) $($(m:.o=-m))), $(m))))
0052 multi-used   := $(multi-used-y) $(multi-used-m)
0053 single-used-m := $(sort $(filter-out $(multi-used-m),$(obj-m)))
0054 
0055 # Build list of the parts of our composite objects, our composite
0056 # objects depend on those (obviously)
0057 multi-objs-y := $(foreach m, $(multi-used-y), $($(m:.o=-objs)) $($(m:.o=-y)))
0058 multi-objs-m := $(foreach m, $(multi-used-m), $($(m:.o=-objs)) $($(m:.o=-y)))
0059 multi-objs   := $(multi-objs-y) $(multi-objs-m)
0060 
0061 # $(subdir-obj-y) is the list of objects in $(obj-y) which uses dir/ to
0062 # tell kbuild to descend
0063 subdir-obj-y := $(filter %/built-in.o, $(obj-y))
0064 
0065 # $(obj-dirs) is a list of directories that contain object files
0066 obj-dirs := $(dir $(multi-objs) $(obj-y))
0067 
0068 # Replace multi-part objects by their individual parts, look at local dir only
0069 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)
0070 real-objs-m := $(foreach m, $(obj-m), $(if $(strip $($(m:.o=-objs)) $($(m:.o=-y)) $($(m:.o=-m))),$($(m:.o=-objs)) $($(m:.o=-y)) $($(m:.o=-m)),$(m)))
0071 
0072 # Add subdir path
0073 
0074 extra-y         := $(addprefix $(obj)/,$(extra-y))
0075 always          := $(addprefix $(obj)/,$(always))
0076 targets         := $(addprefix $(obj)/,$(targets))
0077 modorder        := $(addprefix $(obj)/,$(modorder))
0078 obj-y           := $(addprefix $(obj)/,$(obj-y))
0079 obj-m           := $(addprefix $(obj)/,$(obj-m))
0080 lib-y           := $(addprefix $(obj)/,$(lib-y))
0081 subdir-obj-y    := $(addprefix $(obj)/,$(subdir-obj-y))
0082 real-objs-y     := $(addprefix $(obj)/,$(real-objs-y))
0083 real-objs-m     := $(addprefix $(obj)/,$(real-objs-m))
0084 single-used-m   := $(addprefix $(obj)/,$(single-used-m))
0085 multi-used-y    := $(addprefix $(obj)/,$(multi-used-y))
0086 multi-used-m    := $(addprefix $(obj)/,$(multi-used-m))
0087 multi-objs-y    := $(addprefix $(obj)/,$(multi-objs-y))
0088 multi-objs-m    := $(addprefix $(obj)/,$(multi-objs-m))
0089 subdir-ym       := $(addprefix $(obj)/,$(subdir-ym))
0090 obj-dirs        := $(addprefix $(obj)/,$(obj-dirs))
0091 
0092 # These flags are needed for modversions and compiling, so we define them here
0093 # already
0094 # $(modname_flags) #defines KBUILD_MODNAME as the name of the module it will
0095 # end up in (or would, if it gets compiled in)
0096 # Note: Files that end up in two or more modules are compiled without the
0097 #       KBUILD_MODNAME definition. The reason is that any made-up name would
0098 #       differ in different configs.
0099 name-fix = $(squote)$(quote)$(subst $(comma),_,$(subst -,_,$1))$(quote)$(squote)
0100 basename_flags = -DKBUILD_BASENAME=$(call name-fix,$(basetarget))
0101 modname_flags  = $(if $(filter 1,$(words $(modname))),\
0102                  -DKBUILD_MODNAME=$(call name-fix,$(modname)))
0103 
0104 orig_c_flags   = $(KBUILD_CPPFLAGS) $(KBUILD_CFLAGS) $(KBUILD_SUBDIR_CCFLAGS) \
0105                  $(ccflags-y) $(CFLAGS_$(basetarget).o)
0106 _c_flags       = $(filter-out $(CFLAGS_REMOVE_$(basetarget).o), $(orig_c_flags))
0107 orig_a_flags   = $(KBUILD_CPPFLAGS) $(KBUILD_AFLAGS) $(KBUILD_SUBDIR_ASFLAGS) \
0108                  $(asflags-y) $(AFLAGS_$(basetarget).o)
0109 _a_flags       = $(filter-out $(AFLAGS_REMOVE_$(basetarget).o), $(orig_a_flags))
0110 _cpp_flags     = $(KBUILD_CPPFLAGS) $(cppflags-y) $(CPPFLAGS_$(@F))
0111 
0112 #
0113 # Enable gcov profiling flags for a file, directory or for all files depending
0114 # on variables GCOV_PROFILE_obj.o, GCOV_PROFILE and CONFIG_GCOV_PROFILE_ALL
0115 # (in this order)
0116 #
0117 ifeq ($(CONFIG_GCOV_KERNEL),y)
0118 _c_flags += $(if $(patsubst n%,, \
0119                 $(GCOV_PROFILE_$(basetarget).o)$(GCOV_PROFILE)$(CONFIG_GCOV_PROFILE_ALL)), \
0120                 $(CFLAGS_GCOV))
0121 endif
0122 
0123 #
0124 # Enable address sanitizer flags for kernel except some files or directories
0125 # we don't want to check (depends on variables KASAN_SANITIZE_obj.o, KASAN_SANITIZE)
0126 #
0127 ifeq ($(CONFIG_KASAN),y)
0128 _c_flags += $(if $(patsubst n%,, \
0129                 $(KASAN_SANITIZE_$(basetarget).o)$(KASAN_SANITIZE)y), \
0130                 $(CFLAGS_KASAN))
0131 endif
0132 
0133 ifeq ($(CONFIG_UBSAN),y)
0134 _c_flags += $(if $(patsubst n%,, \
0135                 $(UBSAN_SANITIZE_$(basetarget).o)$(UBSAN_SANITIZE)$(CONFIG_UBSAN_SANITIZE_ALL)), \
0136                 $(CFLAGS_UBSAN))
0137 endif
0138 
0139 ifeq ($(CONFIG_KCOV),y)
0140 _c_flags += $(if $(patsubst n%,, \
0141         $(KCOV_INSTRUMENT_$(basetarget).o)$(KCOV_INSTRUMENT)$(CONFIG_KCOV_INSTRUMENT_ALL)), \
0142         $(CFLAGS_KCOV))
0143 endif
0144 
0145 # If building the kernel in a separate objtree expand all occurrences
0146 # of -Idir to -I$(srctree)/dir except for absolute paths (starting with '/').
0147 
0148 ifeq ($(KBUILD_SRC),)
0149 __c_flags       = $(_c_flags)
0150 __a_flags       = $(_a_flags)
0151 __cpp_flags     = $(_cpp_flags)
0152 else
0153 
0154 # -I$(obj) locates generated .h files
0155 # $(call addtree,-I$(obj)) locates .h files in srctree, from generated .c files
0156 #   and locates generated .h files
0157 # FIXME: Replace both with specific CFLAGS* statements in the makefiles
0158 __c_flags       = $(if $(obj),-I$(srctree)/$(src) -I$(obj)) \
0159                   $(call flags,_c_flags)
0160 __a_flags       = $(call flags,_a_flags)
0161 __cpp_flags     = $(call flags,_cpp_flags)
0162 endif
0163 
0164 c_flags        = -Wp,-MD,$(depfile) $(NOSTDINC_FLAGS) $(LINUXINCLUDE)     \
0165                  $(__c_flags) $(modkern_cflags)                           \
0166                  $(basename_flags) $(modname_flags)
0167 
0168 a_flags        = -Wp,-MD,$(depfile) $(NOSTDINC_FLAGS) $(LINUXINCLUDE)     \
0169                  $(__a_flags) $(modkern_aflags)
0170 
0171 cpp_flags      = -Wp,-MD,$(depfile) $(NOSTDINC_FLAGS) $(LINUXINCLUDE)     \
0172                  $(__cpp_flags)
0173 
0174 ld_flags       = $(LDFLAGS) $(ldflags-y)
0175 
0176 dtc_cpp_flags  = -Wp,-MD,$(depfile).pre.tmp -nostdinc                    \
0177                  -I$(srctree)/arch/$(SRCARCH)/boot/dts                   \
0178                  -I$(srctree)/arch/$(SRCARCH)/boot/dts/include           \
0179                  -I$(srctree)/drivers/of/testcase-data                   \
0180                  -undef -D__DTS__
0181 
0182 # Finds the multi-part object the current object will be linked into
0183 modname-multi = $(sort $(foreach m,$(multi-used),\
0184                 $(if $(filter $(subst $(obj)/,,$*.o), $($(m:.o=-objs)) $($(m:.o=-y))),$(m:.o=))))
0185 
0186 # Useful for describing the dependency of composite objects
0187 # Usage:
0188 #   $(call multi_depend, multi_used_targets, suffix_to_remove, suffix_to_add)
0189 define multi_depend
0190 $(foreach m, $(notdir $1), \
0191         $(eval $(obj)/$m: \
0192         $(addprefix $(obj)/, $(foreach s, $3, $($(m:%$(strip $2)=%$(s)))))))
0193 endef
0194 
0195 ifdef REGENERATE_PARSERS
0196 
0197 # GPERF
0198 # ---------------------------------------------------------------------------
0199 quiet_cmd_gperf = GPERF $@
0200       cmd_gperf = gperf -t --output-file $@ -a -C -E -g -k 1,3,$$ -p -t $<
0201 
0202 .PRECIOUS: $(src)/%.hash.c_shipped
0203 $(src)/%.hash.c_shipped: $(src)/%.gperf
0204         $(call cmd,gperf)
0205 
0206 # LEX
0207 # ---------------------------------------------------------------------------
0208 LEX_PREFIX = $(if $(LEX_PREFIX_${baseprereq}),$(LEX_PREFIX_${baseprereq}),yy)
0209 
0210 quiet_cmd_flex = LEX     $@
0211       cmd_flex = flex -o$@ -L -P $(LEX_PREFIX) $<
0212 
0213 .PRECIOUS: $(src)/%.lex.c_shipped
0214 $(src)/%.lex.c_shipped: $(src)/%.l
0215         $(call cmd,flex)
0216 
0217 # YACC
0218 # ---------------------------------------------------------------------------
0219 YACC_PREFIX = $(if $(YACC_PREFIX_${baseprereq}),$(YACC_PREFIX_${baseprereq}),yy)
0220 
0221 quiet_cmd_bison = YACC    $@
0222       cmd_bison = bison -o$@ -t -l -p $(YACC_PREFIX) $<
0223 
0224 .PRECIOUS: $(src)/%.tab.c_shipped
0225 $(src)/%.tab.c_shipped: $(src)/%.y
0226         $(call cmd,bison)
0227 
0228 quiet_cmd_bison_h = YACC    $@
0229       cmd_bison_h = bison -o/dev/null --defines=$@ -t -l -p $(YACC_PREFIX) $<
0230 
0231 .PRECIOUS: $(src)/%.tab.h_shipped
0232 $(src)/%.tab.h_shipped: $(src)/%.y
0233         $(call cmd,bison_h)
0234 
0235 endif
0236 
0237 # Shipped files
0238 # ===========================================================================
0239 
0240 quiet_cmd_shipped = SHIPPED $@
0241 cmd_shipped = cat $< > $@
0242 
0243 $(obj)/%: $(src)/%_shipped
0244         $(call cmd,shipped)
0245 
0246 # Commands useful for building a boot image
0247 # ===========================================================================
0248 #
0249 #       Use as following:
0250 #
0251 #       target: source(s) FORCE
0252 #               $(if_changed,ld/objcopy/gzip)
0253 #
0254 #       and add target to extra-y so that we know we have to
0255 #       read in the saved command line
0256 
0257 # Linking
0258 # ---------------------------------------------------------------------------
0259 
0260 quiet_cmd_ld = LD      $@
0261 cmd_ld = $(LD) $(LDFLAGS) $(ldflags-y) $(LDFLAGS_$(@F)) \
0262                $(filter-out FORCE,$^) -o $@
0263 
0264 # Objcopy
0265 # ---------------------------------------------------------------------------
0266 
0267 quiet_cmd_objcopy = OBJCOPY $@
0268 cmd_objcopy = $(OBJCOPY) $(OBJCOPYFLAGS) $(OBJCOPYFLAGS_$(@F)) $< $@
0269 
0270 # Gzip
0271 # ---------------------------------------------------------------------------
0272 
0273 quiet_cmd_gzip = GZIP    $@
0274 cmd_gzip = (cat $(filter-out FORCE,$^) | gzip -n -f -9 > $@) || \
0275         (rm -f $@ ; false)
0276 
0277 # DTC
0278 # ---------------------------------------------------------------------------
0279 DTC ?= $(objtree)/scripts/dtc/dtc
0280 
0281 # Disable noisy checks by default
0282 ifeq ($(KBUILD_ENABLE_EXTRA_GCC_CHECKS),)
0283 DTC_FLAGS += -Wno-unit_address_vs_reg
0284 endif
0285 
0286 # Generate an assembly file to wrap the output of the device tree compiler
0287 quiet_cmd_dt_S_dtb= DTB     $@
0288 cmd_dt_S_dtb=                                           \
0289 (                                                       \
0290         echo '\#include <asm-generic/vmlinux.lds.h>';   \
0291         echo '.section .dtb.init.rodata,"a"';           \
0292         echo '.balign STRUCT_ALIGNMENT';                \
0293         echo '.global __dtb_$(*F)_begin';               \
0294         echo '__dtb_$(*F)_begin:';                      \
0295         echo '.incbin "$<" ';                           \
0296         echo '__dtb_$(*F)_end:';                        \
0297         echo '.global __dtb_$(*F)_end';                 \
0298         echo '.balign STRUCT_ALIGNMENT';                \
0299 ) > $@
0300 
0301 $(obj)/%.dtb.S: $(obj)/%.dtb
0302         $(call cmd,dt_S_dtb)
0303 
0304 quiet_cmd_dtc = DTC     $@
0305 cmd_dtc = mkdir -p $(dir ${dtc-tmp}) ; \
0306         $(CPP) $(dtc_cpp_flags) -x assembler-with-cpp -o $(dtc-tmp) $< ; \
0307         $(DTC) -O dtb -o $@ -b 0 \
0308                 -i $(dir $<) $(DTC_FLAGS) \
0309                 -d $(depfile).dtc.tmp $(dtc-tmp) ; \
0310         cat $(depfile).pre.tmp $(depfile).dtc.tmp > $(depfile)
0311 
0312 $(obj)/%.dtb: $(src)/%.dts FORCE
0313         $(call if_changed_dep,dtc)
0314 
0315 dtc-tmp = $(subst $(comma),_,$(dot-target).dts.tmp)
0316 
0317 # Bzip2
0318 # ---------------------------------------------------------------------------
0319 
0320 # Bzip2 and LZMA do not include size in file... so we have to fake that;
0321 # append the size as a 32-bit littleendian number as gzip does.
0322 size_append = printf $(shell                                            \
0323 dec_size=0;                                                             \
0324 for F in $1; do                                                         \
0325         fsize=$$(stat -c "%s" $$F);                                     \
0326         dec_size=$$(expr $$dec_size + $$fsize);                         \
0327 done;                                                                   \
0328 printf "%08x\n" $$dec_size |                                            \
0329         sed 's/\(..\)/\1 /g' | {                                        \
0330                 read ch0 ch1 ch2 ch3;                                   \
0331                 for ch in $$ch3 $$ch2 $$ch1 $$ch0; do                   \
0332                         printf '%s%03o' '\\' $$((0x$$ch));              \
0333                 done;                                                   \
0334         }                                                               \
0335 )
0336 
0337 quiet_cmd_bzip2 = BZIP2   $@
0338 cmd_bzip2 = (cat $(filter-out FORCE,$^) | \
0339         bzip2 -9 && $(call size_append, $(filter-out FORCE,$^))) > $@ || \
0340         (rm -f $@ ; false)
0341 
0342 # Lzma
0343 # ---------------------------------------------------------------------------
0344 
0345 quiet_cmd_lzma = LZMA    $@
0346 cmd_lzma = (cat $(filter-out FORCE,$^) | \
0347         lzma -9 && $(call size_append, $(filter-out FORCE,$^))) > $@ || \
0348         (rm -f $@ ; false)
0349 
0350 quiet_cmd_lzo = LZO     $@
0351 cmd_lzo = (cat $(filter-out FORCE,$^) | \
0352         lzop -9 && $(call size_append, $(filter-out FORCE,$^))) > $@ || \
0353         (rm -f $@ ; false)
0354 
0355 quiet_cmd_lz4 = LZ4     $@
0356 cmd_lz4 = (cat $(filter-out FORCE,$^) | \
0357         lz4c -l -c1 stdin stdout && $(call size_append, $(filter-out FORCE,$^))) > $@ || \
0358         (rm -f $@ ; false)
0359 
0360 # U-Boot mkimage
0361 # ---------------------------------------------------------------------------
0362 
0363 MKIMAGE := $(srctree)/scripts/mkuboot.sh
0364 
0365 # SRCARCH just happens to match slightly more than ARCH (on sparc), so reduces
0366 # the number of overrides in arch makefiles
0367 UIMAGE_ARCH ?= $(SRCARCH)
0368 UIMAGE_COMPRESSION ?= $(if $(2),$(2),none)
0369 UIMAGE_OPTS-y ?=
0370 UIMAGE_TYPE ?= kernel
0371 UIMAGE_LOADADDR ?= arch_must_set_this
0372 UIMAGE_ENTRYADDR ?= $(UIMAGE_LOADADDR)
0373 UIMAGE_NAME ?= 'Linux-$(KERNELRELEASE)'
0374 UIMAGE_IN ?= $<
0375 UIMAGE_OUT ?= $@
0376 
0377 quiet_cmd_uimage = UIMAGE  $(UIMAGE_OUT)
0378       cmd_uimage = $(CONFIG_SHELL) $(MKIMAGE) -A $(UIMAGE_ARCH) -O linux \
0379                         -C $(UIMAGE_COMPRESSION) $(UIMAGE_OPTS-y) \
0380                         -T $(UIMAGE_TYPE) \
0381                         -a $(UIMAGE_LOADADDR) -e $(UIMAGE_ENTRYADDR) \
0382                         -n $(UIMAGE_NAME) -d $(UIMAGE_IN) $(UIMAGE_OUT)
0383 
0384 # XZ
0385 # ---------------------------------------------------------------------------
0386 # Use xzkern to compress the kernel image and xzmisc to compress other things.
0387 #
0388 # xzkern uses a big LZMA2 dictionary since it doesn't increase memory usage
0389 # of the kernel decompressor. A BCJ filter is used if it is available for
0390 # the target architecture. xzkern also appends uncompressed size of the data
0391 # using size_append. The .xz format has the size information available at
0392 # the end of the file too, but it's in more complex format and it's good to
0393 # avoid changing the part of the boot code that reads the uncompressed size.
0394 # Note that the bytes added by size_append will make the xz tool think that
0395 # the file is corrupt. This is expected.
0396 #
0397 # xzmisc doesn't use size_append, so it can be used to create normal .xz
0398 # files. xzmisc uses smaller LZMA2 dictionary than xzkern, because a very
0399 # big dictionary would increase the memory usage too much in the multi-call
0400 # decompression mode. A BCJ filter isn't used either.
0401 quiet_cmd_xzkern = XZKERN  $@
0402 cmd_xzkern = (cat $(filter-out FORCE,$^) | \
0403         sh $(srctree)/scripts/xz_wrap.sh && \
0404         $(call size_append, $(filter-out FORCE,$^))) > $@ || \
0405         (rm -f $@ ; false)
0406 
0407 quiet_cmd_xzmisc = XZMISC  $@
0408 cmd_xzmisc = (cat $(filter-out FORCE,$^) | \
0409         xz --check=crc32 --lzma2=dict=1MiB) > $@ || \
0410         (rm -f $@ ; false)