[CRIU] [PATCH 2/2] build/feature-test: simplify adding a new feature

Dmitry Safonov dsafonov at virtuozzo.com
Fri Feb 19 05:02:51 PST 2016


To add a new feature test - add it to FEATURES_LIST.

Cc: Cyrill Gorcunov <gorcunov at openvz.org>
Signed-off-by: Dmitry Safonov <dsafonov at virtuozzo.com>
---
 criu/Makefile.config      | 75 ++++++++++++++++++++---------------------------
 scripts/feature-tests.mak | 16 +++++-----
 2 files changed, 40 insertions(+), 51 deletions(-)

diff --git a/criu/Makefile.config b/criu/Makefile.config
index 36686d7..0db6dc4 100644
--- a/criu/Makefile.config
+++ b/criu/Makefile.config
@@ -4,7 +4,7 @@ include ../scripts/feature-tests.mak
 
 CONFIG_HEADER := include/config.h
 
-ifeq ($(call try-cc,$(LIBBSD_DEV_TEST),-lbsd),y)
+ifeq ($(call try-cc,$(FEATURE_TEST_LIBBSD_DEV),-lbsd),y)
         LIBS	+= -lbsd
         DEFINES	+= -DCONFIG_HAS_LIBBSD
 endif
@@ -14,49 +14,38 @@ ifeq ($(call pkg-config-check,libselinux),y)
         DEFINES	+= -DCONFIG_HAS_SELINUX
 endif
 
-$(CONFIG_HEADER): include/config-base.h
-	$(call msg-gen, $@)
-	$(Q) @echo '#ifndef __CR_CONFIG_H__' > $@
-	$(Q) @echo '#define __CR_CONFIG_H__' >> $@
-	$(Q) @echo '' >> $@
-	$(Q) @echo '#include "config-base.h"' >> $@
-	$(Q) @echo '' >> $@
-ifeq ($(call try-cc,$(TCP_REPAIR_TEST),,$(DEFINES)),y)
-	$(Q) @echo '#define CONFIG_HAS_TCP_REPAIR' >> $@
-	$(Q) @echo '' >> $@
-endif
-ifeq ($(call try-cc,$(PRLIMIT_TEST),,$(DEFINES)),y)
-	$(Q) @echo '#define CONFIG_HAS_PRLIMIT' >> $@
-	$(Q) @echo '' >> $@
-endif
-ifeq ($(call try-cc,$(STRLCPY_TEST),$(LIBS),$(DEFINES)),y)
-	$(Q) @echo '#define CONFIG_HAS_STRLCPY' >> $@
-	$(Q) @echo '' >> $@
-endif
-ifeq ($(call try-cc,$(STRLCAT_TEST),$(LIBS),$(DEFINES)),y)
-	$(Q) @echo '#define CONFIG_HAS_STRLCAT' >> $@
-	$(Q) @echo '' >> $@
-endif
-ifeq ($(call try-cc,$(PTRACE_PEEKSIGINFO_TEST),,$(DEFINES)),y)
-	$(Q) @echo '#define CONFIG_HAS_PEEKSIGINFO_ARGS' >> $@
-	$(Q) @echo '' >> $@
-endif
-ifeq ($(VDSO),y)
-	$(Q) @echo '#define CONFIG_VDSO' >> $@
-	$(Q) @echo '' >> $@
-endif
-ifeq ($(call try-cc,$(SETPROCTITLE_INIT_TEST),-lbsd,$(DEFINES)),y)
-	$(Q) @echo '#define CONFIG_HAS_SETPROCTITLE_INIT' >> $@
-	$(Q) @echo '' >> $@
-endif
-ifeq ($(call try-cc,$(MEMFD_TEST),),y)
-	$(Q) @echo '#define CONFIG_HAS_MEMFD' >> $@
-endif
-ifeq ($(piegen-y),y)
-	$(Q) @echo '#define CONFIG_PIEGEN' >> $@
-	$(Q) @echo '' >> $@
+FEATURES_LIST	:= TCP_REPAIR PRLIMIT STRLCPY STRLCAT PEEKSIGINFO_ARGS \
+	SETPROCTITLE_INIT MEMFD
+
+# $1 - config name
+define gen-feature-test
+$(\n)ifeq ($$(call try-cc,$$(FEATURE_TEST_$(1)),$$(LIBS),$$(DEFINES)),y)
+	$(Q) @echo '#define CONFIG_HAS_$(1)' >> $$@
+	$(Q) @echo '' >> $$@
 endif
