xref: /linux/scripts/Makefile.lib (revision e76e1fdfa8f8dc1ea6699923cf5d92b5bee9c936)
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)
965bb0571bSMichal Marek# Note: Files that end up in two or more modules are compiled without the
975bb0571bSMichal Marek#       KBUILD_MODNAME definition. The reason is that any made-up name would
985bb0571bSMichal Marek#       differ in different configs.
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
1221da177e4SLinus Torvalds# If building the kernel in a separate objtree expand all occurrences
1231da177e4SLinus Torvalds# of -Idir to -I$(srctree)/dir except for absolute paths (starting with '/').
1241da177e4SLinus Torvalds
1251da177e4SLinus Torvaldsifeq ($(KBUILD_SRC),)
1261da177e4SLinus Torvalds__c_flags	= $(_c_flags)
1271da177e4SLinus Torvalds__a_flags	= $(_a_flags)
1281da177e4SLinus Torvalds__cpp_flags     = $(_cpp_flags)
1291da177e4SLinus Torvaldselse
1301da177e4SLinus Torvalds
1311da177e4SLinus Torvalds# -I$(obj) locates generated .h files
1321da177e4SLinus Torvalds# $(call addtree,-I$(obj)) locates .h files in srctree, from generated .c files
1331da177e4SLinus Torvalds#   and locates generated .h files
1341da177e4SLinus Torvalds# FIXME: Replace both with specific CFLAGS* statements in the makefiles
1351da177e4SLinus Torvalds__c_flags	= $(call addtree,-I$(obj)) $(call flags,_c_flags)
1361da177e4SLinus Torvalds__a_flags	=                          $(call flags,_a_flags)
1371da177e4SLinus Torvalds__cpp_flags     =                          $(call flags,_cpp_flags)
1381da177e4SLinus Torvaldsendif
1391da177e4SLinus Torvalds
140d8672b40SSam Ravnborgc_flags        = -Wp,-MD,$(depfile) $(NOSTDINC_FLAGS) $(LINUXINCLUDE)     \
1411da177e4SLinus Torvalds		 $(__c_flags) $(modkern_cflags)                           \
14252159d98SJason Baron		 -D"KBUILD_STR(s)=\#s" $(basename_flags) $(modname_flags)
1431da177e4SLinus Torvalds
144d8672b40SSam Ravnborga_flags        = -Wp,-MD,$(depfile) $(NOSTDINC_FLAGS) $(LINUXINCLUDE)     \
1451da177e4SLinus Torvalds		 $(__a_flags) $(modkern_aflags)
1461da177e4SLinus Torvalds
147d8672b40SSam Ravnborgcpp_flags      = -Wp,-MD,$(depfile) $(NOSTDINC_FLAGS) $(LINUXINCLUDE)     \
148d8672b40SSam Ravnborg		 $(__cpp_flags)
1491da177e4SLinus Torvalds
150f77bf014SSam Ravnborgld_flags       = $(LDFLAGS) $(ldflags-y)
1511da177e4SLinus Torvalds
152b0a4d8b3SIan Campbelldtc_cpp_flags  = -Wp,-MD,$(depfile).pre.tmp -nostdinc                    \
153e570d7c1SStephen Warren		 -I$(srctree)/arch/$(SRCARCH)/boot/dts                   \
154c58299aaSStephen Warren		 -I$(srctree)/arch/$(SRCARCH)/boot/dts/include           \
155e570d7c1SStephen Warren		 -undef -D__DTS__
156e570d7c1SStephen Warren
1571da177e4SLinus Torvalds# Finds the multi-part object the current object will be linked into
1581da177e4SLinus Torvaldsmodname-multi = $(sort $(foreach m,$(multi-used),\
1591da177e4SLinus Torvalds		$(if $(filter $(subst $(obj)/,,$*.o), $($(m:.o=-objs)) $($(m:.o=-y))),$(m:.o=))))
1601da177e4SLinus Torvalds
1617373f4f8SArnaud Lacombeifdef REGENERATE_PARSERS
1627373f4f8SArnaud Lacombe
1637373f4f8SArnaud Lacombe# GPERF
1647373f4f8SArnaud Lacombe# ---------------------------------------------------------------------------
1657373f4f8SArnaud Lacombequiet_cmd_gperf = GPERF $@
1667373f4f8SArnaud Lacombe      cmd_gperf = gperf -t --output-file $@ -a -C -E -g -k 1,3,$$ -p -t $<
1677373f4f8SArnaud Lacombe
16858238c81SPeter Foley.PRECIOUS: $(src)/%.hash.c_shipped
1697373f4f8SArnaud Lacombe$(src)/%.hash.c_shipped: $(src)/%.gperf
1707373f4f8SArnaud Lacombe	$(call cmd,gperf)
1717373f4f8SArnaud Lacombe
1727373f4f8SArnaud Lacombe# LEX
1737373f4f8SArnaud Lacombe# ---------------------------------------------------------------------------
1747373f4f8SArnaud LacombeLEX_PREFIX = $(if $(LEX_PREFIX_${baseprereq}),$(LEX_PREFIX_${baseprereq}),yy)
1757373f4f8SArnaud Lacombe
1767373f4f8SArnaud Lacombequiet_cmd_flex = LEX     $@
1777373f4f8SArnaud Lacombe      cmd_flex = flex -o$@ -L -P $(LEX_PREFIX) $<
1787373f4f8SArnaud Lacombe
17958238c81SPeter Foley.PRECIOUS: $(src)/%.lex.c_shipped
1807373f4f8SArnaud Lacombe$(src)/%.lex.c_shipped: $(src)/%.l
1817373f4f8SArnaud Lacombe	$(call cmd,flex)
1827373f4f8SArnaud Lacombe
1837373f4f8SArnaud Lacombe# YACC
1847373f4f8SArnaud Lacombe# ---------------------------------------------------------------------------
1857373f4f8SArnaud LacombeYACC_PREFIX = $(if $(YACC_PREFIX_${baseprereq}),$(YACC_PREFIX_${baseprereq}),yy)
1867373f4f8SArnaud Lacombe
1877373f4f8SArnaud Lacombequiet_cmd_bison = YACC    $@
1887373f4f8SArnaud Lacombe      cmd_bison = bison -o$@ -t -l -p $(YACC_PREFIX) $<
1897373f4f8SArnaud Lacombe
19058238c81SPeter Foley.PRECIOUS: $(src)/%.tab.c_shipped
1917373f4f8SArnaud Lacombe$(src)/%.tab.c_shipped: $(src)/%.y
1927373f4f8SArnaud Lacombe	$(call cmd,bison)
1937373f4f8SArnaud Lacombe
1947373f4f8SArnaud Lacombequiet_cmd_bison_h = YACC    $@
1957373f4f8SArnaud Lacombe      cmd_bison_h = bison -o/dev/null --defines=$@ -t -l -p $(YACC_PREFIX) $<
1967373f4f8SArnaud Lacombe
19758238c81SPeter Foley.PRECIOUS: $(src)/%.tab.h_shipped
1987373f4f8SArnaud Lacombe$(src)/%.tab.h_shipped: $(src)/%.y
1997373f4f8SArnaud Lacombe	$(call cmd,bison_h)
2007373f4f8SArnaud Lacombe
2017373f4f8SArnaud Lacombeendif
2027373f4f8SArnaud Lacombe
2031da177e4SLinus Torvalds# Shipped files
2041da177e4SLinus Torvalds# ===========================================================================
2051da177e4SLinus Torvalds
2061da177e4SLinus Torvaldsquiet_cmd_shipped = SHIPPED $@
2071da177e4SLinus Torvaldscmd_shipped = cat $< > $@
2081da177e4SLinus Torvalds
209991d76c9SArnaud Lacombe$(obj)/%: $(src)/%_shipped
2101da177e4SLinus Torvalds	$(call cmd,shipped)
2111da177e4SLinus Torvalds
2121da177e4SLinus Torvalds# Commands useful for building a boot image
2131da177e4SLinus Torvalds# ===========================================================================
2141da177e4SLinus Torvalds#
2151da177e4SLinus Torvalds#	Use as following:
2161da177e4SLinus Torvalds#
2171da177e4SLinus Torvalds#	target: source(s) FORCE
2181da177e4SLinus Torvalds#		$(if_changed,ld/objcopy/gzip)
2191da177e4SLinus Torvalds#
220836caba7SSam Ravnborg#	and add target to extra-y so that we know we have to
2211da177e4SLinus Torvalds#	read in the saved command line
2221da177e4SLinus Torvalds
2231da177e4SLinus Torvalds# Linking
2241da177e4SLinus Torvalds# ---------------------------------------------------------------------------
2251da177e4SLinus Torvalds
2261da177e4SLinus Torvaldsquiet_cmd_ld = LD      $@
227f77bf014SSam Ravnborgcmd_ld = $(LD) $(LDFLAGS) $(ldflags-y) $(LDFLAGS_$(@F)) \
2281da177e4SLinus Torvalds	       $(filter-out FORCE,$^) -o $@
2291da177e4SLinus Torvalds
2301da177e4SLinus Torvalds# Objcopy
2311da177e4SLinus Torvalds# ---------------------------------------------------------------------------
2321da177e4SLinus Torvalds
2331da177e4SLinus Torvaldsquiet_cmd_objcopy = OBJCOPY $@
2341da177e4SLinus Torvaldscmd_objcopy = $(OBJCOPY) $(OBJCOPYFLAGS) $(OBJCOPYFLAGS_$(@F)) $< $@
2351da177e4SLinus Torvalds
2361da177e4SLinus Torvalds# Gzip
2371da177e4SLinus Torvalds# ---------------------------------------------------------------------------
2381da177e4SLinus Torvalds
2391da177e4SLinus Torvaldsquiet_cmd_gzip = GZIP    $@
2406ae9ecb8SMichal Marekcmd_gzip = (cat $(filter-out FORCE,$^) | gzip -n -f -9 > $@) || \
241d3dd3b5aSH. Peter Anvin	(rm -f $@ ; false)
2421da177e4SLinus Torvalds
243aab94339SDirk Brandewie# DTC
244aab94339SDirk Brandewie# ---------------------------------------------------------------------------
245aab94339SDirk Brandewie
246aab94339SDirk Brandewie# Generate an assembly file to wrap the output of the device tree compiler
247aab94339SDirk Brandewiequiet_cmd_dt_S_dtb= DTB    $@
248aab94339SDirk Brandewiecmd_dt_S_dtb=						\
249aab94339SDirk Brandewie(							\
250aab94339SDirk Brandewie	echo '\#include <asm-generic/vmlinux.lds.h>'; 	\
251aab94339SDirk Brandewie	echo '.section .dtb.init.rodata,"a"';		\
252aab94339SDirk Brandewie	echo '.balign STRUCT_ALIGNMENT';		\
253aab94339SDirk Brandewie	echo '.global __dtb_$(*F)_begin';		\
254aab94339SDirk Brandewie	echo '__dtb_$(*F)_begin:';			\
255aab94339SDirk Brandewie	echo '.incbin "$<" ';				\
256aab94339SDirk Brandewie	echo '__dtb_$(*F)_end:';			\
257aab94339SDirk Brandewie	echo '.global __dtb_$(*F)_end';			\
258aab94339SDirk Brandewie	echo '.balign STRUCT_ALIGNMENT'; 		\
259aab94339SDirk Brandewie) > $@
260aab94339SDirk Brandewie
261aab94339SDirk Brandewie$(obj)/%.dtb.S: $(obj)/%.dtb
262aab94339SDirk Brandewie	$(call cmd,dt_S_dtb)
263aab94339SDirk Brandewie
264aab94339SDirk Brandewiequiet_cmd_dtc = DTC     $@
265b40b25ffSStephen Warrencmd_dtc = $(CPP) $(dtc_cpp_flags) -x assembler-with-cpp -o $(dtc-tmp) $< ; \
266b40b25ffSStephen Warren	$(objtree)/scripts/dtc/dtc -O dtb -o $@ -b 0 \
267ad061568SMatthijs Kooijman		-i $(dir $<) $(DTC_FLAGS) \
268b0a4d8b3SIan Campbell		-d $(depfile).dtc.tmp $(dtc-tmp) ; \
269b0a4d8b3SIan Campbell	cat $(depfile).pre.tmp $(depfile).dtc.tmp > $(depfile)
2701da177e4SLinus Torvalds
27190b335fbSStephen Warren$(obj)/%.dtb: $(src)/%.dts FORCE
27290b335fbSStephen Warren	$(call if_changed_dep,dtc)
27390b335fbSStephen Warren
274b0a4d8b3SIan Campbelldtc-tmp = $(subst $(comma),_,$(dot-target).dts.tmp)
27522435f38SStephen Warren
276bc22c17eSAlain Knaff# Bzip2
277bc22c17eSAlain Knaff# ---------------------------------------------------------------------------
278bc22c17eSAlain Knaff
279d3dd3b5aSH. Peter Anvin# Bzip2 and LZMA do not include size in file... so we have to fake that;
280d3dd3b5aSH. Peter Anvin# append the size as a 32-bit littleendian number as gzip does.
2814a2ff67cSMichael Tokarevsize_append = printf $(shell						\
282d3dd3b5aSH. Peter Anvindec_size=0;								\
283d3dd3b5aSH. Peter Anvinfor F in $1; do								\
284d3dd3b5aSH. Peter Anvin	fsize=$$(stat -c "%s" $$F);					\
285d3dd3b5aSH. Peter Anvin	dec_size=$$(expr $$dec_size + $$fsize);				\
286d3dd3b5aSH. Peter Anvindone;									\
2871373411aSJonathan Niederprintf "%08x\n" $$dec_size |						\
2881373411aSJonathan Nieder	sed 's/\(..\)/\1 /g' | {					\
2891373411aSJonathan Nieder		read ch0 ch1 ch2 ch3;					\
2901373411aSJonathan Nieder		for ch in $$ch3 $$ch2 $$ch1 $$ch0; do			\
2911373411aSJonathan Nieder			printf '%s%03o' '\\' $$((0x$$ch)); 		\
2921373411aSJonathan Nieder		done;							\
2931373411aSJonathan Nieder	}								\
294d3dd3b5aSH. Peter Anvin)
295bc22c17eSAlain Knaff
296bc22c17eSAlain Knaffquiet_cmd_bzip2 = BZIP2   $@
297d3dd3b5aSH. Peter Anvincmd_bzip2 = (cat $(filter-out FORCE,$^) | \
298d3dd3b5aSH. Peter Anvin	bzip2 -9 && $(call size_append, $(filter-out FORCE,$^))) > $@ || \
299d3dd3b5aSH. Peter Anvin	(rm -f $@ ; false)
300bc22c17eSAlain Knaff
301bc22c17eSAlain Knaff# Lzma
302bc22c17eSAlain Knaff# ---------------------------------------------------------------------------
303bc22c17eSAlain Knaff
304bc22c17eSAlain Knaffquiet_cmd_lzma = LZMA    $@
305d3dd3b5aSH. Peter Anvincmd_lzma = (cat $(filter-out FORCE,$^) | \
306d3dd3b5aSH. Peter Anvin	lzma -9 && $(call size_append, $(filter-out FORCE,$^))) > $@ || \
307d3dd3b5aSH. Peter Anvin	(rm -f $@ ; false)
3087dd65febSAlbin Tonnerre
3097dd65febSAlbin Tonnerrequiet_cmd_lzo = LZO     $@
3107dd65febSAlbin Tonnerrecmd_lzo = (cat $(filter-out FORCE,$^) | \
3117dd65febSAlbin Tonnerre	lzop -9 && $(call size_append, $(filter-out FORCE,$^))) > $@ || \
3127dd65febSAlbin Tonnerre	(rm -f $@ ; false)
313d61931d8SBorislav Petkov
314*e76e1fdfSKyungsik Leequiet_cmd_lz4 = LZ4     $@
315*e76e1fdfSKyungsik Leecmd_lz4 = (cat $(filter-out FORCE,$^) | \
316*e76e1fdfSKyungsik Lee	lz4c -l -c1 stdin stdout && $(call size_append, $(filter-out FORCE,$^))) > $@ || \
317*e76e1fdfSKyungsik Lee	(rm -f $@ ; false)
318*e76e1fdfSKyungsik Lee
319e3393645SStephen Warren# U-Boot mkimage
320e3393645SStephen Warren# ---------------------------------------------------------------------------
321e3393645SStephen Warren
322e3393645SStephen WarrenMKIMAGE := $(srctree)/scripts/mkuboot.sh
323e3393645SStephen Warren
324e3393645SStephen Warren# SRCARCH just happens to match slightly more than ARCH (on sparc), so reduces
325e3393645SStephen Warren# the number of overrides in arch makefiles
326e3393645SStephen WarrenUIMAGE_ARCH ?= $(SRCARCH)
327e3393645SStephen WarrenUIMAGE_COMPRESSION ?= $(if $(2),$(2),none)
328e3393645SStephen WarrenUIMAGE_OPTS-y ?=
329e3393645SStephen WarrenUIMAGE_TYPE ?= kernel
330e3393645SStephen WarrenUIMAGE_LOADADDR ?= arch_must_set_this
331e3393645SStephen WarrenUIMAGE_ENTRYADDR ?= $(UIMAGE_LOADADDR)
332e3393645SStephen WarrenUIMAGE_NAME ?= 'Linux-$(KERNELRELEASE)'
333e3393645SStephen WarrenUIMAGE_IN ?= $<
334e3393645SStephen WarrenUIMAGE_OUT ?= $@
335e3393645SStephen Warren
336e3393645SStephen Warrenquiet_cmd_uimage = UIMAGE  $(UIMAGE_OUT)
337e3393645SStephen Warren      cmd_uimage = $(CONFIG_SHELL) $(MKIMAGE) -A $(UIMAGE_ARCH) -O linux \
338e3393645SStephen Warren			-C $(UIMAGE_COMPRESSION) $(UIMAGE_OPTS-y) \
339e3393645SStephen Warren			-T $(UIMAGE_TYPE) \
340e3393645SStephen Warren			-a $(UIMAGE_LOADADDR) -e $(UIMAGE_ENTRYADDR) \
341e3393645SStephen Warren			-n $(UIMAGE_NAME) -d $(UIMAGE_IN) $(UIMAGE_OUT)
342e3393645SStephen Warren
34324fa0402SLasse Collin# XZ
34424fa0402SLasse Collin# ---------------------------------------------------------------------------
34524fa0402SLasse Collin# Use xzkern to compress the kernel image and xzmisc to compress other things.
34624fa0402SLasse Collin#
34724fa0402SLasse Collin# xzkern uses a big LZMA2 dictionary since it doesn't increase memory usage
34824fa0402SLasse Collin# of the kernel decompressor. A BCJ filter is used if it is available for
34924fa0402SLasse Collin# the target architecture. xzkern also appends uncompressed size of the data
35024fa0402SLasse Collin# using size_append. The .xz format has the size information available at
35124fa0402SLasse Collin# the end of the file too, but it's in more complex format and it's good to
35224fa0402SLasse Collin# avoid changing the part of the boot code that reads the uncompressed size.
35324fa0402SLasse Collin# Note that the bytes added by size_append will make the xz tool think that
35424fa0402SLasse Collin# the file is corrupt. This is expected.
35524fa0402SLasse Collin#
35624fa0402SLasse Collin# xzmisc doesn't use size_append, so it can be used to create normal .xz
35724fa0402SLasse Collin# files. xzmisc uses smaller LZMA2 dictionary than xzkern, because a very
35824fa0402SLasse Collin# big dictionary would increase the memory usage too much in the multi-call
35924fa0402SLasse Collin# decompression mode. A BCJ filter isn't used either.
36024fa0402SLasse Collinquiet_cmd_xzkern = XZKERN  $@
36124fa0402SLasse Collincmd_xzkern = (cat $(filter-out FORCE,$^) | \
36224fa0402SLasse Collin	sh $(srctree)/scripts/xz_wrap.sh && \
36324fa0402SLasse Collin	$(call size_append, $(filter-out FORCE,$^))) > $@ || \
36424fa0402SLasse Collin	(rm -f $@ ; false)
36524fa0402SLasse Collin
36624fa0402SLasse Collinquiet_cmd_xzmisc = XZMISC  $@
36724fa0402SLasse Collincmd_xzmisc = (cat $(filter-out FORCE,$^) | \
36824fa0402SLasse Collin	xz --check=crc32 --lzma2=dict=1MiB) > $@ || \
36924fa0402SLasse Collin	(rm -f $@ ; false)
37024fa0402SLasse Collin
371d61931d8SBorislav Petkov# misc stuff
372d61931d8SBorislav Petkov# ---------------------------------------------------------------------------
373d61931d8SBorislav Petkovquote:="
374