...

Text file src/github.com/datawire/ambassador/v2/build-aux/prelude_go.mk

Documentation: github.com/datawire/ambassador/v2/build-aux

     1# This is part of `prelude.mk`, split out for organizational purposes.
     2# !!! NOTHING EAGER IS ALLOWED TO HAPPEN IN THIS FILE !!!
     3
     4#
     5# Internal Go language support the rest of prelude.mk (and go-mod.mk)
     6
     7#
     8# Some global constants
     9
    10_prelude.go.HAVE    = $(call lazyonce,_prelude.go.HAVE,$(shell which go 2>/dev/null))
    11_prelude.go.GOPATH  = $(call lazyonce,_prelude.go.GOPATH,$(shell go env GOPATH))
    12_prelude.go.VERSION = $(call lazyonce,_prelude.go.VERSION,$(patsubst go%,%,$(filter go1%,$(shell go version))))
    13
    14#
    15# Pure functions for working with Go version strings
    16
    17# Usage: $(call _prelude.go.VERSION.fill_patch, [MAJOR[ MINOR [PATCH] [PRERELEASE]]])
    18#
    19# Given an already-split Go version string, make sure the PATCH-level
    20# is filled in; `go version` omits it if PATCH==0.
    21_prelude.go.VERSION.fill = \
    22    $(if $(call uint.eq,0,$(words $1)),  0  0  0,\
    23    $(if $(call uint.eq,1,$(words $1)),  $1 0  0,\
    24    $(if $(call uint.eq,2,$(words $1)),  $1    0,\
    25    $(if $(call uint.eq,3,$(words $1)),\
    26         $(if $(filter beta% rc%,$(word 3,$1)),\
    27              $(wordlist 1,2,$1) 0 $(word 3,$1),\
    28              $1),\
    29    $(if $(call uint.eq,4,$(words $1)),  $1     ,\
    30    $(error Could not parse Go version string: '$1'))))))
    31
    32# Usage: $(call _prelude.go.VERSION.parse, MAJOR.MINOR[.PATCH][PRERELEASE])
    33#
    34# Given a Go version string, parse it in to 4 whitespace-separated
    35# segments: MAJOR MINOR PATCH PRERELEASE.  None of MAJOR, MINOR, or PATCH
    36# will be empty in the output.  PRERELEASE may be empty in the output.
    37_prelude.go.VERSION.parse = $(call _prelude.go.VERSION.fill,$(subst ., ,$(subst beta,.beta,$(subst rc,.rc,$1))))
    38
    39# Usage: $(_prelude.go.VERSION.prerelease.ge,A,B) => A >= B
    40#
    41# Compare Go version PRERELEASE strings (since you can't use
    42# $(call uint.ge,A,B) on them).
    43#
    44#   (empty)    , X       => $(TRUE)
    45#   (nonempty) , (empty) => $(FALSE)
    46#   rcX        , betaY   => $(TRUE)
    47#   rcX        , rcY     => (X >= Y)
    48#   betaX      , betaY   => (X >= Y)
    49_prelude.go.VERSION.prerelease.ge = $(strip \
    50    $(if $(call not,$1),$(TRUE),\
    51    $(if $(call not,$2),$(FALSE),\
    52    $(if $(and $(filter rc%,$1),$(filter beta%,$2)),$(TRUE),\
    53    $(if $(and $(filter beta%,$1),$(filter rc%,$2)),$(FALSE),\
    54    $(call uint.ge,\
    55               $(patsubst beta%,%,$(patsubst rc%,%,$1)),\
    56               $(patsubst beta%,%,$(patsubst rc%,%,$2))))))))
    57
    58# Usage: $(call _prelude.go.VERSION._ge, PARSED_A, PARSED_B)
    59_prelude.go.VERSION._ge = $(strip \
    60    $(if $(call uint.gt,$(word 1,$1),$(word 1,$2)),$(TRUE),\
    61    $(if $(call uint.lt,$(word 1,$1),$(word 1,$2)),$(FALSE),\
    62    $(if $(call uint.gt,$(word 2,$1),$(word 2,$2)),$(TRUE),\
    63    $(if $(call uint.lt,$(word 2,$1),$(word 2,$2)),$(FALSE),\
    64    $(if $(call uint.gt,$(word 3,$1),$(word 3,$2)),$(TRUE),\
    65    $(if $(call uint.lt,$(word 3,$1),$(word 3,$2)),$(FALSE),\
    66    $(call _prelude.go.VERSION.prerelease.ge,$(word 4,$1),$(word 4,$2)))))))))
    67
    68# Usage: $(call _prelude.go.VERSION.ge, A, B)
    69_prelude.go.VERSION.ge = $(call _prelude.go.VERSION._ge,$(call _prelude.go.VERSION.parse,$1),$(call _prelude.go.VERSION.parse,$2))
    70
    71#
    72# Function for doing version checks
    73
    74# Usage: $(call _prelude.go.VERSION.HAVE, major.minor[.patch][prerelease])
    75#
    76# Evaluates to $(TRUE) if `go` is >= the specified version, $(FALSE)
    77# otherwise.
    78_prelude.go.VERSION.HAVE = $(if $(_prelude.go.HAVE),$(call _prelude.go.VERSION.ge,$(_prelude.go.VERSION),$1))
    79
    80#
    81# Building Go programs for use by build-aux
    82
    83_prelude.go.ensure = $(if $(call _prelude.go.VERSION.HAVE,$1),,$(error This Makefile requires Go '$1' or newer; you $(if $(_prelude.go.HAVE),have '$(_prelude.go.VERSION)',do not seem to have Go)))

View as plain text