Some cleanups based on patch by Nguyen Anh Quynh

Add include guards to header files.
Disable stack protector on gcc versions with that option.
Fix lds bug in src/rombios32.lds.S
Don't forward declare "struct bregs;" - it may be confusing gcc on some versions.
diff --git a/Makefile b/Makefile
index e747126..ad99d81 100644
--- a/Makefile
+++ b/Makefile
@@ -11,9 +11,17 @@
 SRC16=floppy.c disk.c system.c clock.c serial.c kbd.c mouse.c output.c boot.c
 SRC32=post.c output.c
 
+cc-option = $(shell if test -z "`$(1) $(2) -S -o /dev/null -xc \
+              /dev/null 2>&1`"; then echo "$(2)"; else echo "$(3)"; fi ;)
+
 # Default compiler flags
-CFLAGS = -Wall -g -Os -MD -m32 -march=i386 -mregparm=2 -ffreestanding
-CFLAGS16 = -Wall -Os -MD -m32 -DMODE16 -march=i386 -mregparm=2 -ffreestanding -fno-jump-tables
+COMMONCFLAGS = -Wall -Os -MD -m32 -march=i386 -mregparm=2 -ffreestanding
+COMMONCFLAGS += $(call cc-option,$(CC),-nopie,)
+COMMONCFLAGS += $(call cc-option,$(CC),-fno-stack-protector,)
+COMMONCFLAGS += $(call cc-option,$(CC),-fno-stack-protector-all,)
+
+CFLAGS = $(COMMONCFLAGS) -g
+CFLAGS16 = $(COMMONCFLAGS) -DMODE16 -fno-jump-tables
 
 all: $(OUT) $(OUT)rom.bin
 
diff --git a/src/disk.h b/src/disk.h
index 04600f5..358347a 100644
--- a/src/disk.h
+++ b/src/disk.h
@@ -3,8 +3,11 @@
 // Copyright (C) 2008  Kevin O'Connor <kevin@koconnor.net>
 //
 // This file may be distributed under the terms of the GNU GPLv3 license.
+#ifndef __DISK_H
+#define __DISK_H
 
 #include "ioport.h" // outb
+#include "biosvar.h" // struct bregs
 
 #define DISK_RET_SUCCESS     0x00
 #define DISK_RET_EPARAM      0x01
@@ -15,6 +18,7 @@
 #define DISK_RET_EMEDIA      0xC0
 
 // floppy.c
-struct bregs;
 void floppy_13(struct bregs *regs, u8 drive);
 void floppy_tick();
+
+#endif // disk.h
diff --git a/src/farptr.h b/src/farptr.h
index 86179cc..7216f23 100644
--- a/src/farptr.h
+++ b/src/farptr.h
@@ -3,6 +3,8 @@
 // Copyright (C) 2008  Kevin O'Connor <kevin@koconnor.net>
 //
 // This file may be distributed under the terms of the GNU GPLv3 license.
+#ifndef __FARPTR_H
+#define __FARPTR_H
 
 #define READ8_SEG(SEG, var) ({                                          \
     u8 __value;                                                         \
@@ -97,3 +99,5 @@
 #define GET_FARPTR(ptr) (ptr)
 #define SET_FARPTR(ptr, val) do { (var) = (val); } while (0)
 #endif
+
+#endif // farptr.h
diff --git a/src/rombios32.lds.S b/src/rombios32.lds.S
index 18b8ab0..5d7e772 100644
--- a/src/rombios32.lds.S
+++ b/src/rombios32.lds.S
@@ -9,7 +9,7 @@
 #include "../out/rom16.offset.auto.h"
 
 OUTPUT_FORMAT("elf32-i386", "elf32-i386", "elf32-i386")
-OUTPUT_ARCH(i386)
+OUTPUT_ARCH("i386")
 ENTRY(_start);
 SECTIONS
 {
diff --git a/src/util.h b/src/util.h
index 916f672..53281b5 100644
--- a/src/util.h
+++ b/src/util.h
@@ -3,16 +3,20 @@
 // Copyright (C) 2008  Kevin O'Connor <kevin@koconnor.net>
 //
 // This file may be distributed under the terms of the GNU GPLv3 license.
+#ifndef __UTIL_H
+#define __UTIL_H
 
 #include "ioport.h" // outb
 #include "biosvar.h" // struct bregs
 
-static inline void irq_disable(void) {
-        asm volatile("cli": : :"memory");
+static inline void irq_disable(void)
+{
+    asm volatile("cli": : :"memory");
 }
 
-static inline void irq_enable(void) {
-        asm volatile("sti": : :"memory");
+static inline void irq_enable(void)
+{
+    asm volatile("sti": : :"memory");
 }
 
 static inline unsigned long irq_save(void)
@@ -91,7 +95,6 @@
 // output.c
 void bprintf(u16 action, const char *fmt, ...)
     __attribute__ ((format (printf, 2, 3)));
-struct bregs;
 void __debug_enter(const char *fname, struct bregs *regs);
 void __debug_exit(const char *fname, struct bregs *regs);
 #define debug_enter(regs) \
@@ -115,3 +118,5 @@
     regs->ah = code;
     set_cf(regs, code);
 }
+
+#endif // util.h