changeset 88:7c31bbcf079c draft

We should now compile on OpenBSD. Also, we check we can use some gcc flags before blindly erroring.
author Roy Marples <roy@marples.name>
date Sun, 08 Apr 2007 17:35:22 +0000
parents 8a1c2fd9e7e2
children e8ace53f6ed2
files ChangeLog Makefile socket.c
diffstat 3 files changed, 23 insertions(+), 8 deletions(-) [+]
line wrap: on
line diff
--- a/ChangeLog	Fri Apr 06 12:30:16 2007 +0000
+++ b/ChangeLog	Sun Apr 08 17:35:22 2007 +0000
@@ -1,3 +1,5 @@
+Compile ok on OpenBSD (thanks to icezimm and reb in #gentoo-bsd for testing)
+We check gcc supports -Wextra and friends before using them.
 We now restore the starting MTU value when we exit OR we don't receive a
 a valid MTU value from the dhcp server.
 --nomtu / -M now stops the MTU from being used.
--- a/Makefile	Fri Apr 06 12:30:16 2007 +0000
+++ b/Makefile	Sun Apr 08 17:35:22 2007 +0000
@@ -1,8 +1,20 @@
+VERSION = 3.0.17_pre2
+CFLAGS ?= -O2 -pipe
+
 # Should work for both GNU make and BSD make
 
-VERSION = 3.0.17_pre2
+# Saying that, this function only works with GNU Make :/
+check_gcc=$(shell if $(CC) $(1) -S -o /dev/null -xc /dev/null >/dev/null 2>&1; \
+	  then echo "$(1)"; else echo "$(2)"; fi)
 
-CFLAGS ?= -O2 -pipe
+# Luckily we can do this more long winded thing with pmake used by the BSDs
+# FIXME: Look into making this into a loop
+WAFTST != if $(CC) -Wextra -S -o /dev/null -xc /dev/null >/dev/null 2>&1; \
+	  then echo "-Wdeclaration-after-statement"; fi
+WSEQ   != if $(CC) -Wextra -S -o /dev/null -xc /dev/null >/dev/null 2>&1; \
+	  then echo "-Wsequence-point"; fi
+WEXTRA != if $(CC) -Wextra -S -o /dev/null -xc /dev/null >/dev/null 2>&1; \
+	  then echo "-Wextra"; fi
 
 # Loads of nice flags to ensure our code is good
 # IMPORTANT: We should be using c99 instead of gnu99 but for some reason
@@ -11,11 +23,10 @@
     -Wall -Wunused -Wimplicit -Wshadow -Wformat=2 \
     -Wmissing-declarations -Wno-missing-prototypes -Wwrite-strings \
     -Wbad-function-cast -Wnested-externs -Wcomment -Winline \
-    -Wchar-subscripts -Wcast-align -Wno-format-nonliteral
-
-# Early GCC versions don't support these flags, so you may need to comment
-# this line out
-CFLAGS += -Wsequence-point -Wextra -Wdeclaration-after-statement
+    -Wchar-subscripts -Wcast-align -Wno-format-nonliteral \
+    $(call check_gcc, -Wdeclaration-after-statement) \
+    $(call check_gcc, -Wsequence-point) \
+    $(call check_gcc, -Wextra) $(WAFTST) $(WSEQ) $(WEXTRA)
 
 # -Werrror is a good flag to use for development, but some platforms may
 #  have buggy headers from time to time, so you may need to comment this out
--- a/socket.c	Fri Apr 06 12:30:16 2007 +0000
+++ b/socket.c	Sun Apr 08 17:35:22 2007 +0000
@@ -26,10 +26,12 @@
 #include <sys/uio.h>
 #include <netinet/in_systm.h>
 #include <netinet/in.h>
+#ifndef __OpenBSD__
 #include <netinet/ip.h>
-#include <netinet/udp.h>
 #include <netinet/if_ether.h>
 #include <net/ethernet.h>
+#endif
+#include <netinet/udp.h>
 #ifndef __linux__
 #include <net/if_types.h>
 #endif