github.com/Konstantin8105/c4go@v0.0.0-20240505174241-768bb1c65a51/scripts/vorbis.sh (about) 1 #!/bin/bash 2 3 set -e 4 5 go build 6 7 mkdir -p ./testdata/ 8 9 # prepare variables 10 export C4GO_DIR=$GOPATH/src/github.com/Konstantin8105/c4go 11 export C4GO=$C4GO_DIR/c4go 12 export GIT_SOURCE="https://github.com/nothings/stb.git" 13 export NAME="vorbis" 14 export TEMP_FOLDER="testdata/$NAME" 15 export GO_FILE="$TEMP_FOLDER/$NAME.go" 16 export GO_APP="$TEMP_FOLDER/$NAME.app" 17 export COMMIT=b42009b3b9d4ca35bc703f5310eedc74f584be58 18 19 # prepare C code 20 if [ ! -d $TEMP_FOLDER ]; then 21 mkdir -p $TEMP_FOLDER 22 git clone $GIT_SOURCE $TEMP_FOLDER 23 cd $TEMP_FOLDER/ 24 git checkout $COMMIT 25 cd ../../ 26 fi 27 28 # remove go files from last transpilation 29 echo "***** remove go files" 30 rm -f $TEMP_FOLDER/*.go 31 rm -f $TEMP_FOLDER/*.app 32 33 # transpilation of all projects 34 echo "Transpile to $GO_FILE" 35 $C4GO transpile \ 36 -s \ 37 -clang-flag="-lm" \ 38 -o="$GO_FILE" \ 39 $TEMP_FOLDER/*.c 40 41 # show warnings comments in Go source 42 echo "Calculate warnings in file: $GO_FILE" 43 WARNINGS=`cat $GO_FILE | grep "^// Warning" | sort | uniq | wc -l` 44 echo " After transpiling : $WARNINGS warnings." 45 46 # show other warnings 47 # show amount error from `go build`: 48 echo "Build to $GO_APP file" 49 WARNINGS_GO=`go build -o $GO_APP -gcflags="-e" $GO_FILE 2>&1 | wc -l` 50 echo " Go build : $WARNINGS_GO warnings" 51 # amount unsafe 52 UNSAFE=`cat $GO_FILE | grep "unsafe\." | wc -l` 53 echo " Unsafe : $UNSAFE" 54 # amount Go code lines 55 LINES=`wc $GO_FILE` 56 echo "(lines,words,bytes) : $LINES" 57 # defers 58 DEFER=`cat $GO_FILE | grep "defer func" | wc -l` 59 echo "defer func : $DEFER" 60 61 62 # Arguments menu 63 echo " -s for show detail of Go build errors" 64 if [ "$1" == "-s" ]; then 65 # show go build warnings 66 # c4go warnings 67 cat $GO_FILE | grep "^// Warning" | sort | uniq 68 # show amount error from `go build`: 69 go build -o $GO_APP -gcflags="-e" $GO_FILE 2>&1 | sort 70 fi 71 72