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 71da177e4SLinus Torvalds# Figure out what we need to build from the various variables 81da177e4SLinus Torvalds# =========================================================================== 91da177e4SLinus Torvalds 101da177e4SLinus Torvalds# When an object is listed to be built compiled-in and modular, 111da177e4SLinus Torvalds# only build the compiled-in version 121da177e4SLinus Torvalds 131da177e4SLinus Torvaldsobj-m := $(filter-out $(obj-y),$(obj-m)) 141da177e4SLinus Torvalds 151da177e4SLinus Torvalds# Libraries are always collected in one lib file. 161da177e4SLinus Torvalds# Filter out objects already built-in 171da177e4SLinus Torvalds 181da177e4SLinus Torvaldslib-y := $(filter-out $(obj-y), $(sort $(lib-y) $(lib-m))) 191da177e4SLinus Torvalds 201da177e4SLinus Torvalds 211da177e4SLinus Torvalds# Handle objects in subdirs 221da177e4SLinus Torvalds# --------------------------------------------------------------------------- 231da177e4SLinus Torvalds# o if we encounter foo/ in $(obj-y), replace it by foo/built-in.o 241da177e4SLinus Torvalds# and add the directory to the list of dirs to descend into: $(subdir-y) 251da177e4SLinus Torvalds# o if we encounter foo/ in $(obj-m), remove it from $(obj-m) 261da177e4SLinus Torvalds# and add the directory to the list of dirs to descend into: $(subdir-m) 271da177e4SLinus Torvalds 28*551559e1STejun Heo# Determine modorder. 29*551559e1STejun Heo# Unfortunately, we don't have information about ordering between -y 30*551559e1STejun Heo# and -m subdirs. Just put -y's first. 31*551559e1STejun Heomodorder := $(patsubst %/,%/modules.order, $(filter %/, $(obj-y)) $(obj-m:.o=.ko)) 32*551559e1STejun Heo 331da177e4SLinus Torvalds__subdir-y := $(patsubst %/,%,$(filter %/, $(obj-y))) 341da177e4SLinus Torvaldssubdir-y += $(__subdir-y) 351da177e4SLinus Torvalds__subdir-m := $(patsubst %/,%,$(filter %/, $(obj-m))) 361da177e4SLinus Torvaldssubdir-m += $(__subdir-m) 371da177e4SLinus Torvaldsobj-y := $(patsubst %/, %/built-in.o, $(obj-y)) 381da177e4SLinus Torvaldsobj-m := $(filter-out %/, $(obj-m)) 391da177e4SLinus Torvalds 401da177e4SLinus Torvalds# Subdirectories we need to descend into 411da177e4SLinus Torvalds 421da177e4SLinus Torvaldssubdir-ym := $(sort $(subdir-y) $(subdir-m)) 431da177e4SLinus Torvalds 441da177e4SLinus Torvalds# if $(foo-objs) exists, foo.o is a composite object 451da177e4SLinus Torvaldsmulti-used-y := $(sort $(foreach m,$(obj-y), $(if $(strip $($(m:.o=-objs)) $($(m:.o=-y))), $(m)))) 461da177e4SLinus Torvaldsmulti-used-m := $(sort $(foreach m,$(obj-m), $(if $(strip $($(m:.o=-objs)) $($(m:.o=-y))), $(m)))) 471da177e4SLinus Torvaldsmulti-used := $(multi-used-y) $(multi-used-m) 481da177e4SLinus Torvaldssingle-used-m := $(sort $(filter-out $(multi-used-m),$(obj-m))) 491da177e4SLinus Torvalds 501da177e4SLinus Torvalds# Build list of the parts of our composite objects, our composite 511da177e4SLinus Torvalds# objects depend on those (obviously) 521da177e4SLinus Torvaldsmulti-objs-y := $(foreach m, $(multi-used-y), $($(m:.o=-objs)) $($(m:.o=-y))) 531da177e4SLinus Torvaldsmulti-objs-m := $(foreach m, $(multi-used-m), $($(m:.o=-objs)) $($(m:.o=-y))) 541da177e4SLinus Torvaldsmulti-objs := $(multi-objs-y) $(multi-objs-m) 551da177e4SLinus Torvalds 56f5fb9765SSam Ravnborg# $(subdir-obj-y) is the list of objects in $(obj-y) which uses dir/ to 57f5fb9765SSam Ravnborg# tell kbuild to descend 58f5fb9765SSam Ravnborgsubdir-obj-y := $(filter %/built-in.o, $(obj-y)) 591da177e4SLinus Torvalds 601da177e4SLinus Torvalds# $(obj-dirs) is a list of directories that contain object files 611da177e4SLinus Torvaldsobj-dirs := $(dir $(multi-objs) $(subdir-obj-y)) 621da177e4SLinus Torvalds 631da177e4SLinus Torvalds# Replace multi-part objects by their individual parts, look at local dir only 641da177e4SLinus 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) 651da177e4SLinus Torvaldsreal-objs-m := $(foreach m, $(obj-m), $(if $(strip $($(m:.o=-objs)) $($(m:.o=-y))),$($(m:.o=-objs)) $($(m:.o=-y)),$(m))) 661da177e4SLinus Torvalds 671da177e4SLinus Torvalds# Add subdir path 681da177e4SLinus Torvalds 691da177e4SLinus Torvaldsextra-y := $(addprefix $(obj)/,$(extra-y)) 701da177e4SLinus Torvaldsalways := $(addprefix $(obj)/,$(always)) 711da177e4SLinus Torvaldstargets := $(addprefix $(obj)/,$(targets)) 72*551559e1STejun Heomodorder := $(addprefix $(obj)/,$(modorder)) 731da177e4SLinus Torvaldsobj-y := $(addprefix $(obj)/,$(obj-y)) 741da177e4SLinus Torvaldsobj-m := $(addprefix $(obj)/,$(obj-m)) 751da177e4SLinus Torvaldslib-y := $(addprefix $(obj)/,$(lib-y)) 761da177e4SLinus Torvaldssubdir-obj-y := $(addprefix $(obj)/,$(subdir-obj-y)) 771da177e4SLinus Torvaldsreal-objs-y := $(addprefix $(obj)/,$(real-objs-y)) 781da177e4SLinus Torvaldsreal-objs-m := $(addprefix $(obj)/,$(real-objs-m)) 791da177e4SLinus Torvaldssingle-used-m := $(addprefix $(obj)/,$(single-used-m)) 801da177e4SLinus Torvaldsmulti-used-y := $(addprefix $(obj)/,$(multi-used-y)) 811da177e4SLinus Torvaldsmulti-used-m := $(addprefix $(obj)/,$(multi-used-m)) 821da177e4SLinus Torvaldsmulti-objs-y := $(addprefix $(obj)/,$(multi-objs-y)) 831da177e4SLinus Torvaldsmulti-objs-m := $(addprefix $(obj)/,$(multi-objs-m)) 841da177e4SLinus Torvaldssubdir-ym := $(addprefix $(obj)/,$(subdir-ym)) 851da177e4SLinus Torvaldsobj-dirs := $(addprefix $(obj)/,$(obj-dirs)) 861da177e4SLinus Torvalds 871da177e4SLinus Torvalds# These flags are needed for modversions and compiling, so we define them here 881da177e4SLinus Torvalds# already 891da177e4SLinus Torvalds# $(modname_flags) #defines KBUILD_MODNAME as the name of the module it will 901da177e4SLinus Torvalds# end up in (or would, if it gets compiled in) 911da177e4SLinus Torvalds# Note: It's possible that one object gets potentially linked into more 921da177e4SLinus Torvalds# than one module. In that case KBUILD_MODNAME will be set to foo_bar, 931da177e4SLinus Torvalds# where foo and bar are the name of the modules. 94f83b5e32SUstyugov Romanname-fix = $(subst $(comma),_,$(subst -,_,$1)) 955e8d780dSSam Ravnborgbasename_flags = -D"KBUILD_BASENAME=KBUILD_STR($(call name-fix,$(basetarget)))" 96f83b5e32SUstyugov Romanmodname_flags = $(if $(filter 1,$(words $(modname))),\ 97f83b5e32SUstyugov Roman -D"KBUILD_MODNAME=KBUILD_STR($(call name-fix,$(modname)))") 981da177e4SLinus Torvalds 99f77bf014SSam Ravnborg_c_flags = $(KBUILD_CFLAGS) $(ccflags-y) $(CFLAGS_$(basetarget).o) 100f77bf014SSam Ravnborg_a_flags = $(KBUILD_AFLAGS) $(asflags-y) $(AFLAGS_$(basetarget).o) 101f77bf014SSam Ravnborg_cpp_flags = $(KBUILD_CPPFLAGS) $(cppflags-y) $(CPPFLAGS_$(@F)) 1021da177e4SLinus Torvalds 1031da177e4SLinus Torvalds# If building the kernel in a separate objtree expand all occurrences 1041da177e4SLinus Torvalds# of -Idir to -I$(srctree)/dir except for absolute paths (starting with '/'). 1051da177e4SLinus Torvalds 1061da177e4SLinus Torvaldsifeq ($(KBUILD_SRC),) 1071da177e4SLinus Torvalds__c_flags = $(_c_flags) 1081da177e4SLinus Torvalds__a_flags = $(_a_flags) 1091da177e4SLinus Torvalds__cpp_flags = $(_cpp_flags) 1101da177e4SLinus Torvaldselse 1111da177e4SLinus Torvalds 1121da177e4SLinus Torvalds# -I$(obj) locates generated .h files 1131da177e4SLinus Torvalds# $(call addtree,-I$(obj)) locates .h files in srctree, from generated .c files 1141da177e4SLinus Torvalds# and locates generated .h files 1151da177e4SLinus Torvalds# FIXME: Replace both with specific CFLAGS* statements in the makefiles 1161da177e4SLinus Torvalds__c_flags = $(call addtree,-I$(obj)) $(call flags,_c_flags) 1171da177e4SLinus Torvalds__a_flags = $(call flags,_a_flags) 1181da177e4SLinus Torvalds__cpp_flags = $(call flags,_cpp_flags) 1191da177e4SLinus Torvaldsendif 1201da177e4SLinus Torvalds 12106c5040cSSam Ravnborgc_flags = -Wp,-MD,$(depfile) $(NOSTDINC_FLAGS) $(KBUILD_CPPFLAGS) \ 1221da177e4SLinus Torvalds $(__c_flags) $(modkern_cflags) \ 123f83b5e32SUstyugov Roman -D"KBUILD_STR(s)=\#s" $(basename_flags) $(modname_flags) 1241da177e4SLinus Torvalds 12506c5040cSSam Ravnborga_flags = -Wp,-MD,$(depfile) $(NOSTDINC_FLAGS) $(KBUILD_CPPFLAGS) \ 1261da177e4SLinus Torvalds $(__a_flags) $(modkern_aflags) 1271da177e4SLinus Torvalds 1281da177e4SLinus Torvaldscpp_flags = -Wp,-MD,$(depfile) $(NOSTDINC_FLAGS) $(__cpp_flags) 1291da177e4SLinus Torvalds 130f77bf014SSam Ravnborgld_flags = $(LDFLAGS) $(ldflags-y) 1311da177e4SLinus Torvalds 1321da177e4SLinus Torvalds# Finds the multi-part object the current object will be linked into 1331da177e4SLinus Torvaldsmodname-multi = $(sort $(foreach m,$(multi-used),\ 1341da177e4SLinus Torvalds $(if $(filter $(subst $(obj)/,,$*.o), $($(m:.o=-objs)) $($(m:.o=-y))),$(m:.o=)))) 1351da177e4SLinus Torvalds 1361da177e4SLinus Torvalds# Shipped files 1371da177e4SLinus Torvalds# =========================================================================== 1381da177e4SLinus Torvalds 1391da177e4SLinus Torvaldsquiet_cmd_shipped = SHIPPED $@ 1401da177e4SLinus Torvaldscmd_shipped = cat $< > $@ 1411da177e4SLinus Torvalds 1421da177e4SLinus Torvalds$(obj)/%:: $(src)/%_shipped 1431da177e4SLinus Torvalds $(call cmd,shipped) 1441da177e4SLinus Torvalds 1451da177e4SLinus Torvalds# Commands useful for building a boot image 1461da177e4SLinus Torvalds# =========================================================================== 1471da177e4SLinus Torvalds# 1481da177e4SLinus Torvalds# Use as following: 1491da177e4SLinus Torvalds# 1501da177e4SLinus Torvalds# target: source(s) FORCE 1511da177e4SLinus Torvalds# $(if_changed,ld/objcopy/gzip) 1521da177e4SLinus Torvalds# 153836caba7SSam Ravnborg# and add target to extra-y so that we know we have to 1541da177e4SLinus Torvalds# read in the saved command line 1551da177e4SLinus Torvalds 1561da177e4SLinus Torvalds# Linking 1571da177e4SLinus Torvalds# --------------------------------------------------------------------------- 1581da177e4SLinus Torvalds 1591da177e4SLinus Torvaldsquiet_cmd_ld = LD $@ 160f77bf014SSam Ravnborgcmd_ld = $(LD) $(LDFLAGS) $(ldflags-y) $(LDFLAGS_$(@F)) \ 1611da177e4SLinus Torvalds $(filter-out FORCE,$^) -o $@ 1621da177e4SLinus Torvalds 1631da177e4SLinus Torvalds# Objcopy 1641da177e4SLinus Torvalds# --------------------------------------------------------------------------- 1651da177e4SLinus Torvalds 1661da177e4SLinus Torvaldsquiet_cmd_objcopy = OBJCOPY $@ 1671da177e4SLinus Torvaldscmd_objcopy = $(OBJCOPY) $(OBJCOPYFLAGS) $(OBJCOPYFLAGS_$(@F)) $< $@ 1681da177e4SLinus Torvalds 1691da177e4SLinus Torvalds# Gzip 1701da177e4SLinus Torvalds# --------------------------------------------------------------------------- 1711da177e4SLinus Torvalds 1721da177e4SLinus Torvaldsquiet_cmd_gzip = GZIP $@ 1731da177e4SLinus Torvaldscmd_gzip = gzip -f -9 < $< > $@ 1741da177e4SLinus Torvalds 1751da177e4SLinus Torvalds 176