1f77bf014SSam Ravnborg# Backward compatibility 2f77bf014SSam Ravnborgasflags-y += $(EXTRA_AFLAGS) 3f77bf014SSam Ravnborgccflags-y += $(EXTRA_CFLAGS) 4f77bf014SSam Ravnborgcppflags-y += $(EXTRA_CPPFLAGS) 5f77bf014SSam Ravnborgldflags-y += $(EXTRA_LDFLAGS) 6f77bf014SSam Ravnborg 7720097d8SSam Ravnborg# 8720097d8SSam Ravnborg# flags that take effect in sub directories 9720097d8SSam Ravnborgexport KBUILD_SUBDIR_ASFLAGS := $(KBUILD_SUBDIR_ASFLAGS) $(subdir-asflags-y) 10720097d8SSam Ravnborgexport KBUILD_SUBDIR_CCFLAGS := $(KBUILD_SUBDIR_CCFLAGS) $(subdir-ccflags-y) 11720097d8SSam Ravnborg 121da177e4SLinus Torvalds# Figure out what we need to build from the various variables 131da177e4SLinus Torvalds# =========================================================================== 141da177e4SLinus Torvalds 151da177e4SLinus Torvalds# When an object is listed to be built compiled-in and modular, 161da177e4SLinus Torvalds# only build the compiled-in version 171da177e4SLinus Torvalds 181da177e4SLinus Torvaldsobj-m := $(filter-out $(obj-y),$(obj-m)) 191da177e4SLinus Torvalds 201da177e4SLinus Torvalds# Libraries are always collected in one lib file. 211da177e4SLinus Torvalds# Filter out objects already built-in 221da177e4SLinus Torvalds 231da177e4SLinus Torvaldslib-y := $(filter-out $(obj-y), $(sort $(lib-y) $(lib-m))) 241da177e4SLinus Torvalds 251da177e4SLinus Torvalds 261da177e4SLinus Torvalds# Handle objects in subdirs 271da177e4SLinus Torvalds# --------------------------------------------------------------------------- 281da177e4SLinus Torvalds# o if we encounter foo/ in $(obj-y), replace it by foo/built-in.o 291da177e4SLinus Torvalds# and add the directory to the list of dirs to descend into: $(subdir-y) 301da177e4SLinus Torvalds# o if we encounter foo/ in $(obj-m), remove it from $(obj-m) 311da177e4SLinus Torvalds# and add the directory to the list of dirs to descend into: $(subdir-m) 321da177e4SLinus Torvalds 33551559e1STejun Heo# Determine modorder. 34551559e1STejun Heo# Unfortunately, we don't have information about ordering between -y 35551559e1STejun Heo# and -m subdirs. Just put -y's first. 36551559e1STejun Heomodorder := $(patsubst %/,%/modules.order, $(filter %/, $(obj-y)) $(obj-m:.o=.ko)) 37551559e1STejun Heo 381da177e4SLinus Torvalds__subdir-y := $(patsubst %/,%,$(filter %/, $(obj-y))) 391da177e4SLinus Torvaldssubdir-y += $(__subdir-y) 401da177e4SLinus Torvalds__subdir-m := $(patsubst %/,%,$(filter %/, $(obj-m))) 411da177e4SLinus Torvaldssubdir-m += $(__subdir-m) 421da177e4SLinus Torvaldsobj-y := $(patsubst %/, %/built-in.o, $(obj-y)) 431da177e4SLinus Torvaldsobj-m := $(filter-out %/, $(obj-m)) 441da177e4SLinus Torvalds 451da177e4SLinus Torvalds# Subdirectories we need to descend into 461da177e4SLinus Torvalds 471da177e4SLinus Torvaldssubdir-ym := $(sort $(subdir-y) $(subdir-m)) 481da177e4SLinus Torvalds 491da177e4SLinus Torvalds# if $(foo-objs) exists, foo.o is a composite object 501da177e4SLinus Torvaldsmulti-used-y := $(sort $(foreach m,$(obj-y), $(if $(strip $($(m:.o=-objs)) $($(m:.o=-y))), $(m)))) 511da177e4SLinus Torvaldsmulti-used-m := $(sort $(foreach m,$(obj-m), $(if $(strip $($(m:.o=-objs)) $($(m:.o=-y))), $(m)))) 521da177e4SLinus Torvaldsmulti-used := $(multi-used-y) $(multi-used-m) 531da177e4SLinus Torvaldssingle-used-m := $(sort $(filter-out $(multi-used-m),$(obj-m))) 541da177e4SLinus Torvalds 551da177e4SLinus Torvalds# Build list of the parts of our composite objects, our composite 561da177e4SLinus Torvalds# objects depend on those (obviously) 571da177e4SLinus Torvaldsmulti-objs-y := $(foreach m, $(multi-used-y), $($(m:.o=-objs)) $($(m:.o=-y))) 581da177e4SLinus Torvaldsmulti-objs-m := $(foreach m, $(multi-used-m), $($(m:.o=-objs)) $($(m:.o=-y))) 591da177e4SLinus Torvaldsmulti-objs := $(multi-objs-y) $(multi-objs-m) 601da177e4SLinus Torvalds 61f5fb9765SSam Ravnborg# $(subdir-obj-y) is the list of objects in $(obj-y) which uses dir/ to 62f5fb9765SSam Ravnborg# tell kbuild to descend 63f5fb9765SSam Ravnborgsubdir-obj-y := $(filter %/built-in.o, $(obj-y)) 641da177e4SLinus Torvalds 651da177e4SLinus Torvalds# $(obj-dirs) is a list of directories that contain object files 661da177e4SLinus Torvaldsobj-dirs := $(dir $(multi-objs) $(subdir-obj-y)) 671da177e4SLinus Torvalds 681da177e4SLinus Torvalds# Replace multi-part objects by their individual parts, look at local dir only 691da177e4SLinus Torvaldsreal-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) 701da177e4SLinus Torvaldsreal-objs-m := $(foreach m, $(obj-m), $(if $(strip $($(m:.o=-objs)) $($(m:.o=-y))),$($(m:.o=-objs)) $($(m:.o=-y)),$(m))) 711da177e4SLinus Torvalds 721da177e4SLinus Torvalds# Add subdir path 731da177e4SLinus Torvalds 741da177e4SLinus Torvaldsextra-y := $(addprefix $(obj)/,$(extra-y)) 751da177e4SLinus Torvaldsalways := $(addprefix $(obj)/,$(always)) 761da177e4SLinus Torvaldstargets := $(addprefix $(obj)/,$(targets)) 77551559e1STejun Heomodorder := $(addprefix $(obj)/,$(modorder)) 781da177e4SLinus Torvaldsobj-y := $(addprefix $(obj)/,$(obj-y)) 791da177e4SLinus Torvaldsobj-m := $(addprefix $(obj)/,$(obj-m)) 801da177e4SLinus Torvaldslib-y := $(addprefix $(obj)/,$(lib-y)) 811da177e4SLinus Torvaldssubdir-obj-y := $(addprefix $(obj)/,$(subdir-obj-y)) 821da177e4SLinus Torvaldsreal-objs-y := $(addprefix $(obj)/,$(real-objs-y)) 831da177e4SLinus Torvaldsreal-objs-m := $(addprefix $(obj)/,$(real-objs-m)) 841da177e4SLinus Torvaldssingle-used-m := $(addprefix $(obj)/,$(single-used-m)) 851da177e4SLinus Torvaldsmulti-used-y := $(addprefix $(obj)/,$(multi-used-y)) 861da177e4SLinus Torvaldsmulti-used-m := $(addprefix $(obj)/,$(multi-used-m)) 871da177e4SLinus Torvaldsmulti-objs-y := $(addprefix $(obj)/,$(multi-objs-y)) 881da177e4SLinus Torvaldsmulti-objs-m := $(addprefix $(obj)/,$(multi-objs-m)) 891da177e4SLinus Torvaldssubdir-ym := $(addprefix $(obj)/,$(subdir-ym)) 901da177e4SLinus Torvaldsobj-dirs := $(addprefix $(obj)/,$(obj-dirs)) 911da177e4SLinus Torvalds 921da177e4SLinus Torvalds# These flags are needed for modversions and compiling, so we define them here 931da177e4SLinus Torvalds# already 941da177e4SLinus Torvalds# $(modname_flags) #defines KBUILD_MODNAME as the name of the module it will 951da177e4SLinus Torvalds# end up in (or would, if it gets compiled in) 961da177e4SLinus Torvalds# Note: It's possible that one object gets potentially linked into more 971da177e4SLinus Torvalds# than one module. In that case KBUILD_MODNAME will be set to foo_bar, 981da177e4SLinus Torvalds# where foo and bar are the name of the modules. 99f83b5e32SUstyugov Romanname-fix = $(subst $(comma),_,$(subst -,_,$1)) 1005e8d780dSSam Ravnborgbasename_flags = -D"KBUILD_BASENAME=KBUILD_STR($(call name-fix,$(basetarget)))" 101f83b5e32SUstyugov Romanmodname_flags = $(if $(filter 1,$(words $(modname))),\ 102f83b5e32SUstyugov Roman -D"KBUILD_MODNAME=KBUILD_STR($(call name-fix,$(modname)))") 1031da177e4SLinus Torvalds 104720097d8SSam Ravnborgorig_c_flags = $(KBUILD_CPPFLAGS) $(KBUILD_CFLAGS) $(KBUILD_SUBDIR_CCFLAGS) \ 105d8672b40SSam Ravnborg $(ccflags-y) $(CFLAGS_$(basetarget).o) 106656ee82cSSteven Rostedt_c_flags = $(filter-out $(CFLAGS_REMOVE_$(basetarget).o), $(orig_c_flags)) 107720097d8SSam Ravnborg_a_flags = $(KBUILD_CPPFLAGS) $(KBUILD_AFLAGS) $(KBUILD_SUBDIR_ASFLAGS) \ 108d8672b40SSam Ravnborg $(asflags-y) $(AFLAGS_$(basetarget).o) 109f77bf014SSam Ravnborg_cpp_flags = $(KBUILD_CPPFLAGS) $(cppflags-y) $(CPPFLAGS_$(@F)) 1101da177e4SLinus Torvalds 1112521f2c2SPeter Oberparleiter# 1122521f2c2SPeter Oberparleiter# Enable gcov profiling flags for a file, directory or for all files depending 1132521f2c2SPeter Oberparleiter# on variables GCOV_PROFILE_obj.o, GCOV_PROFILE and CONFIG_GCOV_PROFILE_ALL 1142521f2c2SPeter Oberparleiter# (in this order) 1152521f2c2SPeter Oberparleiter# 1162521f2c2SPeter Oberparleiterifeq ($(CONFIG_GCOV_KERNEL),y) 1172521f2c2SPeter Oberparleiter_c_flags += $(if $(patsubst n%,, \ 1182521f2c2SPeter Oberparleiter $(GCOV_PROFILE_$(basetarget).o)$(GCOV_PROFILE)$(CONFIG_GCOV_PROFILE_ALL)), \ 1192521f2c2SPeter Oberparleiter $(CFLAGS_GCOV)) 1202521f2c2SPeter Oberparleiterendif 1212521f2c2SPeter Oberparleiter 1229e1b9b80SAlan Jenkinsifdef CONFIG_SYMBOL_PREFIX 123d63f6d1bSMike Frysinger_sym_flags = -DSYMBOL_PREFIX=$(patsubst "%",%,$(CONFIG_SYMBOL_PREFIX)) 124d63f6d1bSMike Frysinger_cpp_flags += $(_sym_flags) 125d63f6d1bSMike Frysinger_a_flags += $(_sym_flags) 1269e1b9b80SAlan Jenkinsendif 1279e1b9b80SAlan Jenkins 1289e1b9b80SAlan Jenkins 1291da177e4SLinus Torvalds# If building the kernel in a separate objtree expand all occurrences 1301da177e4SLinus Torvalds# of -Idir to -I$(srctree)/dir except for absolute paths (starting with '/'). 1311da177e4SLinus Torvalds 1321da177e4SLinus Torvaldsifeq ($(KBUILD_SRC),) 1331da177e4SLinus Torvalds__c_flags = $(_c_flags) 1341da177e4SLinus Torvalds__a_flags = $(_a_flags) 1351da177e4SLinus Torvalds__cpp_flags = $(_cpp_flags) 1361da177e4SLinus Torvaldselse 1371da177e4SLinus Torvalds 1381da177e4SLinus Torvalds# -I$(obj) locates generated .h files 1391da177e4SLinus Torvalds# $(call addtree,-I$(obj)) locates .h files in srctree, from generated .c files 1401da177e4SLinus Torvalds# and locates generated .h files 1411da177e4SLinus Torvalds# FIXME: Replace both with specific CFLAGS* statements in the makefiles 1421da177e4SLinus Torvalds__c_flags = $(call addtree,-I$(obj)) $(call flags,_c_flags) 1431da177e4SLinus Torvalds__a_flags = $(call flags,_a_flags) 1441da177e4SLinus Torvalds__cpp_flags = $(call flags,_cpp_flags) 1451da177e4SLinus Torvaldsendif 1461da177e4SLinus Torvalds 147d8672b40SSam Ravnborgc_flags = -Wp,-MD,$(depfile) $(NOSTDINC_FLAGS) $(LINUXINCLUDE) \ 1481da177e4SLinus Torvalds $(__c_flags) $(modkern_cflags) \ 14952159d98SJason Baron -D"KBUILD_STR(s)=\#s" $(basename_flags) $(modname_flags) 1501da177e4SLinus Torvalds 151d8672b40SSam Ravnborga_flags = -Wp,-MD,$(depfile) $(NOSTDINC_FLAGS) $(LINUXINCLUDE) \ 1521da177e4SLinus Torvalds $(__a_flags) $(modkern_aflags) 1531da177e4SLinus Torvalds 154d8672b40SSam Ravnborgcpp_flags = -Wp,-MD,$(depfile) $(NOSTDINC_FLAGS) $(LINUXINCLUDE) \ 155d8672b40SSam Ravnborg $(__cpp_flags) 1561da177e4SLinus Torvalds 157f77bf014SSam Ravnborgld_flags = $(LDFLAGS) $(ldflags-y) 1581da177e4SLinus Torvalds 1591da177e4SLinus Torvalds# Finds the multi-part object the current object will be linked into 1601da177e4SLinus Torvaldsmodname-multi = $(sort $(foreach m,$(multi-used),\ 1611da177e4SLinus Torvalds $(if $(filter $(subst $(obj)/,,$*.o), $($(m:.o=-objs)) $($(m:.o=-y))),$(m:.o=)))) 1621da177e4SLinus Torvalds 1631da177e4SLinus Torvalds# Shipped files 1641da177e4SLinus Torvalds# =========================================================================== 1651da177e4SLinus Torvalds 1661da177e4SLinus Torvaldsquiet_cmd_shipped = SHIPPED $@ 1671da177e4SLinus Torvaldscmd_shipped = cat $< > $@ 1681da177e4SLinus Torvalds 1691da177e4SLinus Torvalds$(obj)/%:: $(src)/%_shipped 1701da177e4SLinus Torvalds $(call cmd,shipped) 1711da177e4SLinus Torvalds 1721da177e4SLinus Torvalds# Commands useful for building a boot image 1731da177e4SLinus Torvalds# =========================================================================== 1741da177e4SLinus Torvalds# 1751da177e4SLinus Torvalds# Use as following: 1761da177e4SLinus Torvalds# 1771da177e4SLinus Torvalds# target: source(s) FORCE 1781da177e4SLinus Torvalds# $(if_changed,ld/objcopy/gzip) 1791da177e4SLinus Torvalds# 180836caba7SSam Ravnborg# and add target to extra-y so that we know we have to 1811da177e4SLinus Torvalds# read in the saved command line 1821da177e4SLinus Torvalds 1831da177e4SLinus Torvalds# Linking 1841da177e4SLinus Torvalds# --------------------------------------------------------------------------- 1851da177e4SLinus Torvalds 1861da177e4SLinus Torvaldsquiet_cmd_ld = LD $@ 187f77bf014SSam Ravnborgcmd_ld = $(LD) $(LDFLAGS) $(ldflags-y) $(LDFLAGS_$(@F)) \ 1881da177e4SLinus Torvalds $(filter-out FORCE,$^) -o $@ 1891da177e4SLinus Torvalds 1901da177e4SLinus Torvalds# Objcopy 1911da177e4SLinus Torvalds# --------------------------------------------------------------------------- 1921da177e4SLinus Torvalds 1931da177e4SLinus Torvaldsquiet_cmd_objcopy = OBJCOPY $@ 1941da177e4SLinus Torvaldscmd_objcopy = $(OBJCOPY) $(OBJCOPYFLAGS) $(OBJCOPYFLAGS_$(@F)) $< $@ 1951da177e4SLinus Torvalds 1961da177e4SLinus Torvalds# Gzip 1971da177e4SLinus Torvalds# --------------------------------------------------------------------------- 1981da177e4SLinus Torvalds 1991da177e4SLinus Torvaldsquiet_cmd_gzip = GZIP $@ 200d3dd3b5aSH. Peter Anvincmd_gzip = (cat $(filter-out FORCE,$^) | gzip -f -9 > $@) || \ 201d3dd3b5aSH. Peter Anvin (rm -f $@ ; false) 2021da177e4SLinus Torvalds 203aab94339SDirk Brandewie# DTC 204aab94339SDirk Brandewie# --------------------------------------------------------------------------- 205aab94339SDirk Brandewie 206aab94339SDirk Brandewie# Generate an assembly file to wrap the output of the device tree compiler 207aab94339SDirk Brandewiequiet_cmd_dt_S_dtb= DTB $@ 208aab94339SDirk Brandewiecmd_dt_S_dtb= \ 209aab94339SDirk Brandewie( \ 210aab94339SDirk Brandewie echo '\#include <asm-generic/vmlinux.lds.h>'; \ 211aab94339SDirk Brandewie echo '.section .dtb.init.rodata,"a"'; \ 212aab94339SDirk Brandewie echo '.balign STRUCT_ALIGNMENT'; \ 213aab94339SDirk Brandewie echo '.global __dtb_$(*F)_begin'; \ 214aab94339SDirk Brandewie echo '__dtb_$(*F)_begin:'; \ 215aab94339SDirk Brandewie echo '.incbin "$<" '; \ 216aab94339SDirk Brandewie echo '__dtb_$(*F)_end:'; \ 217aab94339SDirk Brandewie echo '.global __dtb_$(*F)_end'; \ 218aab94339SDirk Brandewie echo '.balign STRUCT_ALIGNMENT'; \ 219aab94339SDirk Brandewie) > $@ 220aab94339SDirk Brandewie 221aab94339SDirk Brandewie$(obj)/%.dtb.S: $(obj)/%.dtb 222aab94339SDirk Brandewie $(call cmd,dt_S_dtb) 223aab94339SDirk Brandewie 224aab94339SDirk Brandewiequiet_cmd_dtc = DTC $@ 225aab94339SDirk Brandewiecmd_dtc = $(objtree)/scripts/dtc/dtc -O dtb -o $@ -b 0 $(DTC_FLAGS) $< 2261da177e4SLinus Torvalds 227bc22c17eSAlain Knaff# Bzip2 228bc22c17eSAlain Knaff# --------------------------------------------------------------------------- 229bc22c17eSAlain Knaff 230d3dd3b5aSH. Peter Anvin# Bzip2 and LZMA do not include size in file... so we have to fake that; 231d3dd3b5aSH. Peter Anvin# append the size as a 32-bit littleendian number as gzip does. 2324a2ff67cSMichael Tokarevsize_append = printf $(shell \ 233d3dd3b5aSH. Peter Anvindec_size=0; \ 234d3dd3b5aSH. Peter Anvinfor F in $1; do \ 235d3dd3b5aSH. Peter Anvin fsize=$$(stat -c "%s" $$F); \ 236d3dd3b5aSH. Peter Anvin dec_size=$$(expr $$dec_size + $$fsize); \ 237d3dd3b5aSH. Peter Anvindone; \ 2381373411aSJonathan Niederprintf "%08x\n" $$dec_size | \ 2391373411aSJonathan Nieder sed 's/\(..\)/\1 /g' | { \ 2401373411aSJonathan Nieder read ch0 ch1 ch2 ch3; \ 2411373411aSJonathan Nieder for ch in $$ch3 $$ch2 $$ch1 $$ch0; do \ 2421373411aSJonathan Nieder printf '%s%03o' '\\' $$((0x$$ch)); \ 2431373411aSJonathan Nieder done; \ 2441373411aSJonathan Nieder } \ 245d3dd3b5aSH. Peter Anvin) 246bc22c17eSAlain Knaff 247bc22c17eSAlain Knaffquiet_cmd_bzip2 = BZIP2 $@ 248d3dd3b5aSH. Peter Anvincmd_bzip2 = (cat $(filter-out FORCE,$^) | \ 249d3dd3b5aSH. Peter Anvin bzip2 -9 && $(call size_append, $(filter-out FORCE,$^))) > $@ || \ 250d3dd3b5aSH. Peter Anvin (rm -f $@ ; false) 251bc22c17eSAlain Knaff 252bc22c17eSAlain Knaff# Lzma 253bc22c17eSAlain Knaff# --------------------------------------------------------------------------- 254bc22c17eSAlain Knaff 255bc22c17eSAlain Knaffquiet_cmd_lzma = LZMA $@ 256d3dd3b5aSH. Peter Anvincmd_lzma = (cat $(filter-out FORCE,$^) | \ 257d3dd3b5aSH. Peter Anvin lzma -9 && $(call size_append, $(filter-out FORCE,$^))) > $@ || \ 258d3dd3b5aSH. Peter Anvin (rm -f $@ ; false) 2597dd65febSAlbin Tonnerre 2607dd65febSAlbin Tonnerrequiet_cmd_lzo = LZO $@ 2617dd65febSAlbin Tonnerrecmd_lzo = (cat $(filter-out FORCE,$^) | \ 2627dd65febSAlbin Tonnerre lzop -9 && $(call size_append, $(filter-out FORCE,$^))) > $@ || \ 2637dd65febSAlbin Tonnerre (rm -f $@ ; false) 264d61931d8SBorislav Petkov 265*24fa0402SLasse Collin# XZ 266*24fa0402SLasse Collin# --------------------------------------------------------------------------- 267*24fa0402SLasse Collin# Use xzkern to compress the kernel image and xzmisc to compress other things. 268*24fa0402SLasse Collin# 269*24fa0402SLasse Collin# xzkern uses a big LZMA2 dictionary since it doesn't increase memory usage 270*24fa0402SLasse Collin# of the kernel decompressor. A BCJ filter is used if it is available for 271*24fa0402SLasse Collin# the target architecture. xzkern also appends uncompressed size of the data 272*24fa0402SLasse Collin# using size_append. The .xz format has the size information available at 273*24fa0402SLasse Collin# the end of the file too, but it's in more complex format and it's good to 274*24fa0402SLasse Collin# avoid changing the part of the boot code that reads the uncompressed size. 275*24fa0402SLasse Collin# Note that the bytes added by size_append will make the xz tool think that 276*24fa0402SLasse Collin# the file is corrupt. This is expected. 277*24fa0402SLasse Collin# 278*24fa0402SLasse Collin# xzmisc doesn't use size_append, so it can be used to create normal .xz 279*24fa0402SLasse Collin# files. xzmisc uses smaller LZMA2 dictionary than xzkern, because a very 280*24fa0402SLasse Collin# big dictionary would increase the memory usage too much in the multi-call 281*24fa0402SLasse Collin# decompression mode. A BCJ filter isn't used either. 282*24fa0402SLasse Collinquiet_cmd_xzkern = XZKERN $@ 283*24fa0402SLasse Collincmd_xzkern = (cat $(filter-out FORCE,$^) | \ 284*24fa0402SLasse Collin sh $(srctree)/scripts/xz_wrap.sh && \ 285*24fa0402SLasse Collin $(call size_append, $(filter-out FORCE,$^))) > $@ || \ 286*24fa0402SLasse Collin (rm -f $@ ; false) 287*24fa0402SLasse Collin 288*24fa0402SLasse Collinquiet_cmd_xzmisc = XZMISC $@ 289*24fa0402SLasse Collincmd_xzmisc = (cat $(filter-out FORCE,$^) | \ 290*24fa0402SLasse Collin xz --check=crc32 --lzma2=dict=1MiB) > $@ || \ 291*24fa0402SLasse Collin (rm -f $@ ; false) 292*24fa0402SLasse Collin 293d61931d8SBorislav Petkov# misc stuff 294d61931d8SBorislav Petkov# --------------------------------------------------------------------------- 295d61931d8SBorislav Petkovquote:=" 296