[prev in list] [next in list] [prev in thread] [next in thread] 

List:       mandoc-source
Subject:    mdocml: Autodetect if -lrt is needed for nanosleep(3).
From:       schwarze () mdocml ! bsd ! lv
Date:       2016-07-20 14:03:36
Message-ID: 8828057329917709541.enqueue () fantadrom ! bsd ! lv
[Download RAW message or body]

Log Message:
-----------
Autodetect if -lrt is needed for nanosleep(3).
Helpful for Solaris 9 and 10.
Reminded by Thomas Klausner.

Modified Files:
--------------
    mdocml:
        Makefile
        configure
        configure.local.example

Added Files:
-----------
    mdocml:
        test-nanosleep.c

Revision Data
-------------
--- /dev/null
+++ test-nanosleep.c
@@ -0,0 +1,17 @@
+#include <stdio.h>
+#include <time.h>
+
+int
+main(void)
+{
+	struct timespec	 timeout;
+
+	timeout.tv_sec = 0;
+	timeout.tv_nsec = 100000000;	/* 0.1 seconds */
+	
+	if (nanosleep(&timeout, NULL)) {
+		perror("nanosleep");
+		return 1;
+	}
+	return 0;
+}
Index: configure
===================================================================
RCS file: /home/cvs/mdocml/mdocml/configure,v
retrieving revision 1.46
retrieving revision 1.47
diff -Lconfigure -Lconfigure -u -p -r1.46 -r1.47
--- configure
+++ configure
@@ -1,5 +1,7 @@
 #!/bin/sh
 #
+# $Id$
+#
 # Copyright (c) 2014, 2015, 2016 Ingo Schwarze <schwarze@openbsd.org>
 #
 # Permission to use, copy, modify, and distribute this software for any
@@ -39,6 +41,7 @@ CFLAGS="-g -W -Wall -Wmissing-prototypes
 CFLAGS="${CFLAGS} -Wno-unused-parameter"
 LDADD=
 LDFLAGS=
+LD_NANOSLEEP=
 LD_OHASH=
 STATIC="-static"
 
@@ -52,6 +55,7 @@ HAVE_GETLINE=
 HAVE_GETSUBOPT=
 HAVE_ISBLANK=
 HAVE_MKDTEMP=
+HAVE_NANOSLEEP=
 HAVE_OHASH=
 HAVE_PLEDGE=
 HAVE_PROGNAME=
@@ -197,6 +201,20 @@ runtest strtonum	STRTONUM	|| true
 runtest vasprintf	VASPRINTF	|| true
 runtest wchar		WCHAR		|| true
 
+# --- nanosleep ---
+if [ -n "${LD_NANOSLEEP}" ]; then
+	runtest nanosleep NANOSLEEP "${LD_NANOSLEEP}" || true
+elif singletest nanosleep NANOSLEEP; then
+	:
+elif runtest nanosleep NANOSLEEP "-lrt"; then
+	LD_NANOSLEEP="-lrt"
+fi
+if [ "${HAVE_NANOSLEEP}" -eq 0 ]; then
+	echo "FATAL: nanosleep: no" 1>&2
+	echo "FATAL: nanosleep: no" 1>&3
+	exit 1
+fi
+
 # --- ohash ---
 if ismanual ohash "${HAVE_OHASH}"; then
 	:
@@ -212,7 +230,7 @@ if [ "${HAVE_OHASH}" -eq 0 ]; then
 fi
 
 # --- LDADD ---
-LDADD="${LDADD} ${LD_OHASH} -lz"
+LDADD="${LDADD} ${LD_NANOSLEEP} ${LD_OHASH} -lz"
 echo "LDADD=\"${LDADD}\"" 1>&2
 echo "LDADD=\"${LDADD}\"" 1>&3
 echo 1>&3
Index: Makefile
===================================================================
RCS file: /home/cvs/mdocml/mdocml/Makefile,v
retrieving revision 1.489
retrieving revision 1.490
diff -LMakefile -LMakefile -u -p -r1.489 -r1.490
--- Makefile
+++ Makefile
@@ -26,6 +26,7 @@ TESTSRCS	 = test-dirent-namlen.c \
 		   test-getsubopt.c \
 		   test-isblank.c \
 		   test-mkdtemp.c \
+		   test-nanosleep.c \
 		   test-ohash.c \
 		   test-pledge.c \
 		   test-progname.c \
Index: configure.local.example
===================================================================
RCS file: /home/cvs/mdocml/mdocml/configure.local.example,v
retrieving revision 1.16
retrieving revision 1.17
diff -Lconfigure.local.example -Lconfigure.local.example -u -p -r1.16 -r1.17
--- configure.local.example
+++ configure.local.example
@@ -129,11 +129,17 @@ LD_OHASH="-lutil"
 
 CFLAGS="${CFLAGS} -I/usr/local/include"
 
-# Some platforms may need additional linker flags to link against libmandoc
-# that are not autodetected.
-# For example, Solaris 9 and 10 need -lrt for nanosleep(2).
+# Some platforms may need an additional linker flag for nanosleep(2).
+# If none is needed or it is -lrt, it is autodetected.
+# Otherwise, set the following variable.
 
-LDADD="-lrt"
+LD_NANOSLEEP="-lrt"
+
+# Some platforms might need additional linker flags to link against
+# libmandoc that are not autodetected, though no such cases are
+# currently known.
+
+LDADD="-lm"
 
 # Some systems may want to set additional linker flags for all the
 # binaries, not only for those using libmandoc, for example for
--
 To unsubscribe send an email to source+unsubscribe@mdocml.bsd.lv

[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic