-
Notifications
You must be signed in to change notification settings - Fork 7
/
build.sh
executable file
·76 lines (60 loc) · 2.58 KB
/
build.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
#!/bin/bash
pushd $(dirname "${0}") >/dev/null
HACKED_BASE=$(pwd -L)
FOLDER_NAME=inkyblackness-hacked
echo "Cleaning output directories..."
rm -rf _build
rm main-res.syso
mkdir -p $HACKED_BASE/_build/linux/$FOLDER_NAME
mkdir -p $HACKED_BASE/_build/win/$FOLDER_NAME
echo "Determining version"
MAJOR=$(date +%Y)
MINOR=$(date +%m)
PATCH=$(date +%d)
VERSION=$(git describe --tags)
if [ $? -ne 0 ]; then
echo "Could not determine tag, defaulting to revision for version"
REV=$(git rev-parse --short HEAD)
VERSION="rev$REV"
else
VERSION_RAW=$(echo "$VERSION" | cut -d'-' -f 1 | cut -d'v' -f 2)
fi
EXTRA=$(echo "$VERSION" | cut -d'-' -f 2)
if [[ "$VERSION" == "$EXTRA" ]]; then
MAJOR=$(echo "$VERSION_RAW" | cut -d'.' -f 1)
MINOR=$(echo "$VERSION_RAW" | cut -d'.' -f 2)
PATCH=$(echo "$VERSION_RAW" | cut -d'.' -f 3)
fi
echo "Determined version: $VERSION ($MAJOR.$MINOR.$PATCH)"
echo "Preparing build resources"
mkdir -p $HACKED_BASE/_build/win_temp
cp $HACKED_BASE/_resources/build/win/* $HACKED_BASE/_build/win_temp
sed -i "s/§MAJOR/$MAJOR/g" $HACKED_BASE/_build/win_temp/hacked.exe.manifest
sed -i "s/§MINOR/$MINOR/g" $HACKED_BASE/_build/win_temp/hacked.exe.manifest
sed -i "s/§PATCH/$PATCH/g" $HACKED_BASE/_build/win_temp/hacked.exe.manifest
x86_64-w64-mingw32-windres -o main-res.syso $HACKED_BASE/_build/win_temp/hacked.rc
echo "Building executables..."
go build -gcflags "-d=checkptr=0" -ldflags "-X main.version=$VERSION" -a -o $HACKED_BASE/_build/linux/$FOLDER_NAME/hacked -trimpath $(pwd) .
GOOS=windows GOARCH=amd64 CGO_ENABLED=1 CXX=x86_64-w64-mingw32-g++ CC=x86_64-w64-mingw32-gcc go build -gcflags "-d=checkptr=0" -ldflags "-X main.version=$VERSION -H=windowsgui" -a -o $HACKED_BASE/_build/win/$FOLDER_NAME/hacked.exe -trimpath $(pwd) .
echo "Copying distribution resources..."
for os in "linux" "win"; do
packageDir=$HACKED_BASE/_build/$os/$FOLDER_NAME
cp $HACKED_BASE/LICENSE $packageDir
cp -R $HACKED_BASE/_resources/dist/* $packageDir
done
for lib in "libgcc_s_seh-1.dll" "libstdc++-6.dll" "libwinpthread-1.dll"; do
for base in "/usr/x86_64-w64-mingw32/bin" "/usr/lib/gcc/x86_64-w64-mingw32/10-win32" "/usr/x86_64-w64-mingw32/lib"; do
if [ -e $base/$lib ]; then
cp $base/$lib $HACKED_BASE/_build/win/$FOLDER_NAME
fi
done
if [ ! -f $HACKED_BASE/_build/win/$FOLDER_NAME/$lib ]; then
echo " FAIL: file $lib is nowhere found"
fi
done
echo "Creating packages..."
cd $HACKED_BASE/_build/linux
tar -cvzf $HACKED_BASE/_build/$FOLDER_NAME-$VERSION.linux64.tgz ./$FOLDER_NAME
cd $HACKED_BASE/_build/win
zip -r $HACKED_BASE/_build/$FOLDER_NAME-$VERSION.win64.zip .
popd >/dev/null