]> rtime.felk.cvut.cz Git - coffee/buildroot.git/blob - package/pkg-golang.mk
lrzsz: install symlinks for XMODEM and YMODEM
[coffee/buildroot.git] / package / pkg-golang.mk
1 ################################################################################
2 # Golang package infrastructure
3 #
4 # This file implements an infrastructure that eases development of package .mk
5 # files for Go packages. It should be used for all packages that are written in
6 # go.
7 #
8 # See the Buildroot documentation for details on the usage of this
9 # infrastructure
10 #
11 #
12 # In terms of implementation, this golang infrastructure requires the .mk file
13 # to only specify metadata information about the package: name, version,
14 # download URL, etc.
15 #
16 # We still allow the package .mk file to override what the different steps are
17 # doing, if needed. For example, if <PKG>_BUILD_CMDS is already defined, it is
18 # used as the list of commands to perform to build the package, instead of the
19 # default golang behavior. The package can also define some post operation
20 # hooks.
21 #
22 ################################################################################
23
24 GO_BIN = $(HOST_DIR)/bin/go
25
26 # We pass an empty GOBIN, otherwise "go install: cannot install
27 # cross-compiled binaries when GOBIN is set"
28 GO_TARGET_ENV = \
29         $(HOST_GO_TARGET_ENV) \
30         PATH=$(BR_PATH) \
31         GOBIN= \
32         CGO_ENABLED=$(HOST_GO_CGO_ENABLED)
33
34 ################################################################################
35 # inner-golang-package -- defines how the configuration, compilation and
36 # installation of a Go package should be done, implements a few hooks to tune
37 # the build process for Go specificities and calls the generic package
38 # infrastructure to generate the necessary make targets
39 #
40 #  argument 1 is the lowercase package name
41 #  argument 2 is the uppercase package name, including a HOST_ prefix for host
42 #             packages
43 #  argument 3 is the uppercase package name, without the HOST_ prefix for host
44 #             packages
45 #  argument 4 is the type (target or host)
46 #
47 # NOTE Only type target is supported at the moment
48 ################################################################################
49
50 define inner-golang-package
51
52 $(2)_WORKSPACE ?= _gopath
53
54 ifeq ($(BR2_STATIC_LIBS),y)
55 $(2)_LDFLAGS += -extldflags '-static'
56 endif
57
58 $(2)_BUILD_OPTS += -ldflags "$$($(2)_LDFLAGS)"
59 $(2)_BUILD_OPTS += -tags "$$($(2)_TAGS)"
60
61 # Target packages need the Go compiler on the host.
62 $(2)_DEPENDENCIES += host-go
63
64 $(2)_BUILD_TARGETS ?= .
65
66 # If the build target is just ".", then we assume the binary to be
67 # produced is named after the package. If however, a build target has
68 # been specified, we assume that the binaries to be produced are named
69 # after each build target building them (below in <pkg>_BUILD_CMDS).
70 ifeq ($$($(2)_BUILD_TARGETS),.)
71 $(2)_BIN_NAME ?= $(1)
72 endif
73
74 $(2)_INSTALL_BINS ?= $(1)
75
76 # Source files in Go should be extracted in a precise folder in the hierarchy
77 # of GOPATH. It usually resolves around domain/vendor/software. By default, we
78 # derive domain/vendor/software from the upstream URL of the project, but we
79 # allow $(2)_SRC_SUBDIR to be overridden if needed.
80 $(2)_SRC_DOMAIN = $$(call domain,$($(2)_SITE))
81 $(2)_SRC_VENDOR = $$(word 1,$$(subst /, ,$$(call notdomain,$($(2)_SITE))))
82 $(2)_SRC_SOFTWARE = $$(word 2,$$(subst /, ,$$(call notdomain,$($(2)_SITE))))
83
84 $(2)_SRC_SUBDIR ?= $$($(2)_SRC_DOMAIN)/$$($(2)_SRC_VENDOR)/$$($(2)_SRC_SOFTWARE)
85 $(2)_SRC_PATH = $$(@D)/$$($(2)_WORKSPACE)/src/$$($(2)_SRC_SUBDIR)
86
87 # Configure step. Only define it if not already defined by the package .mk
88 # file.
89 ifndef $(2)_CONFIGURE_CMDS
90 define $(2)_CONFIGURE_CMDS
91         mkdir -p $$(dir $$($(2)_SRC_PATH))
92         ln -sf $$(@D) $$($(2)_SRC_PATH)
93 endef
94 endif
95
96 # Build step. Only define it if not already defined by the package .mk
97 # file.
98 ifndef $(2)_BUILD_CMDS
99 define $(2)_BUILD_CMDS
100         $$(foreach d,$$($(2)_BUILD_TARGETS),\
101                 cd $$($(2)_SRC_PATH); \
102                 $$(GO_TARGET_ENV) \
103                         GOPATH="$$(@D)/$$($(2)_WORKSPACE)" \
104                         $$($(2)_GO_ENV) \
105                         $$(GO_BIN) build -v $$($(2)_BUILD_OPTS) \
106                         -o $$(@D)/bin/$$(or $$($(2)_BIN_NAME),$$(notdir $$(d))) \
107                         ./$$(d)
108         )
109 endef
110 endif
111
112 # Target installation step. Only define it if not already defined by the
113 # package .mk file.
114 ifndef $(2)_INSTALL_TARGET_CMDS
115 define $(2)_INSTALL_TARGET_CMDS
116         $$(foreach d,$$($(2)_INSTALL_BINS),\
117                 $(INSTALL) -D -m 0755 $$(@D)/bin/$$(d) $(TARGET_DIR)/usr/bin/$$(d)
118         )
119 endef
120 endif
121
122 # Call the generic package infrastructure to generate the necessary make
123 # targets
124 $(call inner-generic-package,$(1),$(2),$(3),$(4))
125
126 endef # inner-golang-package
127
128 ################################################################################
129 # golang-package -- the target generator macro for Go packages
130 ################################################################################
131
132 golang-package = $(call inner-golang-package,$(pkgname),$(call UPPERCASE,$(pkgname)),$(call UPPERCASE,$(pkgname)),target)