From bcc6816b92ecf409357865589069a82883d589f7 Mon Sep 17 00:00:00 2001
From: Khem Raj <raj.khem@gmail.com>
Date: Tue, 6 Sep 2022 22:53:51 -0700
Subject: [PATCH] scripts/build: Fix the tests to build with clang15

Upstream-Status: Pending
Signed-off-by: Khem Raj <raj.khem@gmail.com>
---
 scripts/build | 50 +++++++++++++++++++++++++-------------------------
 1 file changed, 25 insertions(+), 25 deletions(-)

--- a/scripts/build
+++ b/scripts/build
@@ -21,7 +21,7 @@ trap 'rm -f ${BASE}$$.s ${BASE}$$.c ${BA
 LDLIBS="$LDLIBS -lm"
 
 # check for HP-UX's ANSI compiler
-echo "main(int ac, char *av[]) { int i; }" > ${BASE}$$.c
+echo "int main(int ac, char *av[]) { int i; }" > ${BASE}$$.c
 if ${CC} ${CFLAGS} -o ${BASE}$$ ${BASE}$$.c 1>${NULL} 2>${NULL}
 then
 	true;
@@ -39,7 +39,7 @@ arch=`echo $OS | awk -F- '{print $1;}'`
 if [ "X$CC" = "Xcc" -a "X$arch" = "Xia64" ]
 then
 	echo "#include <stdlib.h>" > ${BASE}$$.c
-	echo "main(int ac, char *av[])" >> ${BASE}$$.c
+	echo "int main(int ac, char *av[])" >> ${BASE}$$.c
 	echo "{ long* p = (long*)malloc(sizeof(long));" >> ${BASE}$$.c
 	echo "*p = 0; exit((int)*p); }" >> ${BASE}$$.c
 	${CC} ${CFLAGS} +DD64 -o ${BASE}$$ ${BASE}$$.c 1>${NULL} 2>${NULL} \
@@ -51,14 +51,14 @@ fi
 
 # check for bcopy (optionally set the SYS5 flag)
 echo "#include <string.h>" > ${BASE}$$.c
-echo "main() { char a[256], b[256]; bcopy(a, b, 256); }" >> ${BASE}$$.c
+echo "int main() { char a[256], b[256]; bcopy(a, b, 256); }" >> ${BASE}$$.c
 ${CC} ${CFLAGS} -o ${BASE}$$ ${BASE}$$.c ${LDLIBS} 1>${NULL} 2>${NULL} \
 	|| CFLAGS="${CFLAGS} -DSYS5"
 rm -f ${BASE}$$ ${BASE}$$.o ${BASE}$$.c
 
 # check for valloc
 echo "#include <stdlib.h>" > ${BASE}$$.c
-echo "main() { char* buf = valloc(123); }" >> ${BASE}$$.c
+echo "int main() { char* buf = valloc(123); }" >> ${BASE}$$.c
 ${CC} ${CFLAGS} -o ${BASE}$$ ${BASE}$$.c ${LDLIBS} 1>${NULL} 2>${NULL} \
 	|| CFLAGS="${CFLAGS} -Dvalloc=malloc"
 rm -f ${BASE}$$ ${BASE}$$.o ${BASE}$$.c
@@ -67,7 +67,7 @@ rm -f ${BASE}$$ ${BASE}$$.o ${BASE}$$.c
 echo "#include <stdlib.h>" > ${BASE}$$.c
 echo "#include <sys/types.h>" >> ${BASE}$$.c
 echo "#include <unistd.h>" >> ${BASE}$$.c
-echo "main() { off64_t off; }" >> ${BASE}$$.c
+echo "int main() { off64_t off; }" >> ${BASE}$$.c
 ${CC} ${CFLAGS} -o ${BASE}$$ ${BASE}$$.c ${LDLIBS} 1>${NULL} 2>${NULL} \
 	&& CFLAGS="${CFLAGS} -DHAVE_off64_t"
 rm -f ${BASE}$$ ${BASE}$$.o ${BASE}$$.c
