+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.
+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
-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
#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