github.com/fzfile/BaiduPCS-Go@v0.0.0-20200606205115-4408961cf336/build.sh (about)

     1  #!/bin/sh
     2  
     3  name="BaiduPCS-Go"
     4  version=$1
     5  
     6  if [ "$1" = "" ]; then
     7    version=v3.6.2
     8  fi
     9  
    10  output="out/"
    11  
    12  old_golang() {
    13    GOROOT=/usr/local/go1.10.8
    14    go=$GOROOT/bin/go
    15  }
    16  
    17  new_golang() {
    18    GOROOT=/usr/local/go
    19    go=$GOROOT/bin/go
    20  }
    21  
    22  Build() {
    23    old_golang
    24    goarm=$4
    25    if [ "$4" = "" ]; then
    26      goarm=7
    27    fi
    28  
    29    echo "Building $1..."
    30    export GOOS=$2 GOARCH=$3 GO386=sse2 CGO_ENABLED=0 GOARM=$4
    31    if [ $2 = "windows" ]; then
    32      goversioninfo -o=resource_windows_386.syso
    33      goversioninfo -64 -o=resource_windows_amd64.syso
    34      $go build -ldflags "-X main.Version=$version -s -w" -o "$output/$1/$name.exe"
    35      RicePack $1 $name.exe
    36    else
    37      $go build -ldflags "-X main.Version=$version -s -w" -o "$output/$1/$name"
    38      RicePack $1 $name
    39    fi
    40  
    41    Pack $1
    42  }
    43  
    44  AndroidBuild() {
    45    new_golang
    46    echo "Building $1..."
    47    export GOOS=$2 GOARCH=$3 GOARM=$4 CGO_ENABLED=1
    48    go build -ldflags "-X main.Version=$version -s -w -linkmode=external -extldflags=-pie" -o "$output/$1/$name"
    49  
    50    RicePack $1 $name
    51    Pack $1
    52  }
    53  
    54  IOSBuild() {
    55    old_golang
    56    echo "Building $1..."
    57    mkdir -p "$output/$1"
    58    cd "$output/$1"
    59    export CC=/usr/local/go/misc/ios/clangwrap.sh GOOS=darwin GOARCH=arm GOARM=7 CGO_ENABLED=1
    60    $go build -ldflags "-X main.Version=$version -s -w" -o "armv7" github.com/iikira/BaiduPCS-Go
    61    jtool --sign --inplace --ent ../../entitlements.xml "armv7"
    62    export GOARCH=arm64
    63    $go build -ldflags "-X main.Version=$version -s -w" -o "arm64" github.com/iikira/BaiduPCS-Go
    64    jtool --sign --inplace --ent ../../entitlements.xml "arm64"
    65    lipo -create "armv7" "arm64" -output $name # merge
    66    rm "armv7" "arm64"
    67    cd ../..
    68    RicePack $1 $name
    69    Pack $1
    70  }
    71  
    72  # zip 打包
    73  Pack() {
    74    cp README.md "$output/$1"
    75  
    76    cd $output
    77    zip -q -r "$1.zip" "$1"
    78  
    79    # 删除
    80    rm -rf "$1"
    81  
    82    cd ..
    83  }
    84  
    85  # rice 打包静态资源
    86  RicePack() {
    87    return # 已取消web功能
    88    rice -i github.com/fzfile/BaiduPCS-Go/internal/pcsweb append --exec "$output/$1/$2"
    89  }
    90  
    91  touch ./vendor/golang.org/x/sys/windows/windows.s
    92  
    93  # Android
    94  export NDK_INSTALL=$ANDROID_NDK_ROOT/bin
    95  # CC=$NDK_INSTALL/arm-linux-androideabi-4.9/bin/arm-linux-androideabi-gcc AndroidBuild $name-$version"-android-16-armv5" android arm 5
    96  # CC=$NDK_INSTALL/arm-linux-androideabi-4.9/bin/arm-linux-androideabi-gcc AndroidBuild $name-$version"-android-16-armv6" android arm 6
    97  CC=$NDK_INSTALL/arm-linux-androideabi-4.9/bin/arm-linux-androideabi-gcc AndroidBuild $name-$version"-android-16-armv7" android arm 7
    98  CC=$NDK_INSTALL/aarch64-linux-android-4.9/bin/aarch64-linux-android-gcc AndroidBuild $name-$version"-android-21-arm64" android arm64 7
    99  CC=$NDK_INSTALL/i686-linux-android-4.9/bin/i686-linux-android-gcc AndroidBuild $name-$version"-android-16-386" android 386 7
   100  CC=$NDK_INSTALL/x86_64-linux-android-4.9/bin/x86_64-linux-android-gcc AndroidBuild $name-$version"-android-21-amd64" android amd64 7
   101  
   102  # iOS
   103  IOSBuild $name-$version"-darwin-ios-arm"
   104  
   105  # OS X / macOS
   106  Build $name-$version"-darwin-osx-amd64" darwin amd64
   107  # Build $name-$version"-darwin-osx-386" darwin 386
   108  
   109  # Windows
   110  Build $name-$version"-windows-x86" windows 386
   111  Build $name-$version"-windows-x64" windows amd64
   112  
   113  # Linux
   114  Build $name-$version"-linux-386" linux 386
   115  Build $name-$version"-linux-amd64" linux amd64
   116  Build $name-$version"-linux-armv5" linux arm 5
   117  Build $name-$version"-linux-armv7" linux arm 7
   118  Build $name-$version"-linux-arm64" linux arm64
   119  GOMIPS=softfloat Build $name-$version"-linux-mips" linux mips
   120  Build $name-$version"-linux-mips64" linux mips64
   121  GOMIPS=softfloat Build $name-$version"-linux-mipsle" linux mipsle
   122  Build $name-$version"-linux-mips64le" linux mips64le
   123  # Build $name-$version"-linux-ppc64" linux ppc64
   124  # Build $name-$version"-linux-ppc64le" linux ppc64le
   125  # Build $name-$version"-linux-s390x" linux s390x
   126  
   127  # Others
   128  # Build $name-$version"-solaris-amd64" solaris amd64
   129  Build $name-$version"-freebsd-386" freebsd 386
   130  Build $name-$version"-freebsd-amd64" freebsd amd64
   131  # Build $name-$version"-freebsd-arm" freebsd arm
   132  # Build $name-$version"-netbsd-386" netbsd	386
   133  # Build $name-$version"-netbsd-amd64" netbsd amd64
   134  # Build $name-$version"-netbsd-arm" netbsd	arm
   135  # Build $name-$version"-openbsd-386" openbsd 386
   136  # Build $name-$version"-openbsd-amd64" openbsd	amd64
   137  # Build $name-$version"-openbsd-arm" openbsd arm
   138  # Build $name-$version"-plan9-386" plan9 386
   139  # Build $name-$version"-plan9-amd64" plan9 amd64
   140  # Build $name-$version"-plan9-arm" plan9 arm
   141  # Build $name-$version"-nacl-386" nacl 386
   142  # Build $name-$version"-nacl-amd64p32" nacl amd64p32
   143  # Build $name-$version"-nacl-arm" nacl arm
   144  # Build $name-$version"-dragonflybsd-amd64" dragonfly amd64