| 1 |
#!/bin/sh |
| 2 |
|
| 3 |
# Public domain notice for all NCBI EDirect scripts is located at: |
| 4 |
# https://www.ncbi.nlm.nih.gov/books/NBK179288/#chapter6.Public_Domain_Notice |
| 5 |
|
| 6 |
# determine current platform |
| 7 |
platform="" |
| 8 |
osname=`uname -s` |
| 9 |
cputype=`uname -m` |
| 10 |
case "$osname-$cputype" in |
| 11 |
Linux-x86_64 ) platform=Linux ;; |
| 12 |
Darwin-x86_64 ) platform=Darwin ;; |
| 13 |
Darwin-*arm* ) platform=Silicon ;; |
| 14 |
CYGWIN_NT-* | MINGW*-* ) platform=CYGWIN_NT ;; |
| 15 |
Linux-*arm* ) platform=ARM ;; |
| 16 |
Linux-aarch64 ) platform=ARM64 ;; |
| 17 |
* ) platform=UNSUPPORTED ;; |
| 18 |
esac |
| 19 |
|
| 20 |
crossCompileAll=false |
| 21 |
install=false |
| 22 |
cleanup=true |
| 23 |
vendor=false |
| 24 |
target="" |
| 25 |
|
| 26 |
# process optional command-line arguments |
| 27 |
while [ "$#" -ne 0 ] |
| 28 |
do |
| 29 |
case "$1" in |
| 30 |
-install | install ) |
| 31 |
# install native executables on development machine |
| 32 |
install=true |
| 33 |
# default executable path |
| 34 |
target="$HOME/Misc/scripts/" |
| 35 |
shift |
| 36 |
;; |
| 37 |
-desktop | desktop ) |
| 38 |
# place native executables on desktop |
| 39 |
install=true |
| 40 |
target="$HOME/Desktop/" |
| 41 |
shift |
| 42 |
;; |
| 43 |
-silicon | silicon ) |
| 44 |
# coerce platform to create Silicon executables |
| 45 |
platform=Silicon |
| 46 |
install=true |
| 47 |
target="$HOME/Desktop/" |
| 48 |
# but do not remove existing native binaries on deskop |
| 49 |
cleanup=false |
| 50 |
shift |
| 51 |
;; |
| 52 |
-distrib | -distribute | distrib | distribute ) |
| 53 |
# cross-compile all versions for ftp distribution |
| 54 |
crossCompileAll=true |
| 55 |
install=true |
| 56 |
# default distribution path |
| 57 |
target="$HOME/goxtract/" |
| 58 |
shift |
| 59 |
;; |
| 60 |
-vendor | vendor ) |
| 61 |
vendor=true |
| 62 |
shift |
| 63 |
;; |
| 64 |
* ) |
| 65 |
if [ -n "$1" ] |
| 66 |
then |
| 67 |
# allow override of default target path |
| 68 |
install=true |
| 69 |
target="$1" |
| 70 |
fi |
| 71 |
# break out of loop |
| 72 |
break |
| 73 |
;; |
| 74 |
esac |
| 75 |
done |
| 76 |
|
| 77 |
# create module files |
| 78 |
if [ ! -f "go.mod" ] |
| 79 |
then |
| 80 |
go mod init edirect |
| 81 |
# add explicit location to find local helper package |
| 82 |
echo "replace eutils => ../eutils" >> go.mod |
| 83 |
# build local eutils library |
| 84 |
go get eutils |
| 85 |
fi |
| 86 |
if [ ! -f "go.sum" ] |
| 87 |
then |
| 88 |
go mod tidy |
| 89 |
fi |
| 90 |
|
| 91 |
# cache external dependencies |
| 92 |
if [ "$vendor" = true ] && [ ! -d "vendor" ] |
| 93 |
then |
| 94 |
go mod vendor -e |
| 95 |
fi |
| 96 |
|
| 97 |
# erase any existing executables in current directory |
| 98 |
for plt in Darwin Silicon Linux CYGWIN_NT ARM ARM64 |
| 99 |
do |
| 100 |
rm -f *.$plt |
| 101 |
done |
| 102 |
|
| 103 |
# platform-specific compiler environment variable values |
| 104 |
mods="darwin amd64 Darwin \ |
| 105 |
darwin arm64 Silicon \ |
| 106 |
linux amd64 Linux \ |
| 107 |
windows 386 CYGWIN_NT \ |
| 108 |
linux arm ARM \ |
| 109 |
linux arm64 ARM64" |
| 110 |
|
| 111 |
# build all executables for each selected platform |
| 112 |
echo "$mods" | |
| 113 |
xargs -n 3 sh -c 'echo "$0 $1 $2"' | |
| 114 |
while read os ar pl |
| 115 |
do |
| 116 |
if [ "$pl" != "$platform" ] && [ "$crossCompileAll" = false ] |
| 117 |
then |
| 118 |
continue |
| 119 |
fi |
| 120 |
for exc in xtract rchive transmute |
| 121 |
do |
| 122 |
env GOOS="$os" GOARCH="$ar" go build -o "$exc.$pl" "$exc.go" |
| 123 |
done |
| 124 |
done |
| 125 |
|
| 126 |
if [ "$install" = true ] && [ -n "$target" ] |
| 127 |
then |
| 128 |
if [ "$cleanup" = true ] |
| 129 |
then |
| 130 |
# remove old executables from target |
| 131 |
for plt in Darwin Silicon Linux CYGWIN_NT ARM ARM64 |
| 132 |
do |
| 133 |
rm -f $target/*.$plt |
| 134 |
done |
| 135 |
fi |
| 136 |
# copy new executables to target |
| 137 |
for plt in Darwin Silicon Linux CYGWIN_NT ARM ARM64 |
| 138 |
do |
| 139 |
for exc in xtract rchive transmute |
| 140 |
do |
| 141 |
if [ -f "$exc.$plt" ] |
| 142 |
then |
| 143 |
mv -f "$exc.$plt" "$target" |
| 144 |
fi |
| 145 |
done |
| 146 |
done |
| 147 |
fi |
| 148 |
|
| 149 |
# erase any remaining executables after compiling |
| 150 |
for plt in Darwin Silicon Linux CYGWIN_NT ARM ARM64 |
| 151 |
do |
| 152 |
rm -f *.$plt |
| 153 |
done |