Received: by 2002:a25:c593:0:0:0:0:0 with SMTP id v141csp25600ybe; Wed, 4 Sep 2019 14:25:37 -0700 (PDT) X-Google-Smtp-Source: APXvYqz1NcrN6UbhcxSlMIj20OdOEXiTNLUDyoq0oXSqDrJsM0+pAswCzK9s4HXfSYRoFpqowQ25 X-Received: by 2002:a17:902:343:: with SMTP id 61mr44456602pld.215.1567632337811; Wed, 04 Sep 2019 14:25:37 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1567632337; cv=none; d=google.com; s=arc-20160816; b=ME1yY3L50PB/q/Hs6u8/bkuLaqhUPfe7irg97evk9sNBoF8Z717FTTAK270zng9doR v44YaQRgb0b/Q2A6HOrJzUIYS94rJz1VB3IQbIlbM9OqGND+ZCi8ZxpkhW9Mm9vCN57Y r+Y+C4nd+jSWMxk/I1ATaoPOb9DC2+PFCfWV6UvUq+SzWm8fG0ugmNT5Yi3EPSyfjc/+ v2qiOTGlHJCzR3rwQEWqqPtA7CZvIz3KCCspSYb7qR/5gojV7I6AfkdCLEPMkFcgCPCn tdH9pj/1F68No31rtBekYilpsIFod3hc+rIuT69qT+PhDc+yi2Q6SbG9oJsGD4Vyhcpk U5EQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:dkim-signature; bh=S7BH2bOuqpWzG3KQU2G046M8ZupbTAkU+KR6zMOgNJI=; b=tjk/iHqekeWRuzgzHPTncjBgafkrIaekPpI4RX2PwKliLuyyLt135nuymOWx15P5LP Ptzzq+3pZ7I7I+iY+6E7iwVz7r9O/cRYGmwr4Muq7XEblcusmpxUM3MGFZ8YP/bxWwe1 NZm5HfQyen5ZHqN6rfa3rfsq+zPqt1SXqKyzUr2Jfmg9+5lggxvg1f09SG40P7Y92mIk YjNoqa7bG1BxEREtLCV4IR9kLl3IUg/9HCBhCMM9BCsYEYO963l/cqAmfMMaW39YUvkX M0ilxunVo9Fi6/IqnH8pNvyKQGeBHRt2yJgUOU8wXBVxdfPXBDtFF+zqn72jg64+/UNC x8gA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=N+hBm0Fd; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id 72si42181ple.381.2019.09.04.14.25.22; Wed, 04 Sep 2019 14:25:37 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=N+hBm0Fd; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730717AbfIDVXM (ORCPT + 99 others); Wed, 4 Sep 2019 17:23:12 -0400 Received: from mail-lj1-f194.google.com ([209.85.208.194]:47010 "EHLO mail-lj1-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730550AbfIDVXL (ORCPT ); Wed, 4 Sep 2019 17:23:11 -0400 Received: by mail-lj1-f194.google.com with SMTP id e17so147755ljf.13 for ; Wed, 04 Sep 2019 14:23:10 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=S7BH2bOuqpWzG3KQU2G046M8ZupbTAkU+KR6zMOgNJI=; b=N+hBm0FdQmrQttzep7czwaMBh1UAfnrbN3973Hn33rJnUCsCcidmdy8VHPuaWuGuv0 25+b2VyQeoEhM1J0hUHbkpMZeNwndzFaRE0S8dREHTa0PP5T7fOxf73nUfg+AbSC2Dho lCthA7fYTbWUWDrPClyG0C0rRDj4HP6S2dgGH9W84BgdIHRjuhApsw0KwKYy4RbCaDSd 7JXdx9cniwUUP1n7VSY11bpix+OGaGkyYkj2reopbGCzbbe7zfi1XMNg2xbwgAZHiRlA ML/AKF493m6fBaA3vQi74YYYwmYhyYqLP8WhLq7Ge0qfBm4nMuE0e7qwtY5YbAWd6k6z hG4w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=S7BH2bOuqpWzG3KQU2G046M8ZupbTAkU+KR6zMOgNJI=; b=epBsBjKZwzIGgYkrpSSYmC78pB2MzHPcnzwOINKRE1wXCU/ywREgXRPHUEV2/SRC6B rg2dyO26IjClCn2N5M+qrcpy2f05bDQe/Ik9ZZzEN7BPrvY5B2rlb6Hg/u6qEpLnuW0I 8eCvpW+/QBTVSLTJ8F7pDVE877xnVaGwqe3WJLi0Cam63LbbxKvM+4tZPFuc+ws66bPc 1gXKZJxxAZ8lJbVVh78mn7HGpbaIXXcFfs7MQydlu85zmazQFDyedvQkPxLAxJeZym2+ gKYM2aVrWoM76Ek/T1qLgslnWClnZ2s1157mpJ9S33GP2qq+CtHEIUefdSFgBr6LUIrE PXig== X-Gm-Message-State: APjAAAW+uPyMq7cHNziAbI3PFhV80YtOgzZqZhZjtNkTzzrCT19A50Bk WYi/iuadsBerrY12EKnCql+Fog== X-Received: by 2002:a2e:6111:: with SMTP id v17mr24187411ljb.30.1567632189413; Wed, 04 Sep 2019 14:23:09 -0700 (PDT) Received: from localhost.localdomain (168-200-94-178.pool.ukrtel.net. [178.94.200.168]) by smtp.gmail.com with ESMTPSA id s8sm3540836ljd.94.2019.09.04.14.23.08 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 04 Sep 2019 14:23:08 -0700 (PDT) From: Ivan Khoronzhuk To: ast@kernel.org, daniel@iogearbox.net, yhs@fb.com, davem@davemloft.net, jakub.kicinski@netronome.com, hawk@kernel.org, john.fastabend@gmail.com Cc: linux-kernel@vger.kernel.org, netdev@vger.kernel.org, bpf@vger.kernel.org, clang-built-linux@googlegroups.com, Ivan Khoronzhuk Subject: [PATCH bpf-next 7/8] samples: bpf: add makefile.prog for separate CC build Date: Thu, 5 Sep 2019 00:22:11 +0300 Message-Id: <20190904212212.13052-8-ivan.khoronzhuk@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190904212212.13052-1-ivan.khoronzhuk@linaro.org> References: <20190904212212.13052-1-ivan.khoronzhuk@linaro.org> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org The HOSTCC is supposed to build binaries and tools running on the host afterwards, in order to simplify build or so, like "fixdep" or else. In case of cross compiling "fixdep" is executed on host when the rest samples should run on target arch. In order to build binaries for target arch with CC and tools running on host with HOSTCC, lets add Makefile.prog for simplicity, having definition and routines similar to ones, used in script/Makefile.host. That allows later add cross-compilation to samples/bpf with minimum changes. Makefile.prog contains only stuff needed for samples/bpf, potentially can be reused and extended for other prog sets later and now needed only for unblocking tricky samples/bpf cross compilation. Signed-off-by: Ivan Khoronzhuk --- samples/bpf/Makefile.prog | 77 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 77 insertions(+) create mode 100644 samples/bpf/Makefile.prog diff --git a/samples/bpf/Makefile.prog b/samples/bpf/Makefile.prog new file mode 100644 index 000000000000..1d138bc21dd4 --- /dev/null +++ b/samples/bpf/Makefile.prog @@ -0,0 +1,77 @@ +# SPDX-License-Identifier: GPL-2.0 +# ========================================================================== +# Building binaries on the host system +# Binaries are not used during the compilation of the kernel, and intendent to +# be build for target board, target board can be host ofc. Added to build +# binaries to run not on host system. +# +# Only C is supported, but can be extended for C++. +# +# Sample syntax (see Documentation/kbuild/makefiles.rst for reference) +# progs-y := xdpsock_example +# Will compile xdpsock_example.c and create an executable named xdpsock_example +# +# progs-y := xdpsock +# xdpsock-objs := xdpsock_user.o xdpsock_user2.o +# Will compile xdpsock.c and xdpsock.c, and then link the executable +# xdpsock, based on xdpsock_user.o and xdpsock_user2.o +# +# Inherited from scripts/Makefile.host +# +__progs := $(sort $(progs-y)) + +# C code +# Executables compiled from a single .c file +prog-csingle := $(foreach m,$(__progs), \ + $(if $($(m)-objs)$($(m)-cxxobjs),,$(m))) + +# C executables linked based on several .o files +prog-cmulti := $(foreach m,$(__progs),\ + $(if $($(m)-cxxobjs),,$(if $($(m)-objs),$(m)))) + +# Object (.o) files compiled from .c files +prog-cobjs := $(sort $(foreach m,$(__progs),$($(m)-objs))) + +prog-csingle := $(addprefix $(obj)/,$(prog-csingle)) +prog-cmulti := $(addprefix $(obj)/,$(prog-cmulti)) +prog-cobjs := $(addprefix $(obj)/,$(prog-cobjs)) + +##### +# Handle options to gcc. Support building with separate output directory + +_progc_flags = $(PROGS_CFLAGS) \ + $(PROGCFLAGS_$(basetarget).o) + +# $(objtree)/$(obj) for including generated headers from checkin source files +ifeq ($(KBUILD_EXTMOD),) +ifdef building_out_of_srctree +_progc_flags += -I $(objtree)/$(obj) +endif +endif + +progc_flags = -Wp,-MD,$(depfile) $(_progc_flags) + +# Create executable from a single .c file +# prog-csingle -> Executable +quiet_cmd_prog-csingle = CC $@ + cmd_prog-csingle = $(CC) $(progc_flags) $(PROGS_LDFLAGS) -o $@ $< \ + $(PROGS_LDLIBS) $(PROGLDLIBS_$(@F)) +$(prog-csingle): $(obj)/%: $(src)/%.c FORCE + $(call if_changed_dep,prog-csingle) + +# Link an executable based on list of .o files, all plain c +# prog-cmulti -> executable +quiet_cmd_prog-cmulti = LD $@ + cmd_prog-cmulti = $(CC) $(progc_flags) $(PROGS_LDFLAGS) -o $@ \ + $(addprefix $(obj)/,$($(@F)-objs)) \ + $(PROGS_LDLIBS) $(PROGLDLIBS_$(@F)) +$(prog-cmulti): $(prog-cobjs) FORCE + $(call if_changed,prog-cmulti) +$(call multi_depend, $(prog-cmulti), , -objs) + +# Create .o file from a single .c file +# prog-cobjs -> .o +quiet_cmd_prog-cobjs = CC $@ + cmd_prog-cobjs = $(CC) $(progc_flags) -c -o $@ $< +$(prog-cobjs): $(obj)/%.o: $(src)/%.c FORCE + $(call if_changed_dep,prog-cobjs) -- 2.17.1