From patchwork Thu Oct 5 12:40:58 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Angelo Compagnucci X-Patchwork-Id: 821747 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.133; helo=hemlock.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=gmail.com header.i=@gmail.com header.b="nTFc8rQR"; dkim-atps=neutral Received: from hemlock.osuosl.org (smtp2.osuosl.org [140.211.166.133]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3y7C7N01h3z9t2l for ; Thu, 5 Oct 2017 23:41:19 +1100 (AEDT) Received: from localhost (localhost [127.0.0.1]) by hemlock.osuosl.org (Postfix) with ESMTP id D32A4889D0; Thu, 5 Oct 2017 12:41:16 +0000 (UTC) X-Virus-Scanned: amavisd-new at osuosl.org Received: from hemlock.osuosl.org ([127.0.0.1]) by localhost (.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id AypIG2BjfGAu; Thu, 5 Oct 2017 12:41:14 +0000 (UTC) Received: from ash.osuosl.org (ash.osuosl.org [140.211.166.34]) by hemlock.osuosl.org (Postfix) with ESMTP id 2A7B8889C9; Thu, 5 Oct 2017 12:41:14 +0000 (UTC) X-Original-To: buildroot@lists.busybox.net Delivered-To: buildroot@osuosl.org Received: from silver.osuosl.org (smtp3.osuosl.org [140.211.166.136]) by ash.osuosl.org (Postfix) with ESMTP id 5451E1C01CA for ; Thu, 5 Oct 2017 12:41:12 +0000 (UTC) Received: from localhost (localhost [127.0.0.1]) by silver.osuosl.org (Postfix) with ESMTP id 46E1F26695 for ; Thu, 5 Oct 2017 12:41:12 +0000 (UTC) X-Virus-Scanned: amavisd-new at osuosl.org Received: from silver.osuosl.org ([127.0.0.1]) by localhost (.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id T8tA9HFCEB+o for ; Thu, 5 Oct 2017 12:41:11 +0000 (UTC) X-Greylist: domain auto-whitelisted by SQLgrey-1.7.6 Received: from mail-wr0-f194.google.com (mail-wr0-f194.google.com [209.85.128.194]) by silver.osuosl.org (Postfix) with ESMTPS id 3F56E25DBB for ; Thu, 5 Oct 2017 12:41:11 +0000 (UTC) Received: by mail-wr0-f194.google.com with SMTP id l10so1280132wre.3 for ; Thu, 05 Oct 2017 05:41:11 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=TptsfQWpg7Js2I+qWEY2FX7rqankaz/422AfU5pEEd4=; b=nTFc8rQR3pu0XMyt+++eQ/iTwqh+vGuwYJdjJCoeefCdsG/PHqMldJhl/BwLicOB3g 8IQXQgbjXxZaTHajDkEE4E3lF6Ylc1oAMI6hoBFWH3oB9avLqtwDNaHdaG8Dugik1Dcv +yZr7buWNDRy2pIZcYKR5tXgS2b8M4ZleCwQEP3/H8Lh0hGchITYSUmSvUJg5RXaT9iy GRulUbzxRc8GmwnGHLVhQS1aqBqbD3OMAcu/w/nmCwiEGdjd5HZIQ+2VFLQ48J5epwxn 7KhVyYTNLWY1ra6+9+uMs+V8ga8BxUciD+I2f8daqFF55BKyGStFRlpjsEM+qWK9LSy5 WKsw== 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=TptsfQWpg7Js2I+qWEY2FX7rqankaz/422AfU5pEEd4=; b=ptBNIPZyiHmN+ivseYTStKlUx5KjY1gfyBJykKyCdTl077HHhho5CcnIUsC+Eif2Qf kXxTCd9xQHsfIk7rHS6K7TXEw677mnarwkjitO09i1BKZCpcSzB8QgFDS7L81NnaWoeK 4FmTgLHH20woTKKqy8sXd428Kuzm1VGcxX6GkjVePZ4g4pyyrbbvF4DmO0AkojdwS2EY dN6t6Otd0DxrNVHNgNK3nRvq0n90UQHA+yYcFNfC53rmGQ83E0aqQubStmUbWP1vv6bA 5N+HjoLFBQAossoOPuKvpoMA0Lym1mP9BXhBkDUUqGxQ6XAgayeVs9CsYhLfdCtDTYPL NDng== X-Gm-Message-State: AMCzsaWc+SKOs9lt46nvieVQ/zEDOBNdA55tRXlqGO6ThtghtEdYIstm V7SaEp6jzRc6+v/ACXFRAsV/v1ED X-Google-Smtp-Source: AOwi7QBQA0fFPCskKCTb9+AJhtht/fuC5xfbo0UsHu9pRUzX75VAa2UHK83z/7anINakNJ1qtKlgBg== X-Received: by 10.223.180.82 with SMTP id v18mr8958792wrd.61.1507207269063; Thu, 05 Oct 2017 05:41:09 -0700 (PDT) Received: from localhost.localdomain ([89.202.204.147]) by smtp.gmail.com with ESMTPSA id c37sm10056896wra.73.2017.10.05.05.41.07 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 05 Oct 2017 05:41:08 -0700 (PDT) From: Angelo Compagnucci To: buildroot@buildroot.org Date: Thu, 5 Oct 2017 14:40:58 +0200 Message-Id: <1507207260-26734-2-git-send-email-angelo.compagnucci@gmail.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1507207260-26734-1-git-send-email-angelo.compagnucci@gmail.com> References: <1507207260-26734-1-git-send-email-angelo.compagnucci@gmail.com> Subject: [Buildroot] [RFC 2/4] package/pkg-golang: new package infrastructure X-BeenThere: buildroot@busybox.net X-Mailman-Version: 2.1.18-1 Precedence: list List-Id: Discussion and development of buildroot List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: buildroot-bounces@busybox.net Sender: "buildroot" This patch adds a new infrastructure for golang based packages. Signed-off-by: Angelo Compagnucci --- 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..c4e6410 --- /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 behaviour. The +# package can also define some post operation hooks. +# +################################################################################ + +################################################################################ +# 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 specifities 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 + +ifndef $(2)_MAKE_ENV +define $(2)_MAKE_ENV + $$(HOST_GO_TARGET_ENV) \ + GOPATH="$$(@D)/gopath" \ + CGO_ENABLED=$$(HOST_GO_CGO_ENABLED) +endef +endif + +# Target packages need the Go compiler on the host. +$(2)_DEPENDENCIES += host-go + +# +# go install command doesn't work well when cross compilation is enabled, +# we set the executable output of the compilation to a specific location. +# We set this variable here to be used by packages if needed. +# +$(2)_EXECUTABLE = $$(@D)/gopath/bin/$(1) + +# +# Source files in Go should be uncompressed in a precise folder in the +# hiearchy of GOPATH. It usually resolves around domain/vendor/software. +# +$(1)_src_path ?= $$(call domain,$($(2)_SITE))/$$(firstword $$(subst /, ,$$(call notdomain,$($(2)_SITE)))) +$(2)_SRC_PATH = $$(@D)/gopath/src/$$($(1)_src_path)/$(1) + +# +# Configure step. Only define it if not already defined by the package +# .mk file. And take care of the differences between host and target +# packages. +# +ifndef $(2)_CONFIGURE_CMDS +define $(2)_CONFIGURE_CMDS + mkdir -p $$(@D)/gopath/bin + mkdir -p $$(@D)/gopath/src/$$($(1)_src_path) + ln -sf $$(@D) $$($(2)_SRC_PATH) +endef +endif + +# +# Build step. Only define it if not already defined by the package .mk file. +# There is no differences between host and target packages. +# +ifndef $(2)_BUILD_CMDS +define $(2)_BUILD_CMDS + cd $$($(2)_SRC_PATH) && $$($(2)_MAKE_ENV) $(HOST_DIR)/bin/go build \ + -o $$($(2)_EXECUTABLE) -v $$($(2)_BUILD_OPTS) +endef +endif + +# +# Host installation step. Only define it if not already defined by the +# package .mk file. +# +ifndef $(2)_INSTALL_CMDS +define $(2)_INSTALL_CMDS + $(INSTALL) -D -m 0755 $$($(2)_EXECUTABLE) $(HOST_DIR)/usr/bin/ +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 $$($(2)_EXECUTABLE) $(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) +host-golang-package = $(call inner-golang-package,host-$(pkgname),$(call UPPERCASE,host-$(pkgname)),$(call UPPERCASE,$(pkgname)),host) +