Jacob Keller
2013-08-30 17:57:35 UTC
Because HWTSTAMP_TX_ONESTEP_SYNC is an enum, and not a define we can't simply
use a pre-processor. Rather, we create a simple test program and compile it. If
it succeeds we define HAVE_ONESTEP_SYNC flag and uset that in missing.h. In
this way we can then define the value since it doesn't exist. This solves some
compilation problems on kernels which don't have the ONESTEP_SYNC flag. It also
works with distro kernels that have backported the SYNC flag.
Signed-off-by: Jacob Keller <***@intel.com>
---
makefile | 3 +++
missing.h | 6 ++++++
onestep_test.c | 5 +++++
3 files changed, 14 insertions(+)
create mode 100644 onestep_test.c
diff --git a/makefile b/makefile
index 71dcf0c..d966675 100644
--- a/makefile
+++ b/makefile
@@ -21,6 +21,9 @@ FEAT_CFLAGS :=
ifneq ($(shell grep --no-messages clock_adjtime /usr/include/bits/time.h),)
FEAT_CFLAGS += -D_GNU_SOURCE -DHAVE_CLOCK_ADJTIME
endif
+ifeq ($(shell gcc -o /dev/null onestep_test.c),)
+FEAT_CFLAGS += -DHAVE_ONESTEP_SYNC
+endif
DEBUG =
CC = $(CROSS_COMPILE)gcc
diff --git a/missing.h b/missing.h
index 3c2b9d8..99a8d83 100644
--- a/missing.h
+++ b/missing.h
@@ -44,6 +44,12 @@
#define FD_TO_CLOCKID(fd) ((~(clockid_t) (fd) << 3) | CLOCKFD)
#define CLOCKID_TO_FD(clk) ((unsigned int) ~((clk) >> 3))
+#ifndef HAVE_ONESTEP_SYNC
+enum _missing_hwtstamp_tx_types {
+ HWTSTAMP_TX_ONESTEP_SYNC = 2,
+}
+#endif
+
#ifndef HAVE_CLOCK_ADJTIME
static inline int clock_adjtime(clockid_t id, struct timex *tx)
{
diff --git a/onestep_test.c b/onestep_test.c
new file mode 100644
index 0000000..d6aaac2
--- /dev/null
+++ b/onestep_test.c
@@ -0,0 +1,5 @@
+#include <linux/net_tstamp.h>
+
+int main() {
+ return HWTSTAMP_TX_ONESTEP_SYNC;
+}
use a pre-processor. Rather, we create a simple test program and compile it. If
it succeeds we define HAVE_ONESTEP_SYNC flag and uset that in missing.h. In
this way we can then define the value since it doesn't exist. This solves some
compilation problems on kernels which don't have the ONESTEP_SYNC flag. It also
works with distro kernels that have backported the SYNC flag.
Signed-off-by: Jacob Keller <***@intel.com>
---
makefile | 3 +++
missing.h | 6 ++++++
onestep_test.c | 5 +++++
3 files changed, 14 insertions(+)
create mode 100644 onestep_test.c
diff --git a/makefile b/makefile
index 71dcf0c..d966675 100644
--- a/makefile
+++ b/makefile
@@ -21,6 +21,9 @@ FEAT_CFLAGS :=
ifneq ($(shell grep --no-messages clock_adjtime /usr/include/bits/time.h),)
FEAT_CFLAGS += -D_GNU_SOURCE -DHAVE_CLOCK_ADJTIME
endif
+ifeq ($(shell gcc -o /dev/null onestep_test.c),)
+FEAT_CFLAGS += -DHAVE_ONESTEP_SYNC
+endif
DEBUG =
CC = $(CROSS_COMPILE)gcc
diff --git a/missing.h b/missing.h
index 3c2b9d8..99a8d83 100644
--- a/missing.h
+++ b/missing.h
@@ -44,6 +44,12 @@
#define FD_TO_CLOCKID(fd) ((~(clockid_t) (fd) << 3) | CLOCKFD)
#define CLOCKID_TO_FD(clk) ((unsigned int) ~((clk) >> 3))
+#ifndef HAVE_ONESTEP_SYNC
+enum _missing_hwtstamp_tx_types {
+ HWTSTAMP_TX_ONESTEP_SYNC = 2,
+}
+#endif
+
#ifndef HAVE_CLOCK_ADJTIME
static inline int clock_adjtime(clockid_t id, struct timex *tx)
{
diff --git a/onestep_test.c b/onestep_test.c
new file mode 100644
index 0000000..d6aaac2
--- /dev/null
+++ b/onestep_test.c
@@ -0,0 +1,5 @@
+#include <linux/net_tstamp.h>
+
+int main() {
+ return HWTSTAMP_TX_ONESTEP_SYNC;
+}