[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>
Signed-off-by: Cyrill Gorcunov <gorcunov at openvz.org>
---
 Makefile                  |  7 +++++--
 Makefile.config           | 15 +++++++++++++++
 scripts/feature-tests.mak | 13 +++++++++++++
 sk-tcp.c                  |  3 +++
 4 files changed, 36 insertions(+), 2 deletions(-)
 create mode 100644 Makefile.config
 create mode 100644 scripts/feature-tests.mak

diff --git a/Makefile b/Makefile
index cffab50..c82d12d 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
@@ -112,13 +113,14 @@ build-crtools := -r -R -f scripts/Makefile.build makefile=Makefile.crtools obj
 PROGRAM		:= criu
 
 .PHONY: all zdtm test rebuild clean distclean tags cscope	\
-	docs help pie protobuf arch/$(ARCH) clean-built
+	docs help pie protobuf arch/$(ARCH) clean-built		\
+	config
 
 ifeq ($(GCOV),1)
 %.o $(PROGRAM): override CFLAGS += --coverage
 endif
 
-all: pie $(VERSION_HEADER)
+all: config pie $(VERSION_HEADER)
 	$(Q) $(MAKE) $(PROGRAM)
 
 protobuf/%::
@@ -158,6 +160,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..993968a
--- /dev/null
+++ b/Makefile.config
@@ -0,0 +1,15 @@
+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)
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..4327c85 100644
--- a/sk-tcp.c
+++ b/sk-tcp.c
@@ -18,10 +18,12 @@
 #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
 struct tcp_repair_opt {
 	u32	opt_code;
 	u32	opt_val;
@@ -33,6 +35,7 @@ enum {
 	TCP_SEND_QUEUE,
 	TCP_QUEUES_NR,
 };
+#endif
 
 #ifndef TCP_TIMESTAMP
 #define TCP_TIMESTAMP	24
-- 
1.8.1.4


--98e8jtXdkpgskNou--


More information about the CRIU mailing list