Skip to contentSkip to conversation

bpfilter: switch to CC from HOSTCC

PATCH Applied Alexei Starovoitov 2 participants 2 messages Jun 5, 2018

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 bpfilter: switch to CC from HOSTCC

check that CC can build executables and use that compiler instead of HOSTCC

---
 Makefile               |  5 +++++
 net/Makefile           |  4 ++++
 net/bpfilter/Makefile  |  2 ++
 scripts/cc-can-link.sh | 11 +++++++++++
 4 files changed, 22 insertions(+)
 create mode 100755 scripts/cc-can-link.sh
Makefile +5 -0
index 56ba070dfa09..62c110084fae 100644
@@ -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
net/Makefile +4 -0
index bdaf53925acd..13ec0d5415c7 100644
@@ -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/
net/bpfilter/Makefile +2 -0
index 3f3cb87c668f..aafa72001fcd 100644
@@ -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
scripts/cc-can-link.sh new file +11 -0
new file mode 100755
index 000000000000..208eb2825dab
@@ -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
Signature · 1 line
2.9.5