@ -1,13 +1,16 @@
all : build -all
CURRENT_MAKEFILE := $( realpath $( word $( words $( MAKEFILE_LIST) ) ,$( MAKEFILE_LIST) ) )
SRC_DIR := $( dir $( CURRENT_MAKEFILE) )
TOPSRC_DIR := $( SRC_DIR) /../..
VPATH = $( SRC_DIR)
all : multiboot .bin linuxboot .bin linuxboot_dma .bin kvmvapic .bin pvh .bin
# Dummy command so that make thinks it has done something
@true
i n c l u d e . . / . . / c o n f i g - h o s t . m a k
i n c l u d e $( SRC_PATH ) / r u l e s . m a k
$( call set -vpath , $ ( SRC_PATH ) /pc -bios /optionrom )
.PHONY : all clean build -all
quiet-command = $( if $( V) ,$1 ,$( if $( 2) ,@printf " %-7s %s\n" $2 $3 && $1 , @$1 ) )
cc-option = $( if $( shell $( CC) $1 -S -o /dev/null -xc /dev/null >/dev/null 2>& 1 && echo OK) , $1 , $2 )
# Compiling with no optimization creates ROMs that are too large
i f e q ( $( lastword $ ( filter -O %, -O 0 $ ( CFLAGS ) ) ) , - O 0 )
@ -15,48 +18,60 @@ override CFLAGS += -O2
e n d i f
o v e r r i d e CFLAGS += -march= i486
# Drop -fstack-protector and the like
QEMU_CFLAGS := $( filter -W%, $( QEMU_CFLAGS) ) $( CFLAGS_NOPIE) -ffreestanding
QEMU_CFLAGS += $( call cc-option, $( QEMU_CFLAGS) , -fno-stack-protector)
QEMU_CFLAGS += $( call cc-option, $( QEMU_CFLAGS) , -m16)
i f e q ( $( filter -m 16, $ ( QEMU_CFLAGS ) ) , )
# Flags for dependency generation
o v e r r i d e CPPFLAGS += -MMD -MP -MT $@ -MF $( @D) /$( *F) .d
o v e r r i d e CFLAGS += $( filter -W%, $( QEMU_CFLAGS) )
o v e r r i d e CFLAGS += $( CFLAGS_NOPIE) -ffreestanding -I$( TOPSRC_DIR) /include
o v e r r i d e CFLAGS += $( call cc-option, -fno-stack-protector)
o v e r r i d e CFLAGS += $( call cc-option, -m16)
i f e q ( $( filter -m 16, $ ( CFLAGS ) ) , )
# Attempt to work around compilers that lack -m16 (GCC <= 4.8, clang <= ??)
# On GCC we add -fno-toplevel-reorder to keep the order of asm blocks with
# respect to the rest of the code. clang does not have -fno-toplevel-reorder,
# but it places all asm blocks at the beginning and we're relying on it for
# the option ROM header. So just force clang not to use the integrated
# assembler, which doesn't support .code16gcc.
QEMU_CFLAGS += $( call cc-option, $( QEMU_CFLAGS) , -fno-toplevel-reorder)
QEMU_CFLAGS += $( call cc-option, $( QEMU_CFLAGS) , -no-integrated-as)
QEMU_CFLAGS += -m32 -include $( SRC_PATH) /pc-bios/optionrom /code16gcc.h
o v e r r i d e CFLAGS += $( call cc-option , -fno-toplevel-reorder)
o v e r r i d e CFLAGS += $( call cc-option , -no-integrated-as)
o v e r r i d e CFLAGS += -m32 -include $( SRC_DIR) /code16gcc.h
e n d i f
QEMU_INCLUDES += -I$( SRC_PATH)
Wa = -Wa,
ASFLAGS += -32
QEMU_CFLAGS += $( call cc-c-option, $( QEMU_CFLAGS) , $( Wa) -32)
o v e r r i d e ASFLAGS += -32
o v e r r i d e CFLAGS += $( call cc-option , $( Wa) -32)
build-all : multiboot .bin linuxboot .bin linuxboot_dma .bin kvmvapic .bin pvh .bin
# suppress auto-removal of intermediate files
.SECONDARY :
LD_I386_EMULATION ?= elf_i386
o v e r r i d e LDFLAGS = -m $( LD_I386_EMULATION) -T $( SRC_DIR) /flat.lds
o v e r r i d e LDFLAGS += $( LDFLAGS_NOPIE)
all : multiboot .bin linuxboot .bin linuxboot_dma .bin kvmvapic .bin pvh .bin
pvh.img : pvh .o pvh_main .o
%.o : %.S
$( call quiet-command,$( CPP) $( QEMU_INCLUDES) $( QEMU_DGFLAGS) -c -o - $< | $( AS) $( ASFLAGS) -o $@ ,"AS" ," $( TARGET_DIR) $@ " )
$( call quiet-command,$( CPP) $( CPP FLAGS) -c -o - $< | $( AS) $( ASFLAGS) -o $@ ,"AS" ," $@ " )
pvh.img : pvh .o pvh_main .o
$( call quiet-command,$( LD) $( LDFLAGS_NOPIE) -m $( LD_I386_EMULATION) -T $( SRC_PATH) /pc-bios/optionrom/flat.lds -s -o $@ $^,"BUILD" ," $( TARGET_DIR) $@ " )
%.o : %.c
$( call quiet-command,$( CC) $( CPPFLAGS) $( CFLAGS) -c $< -o $@ ,"CC" ," $@ " )
%.img : %.o
$( call quiet-command,$( LD) $( LDFLAGS_NOPIE) -m $( LD_I386_EMULATION) -T $( SRC_PATH) /pc-bios/optionrom/flat.lds -s -o $@ $< ,"BUILD" ," $( TARGET_DIR) $@ " )
$( call quiet-command,$( LD) $( LDFLAGS) -s -o $@ $^ ,"BUILD" ," $@ " )
%.raw : %.img
$( call quiet-command,$( OBJCOPY) -O binary -j .text $< $@ ,"BUILD" ," $( TARGET_DIR) $@ " )
$( call quiet-command,$( OBJCOPY) -O binary -j .text $< $@ ,"BUILD" ," $@ " )
%.bin : %.raw
$( call quiet-command,$( PYTHON) $( SRC_PATH) /scripts/signrom.py $< $@ ,"SIGN" ," $( TARGET_DIR) $@ " )
$( call quiet-command,$( PYTHON) $( TOPSRC_DIR) /scripts/signrom.py $< $@ ,"SIGN" ," $@ " )
i n c l u d e $( wildcard *.d )
clean :
rm -f *.o *.d *.raw *.img *.bin *~
# suppress auto-removal of intermediate files
.SECONDARY :
.PHONY : all clean