Commit Diff


commit - b49d4941c8516ec9461a2de2615819f87c4e9acd
commit + 4fccd2fe0ffbbc668b66abe63614470635f92f1b
blob - 7635c72b6f2648b4dbba31fbb5339f3504bee88f
blob + 8260164ab10e214c5fb631392438c6c875be0ed5
--- Makefile.common.in
+++ Makefile.common.in
@@ -21,4 +21,3 @@ AM_CPPFLAGS += \
 	      -I$(top_srcdir)/lib \
 	      -I$(top_srcdir)/include \
 	      -I$(top_srcdir)/template \
-	      -I.
blob - 66f3bdec46092f4f7a2eb50c016c08545d8fc827
blob + 7c49534770b41e67040582c04fef1e6b345e50db
--- compat/Makefile.am
+++ compat/Makefile.am
@@ -5,7 +5,6 @@ include $(top_builddir)/Makefile.common
 libopenbsd_compat_a_SOURCES =  \
 	asprintf.c \
 	base64.c \
-	closefrom.c \
 	fmt_scaled.c \
 	freezero.c \
 	getdtablecount.c \
@@ -31,6 +30,10 @@ if HOST_DARWIN
 libopenbsd_compat_a_SOURCES += uuid.c bsd-poll.c bsd-poll.h
 endif
 
+if !HAVE_CLOSEFROM
+libopenbsd_compat_a_SOURCES += closefrom.c
+endif
+
 if HOST_NETBSD
 libopenbsd_compat_a_SOURCES += bsd-poll.c bsd-poll.h
 endif
@@ -65,6 +68,9 @@ libopenbsd_compat_a_SOURCES += sha2.c sha2.h
 endif
 endif
 
+LDADD = $(libbsd_LIBS)
+AM_CPPFLAGS = $(libbsd_CFLAGS)
+
 EXTRA_DIST = \
 	$(top_srcdir)/include/got_compat.h \
 	imsg.h \
blob - 34194b69d0c46f70a8b0d52de97293a36227c21f
blob + 804ec1e06bbb48c4bd72d6dca974b90ac7dbf247
--- compat/asprintf.c
+++ compat/asprintf.c
@@ -22,6 +22,8 @@
 #include <string.h>
 #include <stdlib.h>
 
+int vasprintf(char **, const char *, va_list);
+
 int
 asprintf(char **ret, const char *fmt, ...)
 {
blob - e90696df6734e087c40036ab7e8b95e68aabe5e7
blob + a8dc07ea20de37cc5003a5c11b340b79718bdb6f
--- compat/base64.c
+++ compat/base64.c
@@ -41,6 +41,8 @@
  * OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE, EVEN
  * IF IBM IS APPRISED OF THE POSSIBILITY OF SUCH DAMAGES.
  */
+
+#include "got_compat.h"
 
 #include <sys/types.h>
 #include <sys/socket.h>
blob - ce3ca9baf57a8856dcbf04e41c7a3ff1e07dda10
blob + 7ce1ea0274181877aed37f955f9319e6961f41c1
--- compat/imsg-buffer.c
+++ compat/imsg-buffer.c
@@ -27,6 +27,7 @@
 #include <unistd.h>
 
 #include "got_compat.h"
+#include "imsg.h"
 
 static int	ibuf_realloc(struct ibuf *, size_t);
 static void	ibuf_enqueue(struct msgbuf *, struct ibuf *);
blob - 5a1d9ff241960d04721b65c6f2c515d4124020a2
blob + 5abfcc2083f819fbd688a2030771bbb2a9b4db69
--- compat/sha2.c
+++ compat/sha2.c
@@ -39,7 +39,6 @@
 #include <string.h>
 
 #include "got_compat.h"
-#include "sha2.h"
 
 #define DEF_WEAK(x)     void __ssh_compat_weak_##x(void)
 
blob - 450ceba22057e009652bb44a1956bfa576cb6ca4
blob + 9b8bcf405ff91d64b71e3904821a73c4085cb23f
--- configure.ac
+++ configure.ac
@@ -10,12 +10,12 @@ AM_INIT_AUTOMAKE([foreign subdir-objects])
 
 AC_CONFIG_HEADERS([include/got_compat.h])
 
-AC_DEFINE_UNQUOTED(VERSION, "$VERSION")
+AC_DEFINE_UNQUOTED(VERSION, $VERSION)
 AC_SUBST(VERSION)
 AC_SUBST(GOT_RELEASE)
 
-AC_DEFINE([GOT_VERSION], [VERSION], [GoT version string])
-AC_DEFINE([GOT_VERSION_NUMBER], [VERSION], [Got version number])
+AC_DEFINE_UNQUOTED([GOT_VERSION], VERSION, [GoT version string])
+AC_DEFINE_UNQUOTED([GOT_VERSION_NUMBER], VERSION, [Got version number])
 
 AC_USE_SYSTEM_EXTENSIONS
 AC_CANONICAL_HOST
@@ -174,6 +174,7 @@ AC_CHECK_FUNCS([ \
 	memchr \
 	memmove \
 	memset \
+	mergesort \
 	mkdir \
 	munmap \
 	nl_langinfo \
@@ -190,7 +191,6 @@ AC_CHECK_FUNCS([ \
 	strcspn \
 	strdup \
 	strerror \
-	strlcpy \
 	strncasecmp \
 	strndup \
 	strrchr \
@@ -227,6 +227,7 @@ AC_REPLACE_FUNCS([ \
 	strsep \
 	strtonum \
 ])
+AM_CONDITIONAL([HAVE_CLOSEFROM], [test "x$ac_cv_func_closefrom" = xyes])
 
 # Always use our getopt because 1) glibc's doesn't enforce argument order 2)
 # musl does not set optarg to NULL for flags without arguments (although it is
@@ -414,7 +415,10 @@ AC_RUN_IFELSE([AC_LANG_PROGRAM(
 # Look for imsg_init in libutil.
 AC_SEARCH_LIBS(imsg_init, util, found_imsg_init=yes, found_imsg_init=no)
 AM_CONDITIONAL([HAVE_IMSG], [test "x$found_imsg_init" = "xyes"])
-if test "x$found_imsg_init" = xno; then
+if test "x$found_imsg_init" = "xyes"; then
+	libutil_LIBS="$ac_cv_search_imsg_init"
+	AC_SUBST(libutil_LIBS)
+else
 	AC_LIBOBJ(imsg)
 	AC_LIBOBJ(imsg-buffer)
 fi
@@ -422,13 +426,15 @@ fi
 # libevent (for gotwebd).  Lifted from tmux.
 # Look for libevent. Try libevent_core or libevent with pkg-config first then
 # look for the library.
+found_libevent=no
 PKG_CHECK_MODULES(
 	LIBEVENT_CORE,
 	[libevent_core >= 2],
 	[
-		AM_CPPFLAGS="$LIBEVENT_CORE_CFLAGS $AM_CPPFLAGS"
-		CPPFLAGS="$AM_CPPFLAGS $SAVED_CPPFLAGS"
-		LIBS="$LIBEVENT_CORE_LIBS $LIBS"
+		libevent_CFLAGS="$LIBEVENT_CORE_CFLAGS"
+		libevent_LIBS="$LIBEVENT_CORE_LIBS"
+		AC_SUBST(libevent_CFLAGS)
+		AC_SUBST(libevent_LIBS)
 		found_libevent=yes
 	],
 	found_libevent=no
@@ -438,9 +444,10 @@ if test x$found_libevent = xno; then
 		LIBEVENT,
 		[libevent >= 2],
 		[
-			AM_CPPFLAGS="$LIBEVENT_CFLAGS $AM_CPPFLAGS"
-			CPPFLAGS="$AM_CPPFLAGS $SAVED_CPPFLAGS"
-			LIBS="$LIBEVENT_LIBS $LIBS"
+			libevent_CFLAGS="$LIBEVENT_CFLAGS"
+			libevent_LIBS="$LIBEVENT_LIBS"
+			AC_SUBST(libevent_CFLAGS)
+			AC_SUBST(libevent_LIBS)
 			found_libevent=yes
 		],
 		found_libevent=no
@@ -453,7 +460,14 @@ if test x$found_libevent = xno; then
 		found_libevent=yes,
 		found_libevent=no
 	)
+
+	if test "x$found_libevent" = "xyes"; then
+		libevent_LIBS="$ac_cv_search_event_init"
+		AC_SUBST(libevent_LIBS)
+	fi
 fi
+
+if test x$found_libevent = xno; then
 AC_CHECK_HEADER(
 	event2/event.h,
 	AC_DEFINE([HAVE_EVENT2_EVENT_H], [1], [libevent2 has event.h]),
@@ -465,6 +479,8 @@ AC_CHECK_HEADER(
 		)
 	]
 )
+fi
+
 if test "x$found_libevent" = xno; then
 	AC_MSG_ERROR("libevent not found")
 fi
@@ -474,9 +490,10 @@ PKG_CHECK_MODULES(
 	LIBCRYPTO,
 	libcrypto,
 	[
-	 	AM_CFLAGS="$LIBCRYPTO_CFLAGS $AM_CFLAGS"
-		CFLAGS="$AM_CFLAGS $SAVED_CFLAGS"
-		LIBS="$LIBCRYPTO_LIBS $LIBS"
+		libcrypto_CFLAGS="$LIBCRYPTO_CORE_CFLAGS"
+		libcrypto_LIBS="$LIBCRYPTO_LIBS"
+		AC_SUBST(libcrypto_CFLAGS)
+		AC_SUBST(libcrypto_LIBS)
 		found_libcrypto=yes
 	],
 	[
@@ -488,9 +505,7 @@ if test "x$found_libcrypto" = "xyes"; then
 	AC_DEFINE([HAVE_LIBCRYPTO], [1], [libcrypto])
 fi
 
-AC_SEARCH_LIBS(uuid_create, , AC_DEFINE([HAVE_BSD_UUID], [1], [BSD UUID]))
-AC_SEARCH_LIBS(uuid_create, found_uuid=no, found_uuid=yes)
-AC_SEARCH_LIBS(mergesort, , AC_DEFINE([HAVE_BSD_MERGESORT], [1], [BSD Mergesort]))
+AC_CHECK_FUNC([uuid_create], [found_uuid=yes], [found_uuid=no])
 
 # Don't define HAVE_BSD_UUID on darwin (Apple) as this breaks the BSD API.
 # Instead, use the UUID implementation wrapper that's in compat/ plus uuid
@@ -502,9 +517,10 @@ else
 		LIBUUID,
 		uuid,
 		[
-			AM_CFLAGS="$LIBUUID_CFLAGS $AM_CFLAGS"
-			CFLAGS="$AM_CFLAGS $SAVED_CFLAGS"
-			LIBS="$LIBUUID_LIBS $LIBS"
+			libuuid_CFLAGS="$LIBUUID_CFLAGS"
+			libuuid_LIBS="$LIBUUID_LIBS"
+			AC_SUBST(libuuid_CFLAGS)
+			AC_SUBST(libuuid_LIBS)
 			found_libuuid=yes
 		],
 		[
@@ -528,9 +544,10 @@ PKG_CHECK_MODULES(
 	ZLIB,
 	zlib,
 	[
-	 	AM_CFLAGS="$ZLIB_CFLAGS $AM_CFLAGS"
-		CFLAGS="$AM_CFLAGS $SAVED_CFLAGS"
-		LIBS="$ZLIB_LIBS $LIBS"
+		zlib_CFLAGS="$ZLIB_CFLAGS"
+		zlib_LIBS="$ZLIB_LIBS"
+		AC_SUBST(zlib_CFLAGS)
+		AC_SUBST(zlib_LIBS)
 		found_zlib=yes
 	],
 	[
@@ -554,9 +571,10 @@ if test "$PLATFORM" = "linux"; then
 		LIBMD,
 		libmd,
 		[
-			AM_CFLAGS="$LIBMD_CFLAGS $AM_CFLAGS"
-			CFLAGS="$AM_CFLAGS $SAVED_CFLAGS"
-			LIBS="$LIBMD_LIBS $LIBS"
+			libmd_CFLAGS="$LIBMD_CFLAGS"
+			libmd_LIBS="$LIBMD_LIBS"
+			AC_SUBST(libmd_CFLAGS)
+			AC_SUBST(libmd_LIBS)
 		],
 		[
 			AC_MSG_ERROR("*** couldn't find libmd via pkg-config")
@@ -566,9 +584,10 @@ if test "$PLATFORM" = "linux"; then
 		LIBBSD,
 		libbsd-overlay,
 		[
-			AM_CFLAGS="$LIBBSD_CFLAGS $AM_CFLAGS"
-			CFLAGS="$AM_CFLAGS $SAVED_CFLAGS"
-			LIBS="$LIBBSD_LIBS $LIBS"
+		 	libbsd_CFLAGS="$LIBBSD_CFLAGS"
+			libbsd_LIBS="$LIBBSD_LIBS"
+			AC_SUBST(libbsd_CFLAGS)
+			AC_SUBST(libbsd_LIBS)
 			AC_DEFINE([HAVE_LIBBSD], [1], [BSD UUID])
 		],
 		[
@@ -576,6 +595,12 @@ if test "$PLATFORM" = "linux"; then
 		]
 
 	)
+
+	# Add LIBBSD_{CFLAGS,LIBS} to the environment here, as libbsd puts its
+	# header files in a non-standard location, which means the overlay for
+	# <sys/tree.h> and <sys/queue.h> won't be found.
+	CFLAGS="$CFLAGS $LIBBSD_CFLAGS"
+	LIBS="$LIBS $LIBBSD_LIBS"
 fi
 
 # Look for a suitable queue.h.  We hope libbsd is enough, but that is missing
@@ -671,12 +696,12 @@ PKG_CHECK_MODULES(
 	found_ncurses=no
 )
 if test "x$found_ncurses" = xyes; then
-	AM_CFLAGS="$LIBNCURSES_CFLAGS $LIBTINFO_CFLAGS $LIBPANELW_CFLAGS $AM_CFLAGS"
-	CFLAGS="$LIBNCURSES_CFLAGS $LIBTINFO_CFLAGS $LIBPANELW_CFLAGS $CFLAGS"
-	LIBS="$LIBNCURSES_LIBS $LIBTINFO_LIBS $LIBPANELW_LIBS $LIBS"
+	libncurses_CFLAGS="$LIBNCURSES_CFLAGS $LIBTINFO_CFLAGS $LIBPANELW_CFLAGS"
+	libncurses_LIBS="$LIBNCURSES_LIBS $LIBTINFO_LIBS $LIBPANELW_LIBS"
+	AC_SUBST(libncurses_CFLAGS)
+	AC_SUBST(libncurses_LIBS)
 else
-	AC_CHECK_LIB(
-		ncursesw,
+	AC_SEARCH_LIBS(
 		setupterm,
 		found_ncurses=yes,
 		found_ncurses=no
@@ -684,10 +709,10 @@ else
 	if test "x$found_ncurses" = xyes; then
 		AC_CHECK_HEADER(
 			ncurses.h,
-			AM_CFLAGS="$LIBPANELW_CFLAGS $AM_CFLAGS"
-			CFLAGS="$LIBPANEL_CFLAGS $CFLAGS"
-			LIBS="$LIBS -lncursesw $LIBPANELW_LIBS",
-			found_ncurses=no
+			libncurses_CFLAGS="$LIBPANELW_CFLAGS $LIBPANEL_CFLAGS"
+			libncurses_LIBS="$LIBPANELW_LIBS -lncursesw"
+			AC_SUBST(libncurses_CFLAGS)
+			AC_SUBST(libncurses_LIBS)
 		)
 	fi
 fi
@@ -695,20 +720,20 @@ if test "x$found_ncurses" = xyes; then
 	AC_DEFINE([HAVE_NCURSES_H], [1], [NCurses])
 else
 	# No ncurses, try curses.
-	AC_CHECK_LIB(
-		cursesw,
+	AC_CHECK_FUNC(
 		setupterm,
 		found_curses=yes,
 		found_curses=no
 	)
 	AC_CHECK_HEADER(
 		curses.h,
-		,
+		found_curses=yes,
 		found_curses=no)
 	if test "x$found_curses" = xyes; then
-		AM_CFLAGS="$LIBPANELW_CFLAGS $AM_CFLAGS"
-		CFLAGS="$LIBPANEL_CFLAGS $CFLAGS"
-		LIBS="$LIBS -lcursesw $LIBPANELW_LIBS"
+		libncurses_CFLAGS="$LIBPANELW_CFLAGS $LIBPANEL_CFLAGS"
+		libncurses_LIBS="$LIBPANELW_LIBS -lncursesw"
+		AC_SUBST(libncurses_CFLAGS)
+		AC_SUBST(libncurses_LIBS)
 		AC_DEFINE([HAVE_CURSES_H], [1], [Curses_h])
 	else
 		AC_MSG_ERROR("curses not found")
@@ -724,6 +749,10 @@ CFLAGS="$SAVED_CFLAGS"
 AC_SUBST(AM_LDFLAGS)
 LDFLAGS="$SAVED_LDFLAGS"
 
+if test x"$PLATFORM" = "xopenbsd"; then
+	LIBS=""
+fi
+
 AH_BOTTOM([#include "got_compat2.h"])
 
 AC_CONFIG_FILES([Makefile
@@ -760,6 +789,7 @@ Configured got-portable with:
  Prefix:       ${prefix}
  Executables:  ${executables}
  Bison:        $YACC
+ CFlags:       $CFLAGS
  Helpers:      ${helpers}
  Man pages:    ${manpages}
 "
blob - ae872a4b3c5ffb787354c7dc39d7ae9624f9238d
blob + cb56b422d772f8bd02bc07e0df192246084d8555
--- got/Makefile.am
+++ got/Makefile.am
@@ -69,6 +69,14 @@ man1_MANS = got.1
 man5_MANS = got.conf.5 git-repository.5 got-worktree.5
 
 LDADD = -L$(top_builddir)/compat -lopenbsd-compat -lm
+LDADD += $(libuuid_LIBS) \
+	 $(zlib_LIBS) \
+	 $(libbsd_LIBS) \
+	 $(libutil_LIBS)
 if HOST_FREEBSD
 LDADD += -lmd
 endif
+
+AM_CPPFLAGS += $(libuuid_CFLAGS) \
+	       $(zlib_CFLAGS) \
+	       $(libbsd_CFLAGS)
blob - 57d449d06d25846b04b67a4520bef7ed129af84b
blob + f47d9defa60c0d149e6367abe262307f7fa4effe
--- got/got.c
+++ got/got.c
@@ -15,6 +15,8 @@
  * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
  * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  */
+
+#include "got_compat.h"
 
 #include <sys/queue.h>
 #include <sys/time.h>
@@ -38,8 +40,6 @@
 #include <paths.h>
 #include <regex.h>
 #include <getopt.h>
-
-#include "got_compat.h"
 
 #include "got_version.h"
 #include "got_error.h"
blob - 7d9b5b5aa0ad80248907cfa93941fba4888f2398
blob + 19d299b3a98acd1563ba1ac874f211f12a6c1e18
--- gotadmin/Makefile.am
+++ gotadmin/Makefile.am
@@ -45,6 +45,9 @@ EXTRA_DIST = gotadmin.1
 man1_MANS = gotadmin.1
 
 LDADD = -L$(top_builddir)/compat -lopenbsd-compat -lm
+LDADD += $(libbsd_LIBS) $(zlib_LIBS) $(libuuid_LIBS) $(libutil_LIBS)
 if HOST_FREEBSD
 LDADD += -lmd
 endif
+
+AM_CPPFLAGS += $(libbsd_CFLAGS) $(zlib_CFLAGS) $(libuuid_CFLAGS)
blob - a7c0b49eb169b3371b17192a5ec228ef57483eb5
blob + a72a024f791dd1baf5ea67c1f1416a7f42950866
--- gotadmin/gotadmin.c
+++ gotadmin/gotadmin.c
@@ -13,6 +13,8 @@
  * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
  * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  */
+
+#include "got_compat.h"
 
 #include <sys/queue.h>
 #include <sys/types.h>
@@ -28,8 +30,6 @@
 #include <signal.h>
 #include <string.h>
 #include <unistd.h>
-
-#include "got_compat.h"
 
 #include "got_version.h"
 #include "got_error.h"
blob - 46f51709d4e05be5f4a1bfc8d485317c05a72111
blob + 00cbec515ac0f3ddd9b01e9526b00fb130742cd7
--- gotd/gotd.c
+++ gotd/gotd.c
@@ -15,7 +15,6 @@
  */
 
 #include <sys/queue.h>
-#include <sys/tree.h>
 #include <sys/time.h>
 #include <sys/types.h>
 #include <sys/stat.h>
blob - f9265999b49a290679c80586abd15f3aad813a2f
blob + 23fc9997d1b17fbbeca50bfea1260e6750607210
--- gotd/privsep_stub.c
+++ gotd/privsep_stub.c
@@ -17,7 +17,6 @@
 #include <sys/types.h>
 #include <sys/time.h>
 #include <sys/queue.h>
-#include <sys/tree.h>
 #include <sys/uio.h>
 
 #include <stdint.h>
blob - 4db7055488067d5e06dd9572c6a2452984f8aedc
blob + 7d216c30fd1e06492e24bd23fce03098762ada66
--- gotd/repo_write.c
+++ gotd/repo_write.c
@@ -16,7 +16,6 @@
 
 #include <sys/queue.h>
 #include <sys/stat.h>
-#include <sys/tree.h>
 #include <sys/types.h>
 
 #include <event.h>
blob - 2dab4b1899454a2d79c63b10b268cda3292031fd
blob + 22c03b9ec660bcf589b5ba045f5c6e3d68a9b5eb
--- gotd/session.c
+++ gotd/session.c
@@ -16,7 +16,6 @@
 
 #include <sys/types.h>
 #include <sys/queue.h>
-#include <sys/tree.h>
 #include <sys/socket.h>
 #include <sys/stat.h>
 #include <sys/uio.h>
blob - 921167c2d746e713f84f96ae2fa4594d6ca0851c
blob + 97159001cc6ca4349365e4806bc117c10461f677
--- gotwebd/Makefile.am
+++ gotwebd/Makefile.am
@@ -87,10 +87,18 @@ man8_MANS = gotwebd.8
 
 LDADD = -L$(top_builddir)/compat -L$(top_builddir)/template \
 	-lopenbsd-compat -lm
+LDADD += $(libbsd_LIBS) \
+	 $(libevent_LIBS) \
+	 $(zlib_LIBS) \
+	 $(libuuid_LIBS) \
+	 $(libutil_LIBS)
 if HOST_FREEBSD
 LDADD += -lmd
 endif
 
+AM_CPPFLAGS += $(libbsd_CFLAGS) $(libevent_CFLAGS) $(zlib_CFLAGS) \
+	       $(libuuid_CFLAGS)
+
 #realinstall:
 #	if [ ! -d ${DESTDIR}${PUB_REPOS_DIR}/. ]; then \
 #		${INSTALL} -d -o root -g daemon -m 755 ${DESTDIR}${PUB_REPOS_DIR}; \
blob - bb5fdc03540ccfbca6182ba7a6cee7837c03e68a
blob + 0ca99d2850d2590cd57a086459f7e8e5b2e77a74
--- gotwebd/fcgi.c
+++ gotwebd/fcgi.c
@@ -15,6 +15,8 @@
  * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
  * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  */
+
+#include "got_compat.h"
 
 #include <arpa/inet.h>
 #include <sys/queue.h>
@@ -33,8 +35,6 @@
 #include <unistd.h>
 
 #include "got_error.h"
-
-#include "got_compat.h"
 
 #include "proc.h"
 #include "gotwebd.h"
blob - 44f5c1f1dfaa5a857e1ad3c7bae54e5f0ff4014c
blob + 49849c1f11676fb3f5efd0fbc0d00c2eae817bec
--- gotwebd/got_operations.c
+++ gotwebd/got_operations.c
@@ -14,6 +14,8 @@
  * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
  * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  */
+
+#include "got_compat.h"
 
 #include <sys/queue.h>
 #include <sys/socket.h>
@@ -36,8 +38,6 @@
 #include "got_commit_graph.h"
 #include "got_blame.h"
 #include "got_privsep.h"
-
-#include "got_compat.h"
 
 #include "proc.h"
 #include "gotwebd.h"
blob - 7f871577f71bf7ed192f9f4d4775c3309b27e7b0
blob + eadd7523213b9ccbb04392c1f1ce4381ff218fc6
--- gotwebd/gotweb.c
+++ gotwebd/gotweb.c
@@ -17,6 +17,7 @@
  * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
  * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  */
+#include "got_compat.h"
 
 #include <net/if.h>
 #include <netinet/in.h>
@@ -47,8 +48,6 @@
 #include "got_blame.h"
 #include "got_privsep.h"
 
-#include "got_compat.h"
-
 #include "proc.h"
 #include "gotwebd.h"
 #include "tmpl.h"
blob - 4d6b91ec76d63560990bb2856aa36f82b6b100da
blob + 970fd2dec57e85de37318509346f66e8c7ef0cd2
--- gotwebd/gotwebd.c
+++ gotwebd/gotwebd.c
@@ -38,13 +38,12 @@
 #include <unistd.h>
 #include <ctype.h>
 
+#include "got_compat.h"
 #include "got_opentemp.h"
 
 #include "proc.h"
 #include "gotwebd.h"
 
-#include "got_compat.h"
-
 __dead void usage(void);
 
 int	 main(int, char **);
blob - 1504f3baa6e43159943e72833c450f5ebbbebf05
blob + 8ce3646dd57116eca048f4b956d3b256e3d67e15
--- gotwebd/log.c
+++ gotwebd/log.c
@@ -14,6 +14,8 @@
  * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  */
 
+#include "got_compat.h"
+
 #include <stdio.h>
 #include <stdlib.h>
 #include <stdarg.h>
@@ -22,8 +24,6 @@
 #include <errno.h>
 #include <time.h>
 
-#include "got_compat.h"
-
 static int	 debug;
 static int	 verbose;
 const char	*log_procname;
blob - 9e131f7f8ea2410519cb28093419e4df01e1ddac
blob + 6b6301601460ed9f36bca0237892906c6761b5a4
--- gotwebd/pages.tmpl
+++ gotwebd/pages.tmpl
@@ -15,6 +15,8 @@
  * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
  * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  */
+
+#include "got_compat.h"
 
 #include <sys/types.h>
 #include <sys/queue.h>
blob - b0756b650ba10f35b64801c17c036af0a82accb9
blob + 2861d081090b8314fc0a8fa65e6ab4aa4694b13a
--- gotwebd/parse.y
+++ gotwebd/parse.y
@@ -21,6 +21,8 @@
  */
 
 %{
+#include "got_compat.h"
+
 #include <sys/ioctl.h>
 #include <sys/types.h>
 #include <sys/queue.h>
@@ -49,7 +51,6 @@
 #include "proc.h"
 #include "gotwebd.h"
 #include "got_sockaddr.h"
-#include "got_compat.h"
 
 TAILQ_HEAD(files, file)		 files = TAILQ_HEAD_INITIALIZER(files);
 static struct file {
blob - 22972bfde8dd77604f386036ac3fa6a4d05846d4
blob + 208d96c56bcaa3315c1baddc10a24b5adf8a38dd
--- gotwebd/proc.c
+++ gotwebd/proc.c
@@ -14,6 +14,7 @@
  * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
  * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  */
+#include "got_compat.h"
 
 #include <sys/types.h>
 #include <sys/queue.h>
@@ -32,8 +33,6 @@
 
 #include "proc.h"
 
-#include "got_compat.h"
-
 void	 proc_exec(struct privsep *, struct privsep_proc *, unsigned int,
 	    int, char **);
 void	 proc_setup(struct privsep *, struct privsep_proc *, unsigned int);
blob - 900136782434063aea4382874f2a1330db7656b6
blob + b57ade9f4b857c2f3544b8ba769c7a33509fac96
--- gotwebd/sockets.c
+++ gotwebd/sockets.c
@@ -16,6 +16,8 @@
  * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
  * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  */
+
+#include "got_compat.h"
 
 #include <sys/param.h>
 #include <sys/ioctl.h>
@@ -54,8 +56,6 @@
 #include "proc.h"
 #include "gotwebd.h"
 #include "tmpl.h"
-
-#include "got_compat.h"
 
 #define SOCKS_BACKLOG 5
 #define MAXIMUM(a, b)	(((a) > (b)) ? (a) : (b))
blob - cf3344de4dcf1c539c459bbcb4a76d7353d28a1c
blob + 04d9f37130897c3e42f77de2de57f8665cb80350
--- include/got_compat2.h
+++ include/got_compat2.h
@@ -59,6 +59,14 @@
 #include <stdio.h>
 #include <stdint.h>
 
+#ifndef __GNUC__
+#define __attribute__(a)
+#endif
+
+#ifndef __bounded__
+#define __bounded__(a, b, c)
+#endif
+
 /* For flock. */
 #ifndef O_EXLOCK
 #define O_EXLOCK 0
@@ -78,11 +86,6 @@
 #define WAIT_ANY (-1)
 #endif
 
-/* SOCK_NONBLOCK isn't available across BSDs... */
-#ifndef SOCK_NONBLOCK
-#define SOCK_NONBLOCK 00004000
-#endif
-
 /* On FreeBSD (and possibly others), EAI_NODATA was removed, in favour of
  * using EAI_NONAME.
  */
@@ -164,10 +167,10 @@ void uuid_to_string(uuid_t *, char **, uint32_t *);
 #include <sys/queue.h>
 #endif
 
-#ifdef HAVE_TREE_H
-#include <sys/tree.h>
-#else
+#ifndef HAVE_TREE_H
 #include "compat/tree.h"
+#else
+#include <sys/tree.h>
 #endif
 
 #ifdef HAVE_UTIL_H
@@ -178,15 +181,18 @@ void uuid_to_string(uuid_t *, char **, uint32_t *);
 #include <libutil.h>
 #endif
 
-#ifdef HAVE_IMSG
-#else
+#ifndef IOV_MAX
+# define IOV_MAX 1024
+#endif
+
+#ifndef HAVE_IMSG
 #include "compat/imsg.h"
 #endif
 
-#ifdef HAVE_SIPHASH
-#include <siphash.h>
-#else
+#ifndef HAVE_SIPHASH
 #include "compat/siphash.h"
+#else
+#include <siphash.h>
 #endif
 
 /* Include Apple-specific headers.  Mostly for crypto.*/
@@ -278,6 +284,11 @@ typedef struct _SHA2_CTX {
 # endif
 #endif
 
+/* SOCK_NONBLOCK isn't available across BSDs... */
+#if !defined(SOCK_NONBLOCK) && !defined(__linux__)
+#define SOCK_NONBLOCK 00004000
+#endif
+
 #ifndef HAVE_ASPRINTF
 /* asprintf.c */
 int		 asprintf(char **, const char *, ...);
@@ -299,10 +310,6 @@ int		 getdtablecount(void);
 void		 closefrom(int);
 #endif
 
-#if defined (__FreeBSD__)
-#define closefrom(fd) (closefrom(fd), 0)
-#endif
-
 #ifndef HAVE_STRSEP
 /* strsep.c */
 char		*strsep(char **, const char *);
@@ -421,7 +428,7 @@ int	BSDgetopt(int, char *const *, const char *);
 	((tvp)->tv_sec cmp (uvp)->tv_sec))
 #endif
 
-#ifndef HAVE_BSD_MERGESORT
+#ifndef HAVE_MERGESORT
 /* mergesort.c */
 int mergesort(void *, size_t, size_t, int (*)(const void *, const void *));
 #endif
blob - ff3e3c32b1744464fe0f014b5fe792249db374c8
blob + 53f181cbdaef76fe21b918d662302e97c34c6b3b
--- include/got_error.h
+++ include/got_error.h
@@ -14,8 +14,6 @@
  * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
  * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  */
-
-#include "got_compat.h"
 
 /* Error codes */
 #define GOT_ERR_OK		0
blob - 531a4c6c7f0f7ee650c3ef2b49aa61e0a2865500
blob + 5025bfe21dc3881b31112c90ba5987b035d9eae6
--- lib/blame.c
+++ lib/blame.c
@@ -14,6 +14,8 @@
  * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
  * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  */
+
+#include "got_compat.h"
 
 #include <sys/queue.h>
 #include <sys/mman.h>
@@ -26,8 +28,6 @@
 #include <time.h>
 #include <limits.h>
 #include <zlib.h>
-
-#include "got_compat.h"
 
 #include "got_error.h"
 #include "got_object.h"
blob - 050225122b5b7622f11da5c0a7196021b719fe68
blob + da410d35b967f8f509d65b491a4f06b7d2e695f0
--- lib/buf.c
+++ lib/buf.c
@@ -23,6 +23,8 @@
  * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
  * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  */
+
+#include "got_compat.h"
 
 #include <sys/queue.h>
 #include <sys/stat.h>
blob - 810758f4341bc956ef1809cb09b43bb7b9368bd8
blob + 3235b8c431f5d9fe37b29f4e87c953e2c0b1b380
--- lib/deflate.c
+++ lib/deflate.c
@@ -23,6 +23,7 @@
 #include <zlib.h>
 #include <time.h>
 
+#include "got_compat.h"
 #include "got_error.h"
 #include "got_object.h"
 #include "got_path.h"
blob - 618841b580474c8ab1894240045e221759e59487
blob + 73d83cfee6cba69b0b670e5f59a8b29e7cbc99fb
--- lib/delta.c
+++ lib/delta.c
@@ -25,6 +25,7 @@
 #include <time.h>
 #include <zlib.h>
 
+#include "got_compat.h"
 #include "got_error.h"
 #include "got_repository.h"
 #include "got_object.h"
blob - 71103e9ede2a7e55e38cf95e643104d11e8ac378
blob + 3f839c82af01a867deb0873649f2be20b393bc62
--- lib/deltify.c
+++ lib/deltify.c
@@ -14,6 +14,8 @@
  * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
  * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  */
+
+#include "got_compat.h"
 
 #include <sys/types.h>
 #include <sys/queue.h>
blob - dc7a448c999c4b5077313b0e944478a315474dbf
blob + 73079c85e3ece1cf8bde4a6a222b3423b80c05b9
--- lib/dial.c
+++ lib/dial.c
@@ -14,6 +14,8 @@
  * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
  * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  */
+
+#include "got_compat.h"
 
 #include <sys/queue.h>
 #include <sys/types.h>
blob - 6f2dfcfbe30bcc4ee982d27c6380d19f5ac22b3a
blob + 10dd64ab2adb789373fe5e625fb09f592f6ccd70
--- lib/diff.c
+++ lib/diff.c
@@ -13,6 +13,8 @@
  * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
  * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  */
+
+#include "got_compat.h"
 
 #include <sys/queue.h>
 #include <sys/stat.h>
@@ -22,8 +24,6 @@
 #include <string.h>
 #include <limits.h>
 #include <zlib.h>
-
-#include "got_compat.h"
 
 #include "got_object.h"
 #include "got_repository.h"
blob - d37a1fd485714bd6f5c33874d408479f38c3421e
blob + 46e322483b38fc4e63b2fed41be53cfb4227b6b3
--- lib/diff3.c
+++ lib/diff3.c
@@ -63,6 +63,8 @@
  *
  *	@(#)diff3.c	8.1 (Berkeley) 6/6/93
  */
+
+#include "got_compat.h"
 
 #include <sys/stat.h>
 #include <sys/queue.h>
blob - 2dff9d2217e21cccb6effd088b7af5ea1198e111
blob + 1b9c44d8abfd973a64562825814d314f19f3b6b8
--- lib/fetch.c
+++ lib/fetch.c
@@ -13,6 +13,7 @@
  * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
  * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  */
+#include "got_compat.h"
 
 #include <sys/types.h>
 #include <sys/stat.h>
blob - 1af66814fbade7825956cd89bee32c1d37572390
blob + 363fec6649f205294d5cb9333ac992bd62a07d9a
--- lib/fileindex.c
+++ lib/fileindex.c
@@ -13,6 +13,8 @@
  * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
  * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  */
+
+#include "got_compat.h"
 
 #include <sys/queue.h>
 #include <sys/stat.h>
@@ -25,8 +27,6 @@
 #include <string.h>
 #include <limits.h>
 #include <unistd.h>
-
-#include "got_compat.h"
 
 #include "got_error.h"
 #include "got_object.h"
blob - ca1719dd8649b956e27783774efab623fdba7ed8
blob + ac496f46223ff4b0af6a50e31808ff95280ff8c3
--- lib/gitproto.c
+++ lib/gitproto.c
@@ -14,6 +14,8 @@
  * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
  * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  */
+
+#include "got_compat.h"
 
 #include <sys/queue.h>
 #include <sys/types.h>
blob - cfdcf7fb14127a2fe5599dece9aa0969e6c76b0a
blob + 3dff610bd701189b93bfd4157175df7ada64b2fb
--- lib/inflate.c
+++ lib/inflate.c
@@ -25,6 +25,7 @@
 #include <zlib.h>
 #include <time.h>
 
+#include "got_compat.h"
 #include "got_error.h"
 #include "got_object.h"
 #include "got_path.h"
blob - e1a1870147bfefcb7e3caaaedf16d6b92e78a5c1
blob + 7bad6c71de40a22d1c400051508cdc928fad6b7e
--- lib/lockfile.c
+++ lib/lockfile.c
@@ -14,6 +14,8 @@
  * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  */
 
+#include "got_compat.h"
+
 #include <sys/stat.h>
 #include <sys/queue.h>
 
blob - 7e7e6427733241033f8682fc9be241bf5de1823a
blob + 45999e4f415da86af0a70702f0cd75bd530205e8
--- lib/object.c
+++ lib/object.c
@@ -13,6 +13,8 @@
  * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
  * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  */
+
+#include "got_compat.h"
 
 #include <sys/types.h>
 #include <sys/stat.h>
@@ -30,8 +32,6 @@
 #include <libgen.h>
 #include <limits.h>
 #include <imsg.h>
-
-#include "got_compat.h"
 
 #include "got_error.h"
 #include "got_object.h"
blob - b1da1e4401a9bbc8ff1965298c713b5f73d95ba7
blob + 0979fc02ac2ba25938969dd9d990fabb0a8b5492
--- lib/object_cache.c
+++ lib/object_cache.c
@@ -25,6 +25,7 @@
 #include <limits.h>
 #include <zlib.h>
 
+#include "got_compat.h"
 #include "got_error.h"
 #include "got_object.h"
 
blob - c32445b4ccf86a89d33fd154fc5385b75914045d
blob + 841e0607932a0e0e3833f2b1584f60dafe2027b0
--- lib/object_create.c
+++ lib/object_create.c
@@ -13,6 +13,8 @@
  * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
  * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  */
+
+#include "got_compat.h"
 
 #include <sys/types.h>
 #include <sys/stat.h>
@@ -29,8 +31,6 @@
 #include <stdint.h>
 #include <unistd.h>
 #include <zlib.h>
-
-#include "got_compat.h"
 
 #include "got_error.h"
 #include "got_object.h"
blob - 7c7d840b419d9c54504a2a26fdb31aec8a56906a
blob + 7dd29c4dcce0d135de22b133789e30d3d6f523c7
--- lib/object_open_io.c
+++ lib/object_open_io.c
@@ -15,7 +15,6 @@
  */
 
 #include <sys/queue.h>
-#include <sys/tree.h>
 #include <sys/stat.h>
 
 #include <errno.h>
blob - a09a1387ed6a59da493df3eba699bf1438a8006c
blob + 4ee0a7e63b6c05b45c15b8c9f3aceacce4ec4b1f
--- lib/object_open_privsep.c
+++ lib/object_open_privsep.c
@@ -30,6 +30,7 @@
 #include <limits.h>
 #include <unistd.h>
 
+#include "got_compat.h"
 #include "got_error.h"
 #include "got_object.h"
 #include "got_repository.h"
blob - 6d050459574522d3b15ab4d56ebd14f4c5c2bf9c
blob + a902ff1efd4ecf292aa42457d41225adb7c7349f
--- lib/object_parse.c
+++ lib/object_parse.c
@@ -13,6 +13,8 @@
  * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
  * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  */
+
+#include "got_compat.h"
 
 #include <sys/types.h>
 #include <sys/stat.h>
@@ -32,8 +34,6 @@
 #include <limits.h>
 #include <time.h>
 #include <unistd.h>
-
-#include "got_compat.h"
 
 #include "got_error.h"
 #include "got_object.h"
blob - df1d59c09c18d172241755b8756c1c74925ae5b3
blob + dbeda341626f70c8dcc4069dfe15c2de7219d792
--- lib/opentemp.c
+++ lib/opentemp.c
@@ -13,6 +13,7 @@
  * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
  * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  */
+#include "got_compat.h"
 
 #include <limits.h>
 #include <stdlib.h>
@@ -20,8 +21,6 @@
 #include <string.h>
 #include <stdio.h>
 
-#include "got_compat.h"
-
 #include "got_opentemp.h"
 #include "got_error.h"
 
blob - f0189ff480b44a73b0aa170458502a0c0deb3cd7
blob + 3ea305d9dc41eabfab9d1cff1c9f83bf8d7d35ef
--- lib/pack.c
+++ lib/pack.c
@@ -32,6 +32,7 @@
 #include <unistd.h>
 #include <zlib.h>
 
+#include "got_compat.h"
 #include "got_error.h"
 #include "got_object.h"
 #include "got_path.h"
blob - 7f48facde10d3f583396ed2c3e933d910b8ab006
blob + 5bb15337dc19cabc0e5b03479522f28b680ceb62
--- lib/pack_create.c
+++ lib/pack_create.c
@@ -15,6 +15,8 @@
  * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  */
 
+#include "got_compat.h"
+
 #include <sys/types.h>
 #include <sys/queue.h>
 #include <sys/uio.h>
@@ -33,10 +35,6 @@
 #include <unistd.h>
 #include <limits.h>
 #include <zlib.h>
-
-#if defined(__FreeBSD__)
-#include <unistd.h>
-#endif
 
 #include "got_error.h"
 #include "got_cancel.h"
blob - 9880eed03a11e8a23ca257f6506fb6bc465e2d6e
blob + 5b4a01d480e789483ffcf854bc3726c183bf3de9
--- lib/pack_create_io.c
+++ lib/pack_create_io.c
@@ -17,7 +17,6 @@
 
 #include <sys/types.h>
 #include <sys/queue.h>
-#include <sys/tree.h>
 #include <sys/uio.h>
 
 #include <limits.h>
blob - c142e7072d23a5474652d25759ba3212fcefc072
blob + df750db5b11d7271c0ba966ee9015336b00a0d8b
--- lib/pack_create_privsep.c
+++ lib/pack_create_privsep.c
@@ -29,6 +29,7 @@
 #include <inttypes.h>
 #include <unistd.h>
 
+#include "got_compat.h"
 #include "got_error.h"
 #include "got_cancel.h"
 #include "got_object.h"
blob - 5725bb0739ba291cf44b381849e3978306776011
blob + 69e5499d5cb289f6d9215e592c5eaa430e891b47
--- lib/pack_index.c
+++ lib/pack_index.c
@@ -14,6 +14,8 @@
  * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
  * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  */
+
+#include "got_compat.h"
 
 #include <sys/queue.h>
 #include <sys/stat.h>
blob - 33b5f481ddcb50dbde193904a0d6e81a6c684a0f
blob + 859db450301302dc99c3de2be338542c3ced2112
--- lib/patch.c
+++ lib/patch.c
@@ -19,6 +19,7 @@
  *     + support indented patches?
  *     + support other kinds of patches?
  */
+#include "got_compat.h"
 
 #include <sys/types.h>
 #include <sys/queue.h>
blob - 2d6982b9e7830aab3274aa68aa2ade900ffc82d2
blob + 1e3fa30aaad109ccf4c3139a2192ca76590d85de
--- lib/path.c
+++ lib/path.c
@@ -15,6 +15,8 @@
  * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
  * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  */
+
+#include "got_compat.h"
 
 #include <sys/queue.h>
 #include <sys/stat.h>
@@ -29,8 +31,6 @@
 #include <string.h>
 #include <dirent.h>
 #include <paths.h>
-
-#include "got_compat.h"
 
 #include "got_error.h"
 #include "got_path.h"
blob - 32efcd7f1a512fe6f1444aaba4ff7e8aa6d051b1
blob + 395fd95072c2e4346a204fa2ac44eb11c2dc9cd4
--- lib/pollfd.c
+++ lib/pollfd.c
@@ -14,6 +14,8 @@
  * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  */
 
+#include "got_compat.h"
+
 #include <errno.h>
 #include <stdio.h>
 #include <signal.h>
blob - bb395ed8acf27a029c07482c594674dc90ca0213
blob + e216540720a3f3a01b5d352278ae176d5785ea0f
--- lib/read_gitconfig_privsep.c
+++ lib/read_gitconfig_privsep.c
@@ -29,6 +29,7 @@
 #include <imsg.h>
 #include <unistd.h>
 
+#include "got_compat.h"
 #include "got_error.h"
 #include "got_object.h"
 #include "got_repository.h"
blob - f67367d1512081ce314c3fdd7062701103036d17
blob + 5ba07c04fa0d8b21bddc184dae05a45bfac49cf3
--- lib/read_gotconfig_privsep.c
+++ lib/read_gotconfig_privsep.c
@@ -28,6 +28,7 @@
 #include <imsg.h>
 #include <limits.h>
 
+#include "got_compat.h"
 #include "got_error.h"
 #include "got_object.h"
 #include "got_repository.h"
blob - 9edc17e29a83d241a4c94296f6a23e0c4335767f
blob + 1a28eb8bf0c585b2e04703c19a1c7b287ca3f878
--- lib/reference.c
+++ lib/reference.c
@@ -13,6 +13,8 @@
  * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
  * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  */
+
+#include "got_compat.h"
 
 #include <sys/types.h>
 #include <sys/queue.h>
@@ -28,8 +30,6 @@
 #include <zlib.h>
 #include <time.h>
 #include <libgen.h>
-
-#include "got_compat.h"
 
 #include "got_error.h"
 #include "got_object.h"
blob - f0c2434d5bb47c3df672fd0fc8a0de49c06ac979
blob + 46248935c1ba42e65fb336a5f2a6128774dc58ba
--- lib/repository.c
+++ lib/repository.c
@@ -13,6 +13,8 @@
  * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
  * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  */
+
+#include "got_compat.h"
 
 #include <sys/types.h>
 #include <sys/queue.h>
blob - 1f97d3b5f98fe4c353a3086843e69a8d679b7674
blob + 96c3b2f9a5dbefe4d4825ddaaa5115c2a7d187ff
--- lib/repository_admin.c
+++ lib/repository_admin.c
@@ -13,6 +13,8 @@
  * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
  * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  */
+
+#include "got_compat.h"
 
 #include <sys/types.h>
 #include <sys/queue.h>
blob - ee84f81fb3bd9c00203b1b436fa5915616a2cb14
blob + d823489f72203b7adc78e6127598a107a3e5df56
--- lib/send.c
+++ lib/send.c
@@ -14,6 +14,8 @@
  * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
  * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  */
+
+#include "got_compat.h"
 
 #include <sys/types.h>
 #include <sys/stat.h>
blob - bb6f7b48aba8f212300f99f8f6124870d2f9b8f4
blob + 636c1fd66bd630b65e959e51ebccac80c8acde76
--- lib/sigs.c
+++ lib/sigs.c
@@ -14,6 +14,8 @@
  * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  */
 
+#include "got_compat.h"
+
 #include <sys/time.h>
 #include <sys/types.h>
 #include <sys/stat.h>
@@ -35,7 +37,6 @@
 #include "got_opentemp.h"
 
 #include "got_sigs.h"
-#include "got_compat.h"
 #include "buf.h"
 
 #ifndef MIN
blob - 7527e3f4c10ad222e8c0ccc0033c317cc384b6e5
blob + 6d5ff023fd59a9646377f95da58b639f453d169c
--- lib/utf8.c
+++ lib/utf8.c
@@ -15,6 +15,8 @@
  * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  */
 
+#include "got_compat.h"
+
 #include <sys/types.h>
 
 #include <err.h>
@@ -23,8 +25,6 @@
 #include <wchar.h>
 #include <langinfo.h>
 
-#include "got_compat.h"
-
 #include "got_error.h"
 #include "got_utf8.h"
 
blob - 3276b68b2bd0121b814c2594012e2db83a044bc5
blob + ee745eb3f76fb98532e0b10186742954965ae7b4
--- lib/worktree.c
+++ lib/worktree.c
@@ -13,6 +13,8 @@
  * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
  * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  */
+
+#include "got_compat.h"
 
 #include <sys/stat.h>
 #include <sys/queue.h>
@@ -30,8 +32,6 @@
 #include <zlib.h>
 #include <fnmatch.h>
 #include <libgen.h>
-
-#include "got_compat.h"
 
 #include "got_error.h"
 #include "got_repository.h"
blob - 6899fcc655eccfe88e1d3e566ff3f224b5cbc71b
blob + da26fa9ba9a5717c35d77d398c8661e5fa721527
--- lib/worktree_open.c
+++ lib/worktree_open.c
@@ -13,6 +13,8 @@
  * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
  * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  */
+
+#include "got_compat.h"
 
 #include <sys/stat.h>
 #include <sys/queue.h>
blob - 6a2be18da50c95a41fe1f11c8dfd17abefb21b70
blob + d3e15704eff350d9b4d1e84aae6c744a1c3f1f50
--- libexec/got-fetch-pack/Makefile.am
+++ libexec/got-fetch-pack/Makefile.am
@@ -18,6 +18,9 @@ got_fetch_pack_SOURCES = \
 got_fetch_pack_DEPENDENCIES = $(top_builddir)/compat/libopenbsd-compat.a
 
 LDADD = -L$(top_builddir)/compat -lopenbsd-compat
+LDADD += $(zlib_LIBS) $(libbsd_LIBS) $(libutil_LIBS) $(libcrypto_LIBS)
 if HOST_FREEBSD
 LDADD += -lmd
 endif
+
+AM_CPPFLAGS += $(zlib_CFLAGS) $(libbsd_CFLAGS) $(libcrypto_CFLAGS)
blob - d852e112633cdbfe94352f5847d90ec6709be8b3
blob + 08963fe3894f2dbb94cd6b8a0e86fa7998b59b04
--- libexec/got-index-pack/Makefile.am
+++ libexec/got-index-pack/Makefile.am
@@ -20,6 +20,9 @@ got_index_pack_SOURCES = got-index-pack.c \
 got_index_pack_DEPENDENCIES = $(top_builddir)/compat/libopenbsd-compat.a
 
 LDADD = -L$(top_builddir)/compat -lopenbsd-compat
+LDADD += $(libbsd_LIBS) $(zlib_LIBS) $(libutil_LIBS)
 if HOST_FREEBSD
 LDADD += -lmd
 endif
+
+AM_CPPFLAGS += $(libbsd_CFLAGS) $(zlib_CFLAGS)
blob - 38cdb5cd39d08a91da9319b72a9899f0f569cb01
blob + f2bf2185dc27d0f3e9af94ce9669b99b2a0f2c82
--- libexec/got-index-pack/got-index-pack.c
+++ libexec/got-index-pack/got-index-pack.c
@@ -29,6 +29,7 @@
 #include <time.h>
 #include <unistd.h>
 
+#include "got_compat.h"
 #include "got_error.h"
 #include "got_object.h"
 
blob - 9ab6c6a286c3fa240c495a586a5ee561bbf7e2a0
blob + 5e1763a7c2298cd68284b381fc7f9ffa176a01b9
--- libexec/got-read-blob/Makefile.am
+++ libexec/got-read-blob/Makefile.am
@@ -14,6 +14,9 @@ got_read_blob_SOURCES = got-read-blob.c \
 got_read_blob_DEPENDENCIES = $(top_builddir)/compat/libopenbsd-compat.a
 
 LDADD = -L$(top_builddir)/compat -lopenbsd-compat
+LDADD += $(zlib_LIBS) $(libbsd_LIBS) $(libutil_LIBS)
 if HOST_FREEBSD
 LDADD += -lmd
 endif
+
+AM_CPPFLAGS += $(zlib_CFLAGS) $(libbsd_CFLAGS)
blob - bd1c4bd26e47dc7f60a0ebd3b31f6bb47d359882
blob + 7eb4daa52dbbdd30cce5f459dd32400df7fab773
--- libexec/got-read-commit/Makefile.am
+++ libexec/got-read-commit/Makefile.am
@@ -14,6 +14,9 @@ got_read_commit_SOURCES = got-read-commit.c \
 got_read_commit_DEPENDENCIES = $(top_builddir)/compat/libopenbsd-compat.a
 
 LDADD = -L$(top_builddir)/compat -lopenbsd-compat
+LDADD += $(zlib_LIBS) $(libbsd_LIBS) $(libutil_LIBS)
 if HOST_FREEBSD
 LDADD += -lmd
 endif
+
+AM_CPPFLAGS += $(zlib_CFLAGS) $(libbsd_CFLAGS)
blob - 6f4bc67b67cb1ca9ebb0a43838b974d77126840f
blob + af3a1fe174af011007b96f738f43fa79b54be709
--- libexec/got-read-gitconfig/Makefile.am
+++ libexec/got-read-gitconfig/Makefile.am
@@ -15,6 +15,9 @@ got_read_gitconfig_SOURCES = got-read-gitconfig.c \
 got_read_gitconfig_DEPENDENCIES = $(top_builddir)/compat/libopenbsd-compat.a
 
 LDADD = -L$(top_builddir)/compat -lopenbsd-compat
+LDADD += $(zlib_LIBS) $(libbsd_LIBS) $(libutil_LIBS)
 if HOST_FREEBSD
 LDADD += -lmd
 endif
+
+AM_CPPFLAGS += $(zlib_CFLAGS) $(libbsd_CFLAGS)
blob - 86ea9e12ca0b24ed15206cf2445968d6c6478b6b
blob + 4dfcd454f8b8fe0a82ed43b7200624d9eeb1748e
--- libexec/got-read-gotconfig/Makefile.am
+++ libexec/got-read-gotconfig/Makefile.am
@@ -17,6 +17,9 @@ got_read_gotconfig_SOURCES = \
 got_read_gotconfig_DEPENDENCIES = $(top_builddir)/compat/libopenbsd-compat.a
 
 LDADD = -L$(top_builddir)/compat -lopenbsd-compat
+LDADD += $(libbsd_LIBS) $(zlib_LIBS) $(libutil_LIBS)
 if HOST_FREEBSD
 LDADD += -lmd
 endif
+
+AM_CPPFLAGS += $(libbsd_CFLAGS) $(zlib_CFLAGS)
blob - 4236ba777f0f997b7f5c92ac68e2480a8f3bf64f
blob + 3059b04c7096a2c0e70448da106d41c4d9ea6530
--- libexec/got-read-gotconfig/got-read-gotconfig.c
+++ libexec/got-read-gotconfig/got-read-gotconfig.c
@@ -13,6 +13,8 @@
  * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
  * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  */
+
+#include "got_compat.h"
 
 #include <sys/types.h>
 #include <sys/queue.h>
@@ -27,8 +29,6 @@
 #include <string.h>
 #include <unistd.h>
 #include <zlib.h>
-
-#include "got_compat.h"
 
 #include "got_error.h"
 #include "got_object.h"
blob - 4e401e4d65b837c06a88508dfcbbfee8fb5741ae
blob + 081c519fdcfb2ad018a4a0b2f954a5bbe6571115
--- libexec/got-read-gotconfig/parse.y
+++ libexec/got-read-gotconfig/parse.y
@@ -22,6 +22,8 @@
  */
 
 %{
+#include "got_compat.h"
+
 #include <sys/types.h>
 #include <sys/queue.h>
 
@@ -35,8 +37,6 @@
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
-
-#include "got_compat.h"
 
 #include "got_error.h"
 #include "gotconfig.h"
blob - 46d2a7c56d65fa37dcc62a462f84a92a70b65e0a
blob + d05d5e2c420f75b9af95993c11631b3682820d71
--- libexec/got-read-object/Makefile.am
+++ libexec/got-read-object/Makefile.am
@@ -14,6 +14,9 @@ got_read_object_SOURCES = got-read-object.c \
 got_read_object_DEPENDENCIES = $(top_builddir)/compat/libopenbsd-compat.a
 
 LDADD = -L$(top_builddir)/compat -lopenbsd-compat
+LDADD += $(zlib_LIBS) $(libbsd_LIBS) $(libutil_LIBS)
 if HOST_FREEBSD
 LDADD += -lmd
 endif
+
+AM_CPPFLAGS += $(zlib_CFLAGS) $(libbsd_CFLAGS)
blob - 05974a29a421a297f80ef43a9dc63821d4c79360
blob + 98b9000d490b932080c1fcb12680dafeca89d2c9
--- libexec/got-read-pack/Makefile.am
+++ libexec/got-read-pack/Makefile.am
@@ -20,6 +20,9 @@ got_read_pack_SOURCES = got-read-pack.c \
 got_read_pack_DEPENDENCIES = $(top_builddir)/compat/libopenbsd-compat.a
 
 LDADD = -L$(top_builddir)/compat -lopenbsd-compat
+LDADD += $(zlib_LIBS) $(libbsd_LIBS) $(libutil_LIBS)
 if HOST_FREEBSD
 LDADD += -lmd
 endif
+
+AM_CPPFLAGS += $(zlib_CFLAGS) $(libbsd_CFLAGS)
blob - 13179ad27a006789e9d95798304f06ea601f25df
blob + da45705204927e59fcf0cd17efc003bdd2b91ac6
--- libexec/got-read-pack/got-read-pack.c
+++ libexec/got-read-pack/got-read-pack.c
@@ -13,6 +13,7 @@
  * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
  * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  */
+#include "got_compat.h"
 
 #include <sys/stat.h>
 #include <sys/types.h>
@@ -31,8 +32,6 @@
 #include <unistd.h>
 #include <zlib.h>
 
-#include "got_compat.h"
-
 #include "got_error.h"
 #include "got_object.h"
 #include "got_path.h"
blob - 9ed6fe35804911506385cd1c2746e3a1e98067dc
blob + cc33b5462261c6fcf82069d88a969fc43fef2545
--- libexec/got-read-patch/Makefile.am
+++ libexec/got-read-patch/Makefile.am
@@ -14,6 +14,9 @@ got_read_patch_SOURCES = got-read-patch.c \
 got_read_patch_DEPENDENCIES = $(top_builddir)/compat/libopenbsd-compat.a
 
 LDADD = -L$(top_builddir)/compat -lopenbsd-compat
+LDADD += $(zlib_LIBS) $(libbsd_LIBS) $(libutil_LIBS)
 if HOST_FREEBSD
 LDADD += -lmd
 endif
+
+AM_CPPFLAGS += $(zlib_CFLAGS) $(libbsd_CFLAGS)
blob - 0674441331f634dc5326c1b041622ea0e37a3121
blob + 356a98a6a2717f7b336945d2f9e218faf421ebda
--- libexec/got-read-patch/got-read-patch.c
+++ libexec/got-read-patch/got-read-patch.c
@@ -34,6 +34,7 @@
  * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
  * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  */
+#include "got_compat.h"
 
 #include <sys/types.h>
 #include <sys/queue.h>
@@ -51,8 +52,6 @@
 #include "got_error.h"
 #include "got_object.h"
 
-#include "got_compat.h"
-
 #include "got_lib_delta.h"
 #include "got_lib_object.h"
 #include "got_lib_privsep.h"
blob - c13b228359922b649e53fcfdc3c2a69e2b7f7ebd
blob + 64c60b679bd8e405282728742e87a069a9645938
--- libexec/got-read-tag/Makefile.am
+++ libexec/got-read-tag/Makefile.am
@@ -14,6 +14,9 @@ got_read_tag_SOURCES = got-read-tag.c \
 got_read_tag_DEPENDENCIES = $(top_builddir)/compat/libopenbsd-compat.a
 
 LDADD = -L$(top_builddir)/compat -lopenbsd-compat
+LDADD += $(zlib_LIBS) $(libbsd_LIBS) $(libutil_LIBS)
 if HOST_FREEBSD
 LDADD += -lmd
 endif
+
+AM_CPPFLAGS += $(zlib_CFLAGS) $(libbsd_CFLAGS)
blob - 33c3af015b63b520d339d28d77f2ac2a810e3476
blob + b0dbebd8f90e8b23398f7e49ddad72a38b51fbc9
--- libexec/got-read-tree/Makefile.am
+++ libexec/got-read-tree/Makefile.am
@@ -14,6 +14,9 @@ got_read_tree_SOURCES = got-read-tree.c \
 got_read_tree_DEPENDENCIES = $(top_builddir)/compat/libopenbsd-compat.a
 
 LDADD = -L$(top_builddir)/compat -lopenbsd-compat
+LDADD += $(zlib_LIBS) $(libbsd_LIBS) $(libutil_LIBS)
 if HOST_FREEBSD
 LDADD += -lmd
 endif
+
+AM_CPPFLAGS += $(zlib_CFLAGS) $(libbsd_CFLAGS)
blob - f8f9345baade6c8e051dd05ab8d63a204e5f9cef
blob + d3f32157b24e52e3e5a8b544be4a700484256514
--- libexec/got-send-pack/Makefile.am
+++ libexec/got-send-pack/Makefile.am
@@ -19,6 +19,9 @@ got_send_pack_SOURCES = \
 got_send_pack_DEPENDENCIES = $(top_builddir)/compat/libopenbsd-compat.a
 
 LDADD = -L$(top_builddir)/compat -lopenbsd-compat
+LDADD += $(zlib_LIBS) $(libbsd_LIBS) $(libutil_LIBS)
 if HOST_FREEBSD
 LDADD += -lmd
 endif
+
+AM_CPPFLAGS += $(zlib_CFLAGS) $(libbsd_CFLAGS)
blob - 6d16143a6eaa88639c64666308cd31dc48b99012
blob + 48bdedda02f983189b3ee1273078927953fa18e8
--- libexec/got-send-pack/got-send-pack.c
+++ libexec/got-send-pack/got-send-pack.c
@@ -34,6 +34,7 @@
 #include <zlib.h>
 #include <err.h>
 
+#include "got_compat.h"
 #include "got_error.h"
 #include "got_object.h"
 #include "got_path.h"
blob - a217b4ba7e1b2c2eb6b606300599ec14ee4221ae
blob + c37288bd51b1eba89d4abfc4df748012809f86d2
--- tog/Makefile.am
+++ tog/Makefile.am
@@ -60,6 +60,9 @@ man1_MANS = tog.1
 EXTRA_DIST = tog.1
 
 LDADD = -L$(top_builddir)/compat -lopenbsd-compat -lpthread -lm
+LDADD += $(libbsd_LIBS) $(libncurses_LIBS) $(libuuid_LIBS) $(zlib_LIBS) $(libutil_LIBS)
 if HOST_FREEBSD
 LDADD += -lmd
 endif
+
+AM_CPPFLAGS += $(libbsd_CFLAGS) $(libncurses_CFLAGS) $(libuuid_CFLAGS)
blob - 538114b0dd798c030f1eb44257fbac707152a44f
blob + 7a443c32222603c98870189473ea2ab0ce7289d0
--- tog/tog.c
+++ tog/tog.c
@@ -13,6 +13,8 @@
  * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
  * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  */
+
+#include "got_compat.h"
 
 #include <sys/queue.h>
 #include <sys/stat.h>
@@ -41,8 +43,6 @@
 #include <libgen.h>
 #include <regex.h>
 #include <sched.h>
-
-#include "got_compat.h"
 
 #include "got_version.h"
 #include "got_error.h"