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