summaryrefslogtreecommitdiff
path: root/docs/env.sh
blob: 8a82ad083322d9784c59bfd827a46273961b02b5 (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
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
#!/bin/sh
#
# NetSurf Library, tool and browser support script
#
# Usage: source env.sh
# TARGET_ABI / HOST sets the target for library builds
# TARGET_WORKSPACE is the workspace directory to keep the sandboxes
#
# This script allows NetSurf and its libraries to be built without
#   requiring installation into a system.
#
# Copyright 2013 Vincent Sanders <vince@netsurf-browser.org>
# Released under the MIT Licence

# parameters

# The system doing the building
if [ "x${BUILD}" = "x" ]; then
    BUILD=$(cc -dumpmachine)
fi

# Get the host build if unset
if [ "x${HOST}" = "x" ]; then
    if [ "x${TARGET_ABI}" = "x" ]; then
        HOST=${BUILD}
    else
        HOST=${TARGET_ABI}
    fi
else
    HOST_CC_LIST="${HOST}-cc ${HOST}-gcc /opt/netsurf/${HOST}/cross/bin/${HOST}-cc /opt/netsurf/${HOST}/cross/bin/${HOST}-gcc"
    for HOST_CC_V in $(echo ${HOST_CC_LIST});do
        HOST_CC=$(/bin/which ${HOST_CC_V})
        if [ "x${HOST_CC}" != "x" ];then
            break
        fi
    done
    if [ "x${HOST_CC}" = "x" ];then
        echo "Unable to execute host compiler for HOST=${HOST}. is it set correctly?"
        return 1
    fi

    HOST_CC_MACHINE=$(${HOST_CC} -dumpmachine 2>/dev/null)

    if [ "${HOST_CC_MACHINE}" != "${HOST}" ];then
        echo "Compiler dumpmachine differes from HOST setting"
        return 2
    fi
    unset HOST_CC_LIST HOST_CC_V HOST_CC HOST_CC_MACHINE
fi

if [ "x${TARGET_WORKSPACE}" = "x" ]; then
    TARGET_WORKSPACE=${HOME}/dev-netsurf/workspace
fi

if [ "x${USE_CPUS}" = "x" ]; then
    NCPUS=$(getconf _NPROCESSORS_ONLN 2>/dev/null || getconf NPROCESSORS_ONLN 2>/dev/null)
    NCPUS="${NCPUS:-1}"
    NCPUS=$((NCPUS * 2))
    USE_CPUS="-j${NCPUS}"
fi

# The GTK version to build for (either 2 or 3 currently)
if [ "x${NETSURF_GTK_MAJOR}" = "x" ]; then
    NETSURF_GTK_MAJOR=2
fi


###############################################################################
# Setup environment
###############################################################################

echo "BUILD=${BUILD}"
echo "HOST=${HOST}"
echo "TARGET_WORKSPACE=${TARGET_WORKSPACE}"
echo "USE_CPUS=${USE_CPUS}"

export PREFIX=${TARGET_WORKSPACE}/inst-${HOST}
export PKG_CONFIG_PATH=${PREFIX}/lib/pkgconfig:${PKG_CONFIG_PATH}::
export LD_LIBRARY_PATH=${LD_LIBRARY_PATH}:${PREFIX}/lib
export PATH=${PATH}:${PREFIX}/bin
export NETSURF_GTK_MAJOR

# make tool
MAKE=make

# NetSurf GIT repositories
NS_GIT="git://git.netsurf-browser.org"

# Buildsystem: everything depends on this
NS_BUILDSYSTEM="buildsystem"

# internal libraries all frontends require (order is important)
NS_INTERNAL_LIBS="libwapcaplet libparserutils libhubbub libdom libcss libnsgif libnsbmp libutf8proc libnsutils libnspsl libnslog"

# The browser itself
NS_BROWSER="netsurf"


# add target specific libraries
case "${HOST}" in
    i586-pc-haiku)
        # tools required to build the browser for haiku (beos)
        NS_TOOLS="nsgenbind"
        # libraries required for the haiku target abi
        NS_FRONTEND_LIBS="libsvgtiny"
        ;;
    *arwin*)
        # tools required to build the browser for OS X
        NS_TOOLS=""
        # libraries required for the Darwin target abi
        NS_FRONTEND_LIBS="libsvgtiny libnsfb"
        ;;
    arm-unknown-riscos)
        # tools required to build the browser for RISC OS
        NS_TOOLS="nsgenbind"
        # libraries required for the risc os target abi
        NS_FRONTEND_LIBS="libsvgtiny librufl libpencil librosprite"
        ;;
    *-atari-mint)
        # tools required to build the browser for atari
        NS_TOOLS=""
        # libraries required for the atari frontend
        NS_FRONTEND_LIBS=""
        ;;
    ppc-amigaos)
        # default tools required to build the browser
        NS_TOOLS="nsgenbind"
        # default additional internal libraries
        NS_FRONTEND_LIBS="libsvgtiny"
        ;;
    m68k-unknown-amigaos)
        # default tools required to build the browser
        NS_TOOLS="nsgenbind"
        # default additional internal libraries
        NS_FRONTEND_LIBS="libsvgtiny"
        ;;
    *-unknown-freebsd*)
        # tools required to build the browser for freebsd
        NS_TOOLS=""
        # libraries required for the freebsd frontend
        NS_FRONTEND_LIBS=""
        # select gnu make
        MAKE=gmake
        ;;
    *)
        # default tools required to build the browser
        NS_TOOLS="nsgenbind"
        # default additional internal libraries
        NS_FRONTEND_LIBS="libsvgtiny libnsfb"
        ;;
