
installpath=`go env GOPATH | awk -F ':' '{print $1}'`/bin

buildmql() {

echo build
CGO_ENABLED=0 go test -o  ./mql -c -args

echo build linux
CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go test -o  ${installpath}/matrix/mql/mql -c -args

echo build arm64
CGO_ENABLED=0 GOOS=linux GOARCH=arm64 go test -o  ${installpath}/matrix/mql/mql_arm -c -args

echo build darwin
CGO_ENABLED=0 GOOS=darwin go test -o  ${installpath}/matrix/mql/mql_mac -c -args

echo build windows
CGO_ENABLED=0 GOOS=windows go test -o  ${installpath}/matrix/mql/mql.exe -c -args

echo build loong64
CGO_ENABLED=0 GOOS=linux GOARCH=loong64 go test -o  ${installpath}/matrix/mql/mql_loong -c -args

cp -pf ${installpath}/matrix/mql/mql ${installpath}/linux_amd64

echo "${newdirinfo}" > mqldirinfo

}

codeversion=`git log -1 --format=%cd --date=format:%Y%m%d%H%M%S`
echo code.version="${codeversion}"
echo "/* test.code.version="${codeversion}" */;" > basic/99ver/99ver.mql

newdirinfo=`ls -lrt *.go ../odbcmql/*.go ../../go.*`
dirinfo=`cat mqldirinfo`
if [[ "${dirinfo}" != "${newdirinfo}" || "$1" == "force" ]]; then
    buildmql
fi

# ls -l | grep '^d' | awk '{print $9}' | xargs -I % cp -rf % ${installpath}/matrix/mql

cp -pf initkeyspace.sh ${installpath}/matrix/mql
cp -pf initkeyspace.sh ${installpath}/linux_amd64
cp -pf mqltest.sh ${installpath}/matrix/mql
cp -pf mqltest.sh ${installpath}/linux_amd64
cp -pf oktest.sh ${installpath}/matrix/mql
cp -pf oktest.sh ${installpath}/linux_amd64
cp -pf pprof.sh ${installpath}/matrix/mql
cp -pf pprof.sh ${installpath}/linux_amd64

cp -pf ${installpath}/linux_amd64/msh ${installpath}/matrix/mql

./syncmql.sh
