From patchwork Mon Oct 23 16:40:11 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Angelo Compagnucci X-Patchwork-Id: 829415 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.138; helo=whitealder.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="n8QkJEV0"; dkim-atps=neutral Received: from whitealder.osuosl.org (smtp1.osuosl.org [140.211.166.138]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3yLMb01DDGz9tX8 for ; Tue, 24 Oct 2017 03:40:28 +1100 (AEDT) Received: from localhost (localhost [127.0.0.1]) by whitealder.osuosl.org (Postfix) with ESMTP id DCD4786A89; Mon, 23 Oct 2017 16:40:25 +0000 (UTC) X-Virus-Scanned: amavisd-new at osuosl.org Received: from whitealder.osuosl.org ([127.0.0.1]) by localhost (.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id 5XBt+PZ8WiK5; Mon, 23 Oct 2017 16:40:24 +0000 (UTC) Received: from ash.osuosl.org (ash.osuosl.org [140.211.166.34]) by whitealder.osuosl.org (Postfix) with ESMTP id 411E286AC4; Mon, 23 Oct 2017 16:40:24 +0000 (UTC) X-Original-To: buildroot@lists.busybox.net Delivered-To: buildroot@osuosl.org Received: from hemlock.osuosl.org (smtp2.osuosl.org [140.211.166.133]) by ash.osuosl.org (Postfix) with ESMTP id 6E7611BFB70 for ; Mon, 23 Oct 2017 16:40:23 +0000 (UTC) Received: from localhost (localhost [127.0.0.1]) by hemlock.osuosl.org (Postfix) with ESMTP id 692A587669 for ; Mon, 23 Oct 2017 16:40:23 +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 04Qk-Otum7XY for ; Mon, 23 Oct 2017 16:40:22 +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 hemlock.osuosl.org (Postfix) with ESMTPS id 5316C87140 for ; Mon, 23 Oct 2017 16:40:22 +0000 (UTC) Received: by mail-wr0-f194.google.com with SMTP id j15so5894472wre.8 for ; Mon, 23 Oct 2017 09:40:22 -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; bh=BFtFBF/O6DqyaAgCCCpo5PsGjdtp9MY47Ss9MbZz20g=; b=n8QkJEV0PFiCPGR6R5kRqzXEvymMcL80K7OPPYv0m2KOu6MHOFMroBW6pV2auPdO7w uGhE93RFDLer8of11Q3F3zMcdeslHv2pjBqg+cC06YQllbr6h/KziGvpzVtuBVRxY+ab 4EudVObTmaxU+QPb52nnr4sbGYlknhtP5PI4ZzYQnhjLkneyleXHk9OW70SmdZsQY95h 20hOY1TgFVxhwzvle6l47/WyQmFLlKBPCEHXB/BJZbjmSe+LcLTJ8t3TWa4EW8EQ+Tuk 252ofkn+A7ywOyoML2u1QlKKVGrCQGm3+Ic4sV5+ohvV00ORV79/Vs3JBCbFlpr0/lEV pNJQ== 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; bh=BFtFBF/O6DqyaAgCCCpo5PsGjdtp9MY47Ss9MbZz20g=; b=pRWn73Qo7TqakjvdAbCzKI23YUYc3bwExcgQYsp9GiXqChmQIi2hU/BdTko5KnNg+2 J3FbhSE4rBD39t9w8mayZ0kQWmVezqR7hnIbJKV+ukZc91O568tA8PZ+1KLqcTkwOpuj 6/Mlukd4Ggf+gRCGEbYTNF5V5ceEOuJdVDEbgo81HJyh/M2LOYm6prt9UlytQN2SZ3Bt 19mcnDPo/55tqFEh04RhM+J61IN89nGb+FqEW+xUrgNFyXcG5M7KKBqEKtMpy6vWXhR9 /UDKqXkB/838E9soFJ3arCSm62gu4yg0jk8nyQBamHqhFY6wcCyavhq+oFvRsQpMkO1j 6ihw== X-Gm-Message-State: AMCzsaXC8PgTdyVzO2iR8NT2t5hd1P17Gse1eVKnQGGRHVEURHrwGA3D ilRNPq/wD0Auysl1n84e7a/QJ2SB X-Google-Smtp-Source: ABhQp+RhinJ2/sb9Cba/TLKYSccC/b/kz/4tQbQvPgNr9edHoldnkqXoa4hdxlPqYcjoChRgL+U8QQ== X-Received: by 10.223.163.143 with SMTP id l15mr700931wrb.149.1508776819964; Mon, 23 Oct 2017 09:40:19 -0700 (PDT) Received: from localhost.localdomain ([89.202.204.147]) by smtp.gmail.com with ESMTPSA id w5sm5222450wrg.65.2017.10.23.09.40.18 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 23 Oct 2017 09:40:18 -0700 (PDT) From: Angelo Compagnucci To: buildroot@buildroot.org Date: Mon, 23 Oct 2017 18:40:11 +0200 Message-Id: <1508776814-18723-1-git-send-email-angelo.compagnucci@gmail.com> X-Mailer: git-send-email 2.7.4 Subject: [Buildroot] [RFC v3 1/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 | 140 ++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 141 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..262f0e0 --- /dev/null +++ b/package/pkg-golang.mk @@ -0,0 +1,140 @@ +################################################################################ +# 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. +# +################################################################################ + +################################################################################ +# 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 + +ifndef $(2)_MAKE_ENV +define $(2)_MAKE_ENV + $$(HOST_GO_TARGET_ENV) \ + GOPATH="$$(@D)/$$($(2)_GOPATH)" \ + CGO_ENABLED=$$(HOST_GO_CGO_ENABLED) +endef +endif + +ifdef $(2)_GO_LDFLAGS + $(2)_BUILD_OPTS += -ldflags "$$($(2)_GO_LDFLAGS)" +endif + +ifeq ($(BR2_STATIC_LIBS),y) + $(2)_BUILD_OPTS += -extldflags '-static' +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 = $$(@D)/$$($(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. And take care of the differences between host and target +# packages. +# +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. +# There is no differences between host and target packages. +# 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)_MAKE_ENV) $(HOST_DIR)/bin/go install \ + -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)_BINDIR)/$(1) $(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)_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) +host-golang-package = $(call inner-golang-package,host-$(pkgname),$(call UPPERCASE,host-$(pkgname)),$(call UPPERCASE,$(pkgname)),host) +