esac

export MAKE

################ OS Package installation ################

# deb packages for dpkg based systems
NS_DEV_DEB="build-essential pkg-config git gperf libcurl3-dev libssl-dev libpng-dev libjpeg-dev"
NS_TOOL_DEB="flex bison libhtml-parser-perl"
if [ "x${NETSURF_GTK_MAJOR}" = "x3" ]; then
    NS_GTK_DEB="libgtk-3-dev librsvg2-dev"
else
    NS_GTK_DEB="libgtk2.0-dev librsvg2-dev"
fi

# apt get commandline to install necessary dev packages
ns-apt-get-install()
{
    sudo apt-get install $(echo ${NS_DEV_DEB} ${NS_TOOL_DEB} ${NS_GTK_DEB})
}

# RPM packages for rpm based systems (tested on fedora 20)
NS_DEV_RPM="git gcc pkgconfig libexpat-devel openssl-devel libcurl-devel perl-Digest-MD5-File libjpeg-devel libpng-devel"
NS_TOOL_RPM="flex bison"
if [ "x${NETSURF_GTK_MAJOR}" = "x3" ]; then
    NS_GTK_RPM="gtk3-devel librsvg2-devel"
else
    NS_GTK_RPM="gtk2-devel librsvg2-devel"
fi

# yum commandline to install necessary dev packages
ns-yum-install()
{
    sudo yum -y install $(echo ${NS_DEV_RPM} ${NS_TOOL_RPM} ${NS_GTK_RPM})
}


# DNF RPM packages for rpm based systems (tested on fedora 25)
NS_DEV_DNF_RPM="java-1.8.0-openjdk-headless gcc clang pkgconfig libcurl-devel libjpeg-devel expat-devel libpng-devel openssl-devel gperf perl-HTML-Parser"
NS_TOOL_DNF_RPM="git flex bison ccache screen"
if [ "x${NETSURF_GTK_MAJOR}" = "x3" ]; then
    NS_GTK_DNF_RPM="gtk3-devel"
else
    NS_GTK_DNF_RPM="gtk2-devel"
fi

# dnf commandline to install necessary dev packages
ns-dnf-install()
{
    sudo dnf install $(echo ${NS_DEV_DNF_RPM} ${NS_TOOL_DNF_RPM} ${NS_GTK_DNF_RPM})
}



# Haiku secondary arch suffix:
# empty for primary (gcc2 on x86),
# "_x86" for gcc4 secondary.
HA=_x86
# Haiku packages
NS_DEV_HPKG="devel:libcurl${HA} devel:libpng${HA} devel:libjpeg${HA} devel:libcrypto${HA} devel:libiconv${HA} devel:libexpat${HA} cmd:pkg_config${HA} cmd:gperf html_parser"

# pkgman commandline to install necessary dev packages
ns-pkgman-install()
{
    pkgman install $(echo ${NS_DEV_HPKG})
}

# MAC OS X
NS_DEV_MACPORT="git expat openssl curl libjpeg-turbo libpng"

ns-macport-install()
{
    PATH=/opt/local/bin:/opt/local/sbin:$PATH sudo /opt/local/bin/port install $(echo ${NS_DEV_MACPORT})
}

NS_DEV_FREEBSDPKG="gmake curl"

