github.com/mysteriumnetwork/node@v0.0.0-20240516044423-365054f76801/bin/build (about)

     1  #!/bin/bash
     2  
     3  # Usage:
     4  #> bin/build
     5  #
     6  # Compile with race detector enabled:
     7  #> FLAG_RACE=true bin/build
     8  #
     9  # Cross compile (Unix):
    10  #> GOOS=linux GOARCH=amd64 bin/build
    11  #
    12  # Cross compile (OSX):
    13  #> GOOS=darwin GOARCH=amd64 bin/build
    14  #
    15  # Cross compile (Windows):
    16  #> GOOS=windows GOARCH=amd64 bin/build
    17  #
    18  # Check if program has dynamic libraries:
    19  #> brew install readelf
    20  #> readelf -d build/myst/myst
    21  
    22  source bin/helpers/functions.sh
    23  source bin/helpers/output.sh
    24  
    25  export GOOS=${GOOS:-`go env GOHOSTOS`}
    26  export GOARCH=${GOARCH:-`go env GOHOSTARCH`}
    27  export GOBIN=`pwd`/build/myst
    28  if [ "$FLAG_RACE" == "true" ]; then R=-race; fi
    29  
    30  echo "Compiling 'myst' for '$GOOS/$GOARCH'.."
    31  
    32  LD_FLAGS="-w -s $(get_linker_ldflags)"
    33  STATIC_OPTS=
    34  
    35  if [[ "$BUILD_STATIC" = 1 ]] ; then
    36  	export CGO_ENABLED=0
    37  	LD_FLAGS="$LD_FLAGS"' -extldflags "-static"'
    38  	STATIC_OPTS="$STATIC_OPTS -a -tags netgo"
    39  fi
    40  
    41  go build $R -ldflags="$LD_FLAGS" $STATIC_OPTS -o $GOBIN/myst cmd/mysterium_node/mysterium_node.go
    42  if [ $? -ne 0 ]; then
    43      print_error "Compile failed!"
    44      exit 1
    45  fi
    46  
    47  mkdir -p $GOBIN/config
    48  copy_config $GOOS $GOBIN
    49