NetSurf
env.sh
Go to the documentation of this file.
1# This shell fragment is intended for use in `bash` or `zsh`. While it
2# may work in other shells it is not meant to, and any misbehaviour is not
3# considered a bug in that case.
4#
5# NetSurf Library, tool and browser development support script
6#
7# Copyright 2013-2024 Vincent Sanders <vince@netsurf-browser.org>
8# Released under the MIT Licence
9#
10# This script allows NetSurf and its libraries to be built without
11# requiring installation into a system.
12#
13# Usage: source env.sh
14#
15# Controlling variables
16# HOST sets the target architecture for library builds
17# BUILD sets the building machines architecture
18# TARGET_WORKSPACE is the workspace directory to keep the sandboxes
19# TARGET_TOOLKIT controls development package installs
20# can be unset or one of framebuffer, gtk2, gtk3, qt6
21#
22# The use of HOST and BUILD here is directly comprable to the GCC
23# usage as described at:
24# http://gcc.gnu.org/onlinedocs/gccint/Configure-Terms.html
25#
26
27###############################################################################
28# OS Package installation
29###############################################################################
30
31
32# apt get commandline to install necessary dev packages
33ns_apt_get_install()
34{
35 NS_DEV_DEB="build-essential pkg-config git gperf libcurl3-dev libexpat1-dev libpng-dev libjpeg-dev"
36 LIBCURL_OPENSSL_CONFLICTS="$(/usr/bin/apt-cache show libcurl4-openssl-dev | grep Conflicts | grep -o libssl1.0-dev)"
37 if [ "x${LIBCURL_OPENSSL_CONFLICTS}" != "x" ]; then
38 NS_DEV_DEB="${NS_DEV_DEB} libssl-dev"
39 elif /usr/bin/apt-cache show libssl1.0-dev >/dev/null 2>&1; then
40 NS_DEV_DEB="${NS_DEV_DEB} libssl1.0-dev"
41 else
42 NS_DEV_DEB="${NS_DEV_DEB} libssl-dev"
43 fi
44
45 NS_TOOL_DEB="flex bison libhtml-parser-perl"
46
47 case "${TARGET_TOOLKIT}" in
48 gtk2)
49 NS_TK_DEB="libgtk2.0-dev librsvg2-dev"
50 ;;
51 gtk3)
52 NS_TK_DEB="libgtk-3-dev librsvg2-dev"
53 ;;
54 qt6)
55 NS_TK_DEB="qt6-base-dev-tools qt6-base-dev"
56 ;;
57 framebuffer)
58 NS_TK_DEB="libfreetype-dev libsdl1.2-compat-dev libxcb-util-dev libxcb-icccm4-dev libxcb-image0-dev libxcb-keysyms1-dev"
59 ;;
60 *)
61 NS_TK_DEB=""
62 ;;
63 esac
64
65 sudo apt-get install --no-install-recommends $(echo ${NS_DEV_DEB} ${NS_TOOL_DEB} ${NS_TK_DEB})
66}
67
68
69# packages for yum installer RPM based systems (tested on fedora 20)
70# yum commandline to install necessary dev packages
71ns_yum_install()
72{
73 NS_DEV_YUM_RPM="git gcc pkgconfig expat-devel openssl-devel gperf libcurl-devel perl-Digest-MD5-File libjpeg-devel libpng-devel"
74
75 NS_TOOL_YUM_RPM="flex bison"
76
77 case "${TARGET_TOOLKIT}" in
78 gtk2)
79 NS_TK_YUM_RPM="gtk2-devel librsvg2-devel"
80 ;;
81 gtk3)
82 NS_TK_YUM_RPM="gtk3-devel librsvg2-devel"
83 ;;
84 *)
85 NS_TK_YUM_RPM=""
86 ;;
87 esac
88
89 sudo yum -y install $(echo ${NS_DEV_YUM_RPM} ${NS_TOOL_YUM_RPM} ${NS_TK_YUM_RPM})
90}
91
92
93# packages for dnf installer RPM based systems (tested on fedora 25)
94# dnf commandline to install necessary dev packages
95ns_dnf_install()
96{
97 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"
98
99 NS_TOOL_DNF_RPM="git flex bison ccache screen"
100
101 case "${TARGET_TOOLKIT}" in
102 gtk2)
103 NS_TK_DNF_RPM="gtk2-devel"
104 ;;
105 gtk3)
106 NS_TK_DNF_RPM="gtk3-devel"
107 ;;
108 *)
109 NS_TK_DNF_RPM=""
110 ;;
111 esac
112
113 sudo dnf install $(echo ${NS_DEV_DNF_RPM} ${NS_TOOL_DNF_RPM} ${NS_TK_DNF_RPM})
114}
115
116
117# packages for zypper installer RPM based systems (tested on openSUSE leap 42)
118# zypper commandline to install necessary dev packages
119ns_zypper_install()
120{
121 NS_DEV_ZYP_RPM="java-1_8_0-openjdk-headless gcc clang pkgconfig libcurl-devel libjpeg-devel libexpat-devel libpng-devel openssl-devel gperf perl-HTML-Parser"
122
123 NS_TOOL_ZYP_RPM="git flex bison gperf ccache screen"
124
125 case "${TARGET_TOOLKIT}" in
126 gtk2)
127 NS_TK_ZYP_RPM="gtk2-devel"
128 ;;
129 gtk3)
130 NS_TK_ZYP_RPM="gtk3-devel"
131 ;;
132 *)
133 NS_TK_ZYP_RPM=""
134 ;;
135 esac
136
137 sudo zypper install -y $(echo ${NS_DEV_ZYP_RPM} ${NS_TOOL_ZYP_RPM} ${NS_TK_ZYP_RPM})
138}
139
140
141# Packages for Haiku install
142# pkgman commandline to install necessary dev packages
143ns_pkgman_install()
144{
145 # Haiku secondary arch suffix:
146 # empty for primary (gcc2 on x86) or "_x86" for gcc4 secondary.
147 HA=_x86
148
149 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"
150
151 pkgman install $(echo ${NS_DEV_HPKG})
152}
153
154
155# MAC OS X
156ns_macport_install()
157{
158 NS_DEV_MACPORT="git expat openssl curl libjpeg-turbo libpng"
159
160 PATH=/opt/local/bin:/opt/local/sbin:$PATH sudo /opt/local/bin/port install $(echo ${NS_DEV_MACPORT})
161}
162
163
164# packages for FreeBSD install
165# FreeBSD package install
166ns_freebsdpkg_install()
167{
168 NS_DEV_FREEBSDPKG="gmake curl"
169 pkg install $(echo ${NS_DEV_FREEBSDPKG})
170}
171
172
173# generic for help text
174ns_generic_install()
175{
176 NS_DEV_GEN="git, gcc, pkgconfig, expat library, openssl library, libcurl, perl, perl MD5 digest, libjpeg library, libpng library"
177
178 NS_TOOL_GEN="flex tool, bison tool"
179
180 case "${TARGET_TOOLKIT}" in
181 gtk2)
182 NS_TK_GEN="gtk+ 2 toolkit library, librsvg2 library"
183 ;;
184 gtk3)
185 NS_TK_GEN="gtk+ 3 toolkit library, librsvg2 library"
186 ;;
187 qt6)
188 NS_TK_GEN="qt6 toolkit dev library"
189 ;;
190 framebuffer)
191 NS_TK_GEN="freetype2 dev library, SDL 1.2 compatible library"
192 ;;
193 *)
194 NS_TK_DEB=""
195 ;;
196 esac
197
198 echo "Unable to determine OS packaging system in use."
199 echo "Please ensure development packages are installed for:"
200 echo ${NS_DEV_GEN}"," ${NS_TOOL_GEN}"," ${NS_TK_GEN}
201}
202
203
204# OS package install
205# looks for package managers and tries to use them if present
206ns-package-install()
207{
208 if [ -x "/usr/bin/zypper" ]; then
209 ns_zypper_install
210 elif [ -x "/usr/bin/apt-get" ]; then
211 ns_apt_get_install
212 elif [ -x "/usr/bin/dnf" ]; then
213 ns_dnf_install
214 elif [ -x "/usr/bin/yum" ]; then
215 ns_yum_install
216 elif [ -x "/bin/pkgman" ]; then
217 ns_pkgman_install
218 elif [ -x "/opt/local/bin/port" ]; then
219 ns_macport_install
220 elif [ -x "/usr/sbin/pkg" ]; then
221 ns_freebsdpkg_install
222 else
223 ns_generic_install
224 fi
225}
226
227###############################################################################
228# Setup environment
229###############################################################################
230
231# environment parameters
232
233# The system doing the building
234if [ "x${BUILD}" = "x" ]; then
235 BUILD_CC=$(command -v cc)
236 if [ $? -eq 0 ];then
237 BUILD=$(${BUILD_CC} -dumpmachine)
238 else
239 echo "Unable to locate a compiler. Perhaps run ns-package-install"
240 return 1
241 fi
242fi
243
244# work out the host compiler to use
245if [ "x${HOST}" = "x" ]; then
246 # no host ABI set so host is the same as build unless a target ABI is set
247 if [ "x${TARGET_ABI}" = "x" ]; then
248 HOST=${BUILD}
249 else
250 HOST=${TARGET_ABI}
251 fi
252else
253 # attempt to find host tools with the specificed ABI
254 HOST_CC_LIST="/opt/netsurf/${HOST}/cross/bin/${HOST}-cc /opt/netsurf/${HOST}/cross/bin/${HOST}-gcc ${HOST}-cc ${HOST}-gcc"
255 for HOST_CC_V in $(echo ${HOST_CC_LIST});do
256 HOST_CC=$(command -v ${HOST_CC_V})
257 if [ $? -eq 0 ];then
258 break
259 fi
260 done
261 if [ "x${HOST_CC}" = "x" ];then
262 echo "Unable to execute host compiler for HOST=${HOST}. is it set correctly?"
263 return 1
264 fi
265
266 HOST_CC_MACHINE=$(${HOST_CC} -dumpmachine 2>/dev/null)
267
268 if [ "${HOST_CC_MACHINE}" != "${HOST}" ];then
269 echo "Compiler dumpmachine differs from HOST setting"
270 return 2
271 fi
272
273 NS_ENV_CC="${HOST_CC}"
274 export NS_ENV_CC
275
276 unset HOST_CC_LIST HOST_CC_V HOST_CC HOST_CC_MACHINE
277fi
278
279# set up a default target workspace
280if [ "x${TARGET_WORKSPACE}" = "x" ]; then
281 TARGET_WORKSPACE=${HOME}/dev-netsurf/workspace
282fi
283
284# set up default parallelism
285if [ "x${USE_CPUS}" = "x" ]; then
286 NCPUS=$(getconf _NPROCESSORS_ONLN 2>/dev/null || getconf NPROCESSORS_ONLN 2>/dev/null)
287 NCPUS="${NCPUS:-1}"
288 NCPUS=$((NCPUS * 2))
289 USE_CPUS="-j${NCPUS}"
290fi
291
292# Setup GTK major version if required (either 2 or 3 currently)
293case "${TARGET_TOOLKIT}" in
294 gtk2)
295 NETSURF_GTK_MAJOR=2
296 ;;
297 gtk3)
298 NETSURF_GTK_MAJOR=3
299 ;;
300 *)
301 if [ "x${NETSURF_GTK_MAJOR}" = "x" ]; then
302 NETSURF_GTK_MAJOR=2
303 fi
304 ;;
305esac
306
307# report to user
308echo "BUILD=${BUILD}"
309echo "HOST=${HOST}"
310echo "TARGET_WORKSPACE=${TARGET_WORKSPACE}"
311echo "USE_CPUS=${USE_CPUS}"
312
313export PREFIX=${TARGET_WORKSPACE}/inst-${HOST}
314export BUILD_PREFIX=${TARGET_WORKSPACE}/inst-${BUILD}
315export PKG_CONFIG_PATH=${PREFIX}/lib/pkgconfig:${PKG_CONFIG_PATH}::
316export LD_LIBRARY_PATH=${LD_LIBRARY_PATH}:${PREFIX}/lib
317export PATH=${PATH}:${BUILD_PREFIX}/bin
318export NETSURF_GTK_MAJOR
319
320# make tool
321MAKE=make
322
323# NetSurf GIT repositories
324NS_GIT="git://git.netsurf-browser.org"
325
326# Buildsystem: everything depends on this
327NS_BUILDSYSTEM="buildsystem"
328
329NS_TOOLS=""
330NS_FRONTEND_LIBS=""
331
332BUILD_TARGET="${TARGET:-netsurf}"
333
334case "$BUILD_TARGET" in
335 libhubbub)
336 NS_INTERNAL_LIBS="libparserutils"
337 ;;
338
339 libdom)
340 NS_INTERNAL_LIBS="libwapcaplet libparserutils libhubbub"
341 ;;
342
343 libcss)
344 NS_INTERNAL_LIBS="libwapcaplet libparserutils"
345 ;;
346
347 netsurf)
348 # internal libraries all frontends require (order is important)
349 NS_INTERNAL_LIBS="libwapcaplet libparserutils libhubbub libdom libcss libnsgif libnsbmp libutf8proc libnsutils libnspsl libnslog"
350
351 # add target specific libraries
352 case "${HOST}" in
353 i586-pc-haiku)
354 # tools required to build the browser for haiku (beos)
355 NS_TOOLS="nsgenbind"
356 # libraries required for the haiku target abi
357 NS_FRONTEND_LIBS="libsvgtiny"
358 ;;
359 *arwin*)
360 # tools required to build the browser for OS X
361 NS_TOOLS=""
362 # libraries required for the Darwin target abi
363 NS_FRONTEND_LIBS="libsvgtiny libnsfb"
364 ;;
365 arm-unknown-riscos|arm-riscos-gnueabi*)
366 # tools required to build the browser for RISC OS
367 NS_TOOLS="nsgenbind"
368 # libraries required for the risc os target abi
369 NS_FRONTEND_LIBS="libsvgtiny librufl libpencil librosprite"
370 ;;
371 *-atari-mint)
372 # tools required to build the browser for atari
373 NS_TOOLS=""
374 # libraries required for the atari frontend
375 NS_FRONTEND_LIBS=""
376 ;;
377 ppc-amigaos)
378 # default tools required to build the browser
379 NS_TOOLS="nsgenbind"
380 # default additional internal libraries
381 NS_FRONTEND_LIBS="libsvgtiny"
382 ;;
383 m68k-unknown-amigaos)
384 # default tools required to build the browser
385 NS_TOOLS="nsgenbind"
386 # default additional internal libraries
387 NS_FRONTEND_LIBS="libsvgtiny"
388 ;;
389 *-unknown-freebsd*)
390 # tools required to build the browser for freebsd
391 NS_TOOLS=""
392 # libraries required for the freebsd frontend
393 NS_FRONTEND_LIBS=""
394 # select gnu make
395 MAKE=gmake
396 ;;
397 *)
398 # default tools required to build the browser
399 NS_TOOLS="nsgenbind"
400 # default additional internal libraries
401 NS_FRONTEND_LIBS="libsvgtiny libnsfb"
402 ;;
403 esac
404 ;;
405esac
406
407export MAKE
408
409################ Development helpers ################
410
411# git pull in all repos parameters are passed to git pull
412ns-pull()
413{
414 for REPO in $(echo ${NS_BUILDSYSTEM} ${NS_INTERNAL_LIBS} ${NS_FRONTEND_LIBS} ${NS_TOOLS} ${BUILD_TARGET}) ; do
415 echo -n " GIT: Pulling ${REPO}: "
416 if [ -f "${TARGET_WORKSPACE}/${REPO}/.git/config" ]; then
417 (cd ${TARGET_WORKSPACE}/${REPO} && git pull $*; )
418 else
419 echo "Repository not present"
420 fi
421 done
422}
423
424# clone all repositories
425ns-clone()
426{
427 SHALLOW=""
428 SKIP=""
429 while [ $# -gt 0 ]
430 do
431 case "$1" in
432 -d | --deps-only) SKIP="${BUILD_TARGET}"
433 shift
434 ;;
435 -s | --shallow) SHALLOW="--depth 1"
436 shift
437 ;;
438 -*) echo "Error: Unknown option: $1" >&2
439 exit 1
440 ;;
441 *) # No more options
442 break
443 ;;
444 esac
445 done
446
447 mkdir -p ${TARGET_WORKSPACE}
448 for REPO in $(echo ${NS_BUILDSYSTEM} ${NS_INTERNAL_LIBS} ${NS_FRONTEND_LIBS} ${NS_RISCOS_LIBS} ${NS_TOOLS} ${BUILD_TARGET}) ; do
449 [ "x${REPO}" != "x${SKIP}" ] || continue
450 echo -n " GIT: Cloning ${REPO}: "
451 if [ -f ${TARGET_WORKSPACE}/${REPO}/.git/config ]; then
452 echo "Repository already present"
453 else
454 (cd ${TARGET_WORKSPACE} && git clone ${SHALLOW} ${NS_GIT}/${REPO}.git; )
455 fi
456 done
457
458 # put current env.sh in place in workspace
459 if [ "x$NS_BROWSER" = "x" ]; then
460 if [ ! -f "${TARGET_WORKSPACE}/env.sh" -a -f ${TARGET_WORKSPACE}/${NS_BROWSER}/docs/env.sh ]; then
461 cp ${TARGET_WORKSPACE}/${NS_BROWSER}/docs/env.sh ${TARGET_WORKSPACE}/env.sh
462 fi
463 fi
464}
465
466# issues a make command to all libraries
467ns-make-libs()
468{
469 for REPO in $(echo ${NS_BUILDSYSTEM} ${NS_INTERNAL_LIBS} ${NS_FRONTEND_LIBS}); do
470 echo " MAKE: make -C ${REPO} $USE_CPUS $*"
471 ${MAKE} -C ${TARGET_WORKSPACE}/${REPO} HOST=${HOST} $USE_CPUS $*
472 if [ $? -ne 0 ]; then
473 return $?
474 fi
475 done
476}
477
478# issues make command for all tools
479ns-make-tools()
480{
481 for REPO in $(echo ${NS_BUILDSYSTEM} ${NS_TOOLS}); do
482 echo " MAKE: make -C ${REPO} $USE_CPUS $*"
483 ${MAKE} -C ${TARGET_WORKSPACE}/${REPO} PREFIX=${BUILD_PREFIX} HOST=${BUILD} $USE_CPUS $*
484 if [ $? -ne 0 ]; then
485 return $?
486 fi
487 done
488}
489
490# issues a make command for framebuffer libraries
491ns-make-libnsfb()
492{
493 echo " MAKE: make -C libnsfb $USE_CPUS $*"
494 ${MAKE} -C ${TARGET_WORKSPACE}/libnsfb HOST=${HOST} $USE_CPUS $*
495}
496
497# pulls all repos and makes and installs the libraries and tools
498ns-pull-install()
499{
500 ns-pull $*
501
502 ns-make-tools install
503 ns-make-libs install
504}
505
506# Passes appropriate flags to make
507ns-make()
508{
509 ${MAKE} $USE_CPUS "$@"
510}