-	$(Q) @echo '#endif /* __CR_CONFIG_H__ */' >> $@
+endef
+
+define config-header-rule
+$(CONFIG_HEADER): include/config-base.h
+	$$(call msg-gen, $$@)
+	$(Q) @echo '#ifndef __CR_CONFIG_H__'				> $$@
+	$(Q) @echo '#define __CR_CONFIG_H__'				>> $$@
+	$(Q) @echo ''							>> $$@
+	$(Q) @echo '#include "config-base.h"'				>> $$@
+	$(Q) @echo ''							>> $$@
+$(call map,gen-feature-test,$(FEATURES_LIST))
+ifeq ($$(VDSO),y)
+	$(Q) @echo '#define CONFIG_VDSO'				>> $$@
+	$(Q) @echo ''							>> $$@
+endif
+ifeq ($$(piegen-y),y)
+	$(Q) @echo '#define CONFIG_PIEGEN'				>> $$@
+	$(Q) @echo ''							>> $$@
+endif
+	$(Q) @echo '#endif /* __CR_CONFIG_H__ */'			>> $$@
+endef
+
+$(eval $(config-header-rule))
 
 config: $(CONFIG_HEADER)
 PHONY += config
diff --git a/scripts/feature-tests.mak b/scripts/feature-tests.mak
index 5ccfc78..525c73e 100644
--- a/scripts/feature-tests.mak
+++ b/scripts/feature-tests.mak
@@ -1,4 +1,4 @@
-define TCP_REPAIR_TEST
+define FEATURE_TEST_TCP_REPAIR
 
 #include <netinet/tcp.h>
 
@@ -12,7 +12,7 @@ int main(void)
 }
 endef
 
-define PRLIMIT_TEST
+define FEATURE_TEST_PRLIMIT
 
 #include <stdlib.h>
 #include <sys/types.h>
@@ -30,7 +30,7 @@ int main(void)
 }
 endef
 
-define LIBBSD_DEV_TEST
+define FEATURE_TEST_LIBBSD_DEV
 #include <bsd/string.h>
 
 int main(void)
@@ -39,7 +39,7 @@ int main(void)
 }
 endef
 
-define STRLCPY_TEST
+define FEATURE_TEST_STRLCPY
 
 #include <string.h>
 
@@ -53,7 +53,7 @@ int main(void)
 }
 endef
 
-define STRLCAT_TEST
+define FEATURE_TEST_STRLCAT
 
 #include <string.h>
 
@@ -67,7 +67,7 @@ int main(void)
 }
 endef
 
-define PTRACE_PEEKSIGINFO_TEST
+define FEATURE_TEST_PTRACE_PEEKSIGINFO
 
 #include <sys/ptrace.h>
 
@@ -80,7 +80,7 @@ int main(void)
 
 endef
 
-define SETPROCTITLE_INIT_TEST
+define FEATURE_TEST_SETPROCTITLE_INIT
 
 #include <bsd/unistd.h>
 
@@ -93,7 +93,7 @@ int main(int argc, char *argv[], char *envp[])
 
 endef
 
-define MEMFD_TEST
+define FEATURE_TEST_MEMFD
 
 #include <unistd.h>
 #include <sys/syscall.h>
-- 
2.7.1



More information about the CRIU mailing list