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.
5# NetSurf Library, tool and browser development support script
7# Copyright 2013-2024 Vincent Sanders <vince@netsurf-browser.org>
8# Released under the MIT Licence
10# This script allows NetSurf and its libraries to be built without
11# requiring installation into a system.
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
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
27###############################################################################
28# OS Package installation
29###############################################################################
32# apt get commandline to install necessary dev packages
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"
42 NS_DEV_DEB="${NS_DEV_DEB} libssl-dev"
45 NS_TOOL_DEB="flex bison libhtml-parser-perl"
47 case "${TARGET_TOOLKIT}" in
49 NS_TK_DEB="libgtk2.0-dev librsvg2-dev"
52 NS_TK_DEB="libgtk-3-dev librsvg2-dev"
55 NS_TK_DEB="qt6-base-dev-tools qt6-base-dev"
58 NS_TK_DEB="libfreetype-dev libsdl1.2-compat-dev libxcb-util-dev libxcb-icccm4-dev libxcb-image0-dev libxcb-keysyms1-dev"
65 sudo apt-get install --no-install-recommends $(echo ${NS_DEV_DEB} ${NS_TOOL_DEB} ${NS_TK_DEB})
69# packages for yum installer RPM based systems (tested on fedora 20)
70# yum commandline to install necessary dev packages
73 NS_DEV_YUM_RPM="git gcc pkgconfig expat-devel openssl-devel gperf libcurl-devel perl-Digest-MD5-File libjpeg-devel libpng-devel"
75 NS_TOOL_YUM_RPM="flex bison"
77 case "${TARGET_TOOLKIT}" in
79 NS_TK_YUM_RPM="gtk2-devel librsvg2-devel"
82 NS_TK_YUM_RPM="gtk3-devel librsvg2-devel"
89 sudo yum -y install $(echo ${NS_DEV_YUM_RPM} ${NS_TOOL_YUM_RPM} ${NS_TK_YUM_RPM})
93# packages for dnf installer RPM based systems (tested on fedora 25)
94# dnf commandline to install necessary dev packages
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"
99 NS_TOOL_DNF_RPM="git flex bison ccache screen"
101 case "${TARGET_TOOLKIT}" in
103 NS_TK_DNF_RPM="gtk2-devel"
106 NS_TK_DNF_RPM="gtk3-devel"
113 sudo dnf install $(echo ${NS_DEV_DNF_RPM} ${NS_TOOL_DNF_RPM} ${NS_TK_DNF_RPM})
117# packages for zypper installer RPM based systems (tested on openSUSE leap 42)
118# zypper commandline to install necessary dev packages
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"
123 NS_TOOL_ZYP_RPM="git flex bison gperf ccache screen"
125 case "${TARGET_TOOLKIT}" in
127 NS_TK_ZYP_RPM="gtk2-devel"
130 NS_TK_ZYP_RPM="gtk3-devel"
137 sudo zypper install -y $(echo ${NS_DEV_ZYP_RPM} ${NS_TOOL_ZYP_RPM} ${NS_TK_ZYP_RPM})
141# Packages for Haiku install
142# pkgman commandline to install necessary dev packages
145 # Haiku secondary arch suffix:
146 # empty for primary (gcc2 on x86) or "_x86" for gcc4 secondary.
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"
151 pkgman install $(echo ${NS_DEV_HPKG})
158 NS_DEV_MACPORT="git expat openssl curl libjpeg-turbo libpng"
160 PATH=/opt/local/bin:/opt/local/sbin:$PATH sudo /opt/local/bin/port install $(echo ${NS_DEV_MACPORT})
164# packages for FreeBSD install
165# FreeBSD package install
166ns_freebsdpkg_install()
168 NS_DEV_FREEBSDPKG="gmake curl"
169 pkg install $(echo ${NS_DEV_FREEBSDPKG})
173# generic for help text
176 NS_DEV_GEN="git, gcc, pkgconfig, expat library, openssl library, libcurl, perl, perl MD5 digest, libjpeg library, libpng library"
178 NS_TOOL_GEN="flex tool, bison tool"
180 case "${TARGET_TOOLKIT}" in
182 NS_TK_GEN="gtk+ 2 toolkit library, librsvg2 library"
185 NS_TK_GEN="gtk+ 3 toolkit library, librsvg2 library"
188 NS_TK_GEN="qt6 toolkit dev library"
191 NS_TK_GEN="freetype2 dev library, SDL 1.2 compatible library"
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}
205# looks for package managers and tries to use them if present
208 if [ -x "/usr/bin/zypper" ]; then
210 elif [ -x "/usr/bin/apt-get" ]; then
212 elif [ -x "/usr/bin/dnf" ]; then
214 elif [ -x "/usr/bin/yum" ]; then
216 elif [ -x "/bin/pkgman" ]; then
218 elif [ -x "/opt/local/bin/port" ]; then
220 elif [ -x "/usr/sbin/pkg" ]; then
221 ns_freebsdpkg_install
227###############################################################################
229###############################################################################
231# environment parameters
233# The system doing the building
234if [ "x${BUILD}" = "x" ]; then
235 BUILD_CC=$(command -v cc)
237 BUILD=$(${BUILD_CC} -dumpmachine)
239 echo "Unable to locate a compiler. Perhaps run ns-package-install"
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
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})
261 if [ "x${HOST_CC}" = "x" ];then
262 echo "Unable to execute host compiler for HOST=${HOST}. is it set correctly?"
266 HOST_CC_MACHINE=$(${HOST_CC} -dumpmachine 2>/dev/null)
268 if [ "${HOST_CC_MACHINE}" != "${HOST}" ];then
269 echo "Compiler dumpmachine differs from HOST setting"
273 NS_ENV_CC="${HOST_CC}"
276 unset HOST_CC_LIST HOST_CC_V HOST_CC HOST_CC_MACHINE
279# set up a default target workspace
280if [ "x${TARGET_WORKSPACE}" = "x" ]; then
281 TARGET_WORKSPACE=${HOME}/dev-netsurf/workspace
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)
289 USE_CPUS="-j${NCPUS}"
292# Setup GTK major version if required (either 2 or 3 currently)
293case "${TARGET_TOOLKIT}" in
301 if [ "x${NETSURF_GTK_MAJOR}" = "x" ]; then
310echo "TARGET_WORKSPACE=${TARGET_WORKSPACE}"
311echo "USE_CPUS=${USE_CPUS}"
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
323# NetSurf GIT repositories
324NS_GIT="git://git.netsurf-browser.org"
326# Buildsystem: everything depends on this
327NS_BUILDSYSTEM="buildsystem"
332BUILD_TARGET="${TARGET:-netsurf}"
334case "$BUILD_TARGET" in
336 NS_INTERNAL_LIBS="libparserutils"
340 NS_INTERNAL_LIBS="libwapcaplet libparserutils libhubbub"
344 NS_INTERNAL_LIBS="libwapcaplet libparserutils"
348 # internal libraries all frontends require (order is important)
349 NS_INTERNAL_LIBS="libwapcaplet libparserutils libhubbub libdom libcss libnsgif libnsbmp libutf8proc libnsutils libnspsl libnslog"
351 # add target specific libraries
354 # tools required to build the browser for haiku (beos)
356 # libraries required for the haiku target abi
357 NS_FRONTEND_LIBS="libsvgtiny"
360 # tools required to build the browser for OS X
362 # libraries required for the Darwin target abi
363 NS_FRONTEND_LIBS="libsvgtiny libnsfb"
365 arm-unknown-riscos|arm-riscos-gnueabi*)
366 # tools required to build the browser for RISC OS
368 # libraries required for the risc os target abi
369 NS_FRONTEND_LIBS="libsvgtiny librufl libpencil librosprite"
372 # tools required to build the browser for atari
374 # libraries required for the atari frontend
378 # default tools required to build the browser
380 # default additional internal libraries
381 NS_FRONTEND_LIBS="libsvgtiny"
383 m68k-unknown-amigaos)
384 # default tools required to build the browser
386 # default additional internal libraries
387 NS_FRONTEND_LIBS="libsvgtiny"
390 # tools required to build the browser for freebsd
392 # libraries required for the freebsd frontend
398 # default tools required to build the browser
400 # default additional internal libraries
401 NS_FRONTEND_LIBS="libsvgtiny libnsfb"
409################ Development helpers ################
411# git pull in all repos parameters are passed to git pull
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 $*; )
419 echo "Repository not present"
424# clone all repositories
432 -d | --deps-only) SKIP="${BUILD_TARGET}"
435 -s | --shallow) SHALLOW="--depth 1"
438 -*) echo "Error: Unknown option: $1" >&2
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"
454 (cd ${TARGET_WORKSPACE} && git clone ${SHALLOW} ${NS_GIT}/${REPO}.git; )
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
466# issues a make command to all libraries
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
478# issues make command for all tools
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
490# issues a make command for framebuffer libraries
493 echo " MAKE: make -C libnsfb $USE_CPUS $*"
494 ${MAKE} -C ${TARGET_WORKSPACE}/libnsfb HOST=${HOST} $USE_CPUS $*
497# pulls all repos and makes and installs the libraries and tools
502 ns-make-tools install
506# Passes appropriate flags to make
509 ${MAKE} $USE_CPUS "$@"