[PATCH] make: Introduce compile time include/config.h generation
Cyrill Gorcunov
gorcunov at openvz.org
Fri May 3 11:14:55 EDT 2013
It's being reported that some systems (as Ubuntu 13.04) already
have struct tcp_repair_opt definition in their system headers.
| sk-tcp.c:25:8: error: redefinition of struct tcp_repair_opt
| sk-tcp.c:31:2: error: redeclaration of enumerator TCP_NO_QUEUE
So add a facility for compile time testing for reported entities
to be present on a system. For this we generate include/config.h
where all tested entries will lay and source code need to include
it only in places where really needed.
Reported-by: Vasily Averin <vvs at parallels.com>
Acked-by: Kir Kolyshkin <kir at openvz.org>
Signed-off-by: Cyrill Gorcunov <gorcunov at openvz.org>
---
Makefile | 4 +++-
Makefile.config | 17 +++++++++++++++++
scripts/feature-tests.mak | 13 +++++++++++++
sk-tcp.c | 10 ++++++++++
4 files changed, 43 insertions(+), 1 deletion(-)
create mode 100644 Makefile.config
create mode 100644 scripts/feature-tests.mak
diff --git a/Makefile b/Makefile
index cffab50..cba2f12 100644
--- a/Makefile
+++ b/Makefile
@@ -17,6 +17,7 @@ export VERSION_MAJOR VERSION_MINOR VERSION_SUBLEVEL VERSION_EXTRA VERSION_NAME
#MAKEFLAGS := -r -R
include Makefile.inc
+include Makefile.config
#
# Common definitions
@@ -118,7 +119,7 @@ ifeq ($(GCOV),1)
%.o $(PROGRAM): override CFLAGS += --coverage
endif
-all: pie $(VERSION_HEADER)
+all: config pie $(VERSION_HEADER)
$(Q) $(MAKE) $(PROGRAM)
protobuf/%::
@@ -158,6 +159,7 @@ clean-built:
$(Q) $(MAKE) $(build)=pie clean
$(Q) $(MAKE) $(build-crtools)=. clean
$(Q) $(MAKE) -C Documentation clean
+ $(Q) $(RM) ./include/config.h
$(Q) $(RM) ./$(PROGRAM)
rebuild: clean-built
diff --git a/Makefile.config b/Makefile.config
new file mode 100644
index 0000000..dd3c2ba
--- /dev/null
+++ b/Makefile.config
@@ -0,0 +1,17 @@
+include scripts/utilities.mak
+include scripts/feature-tests.mak
+
+CONFIG := include/config.h
+
+$(CONFIG): scripts/utilities.mak scripts/feature-tests.mak
+ $(E) " GEN " $@
+ $(Q) @echo '#ifndef __CR_CONFIG_H__' > $@
+ $(Q) @echo '#define __CR_CONFIG_H__' >> $@
+ifeq ($(call try-cc,$(TCP_REPAIR_TEST),,),y)
+ $(Q) @echo '#define CONFIG_HAS_TCP_REPAIR' >> $@
+endif
+ $(Q) @echo '#endif /* __CR_CONFIG_H__ */' >> $@
+
+config: $(CONFIG)
+
+.PHONY: config
diff --git a/scripts/feature-tests.mak b/scripts/feature-tests.mak
new file mode 100644
index 0000000..c961153
--- /dev/null
+++ b/scripts/feature-tests.mak
@@ -0,0 +1,13 @@
+define TCP_REPAIR_TEST
+
+#include <netinet/tcp.h>
+
+int main(void)
+{
+ struct tcp_repair_opt opts;
+ opts.opt_code = TCP_NO_QUEUE;
+ opts.opt_val = 0;
+
+ return opts.opt_val;
+}
+endef
diff --git a/sk-tcp.c b/sk-tcp.c
index ff51783..34eb33e 100644
--- a/sk-tcp.c
+++ b/sk-tcp.c
@@ -18,10 +18,19 @@
#include "netfilter.h"
#include "image.h"
#include "namespaces.h"
+#include "config.h"
#include "protobuf.h"
#include "protobuf/tcp-stream.pb-c.h"
+#ifndef CONFIG_HAS_TCP_REPAIR
+/*
+ * It's been reported that both tcp_repair_opt
+ * and TCP_ enum already shipped in netinet/tcp.h
+ * system header by some distros thus we need a
+ * test if we can use predefined ones or provide
+ * our own.
+ */
struct tcp_repair_opt {
u32 opt_code;
u32 opt_val;
@@ -33,6 +42,7 @@ enum {
TCP_SEND_QUEUE,
TCP_QUEUES_NR,
};
+#endif
#ifndef TCP_TIMESTAMP
#define TCP_TIMESTAMP 24
--
1.8.1.4
--4Ckj6UjgE2iN1+kY--
More information about the CRIU
mailing list