summaryrefslogtreecommitdiff
path: root/gui/build.sh
blob: 8b336fa79b87a0588c7322a8a7a1f13e2b9caea1 (plain)
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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
#!/bin/bash
set -e
set -x

XBUILD=${XBUILD-no}
OSX_TARGET=10.11
WIN64="win64"
GO=`which go`

PROJECT=bitmask.pro
TARGET_GOLIB=lib/libgoshim.a
SOURCE_GOLIB=gui/backend.go

QTBUILD=build/qt
RELEASE=$QTBUILD/release

PLATFORM=$(uname -s)
LDFLAGS=""

if [ "$TARGET" == "" ]
then
    TARGET=riseup-vpn
fi

if [ "$XBUILD" == "$WIN64" ]
then
    # TODO allow to override vars
    QMAKE="`pwd`/../../mxe/usr/x86_64-w64-mingw32.static/qt5/bin/qmake"
    PATH="`pwd`/../../mxe/usr/bin"/:$PATH
    CC=x86_64-w64-mingw32.static-gcc
else
    if [ "$QMAKE" == "" ]
    then
        QMAKE=`which qmake`
    fi
fi

PLATFORM=`uname -s`

function init {
    mkdir -p lib
}

# TODO this should be moved to the makefile
function buildGoLib {
    echo "[+] Using go in" $GO "[`go version`]"
    $GO generate ./pkg/config/version/genver/gen.go
    if [ "$PLATFORM" == "Darwin" ]
    then
        GOOS=darwin
	CC=clang
	CGO_CFLAGS="-g -O2 -mmacosx-version-min=$OSX_TARGET"
	CGO_LDFLAGS="-g -O2 -mmacosx-version-min=$OSX_TARGET"
    fi
    if [ "$PLATFORM" == "MINGW64_NT-10.0" ]
    then
	LDFLAGS="-H=windowsgui"
    fi
    if [ "$XBUILD" == "no" ]
    then
        echo "[+] Building Go library with standard Go compiler"
        CGO_ENABLED=1 GOOS=$GOOS CC=$CC CGO_CFLAGS=$CGO_CFLAGS CGO_LDFLAGS=$CGO_LDFLAGS go build -ldflags $LDFLAGS -buildmode=c-archive -o $TARGET_GOLIB $SOURCE_GOLIB
    fi
    if [ "$XBUILD" == "$WIN64" ]
    then
        echo "[+] Building Go library with mxe"
        echo "[+] Using cc:" $CC
        CC=$CC CGO_ENABLED=1 GOOS=windows GOARCH=amd64 go build -buildmode=c-archive -o $TARGET_GOLIB $SOURCE_GOLIB
    fi
}

function buildQmake {
    echo "[+] Now building Qml app with Qt qmake"
    echo "[+] Using qmake in:" $QMAKE
    mkdir -p $QTBUILD
    $QMAKE -o $QTBUILD/Makefile "CONFIG-=debug CONFIG+=release" $PROJECT
}

function renameOutput {
    # i would expect that passing QMAKE_TARGET would produce the right output, but nope.
    if [ "$PLATFORM" == "Linux" ]
    then
    	mv $RELEASE/bitmask $RELEASE/$TARGET
    	strip $RELEASE/$TARGET
    	echo "[+] Binary is in" $RELEASE/$TARGET
    fi
    if [ "$PLATFORM" == "Darwin" ]
    then
    	rm -rf $RELEASE/$TARGET.app
    	mv $RELEASE/bitmask.app/ $RELEASE/$TARGET.app/
    	echo "[+] App is in" $RELEASE/$TARGET
    fi
    if [ "$PLATFORM" == "MINGW64_NT-10.0" ]
    then
    	mv $RELEASE/bitmask.exe $RELEASE/$TARGET.exe
    fi
}

echo "[+] Building BitmaskVPN"

lrelease bitmask.pro

# FIXME move buildGoLib to the main makefile, to avoid redundant builds if possible
buildGoLib
buildQmake

make -C $QTBUILD clean
make -C $QTBUILD -j4 all

renameOutput
echo "[+] Done."