github.com/mit-dci/lit@v0.0.0-20221102210550-8c3d3b49f2ce/build/releasebuild.sh (about) 1 #!/bin/bash 2 3 set -e 4 5 outdir=build/_outdir 6 releasedir=build/_releasedir 7 8 if [ ! -f "build/releasebuild.sh" ]; then 9 echo "$0 must be run from the root of the repository." 10 exit 2 11 fi 12 13 if [ "$1" == "clean" ]; then 14 rm -rf $outdir $releasedir 15 exit 16 fi 17 18 mkdir -p $outdir $releasedir 19 20 function gen_arc_name() { 21 os=$1 22 arch=$2 23 24 ext='tar.gz' 25 if [ "$os" == "win" ]; then 26 ext='zip' 27 fi 28 29 echo $(gen_out_dir_name)-$os-$arch.$ext 30 } 31 32 function gen_out_dir_name() { 33 vermarker=$(git rev-parse --short HEAD) 34 35 gittag=$(git describe --tags --exact-match HEAD 2> /dev/null) 36 if [ "$?" == "0" ]; then 37 vermarker=$(echo "$gittag" | head -n 1) 38 fi 39 40 echo lit-$vermarker 41 } 42 43 function get_work_dir_path() { 44 os=$1 45 arch=$2 46 echo $outdir/$os-$arch 47 } 48 49 function run_build_for_platform() { 50 os=$1 51 arch=$2 52 53 # Set up the output directory. 54 workdir=$(get_work_dir_path $os $arch) 55 gooutdir=$workdir/$(gen_out_dir_name) 56 mkdir -p $gooutdir 57 58 # Figure out some other details. 59 binext='' 60 goos=$os 61 goarch=$arch 62 63 if [ "$os" == "win" ]; then 64 goos='windows' 65 binext='.exe' 66 fi 67 68 if [ "$arch" == "i386" ]; then 69 goarch='386' 70 fi 71 72 # Actually build the binaries. 73 env GOOS=$goos GOARCH=$goarch GO_BUILD_EX_ARGS="-o $gooutdir/lit$binext" make lit 74 env GOOS=$goos GOARCH=$goarch GO_BUILD_EX_ARGS="-o $gooutdir/lit-af$binext" make lit-af 75 76 } 77 78 function compile_and_package() { 79 os=$1 80 arch=$2 81 82 outdirname=$(gen_out_dir_name) 83 arcname=$(gen_arc_name $os $arch) 84 85 run_build_for_platform $os $arch 86 87 # Copy some other files into what the archive's going to copy up. 88 for f in 'README.md LICENSE litlogo145.png'; do 89 cp -r $f $workdir/$outdirname 90 done 91 92 # This is where we actually make the archive of it. 93 set +e 94 workdir=$(get_work_dir_path $os $arch) 95 pushd $workdir 96 if [ "$os" != "win" ]; then 97 tar -cvzf $arcname $outdirname 98 else 99 zip -r $arcname $outdirname 100 fi 101 popd 102 set -e 103 104 # And them move it into the release directory. 105 if [ -e "$workdir/$arcname" ]; then 106 mv $workdir/$arcname $releasedir 107 fi 108 109 } 110 111 if [ -n "$1" ] && [ -n "$2" ]; then 112 compile_and_package $1 $2 113 else 114 115 if [ -z "$1" ]; then 116 117 # Linux 118 compile_and_package linux amd64 119 compile_and_package linux i386 120 compile_and_package linux arm 121 122 # macOS (Darwin) 123 compile_and_package darwin amd64 124 125 # Windows 126 compile_and_package win amd64 127 compile_and_package win i386 128 129 else 130 echo "usage: $0 <os> <arch>" 131 exit 1 132 fi 133 134 fi