Author: Robert Millan <rmh@aybabtu.com>
Author: Stefan Potyra <sistpoty@ubuntu.com>
Author: Kees Cook <kees@ubuntu.com>
Author: Carl-Daniel Hailfinger <c-d.hailfinger.devel.2006 at gmx.net>
Author: Fabian Greffrath <fabian+debian@greffrath.com>
Author: Thomas Lane <thomas_lane@icloud.com>
Origin: http://www.coreboot.org/pipermail/coreboot/2009-April/046558.html
Origin: https://github.com/allbombson/grub-invaders/commit/172aea74fe55eab36937631c37837c6cd8bca2fd
Description: Support for building on amd64 and others,
 move -nostdlib to CFLAGS, as it's a compiler flag,
 use CFLAGS for linking as well (since gcc is used),
 replace -fno-builtin with -ffreestanding,
 replace -Werror with -W,
 and fix an incompatibility with newer gcc and binutils.
Bug-Debian: http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=422364

--- a/compile.sh
+++ b/compile.sh
@@ -3,16 +3,19 @@
 set -e
 set -v
 
-CFLAGS="-fno-builtin -nostdinc -O2 -I. -Wall -Werror"
-LDFLAGS="-nostdlib -Wl,-N -Wl,-Ttext -Wl,100000"
-gcc $CFLAGS -c keyboard.c
-gcc $CFLAGS -c delay.c
-gcc $CFLAGS -c common.c
-gcc $CFLAGS -c sound.c
-gcc $CFLAGS -c game.c
-gcc $CFLAGS -c kernel.c
-gcc $CFLAGS -c video.c
-gcc $CFLAGS -c memory.c
-gcc $CFLAGS -c boot.S
-gcc $LDFLAGS -o invaders.exec boot.o kernel.o keyboard.o video.o game.o sound.o delay.o common.o memory.o
-objcopy -O binary invaders.exec invaders
+CC="${CC:=gcc}"
+OBJCOPY="${OBJCOPY:=objcopy}"
+
+CFLAGS="-ffreestanding -fno-stack-protector -m32 -nostdinc -nostdlib --param=min-pagesize=0 -I. -O2 -Wall"
+LDFLAGS="-Wl,-N -Wl,-T -Wl,debian/invaders.ld -Wl,--build-id=none"
+$CC $CFLAGS -c keyboard.c
+$CC $CFLAGS -c delay.c
+$CC $CFLAGS -c common.c
+$CC $CFLAGS -c sound.c
+$CC $CFLAGS -c game.c
+$CC $CFLAGS -c kernel.c
+$CC $CFLAGS -c video.c
+$CC $CFLAGS -c memory.c
+$CC $CFLAGS -c boot.S
+$CC $CFLAGS $LDFLAGS -o invaders.exec boot.o kernel.o keyboard.o video.o game.o sound.o delay.o common.o memory.o
+$OBJCOPY -O binary invaders.exec invaders
