On some platforms compilation issues due to clock_nanosleep were occuring. The
simple test for __uClinux__ was not sufficient.

Implement full detection of clock_nanosleep in incdefs.h by compiling a short C
file.  incdefs.sh now sets a new HAVE_CLOCK_NANOSLEEP literal. missing.h is
changed accordingly.

For cross-compilation purposes CFLAGS in makefile is not set but += is used.
Also the CC variable is passed to the incdefs.sh script.

Signed-off-by: Petr Kulhavy <br...@jikos.cz>
---
 incdefs.sh | 14 ++++++++++++++
 makefile   |  4 ++--
 missing.h  | 15 +++++++++------
 3 files changed, 25 insertions(+), 8 deletions(-)

diff --git a/incdefs.sh b/incdefs.sh
index 8232b5c..9a870ac 100755
--- a/incdefs.sh
+++ b/incdefs.sh
@@ -40,6 +40,20 @@ user_flags()
                done
        done
 
+       # Look for clock_nanosleep().
+       echo '
+#include <time.h>
+
+void test(void)
+{
+        clock_nanosleep(CLOCK_REALTIME, 0, NULL, NULL);
+}
+       ' > .incdefs-test.c
+       if ${CC} -c -Werror .incdefs-test.c 2> /dev/null ; then
+               printf " -DHAVE_CLOCK_NANOSLEEP"
+       fi
+       rm -f .incdefs-test.c .incdefs-test.o
+
        # Look for posix_spawn().
        for d in $dirs; do
                files=$(find $d -type f -name spawn.h)
diff --git a/makefile b/makefile
index f898336..a54ee00 100644
--- a/makefile
+++ b/makefile
@@ -20,7 +20,7 @@ KBUILD_OUTPUT =
 DEBUG  =
 CC     = $(CROSS_COMPILE)gcc
 VER     = -DVER=$(version)
-CFLAGS = -Wall $(VER) $(incdefs) $(DEBUG) $(EXTRA_CFLAGS)
+CFLAGS += -Wall $(VER) $(incdefs) $(DEBUG) $(EXTRA_CFLAGS)
 LDLIBS = -lm -lrt $(EXTRA_LDFLAGS)
 PRG    = ptp4l pmc phc2sys hwstamp_ctl phc_ctl timemaster
 OBJ     = bmc.o clock.o clockadj.o clockcheck.o config.o fault.o \
@@ -33,7 +33,7 @@ OBJECTS       = $(OBJ) hwstamp_ctl.o phc2sys.o phc_ctl.o 
pmc.o pmc_common.o \
 SRC    = $(OBJECTS:.o=.c)
 DEPEND = $(OBJECTS:.o=.d)
 srcdir := $(dir $(lastword $(MAKEFILE_LIST)))
-incdefs := $(shell $(srcdir)/incdefs.sh)
+incdefs := $(shell CC="$(CC)" $(srcdir)/incdefs.sh)
 version := $(shell $(srcdir)/version.sh $(srcdir))
 VPATH  = $(srcdir)
 
diff --git a/missing.h b/missing.h
index f7efd92..7279ece 100644
--- a/missing.h
+++ b/missing.h
@@ -69,18 +69,21 @@ static inline int clock_adjtime(clockid_t id, struct timex 
*tx)
 }
 #endif
 
-#ifndef __uClinux__
-
-#include <sys/timerfd.h>
-
-#else
-
+#if !defined ( HAVE_CLOCK_NANOSLEEP ) || defined ( __uClinux__ )
 static inline int clock_nanosleep(clockid_t clock_id, int flags,
                                  const struct timespec *request,
                                  struct timespec *remain)
 {
        return syscall(__NR_clock_nanosleep, clock_id, flags, request, remain);
 }
+#endif
+
+
+#ifndef __uClinux__
+
+#include <sys/timerfd.h>
+
+#else
 
 static inline int timerfd_create(int clockid, int flags)
 {
-- 
2.7.4


------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot
_______________________________________________
Linuxptp-devel mailing list
Linuxptp-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/linuxptp-devel

Reply via email to