Subject: [Bug] Compat objects not added to CLAR_TEST_PROG

From: "Osipov, Michael (IN IT IN)" <[email-masked]>
Date: Fri, 5 Sep 2025 15:19:50 +0200

Hi folks,

I am building Git 2.51.0 on HP-UX 11.31, previous releases went 
smoothly. This release now fails with:
> "t/unit-tests/clar/clar.c", line 90: warning #2047-D: incompatible
>           redefinition of macro "MAX" (declared at line 426 of
>           "/usr/include/sys/param.h")
>   #define MAX(x, y) (((x) > (y)) ? (x) : (y))
>           ^
> 
> "t/unit-tests/clar/clar/sandbox.h", line 138: warning #2223-D: function
>           "mkdtemp" declared implicitly
>         if (mkdtemp(_clar_path) == NULL)
>             ^
> 
> ld: Unsatisfied symbol "mkdtemp" in file t/unit-tests/clar/clar.o
> 1 error.
> gmake: *** [Makefile:3938: t/unit-tests/bin/unit-tests] Error 1
> gmake: *** Deleting file 't/unit-tests/bin/unit-tests'

HP-UX' libc does not contain mkdtemp() and the configure script properly 
detects this. NO_MKDTEMP is passed and the gitmkdtemp() function in 
compat/ is compiled. sandbox.h makes use of mkdtemp(), but never 
includes the protoype and the actual object isn't added to the linker path.
I have written a minimalistic patch (see attachment), maybe there is a 
better way. This perfectly works for me now with other warnings:
> "t/unit-tests/clar/clar.c", line 90: warning #2047-D: incompatible
>           redefinition of macro "MAX" (declared at line 426 of
>           "/usr/include/sys/param.h")
>   #define MAX(x, y) (((x) > (y)) ? (x) : (y))
>           ^
> 
> "t/unit-tests/clar/clar/../../../../compat/posix.h", line 68: warning #2047-D:
>           incompatible redefinition of macro "_XOPEN_SOURCE_EXTENDED"
>           (declared at line 260 of "/usr/include/sys/stdsyms.h")
>   #define _XOPEN_SOURCE_EXTENDED 1 /* AIX 5.3L needs this */
>           ^
> 
> "t/unit-tests/clar/clar/../../../../compat/posix.h", line 72: warning #2047-D:
>           incompatible redefinition of macro "_BSD_SOURCE" (declared at line 8
>           of "t/unit-tests/clar/clar.c")
>   #define _BSD_SOURCE 1
>           ^
> 
> "t/unit-tests/clar/clar/../../../../compat/posix.h", line 73: warning #2047-D:
>           incompatible redefinition of macro "_DEFAULT_SOURCE" (declared at
>           line 10 of "t/unit-tests/clar/clar.c")
>   #define _DEFAULT_SOURCE 1
>           ^

Executable in question:> root@deblndw002x:/var/tmp/ports/work
> # nm git-2.51.0.patched/t/unit-tests/bin/unit-tests | grep mkdtemp
> [1052]   |            0|       0|FILE |LOCAL|0|     ABS|compat/mkdtemp.c
> [16407]  |     69365552|     272|FUNC |GLOB |0|   .text|gitmkdtemp

Would be nice to bring this upstream for HP-UX and non-HP-UX of course.

Michael
diff -u -ur Makefile Makefile
--- Makefile	2025-08-18 02:35:38 +0200
+++ Makefile	2025-09-05 14:34:43 +0200
@@ -3933,7 +3933,7 @@
 $(UNIT_TEST_DIR)/clar/clar.o: $(UNIT_TEST_DIR)/clar.suite
 $(CLAR_TEST_OBJS): $(UNIT_TEST_DIR)/clar-decls.h
 $(CLAR_TEST_OBJS): EXTRA_CPPFLAGS = -I$(UNIT_TEST_DIR)
-$(CLAR_TEST_PROG): $(UNIT_TEST_DIR)/clar.suite $(CLAR_TEST_OBJS) $(GITLIBS) GIT-LDFLAGS
+$(CLAR_TEST_PROG): $(UNIT_TEST_DIR)/clar.suite $(CLAR_TEST_OBJS) $(COMPAT_OBJS) $(GITLIBS) GIT-LDFLAGS
 	$(call mkdir_p_parent_template)
 	$(QUIET_LINK)$(CC) $(ALL_CFLAGS) -o $@ $(ALL_LDFLAGS) $(filter %.o,$^) $(LIBS)
 
diff -u -ur t/unit-tests/clar/clar/sandbox.h git-2.51.0.patched/t/unit-tests/clar/clar/sandbox.h
--- t/unit-tests/clar/clar/sandbox.h	2025-08-18 02:35:38 +0200
+++ t/unit-tests/clar/clar/sandbox.h	2025-09-05 14:10:52 +0200
@@ -2,6 +2,8 @@
 #include <sys/syslimits.h>
 #endif
 
+#include "../../../../compat/posix.h"
+
 static char _clar_path[4096 + 1];
 
 static int