# FreeBSD package install
ns-freebsdpkg-install()
{
    pkg install $(echo ${NS_DEV_FREEBSDPKG})
}

# generic for help text
NS_DEV_GEN="git, gcc, pkgconfig, expat library, openssl library, libcurl, perl, perl MD5 digest, libjpeg library, libpng library"
NS_TOOL_GEN="flex tool, bison tool"
if [ "x${NETSURF_GTK_MAJOR}" = "x3" ]; then
    NS_GTK_GEN="gtk+ 3 toolkit library, librsvg2 library"
else
    NS_GTK_GEN="gtk+ 2 toolkit library, librsvg2 library"
fi

# Genertic OS package install
#  looks for package managers and tries to use them if present
ns-package-install()
{
    if [ -x "/usr/bin/apt-get" ]; then
        ns-apt-get-install
    elif [ -x "/usr/bin/dnf" ]; then
        ns-dnf-install
    elif [ -x "/usr/bin/yum" ]; then
        ns-yum-install
    elif [ -x "/bin/pkgman" ]; then
        ns-pkgman-install
    elif [ -x "/opt/local/bin/port" ]; then
        ns-macport-install
    elif [ -x "/usr/sbin/pkg" ]; then
        ns-freebsdpkg-install
    else
        echo "Unable to determine OS packaging system in use."
        echo "Please ensure development packages are installed for:"
        echo ${NS_DEV_GEN}"," ${NS_TOOL_GEN}"," ${NS_GTK_GEN}
    fi
}

################ Development helpers ################

# git pull in all repos parameters are passed to git pull
ns-pull()
{
    for REPO in $(echo ${NS_BUILDSYSTEM} ${NS_INTERNAL_LIBS} ${NS_FRONTEND_LIBS} ${NS_TOOLS} ${NS_BROWSER}) ; do
        echo -n "     GIT: Pulling ${REPO}: "
        if [ -f "${TARGET_WORKSPACE}/${REPO}/.git/config" ]; then
            (cd ${TARGET_WORKSPACE}/${REPO} && git pull $*; )
        else
            echo "Repository not present"
        fi
    done
}

# clone all repositories
ns-clone()
{
    mkdir -p ${TARGET_WORKSPACE}
    for REPO in $(echo ${NS_BUILDSYSTEM} ${NS_INTERNAL_LIBS} ${NS_FRONTEND_LIBS} ${NS_RISCOS_LIBS} ${NS_TOOLS} ${NS_BROWSER}) ; do
        echo -n "     GIT: Cloning ${REPO}: "
        if [ -f ${TARGET_WORKSPACE}/${REPO}/.git/config ]; then
            echo "Repository already present"
        else
            (cd ${TARGET_WORKSPACE} && git clone ${NS_GIT}/${REPO}.git; )
        fi
    done

    # put current env.sh in place in workspace
    if [ ! -f "${TARGET_WORKSPACE}/env.sh" -a -f ${TARGET_WORKSPACE}/${NS_BROWSER}/docs/env.sh ]; then
        cp ${TARGET_WORKSPACE}/${NS_BROWSER}/docs/env.sh ${TARGET_WORKSPACE}/env.sh
    fi
}

# issues a make command to all libraries
ns-make-libs()
{
    for REPO in $(echo ${NS_BUILDSYSTEM} ${NS_TOOLS}); do
        echo "    MAKE: make -C ${REPO} $USE_CPUS $*"
        ${MAKE} -C ${TARGET_WORKSPACE}/${REPO} $USE_CPUS $*
        if [ $? -ne 0 ]; then
            return $?
        fi
    done

    for REPO in $(echo ${NS_INTERNAL_LIBS} ${NS_FRONTEND_LIBS}); do
        echo "    MAKE: make -C ${REPO} $USE_CPUS $*"
        ${MAKE} -C ${TARGET_WORKSPACE}/${REPO} HOST=${HOST} $USE_CPUS $*
        if [ $? -ne 0 ]; then
            return $?
        fi
    done
}

# issues a make command for framebuffer libraries
ns-make-libnsfb()
{
    echo "    MAKE: make -C libnsfb $USE_CPUS $*"
    ${MAKE} -C ${TARGET_WORKSPACE}/libnsfb HOST=${HOST} $USE_CPUS $*
}

# pulls all repos and makes and installs the libraries and tools
ns-pull-install()
{
    ns-pull $*

    ns-make-libs install
}

# Passes appropriate flags to make
ns-make()
{
    ${MAKE} $USE_CPUS "$@"
}