bpfilter: switch to CC from HOSTCC
authorAlexei Starovoitov <ast@kernel.org>
Tue, 5 Jun 2018 02:53:41 +0000 (19:53 -0700)
committerDavid S. Miller <davem@davemloft.net>
Tue, 5 Jun 2018 14:21:18 +0000 (10:21 -0400)
check that CC can build executables and use that compiler instead of HOSTCC

Suggested-by: Arnd Bergmann <arnd@arndb.de>
Signed-off-by: Alexei Starovoitov <ast@kernel.org>
Signed-off-by: David S. Miller <davem@davemloft.net>
Makefile
net/Makefile
net/bpfilter/Makefile
scripts/cc-can-link.sh [new file with mode: 0755]

index 56ba070dfa09022616736b8add505bb681adfadf..62c110084fae74c25eb68d312ba57fd4e3f3a883 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -510,6 +510,11 @@ ifeq ($(call shell-cached,$(CONFIG_SHELL) $(srctree)/scripts/gcc-goto.sh $(CC) $
   KBUILD_AFLAGS += -DCC_HAVE_ASM_GOTO
 endif
 
+ifeq ($(call shell-cached,$(CONFIG_SHELL) $(srctree)/scripts/cc-can-link.sh $(CC)), y)
+  CC_CAN_LINK := y
+  export CC_CAN_LINK
+endif
+
 ifeq ($(config-targets),1)
 # ===========================================================================
 # *config targets only - make sure prerequisites are updated, and descend
index bdaf53925acd5606fdb953800620bd05cf0f259e..13ec0d5415c74486c68f8290689d16d78513e6e9 100644 (file)
@@ -20,7 +20,11 @@ obj-$(CONFIG_TLS)            += tls/
 obj-$(CONFIG_XFRM)             += xfrm/
 obj-$(CONFIG_UNIX)             += unix/
 obj-$(CONFIG_NET)              += ipv6/
+ifneq ($(CC_CAN_LINK),y)
+$(warning CC cannot link executables. Skipping bpfilter.)
+else
 obj-$(CONFIG_BPFILTER)         += bpfilter/
+endif
 obj-$(CONFIG_PACKET)           += packet/
 obj-$(CONFIG_NET_KEY)          += key/
 obj-$(CONFIG_BRIDGE)           += bridge/
index 3f3cb87c668fa40b8072bb1c4aab930d96f7b1a1..aafa72001fcd7c69b1a21d09e18fff7ac1b3c783 100644 (file)
@@ -6,6 +6,8 @@
 hostprogs-y := bpfilter_umh
 bpfilter_umh-objs := main.o
 HOSTCFLAGS += -I. -Itools/include/ -Itools/include/uapi
+HOSTCC := $(CC)
+
 ifeq ($(CONFIG_BPFILTER_UMH), y)
 # builtin bpfilter_umh should be compiled with -static
 # since rootfs isn't mounted at the time of __init
diff --git a/scripts/cc-can-link.sh b/scripts/cc-can-link.sh
new file mode 100755 (executable)
index 0000000..208eb28
--- /dev/null
@@ -0,0 +1,11 @@
+#!/bin/sh
+# SPDX-License-Identifier: GPL-2.0
+
+cat << "END" | $@ -x c - -o /dev/null >/dev/null 2>&1 && echo "y"
+#include <stdio.h>
+int main(void)
+{
+       printf("");
+       return 0;
+}
+END