From patchwork Sat Dec 30 10:02:01 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Angelo Compagnucci X-Patchwork-Id: 854078 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=busybox.net (client-ip=140.211.166.137; helo=fraxinus.osuosl.org; envelope-from=buildroot-bounces@busybox.net; receiver=) Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=amarulasolutions-com.20150623.gappssmtp.com header.i=@amarulasolutions-com.20150623.gappssmtp.com header.b="NoLOSX7t"; dkim-atps=neutral Received: from fraxinus.osuosl.org (smtp4.osuosl.org [140.211.166.137]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3z7zXG1hbMz9s7g for ; Sat, 30 Dec 2017 21:02:21 +1100 (AEDT) Received: from localhost (localhost [127.0.0.1]) by fraxinus.osuosl.org (Postfix) with ESMTP id 85A8D8661A; Sat, 30 Dec 2017 10:02:19 +0000 (UTC) X-Virus-Scanned: amavisd-new at osuosl.org Received: from fraxinus.osuosl.org ([127.0.0.1]) by localhost (.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id 0pTydvAV-eOS; Sat, 30 Dec 2017 10:02:18 +0000 (UTC) Received: from ash.osuosl.org (ash.osuosl.org [140.211.166.34]) by fraxinus.osuosl.org (Postfix) with ESMTP id 7F92386020; Sat, 30 Dec 2017 10:02:18 +0000 (UTC) X-Original-To: buildroot@lists.busybox.net Delivered-To: buildroot@osuosl.org Received: from fraxinus.osuosl.org (smtp4.osuosl.org [140.211.166.137]) by ash.osuosl.org (Postfix) with ESMTP id CD8831C0B30 for ; Sat, 30 Dec 2017 10:02:16 +0000 (UTC) Received: from localhost (localhost [127.0.0.1]) by fraxinus.osuosl.org (Postfix) with ESMTP id CB38C86004 for ; Sat, 30 Dec 2017 10:02:16 +0000 (UTC) X-Virus-Scanned: amavisd-new at osuosl.org Received: from fraxinus.osuosl.org ([127.0.0.1]) by localhost (.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id OicxqqKnlr0S for ; Sat, 30 Dec 2017 10:02:15 +0000 (UTC) X-Greylist: domain auto-whitelisted by SQLgrey-1.7.6 Received: from mail-wm0-f46.google.com (mail-wm0-f46.google.com [74.125.82.46]) by fraxinus.osuosl.org (Postfix) with ESMTPS id 0F3F686020 for ; Sat, 30 Dec 2017 10:02:15 +0000 (UTC) Received: by mail-wm0-f46.google.com with SMTP id i11so51034811wmf.4 for ; Sat, 30 Dec 2017 02:02:14 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amarulasolutions-com.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=4uP6EfEdg2rSbJdTAOfQEYc3jbgWaM1UhS9WK0PP4JE=; b=NoLOSX7tRxvIqRSyG7smV1di3H78KRU1R4Y6416gaerHuYAMpAEJ6JVVTo0cT63Ti+ /OsYDLCb7S0eAF/+HYlrJOBiR+pM051+N3eiF5l2WT2q3ufj7UnmefBRdbKDyj7ERlqn 40WNgMtV9nr2tox1/bJrWamOxNk+AfCDSTHrzS9H2r8N4eMOI6a1YHIWuad/XCpszhBj trjINUH7D0ZzOj/3ABowSM7/F69okrZQDSXPwqHaAp7QP7Py4P8+kcoHg9GYeTQu1b5o ITkM63h3k1sLYFr6ExbxDGlXUbZIcvJstBYNRabu93M9N+oMJxT4SAINiVp2w4EsHlMG S5nw== 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=4uP6EfEdg2rSbJdTAOfQEYc3jbgWaM1UhS9WK0PP4JE=; b=TaADULsxZO/H9cfm0zL+xOhKOxnqBJGSAkdcF2TioUAUVf4PBLtC1Qhk2vVVZHcv9F 8XL/8Cb67895/rwkVIK1zpHlNuXRGfKNozZRXAqwqRjgBuiT4ndkHt9NnmZkV6nrpDOH X8D04kF8sRuBHaiX965KZHJgd8KIwLMSxLE2Q2XqlQeXEDQ/lxrJpDY8iptx+O1UtAwY kSH4NYthgm9ZRti6Tdx9mNgQep+V0JwJcep3iESErr185ssYY/qpR4gB3fcI4GJv/kNj E7YDOmjdOBf/S3tE79w1eTAkokd19MywllWfeLQ0arerQyZJf5fHuJHxeUjXE7lfMfVc XcKQ== X-Gm-Message-State: AKGB3mLuOXVwVaEhujIb/WR8eosx9+lMUW4OnIVvdDt+clXt2nYkG0Xn sjVNFQLaiOh5JK5OaS6k3DHt3MHu8q0= X-Google-Smtp-Source: ACJfBotZTp0INlUoHCShT/4z36PyJM033vSvD6EOVEN8703o1sw2hJAuiRRHQej3uS9+7AuA/Fd3JQ== X-Received: by 10.28.141.11 with SMTP id p11mr6417518wmd.149.1514628133213; Sat, 30 Dec 2017 02:02:13 -0800 (PST) Received: from localhost.localdomain ([89.202.204.147]) by smtp.gmail.com with ESMTPSA id n65sm66180723wrb.17.2017.12.30.02.02.12 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Sat, 30 Dec 2017 02:02:12 -0800 (PST) From: Angelo Compagnucci To: buildroot@buildroot.org Date: Sat, 30 Dec 2017 11:02:01 +0100 Message-Id: <1514628127-15938-2-git-send-email-angelo@amarulasolutions.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1514628127-15938-1-git-send-email-angelo@amarulasolutions.com> References: <1514628127-15938-1-git-send-email-angelo@amarulasolutions.com> Subject: [Buildroot] [PATCH v2 1/7] package/pkg-golang: new package infrastructure X-BeenThere: buildroot@busybox.net X-Mailman-Version: 2.1.24 Precedence: list List-Id: Discussion and development of buildroot List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Angelo Compagnucci MIME-Version: 1.0 Errors-To: buildroot-bounces@busybox.net Sender: "buildroot" From: Angelo Compagnucci This patch adds a new infrastructure for golang based packages. Signed-off-by: Angelo Compagnucci --- Changes: v1 -> v2: Renamed GOBIN to GO_BIN for clarity package/Makefile.in | 1 + package/pkg-golang.mk | 121 ++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 122 insertions(+) create mode 100644 package/pkg-golang.mk diff --git a/package/Makefile.in b/package/Makefile.in index a1a5316..60d98d0 100644 --- a/package/Makefile.in +++ b/package/Makefile.in @@ -429,3 +429,4 @@ include package/pkg-kconfig.mk include package/pkg-rebar.mk include package/pkg-kernel-module.mk include package/pkg-waf.mk +include package/pkg-golang.mk diff --git a/package/pkg-golang.mk b/package/pkg-golang.mk new file mode 100644 index 0000000..f6052a6 --- /dev/null +++ b/package/pkg-golang.mk @@ -0,0 +1,121 @@ +################################################################################ +# Golang package infrastructure +# +# This file implements an infrastructure that eases development of +# package .mk files for Go packages. It should be used for all +# packages that are written in go. +# +# See the Buildroot documentation for details on the usage of this +# infrastructure +# +# +# In terms of implementation, this golang infrastructure requires +# the .mk file to only specify metadata information about the +# package: name, version, download URL, etc. +# +# We still allow the package .mk file to override what the different +# steps are doing, if needed. For example, if _BUILD_CMDS is +# already defined, it is used as the list of commands to perform to +# build the package, instead of the default golang behavior. The +# package can also define some post operation hooks. +# +################################################################################ + +GO_BIN = $(HOST_DIR)/bin/go + +################################################################################ +# inner-golang-package -- defines how the configuration, compilation and +# installation of a Go package should be done, implements a few hooks to +# tune the build process for Go specificities and calls the generic package +# infrastructure to generate the necessary make targets +# +# argument 1 is the lowercase package name +# argument 2 is the uppercase package name, including a HOST_ prefix +# for host packages +# argument 3 is the uppercase package name, without the HOST_ prefix +# for host packages +# argument 4 is the type (target or host) +################################################################################ + +define inner-golang-package + +$(2)_GOPATH ?= _gopath +$(2)_GO_ENV ?= $$(HOST_GO_TARGET_ENV) \ + GOPATH="$$(@D)/$$($(2)_GOPATH)" \ + CGO_ENABLED=$$(HOST_GO_CGO_ENABLED) + +ifeq ($(BR2_STATIC_LIBS),y) + $(2)_GO_LDFLAGS += -extldflags '-static' +endif + +ifdef $(2)_GO_LDFLAGS + $(2)_BUILD_OPTS += -ldflags "$$($(2)_GO_LDFLAGS)" +endif + +ifdef $(2)_GO_TAGS + $(2)_BUILD_OPTS += -tags "$$($(2)_GO_TAGS)" +endif + +# Target packages need the Go compiler on the host. +$(2)_DEPENDENCIES += host-go + +# +# The go build/install command installs the binaries inside +# gopath/bin/linux_GOARCH/ when cross compilation is enabled. +# We set this variable here to be used by packages if needed. +# +$(2)_BINDIR = $$($(2)_GOPATH)/bin/linux_$$(GO_GOARCH) + +# +# Source files in Go should be uncompressed in a precise folder in the +# hierarchy of GOPATH. It usually resolves around domain/vendor/software. +# +$(2)_GO_SRC_PATH ?= $$(call domain,$($(2)_SITE))/$$(firstword $$(subst /, ,$$(call notdomain,$($(2)_SITE)))) +$(2)_SRC_PATH = $$(@D)/$$($(2)_GOPATH)/src/$$($(2)_GO_SRC_PATH)/$(1) + +# +# Configure step. Only define it if not already defined by the package +# .mk file. +# +ifndef $(2)_CONFIGURE_CMDS +define $(2)_CONFIGURE_CMDS + mkdir -p $$(@D)/$$($(2)_GOPATH)/bin + mkdir -p $$(@D)/$$($(2)_GOPATH)/src/$$($(2)_GO_SRC_PATH) + ln -sf $$(@D) $$($(2)_SRC_PATH) +endef +endif + +# +# Build step. Only define it if not already defined by the package .mk file. +# We use the install command instead of build command here because the +# install command also moves the package binaries in gopath/bin/linux_GOARCH/. +# Using the install command also leverages the go build infrastructure +# for building and installing multiple binaries. +# +ifndef $(2)_BUILD_CMDS +define $(2)_BUILD_CMDS + cd $$($(2)_SRC_PATH) && $$($(2)_GO_ENV) $$(GO_BIN) install -v $$($(2)_BUILD_OPTS) +endef +endif + +# +# Target installation step. Only define it if not already defined by the +# package .mk file. +# +ifndef $(2)_INSTALL_TARGET_CMDS +define $(2)_INSTALL_TARGET_CMDS + $(INSTALL) -D -m 0755 $$(@D)/$$($(2)_BINDIR)/$(1) $(TARGET_DIR)/usr/bin/ +endef +endif + +# Call the generic package infrastructure to generate the necessary make +# targets +$(call inner-generic-package,$(1),$(2),$(3),$(4)) + +endef # inner-golang-package + +################################################################################ +# golang-package -- the target generator macro for Go packages +################################################################################ + +golang-package = $(call inner-golang-package,$(pkgname),$(call UPPERCASE,$(pkgname)),$(call UPPERCASE,$(pkgname)),target)