@@ -76,7 +76,7 @@ rm -f ${BASE}$$ ${BASE}$$.o ${BASE}$$.c
 echo "#include <stdlib.h>" > ${BASE}$$.c
 echo "#include <sys/types.h>" >> ${BASE}$$.c
 echo "#include <unistd.h>" >> ${BASE}$$.c
-echo "main() { int fd = 0; off64_t off = 0; off = lseek64(fd, off, SEEK_SET); }" >> ${BASE}$$.c
+echo "int main() { int fd = 0; off64_t off = 0; off = lseek64(fd, off, SEEK_SET); }" >> ${BASE}$$.c
 ${CC} ${CFLAGS} -o ${BASE}$$ ${BASE}$$.c ${LDLIBS} 1>${NULL} 2>${NULL} \
 	&& CFLAGS="${CFLAGS} -DHAVE_lseek64"
 rm -f ${BASE}$$ ${BASE}$$.o ${BASE}$$.c
@@ -88,7 +88,7 @@ echo "#include <sys/resource.h>" >> ${BA
 echo "#ifndef RUSAGE_SELF" >> ${BASE}$$.c
 echo "#define RUSAGE_SELF 0" >> ${BASE}$$.c
 echo "#endif /* RUSAGE_SELF */" >> ${BASE}$$.c
-echo "main() { struct rusage ru; getrusage(RUSAGE_SELF, &ru); }" >> ${BASE}$$.c
+echo "int main() { struct rusage ru; getrusage(RUSAGE_SELF, &ru); }" >> ${BASE}$$.c
 ${CC} ${CFLAGS} -o ${BASE}$$ ${BASE}$$.c ${LDLIBS} 1>${NULL} 2>${NULL} \
 	&& CFLAGS="${CFLAGS} -DRUSAGE"
 rm -f ${BASE}$$ ${BASE}$$.o ${BASE}$$.c
@@ -125,24 +125,24 @@ fi
 rm -f ${BASE}$$ ${BASE}$$.o ${BASE}$$.c
 
 # check for -lrpc (cygwin/Windows)
-echo "extern int pmap_set(); main() { pmap_set(); }" >${BASE}$$.c
+echo "extern int pmap_set(void); int main() { pmap_set(); }" >${BASE}$$.c
 if ${CC} ${CFLAGS} -o ${BASE}$$ ${BASE}$$.c ${LDLIBS} 1>${NULL} 2>${NULL}; then
        true;
-else
-       ${CC} ${CFLAGS} -o ${BASE}$$ ${BASE}$$.c ${LDLIBS} -lrpc 1>${NULL} 2>${NULL} \
-               && LDLIBS="${LDLIBS} -lrpc"
+elif ${CC} ${CFLAGS} -o ${BASE}$$ ${BASE}$$.c ${LDLIBS} -lrpc 1>${NULL} 2>${NULL}; then
+      LDLIBS="${LDLIBS} -lrpc"
+else ${CC} ${CFLAGS} -o ${BASE}$$ ${BASE}$$.c ${LDLIBS} -ltirpc 1>${NULL} 2>${NULL} && LDLIBS="${LDLIBS} -ltirpc"
 fi
 rm -f ${BASE}$$ ${BASE}$$.o ${BASE}$$.c
 
 # check for OSs that have S_IFFIFO instead of S_IFIFO
 echo "#include <sys/stat.h>" > ${BASE}$$.c
-echo "main() { return (S_IFIFO); }" >> ${BASE}$$.c
+echo "int main() { return (S_IFIFO); }" >> ${BASE}$$.c
 if ${CC} ${CFLAGS} -o ${BASE}$$ ${BASE}$$.c ${LDLIBS} 1>${NULL} 2>${NULL}; then
 	true;
 else
 	rm -f ${BASE}$$ ${BASE}$$.o ${BASE}$$.c
 	echo "#include <sys/stat.h>" > ${BASE}$$.c
-	echo "main() { return (S_IFFIFO); }" >> ${BASE}$$.c
+	echo "int main() { return (S_IFFIFO); }" >> ${BASE}$$.c
 	${CC} ${CFLAGS} -o ${BASE}$$ ${BASE}$$.c ${LDLIBS} 1>${NULL} 2>${NULL} \
 		|| CFLAGS="${CFLAGS} -DS_IFIFO=S_IFFIFO"
 fi
@@ -151,7 +151,7 @@ rm -f ${BASE}$$ ${BASE}$$.o ${BASE}$$.c
 # check that we have uint
 echo "#include <stdlib.h>" > ${BASE}$$.c
 echo "#include <sys/types.h>" >> ${BASE}$$.c
-echo "main() { uint i = 0; return (i); }" >> ${BASE}$$.c
+echo "int main() { uint i = 0; return (i); }" >> ${BASE}$$.c
 ${CC} ${CFLAGS} -o ${BASE}$$ ${BASE}$$.c ${LDLIBS} 1>${NULL} 2>${NULL} \
 	&& CFLAGS="${CFLAGS} -DHAVE_uint=1";
 rm -f ${BASE}$$ ${BASE}$$.o ${BASE}$$.c
@@ -161,7 +161,7 @@ HAVE_uint64=0
 echo "#include <stdlib.h>" > ${BASE}$$.c
 echo "#include <sys/types.h>" >> ${BASE}$$.c
 echo "#include <rpc/types.h>" >> ${BASE}$$.c
-echo "main() { uint64 i = 0; return (int)(i); }" >> ${BASE}$$.c
+echo "int main() { uint64 i = 0; return (int)(i); }" >> ${BASE}$$.c
 ${CC} ${CFLAGS} -o ${BASE}$$ ${BASE}$$.c ${LDLIBS} 1>${NULL} 2>${NULL} \
 	&& CFLAGS="${CFLAGS} -DHAVE_uint64=1" && HAVE_uint64=1;
 rm -f ${BASE}$$ ${BASE}$$.o ${BASE}$$.c
@@ -170,7 +170,7 @@ rm -f ${BASE}$$ ${BASE}$$.o ${BASE}$$.c
 if [ ${HAVE_uint64} = 0 ]; then
     echo "#include <stdlib.h>" > ${BASE}$$.c
     echo "#include <sys/types.h>" >> ${BASE}$$.c
-    echo "main() { uint64_t i = 0; return (int)(i); }" >> ${BASE}$$.c
+    echo "int main() { uint64_t i = 0; return (int)(i); }" >> ${BASE}$$.c
     ${CC} ${CFLAGS} -o ${BASE}$$ ${BASE}$$.c ${LDLIBS} 1>${NULL} 2>${NULL} \
 	&& CFLAGS="${CFLAGS} -DHAVE_uint64_t=1";
     rm -f ${BASE}$$ ${BASE}$$.o ${BASE}$$.c
@@ -181,7 +181,7 @@ HAVE_int64=0
 echo "#include <stdlib.h>" > ${BASE}$$.c
 echo "#include <sys/types.h>" >> ${BASE}$$.c
 echo "#include <rpc/types.h>" >> ${BASE}$$.c
-echo "main() { int64 i = 0; return (int)(i); }" >> ${BASE}$$.c
+echo "int main() { int64 i = 0; return (int)(i); }" >> ${BASE}$$.c
 ${CC} ${CFLAGS} -o ${BASE}$$ ${BASE}$$.c ${LDLIBS} 1>${NULL} 2>${NULL} \
 	&& CFLAGS="${CFLAGS} -DHAVE_int64=1" && HAVE_int64=1;
 rm -f ${BASE}$$ ${BASE}$$.o ${BASE}$$.c
@@ -190,7 +190,7 @@ rm -f ${BASE}$$ ${BASE}$$.o ${BASE}$$.c
 if [ ${HAVE_int64} = 0 ]; then
     echo "#include <stdlib.h>" > ${BASE}$$.c
     echo "#include <sys/types.h>" >> ${BASE}$$.c
-    echo "main() { int64_t i = 0; return (int)(i); }" >> ${BASE}$$.c
+    echo "int main() { int64_t i = 0; return (int)(i); }" >> ${BASE}$$.c
     ${CC} ${CFLAGS} -o ${BASE}$$ ${BASE}$$.c ${LDLIBS} 1>${NULL} 2>${NULL} \
 	&& CFLAGS="${CFLAGS} -DHAVE_int64_t=1";
     rm -f ${BASE}$$ ${BASE}$$.o ${BASE}$$.c
@@ -209,7 +209,7 @@ rm -f ${BASE}$$ ${BASE}$$.o ${BASE}$$.c
 echo "#include <stdlib.h>" > ${BASE}$$.c
 echo "#include <sys/types.h>" >> ${BASE}$$.c
 echo "#include <sys/socket.h>" >> ${BASE}$$.c
-echo "main() { int s; struct sockaddr dest; socklen_t len; getsockname(s, &dest, &len); }" >> ${BASE}$$.c
+echo "int main() { int s; struct sockaddr dest; socklen_t len; getsockname(s, &dest, &len); }" >> ${BASE}$$.c
 ${CC} ${CFLAGS} -o ${BASE}$$ ${BASE}$$.c ${LDLIBS} 1>${NULL} 2>${NULL} \
 	&& CFLAGS="${CFLAGS} -DHAVE_socklen_t"
 rm -f ${BASE}$$ ${BASE}$$.o ${BASE}$$.c
@@ -217,7 +217,7 @@ rm -f ${BASE}$$ ${BASE}$$.o ${BASE}$$.c
 # check that we have drand48 and srand48
 HAVE_RANDOM=0
 echo "#include <stdlib.h>" > ${BASE}$$.c
-echo "main() { srand48(973); return (int)(1.0E9 * drand48()); }" >> ${BASE}$$.c
+echo "int main() { srand48(973); return (int)(1.0E9 * drand48()); }" >> ${BASE}$$.c
 if ${CC} ${CFLAGS} -o ${BASE}$$ ${BASE}$$.c ${LDLIBS} 1>${NULL} 2>${NULL}; then
 	CFLAGS="${CFLAGS} -DHAVE_DRAND48"
 	HAVE_RANDOM=1
@@ -226,7 +226,7 @@ rm -f ${BASE}$$ ${BASE}$$.o ${BASE}$$.c
 
 if [ ${HAVE_RANDOM} -eq 0 ]; then
     echo "#include <stdlib.h>" > ${BASE}$$.c
-    echo "main() { srand(973); return (10 * rand()) / RAND_MAX; }" >> ${BASE}$$.c
+    echo "int main() { srand(973); return (10 * rand()) / RAND_MAX; }" >> ${BASE}$$.c
     if ${CC} ${CFLAGS} -o ${BASE}$$ ${BASE}$$.c ${LDLIBS} 1>${NULL} 2>${NULL}; then
 	CFLAGS="${CFLAGS} -DHAVE_RAND"
 	HAVE_RANDOM=1
@@ -236,7 +236,7 @@ fi
 
 if [ ${HAVE_RANDOM} -eq 0 ]; then
     echo "#include <stdlib.h>" > ${BASE}$$.c
-    echo "main() { srandom(973); return (10 * random()) / RAND_MAX; }" >> ${BASE}$$.c
+    echo "int main() { srandom(973); return (10 * random()) / RAND_MAX; }" >> ${BASE}$$.c
     if ${CC} ${CFLAGS} -o ${BASE}$$ ${BASE}$$.c ${LDLIBS} 1>${NULL} 2>${NULL}; then
 	CFLAGS="${CFLAGS} -DHAVE_RANDOM"
 	HAVE_RANDOM=1
@@ -247,7 +247,7 @@ fi
 # check that we have sysmp
 echo "#include <sys/types.h>" > ${BASE}$$.c
 echo "#include <sys/sysmp.h>" >> ${BASE}$$.c
-echo "main() { return (int)sysmp(MP_NPROCS); }" >> ${BASE}$$.c
+echo "int main() { return (int)sysmp(MP_NPROCS); }" >> ${BASE}$$.c
 ${CC} ${CFLAGS} -o ${BASE}$$ ${BASE}$$.c ${LDLIBS} 1>${NULL} 2>${NULL} \
 	&& CFLAGS="${CFLAGS} -DHAVE_SYSMP=1";
 rm -f ${BASE}$$ ${BASE}$$.o ${BASE}$$.c
@@ -257,7 +257,7 @@ echo "#include <stdlib.h>" > ${BASE}$$.c
 echo "#include <unistd.h>" >> ${BASE}$$.c
 echo "#include <sys/types.h>" >> ${BASE}$$.c
 echo "#include <sys/processor.h>" >> ${BASE}$$.c
-echo "main() { return bindprocessor(BINDPROCESS, getpid(), 0); }" >> ${BASE}$$.c
+echo "int main() { return bindprocessor(BINDPROCESS, getpid(), 0); }" >> ${BASE}$$.c
 ${CC} ${CFLAGS} -o ${BASE}$$ ${BASE}$$.c ${LDLIBS} 1>${NULL} 2>${NULL} \
 	&& CFLAGS="${CFLAGS} -DHAVE_BINDPROCESSOR=1";
 rm -f ${BASE}$$ ${BASE}$$.o ${BASE}$$.c
@@ -267,16 +267,17 @@ echo "#include <stdlib.h>" > ${BASE}$$.c
 echo "#include <sys/types.h>" >> ${BASE}$$.c
 echo "#include <sys/processor.h>" >> ${BASE}$$.c
 echo "#include <sys/procset.h>" >> ${BASE}$$.c
-echo "main() { return processor(P_PID, P_MYPID, 0, NULL); }" >> ${BASE}$$.c
+echo "int main() { return processor(P_PID, P_MYPID, 0, NULL); }" >> ${BASE}$$.c
 ${CC} ${CFLAGS} -o ${BASE}$$ ${BASE}$$.c ${LDLIBS} 1>${NULL} 2>${NULL} \
 	&& CFLAGS="${CFLAGS} -DHAVE_BINDPROCESSOR=1";
 rm -f ${BASE}$$ ${BASE}$$.o ${BASE}$$.c
 
 # check that we have sched_setaffinity
-echo "#include <stdlib.h>" > ${BASE}$$.c
+echo "#define _GNU_SOURCE" > ${BASE}$$.c
+echo "#include <stdlib.h>" >> ${BASE}$$.c
 echo "#include <unistd.h>" >> ${BASE}$$.c
 echo "#include <sched.h>" >> ${BASE}$$.c
-echo "main() { unsigned long mask = 1; return sched_setaffinity(0, sizeof(unsigned long), &mask); }" >> ${BASE}$$.c
+echo "int main() { unsigned long mask = 1; return sched_setaffinity(0, sizeof(unsigned long), &mask); }" >> ${BASE}$$.c
 ${CC} ${CFLAGS} -o ${BASE}$$ ${BASE}$$.c ${LDLIBS} 1>${NULL} 2>${NULL} \
 	&& CFLAGS="${CFLAGS} -DHAVE_SCHED_SETAFFINITY=1";
 rm -f ${BASE}$$ ${BASE}$$.o ${BASE}$$.c
@@ -285,4 +286,4 @@ rm -f ${BASE}$$ ${BASE}$$.o ${BASE}$$.c
 if [ ! -d ${BINDIR} ]; then mkdir -p ${BINDIR}; fi
 
 # now go ahead and build everything!
-${MAKE} OS="${OS}" CC="${CC}" CFLAGS="${CFLAGS}" LDLIBS="${LDLIBS}" O="${BINDIR}" $*
+${MAKE} OS="${OS}" CC="${CC}" CFLAGS="${CFLAGS}" LDLIBS="${LDLIBS}" O="${BINDIR}" ${EXTRA_OEMAKE} $*
--- a/src/lib_sched.c
+++ b/src/lib_sched.c
@@ -1,3 +1,4 @@
+#define _GNU_SOURCE
 #include "bench.h"
 
 /* #define _DEBUG */
