2 # linux/arch/x86/boot/compressed/Makefile
4 # create a compressed vmlinux image from the original vmlinux
7 # decompression code (*.o)
8 # asm globals (piggy.S), including:
9 # vmlinux.bin.(gz|bz2|lzma|...)
12 # vmlinux stripped of debugging and comments
14 # vmlinux.bin + vmlinux.relocs
15 # vmlinux.bin.(gz|bz2|lzma|...) is:
16 # (see scripts/Makefile.lib size_append)
17 # compressed vmlinux.bin.all + u32 size of vmlinux.bin.all
21 targets := vmlinux vmlinux.bin vmlinux.bin.gz vmlinux.bin.bz2 vmlinux.bin.lzma \
22 vmlinux.bin.xz vmlinux.bin.lzo vmlinux.bin.lz4
24 KBUILD_CFLAGS := -m$(BITS) -D__KERNEL__ $(LINUX_INCLUDE) -O2
25 KBUILD_CFLAGS += -fno-strict-aliasing $(call cc-option, -fPIE, -fPIC)
26 KBUILD_CFLAGS += -DDISABLE_BRANCH_PROFILING
27 cflags-$(CONFIG_X86_32) := -march=i386
28 cflags-$(CONFIG_X86_64) := -mcmodel=small
29 KBUILD_CFLAGS += $(cflags-y)
30 KBUILD_CFLAGS += -mno-mmx -mno-sse
31 KBUILD_CFLAGS += $(call cc-option,-ffreestanding)
32 KBUILD_CFLAGS += $(call cc-option,-fno-stack-protector)
34 KBUILD_AFLAGS := $(KBUILD_CFLAGS) -D__ASSEMBLY__
37 LDFLAGS := -m elf_$(UTS_MACHINE)
38 ifeq ($(CONFIG_RELOCATABLE),y)
39 # If kernel is relocatable, build compressed kernel as PIE.
40 ifeq ($(CONFIG_X86_32),y)
41 LDFLAGS += $(call ld-option, -pie) $(call ld-option, --no-dynamic-linker)
43 # To build 64-bit compressed kernel as PIE, we disable relocation
44 # overflow check to avoid relocation overflow error with a new linker
45 # command-line option, -z noreloc-overflow.
46 LDFLAGS += $(shell $(LD) --help 2>&1 | grep -q "\-z noreloc-overflow" \
47 && echo "-z noreloc-overflow -pie --no-dynamic-linker")
52 hostprogs-y := mkpiggy
53 HOST_EXTRACFLAGS += -I$(srctree)/tools/include
55 vmlinux-objs-y := $(obj)/vmlinux.lds $(obj)/head_$(BITS).o $(obj)/misc.o \
56 $(obj)/string.o $(obj)/cmdline.o \
57 $(obj)/piggy.o $(obj)/cpuflags.o
59 vmlinux-objs-$(CONFIG_EARLY_PRINTK) += $(obj)/early_serial_console.o
60 vmlinux-objs-$(CONFIG_RANDOMIZE_BASE) += $(obj)/aslr.o
62 $(obj)/eboot.o: KBUILD_CFLAGS += -fshort-wchar -mno-red-zone
64 vmlinux-objs-$(CONFIG_EFI_STUB) += $(obj)/eboot.o $(obj)/efi_stub_$(BITS).o \
65 $(objtree)/drivers/firmware/efi/libstub/lib.a
66 vmlinux-objs-$(CONFIG_EFI_MIXED) += $(obj)/efi_thunk_$(BITS).o
68 $(obj)/vmlinux: $(vmlinux-objs-y) FORCE
72 OBJCOPYFLAGS_vmlinux.bin := -R .comment -S
73 $(obj)/vmlinux.bin: vmlinux FORCE
74 $(call if_changed,objcopy)
76 targets += $(patsubst $(obj)/%,%,$(vmlinux-objs-y)) vmlinux.bin.all vmlinux.relocs
78 CMD_RELOCS = arch/x86/tools/relocs
79 quiet_cmd_relocs = RELOCS $@
80 cmd_relocs = $(CMD_RELOCS) $< > $@;$(CMD_RELOCS) --abs-relocs $<
81 $(obj)/vmlinux.relocs: vmlinux FORCE
82 $(call if_changed,relocs)
84 vmlinux.bin.all-y := $(obj)/vmlinux.bin
85 vmlinux.bin.all-$(CONFIG_X86_NEED_RELOCS) += $(obj)/vmlinux.relocs
87 $(obj)/vmlinux.bin.gz: $(vmlinux.bin.all-y) FORCE
88 $(call if_changed,gzip)
89 $(obj)/vmlinux.bin.bz2: $(vmlinux.bin.all-y) FORCE
90 $(call if_changed,bzip2)
91 $(obj)/vmlinux.bin.lzma: $(vmlinux.bin.all-y) FORCE
92 $(call if_changed,lzma)
93 $(obj)/vmlinux.bin.xz: $(vmlinux.bin.all-y) FORCE
94 $(call if_changed,xzkern)
95 $(obj)/vmlinux.bin.lzo: $(vmlinux.bin.all-y) FORCE
96 $(call if_changed,lzo)
97 $(obj)/vmlinux.bin.lz4: $(vmlinux.bin.all-y) FORCE
98 $(call if_changed,lz4)
100 suffix-$(CONFIG_KERNEL_GZIP) := gz
101 suffix-$(CONFIG_KERNEL_BZIP2) := bz2
102 suffix-$(CONFIG_KERNEL_LZMA) := lzma
103 suffix-$(CONFIG_KERNEL_XZ) := xz
104 suffix-$(CONFIG_KERNEL_LZO) := lzo
105 suffix-$(CONFIG_KERNEL_LZ4) := lz4
107 RUN_SIZE = $(shell $(OBJDUMP) -h vmlinux | \
108 $(CONFIG_SHELL) $(srctree)/arch/x86/tools/calc_run_size.sh)
109 quiet_cmd_mkpiggy = MKPIGGY $@
110 cmd_mkpiggy = $(obj)/mkpiggy $< $(RUN_SIZE) > $@ || ( rm -f $@ ; false )
113 $(obj)/piggy.S: $(obj)/vmlinux.bin.$(suffix-y) $(obj)/mkpiggy FORCE
114 $(call if_changed,mkpiggy)