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-2017 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
20# The use of HOST and BUILD here is directly comprable to the GCC
21# usage as described at:
22# http://gcc.gnu.org/onlinedocs/gccint/Configure-Terms.html
25###############################################################################
26# OS Package installation
27###############################################################################
29# deb packages for dpkg based systems
30NS_DEV_DEB="build-essential pkg-config git gperf libcurl3-dev libpng-dev libjpeg-dev"
31NS_TOOL_DEB="flex bison libhtml-parser-perl"
32if [ "x${NETSURF_GTK_MAJOR}" = "x3" ]; then
33 NS_GTK_DEB="libgtk-3-dev librsvg2-dev"
35 NS_GTK_DEB="libgtk2.0-dev librsvg2-dev"
38# apt get commandline to install necessary dev packages
41 LIBCURL_OPENSSL_CONFLICTS="$(/usr/bin/apt-cache show libcurl4-openssl-dev | grep Conflicts | grep -o libssl1.0-dev)"
42 if [ "x${LIBCURL_OPENSSL_CONFLICTS}" != "x" ]; then
43 NS_DEV_DEB="${NS_DEV_DEB} libssl-dev"
44 elif /usr/bin/apt-cache show libssl1.0-dev >/dev/null 2>&1; then
45 NS_DEV_DEB="${NS_DEV_DEB} libssl1.0-dev"
47 NS_DEV_DEB="${NS_DEV_DEB} libssl-dev"
49 sudo apt-get install $(echo ${NS_DEV_DEB} ${NS_TOOL_DEB} ${NS_GTK_DEB})
53# packages for yum installer RPM based systems (tested on fedora 20)
54NS_DEV_YUM_RPM="git gcc pkgconfig expat-devel openssl-devel gperf libcurl-devel perl-Digest-MD5-File libjpeg-devel libpng-devel"
55NS_TOOL_YUM_RPM="flex bison"
56if [ "x${NETSURF_GTK_MAJOR}" = "x3" ]; then
57 NS_GTK_YUM_RPM="gtk3-devel librsvg2-devel"
59 NS_GTK_YUM_RPM="gtk2-devel librsvg2-devel"
62# yum commandline to install necessary dev packages
65 sudo yum -y install $(echo ${NS_DEV_YUM_RPM} ${NS_TOOL_YUM_RPM} ${NS_GTK_YUM_RPM})
69# packages for dnf installer RPM based systems (tested on fedora 25)
70NS_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"
71NS_TOOL_DNF_RPM="git flex bison ccache screen"
72if [ "x${NETSURF_GTK_MAJOR}" = "x3" ]; then
73 NS_GTK_DNF_RPM="gtk3-devel"
75 NS_GTK_DNF_RPM="gtk2-devel"
78# dnf commandline to install necessary dev packages
81 sudo dnf install $(echo ${NS_DEV_DNF_RPM} ${NS_TOOL_DNF_RPM} ${NS_GTK_DNF_RPM})
85# packages for zypper installer RPM based systems (tested on openSUSE leap 42)
86NS_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"
87NS_TOOL_ZYP_RPM="git flex bison gperf ccache screen"
88if [ "x${NETSURF_GTK_MAJOR}" = "x3" ]; then
89 NS_GTK_ZYP_RPM="gtk3-devel"
91 NS_GTK_ZYP_RPM="gtk2-devel"
94# zypper commandline to install necessary dev packages
97 sudo zypper install -y $(echo ${NS_DEV_ZYP_RPM} ${NS_TOOL_ZYP_RPM} ${NS_GTK_ZYP_RPM})
101# Packages for Haiku install
103# Haiku secondary arch suffix:
104# empty for primary (gcc2 on x86) or "_x86" for gcc4 secondary.
107NS_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"
109# pkgman commandline to install necessary dev packages
112 pkgman install $(echo ${NS_DEV_HPKG})
117NS_DEV_MACPORT="git expat openssl curl libjpeg-turbo libpng"
121 PATH=/opt/local/bin:/opt/local/sbin:$PATH sudo /opt/local/bin/port install $(echo ${NS_DEV_MACPORT})
125# packages for FreeBSD install
126NS_DEV_FREEBSDPKG="gmake curl"
128# FreeBSD package install
129ns-freebsdpkg-install()
131 pkg install $(echo ${NS_DEV_FREEBSDPKG})
135# generic for help text
136NS_DEV_GEN="git, gcc, pkgconfig, expat library, openssl library, libcurl, perl, perl MD5 digest, libjpeg library, libpng library"
137NS_TOOL_GEN="flex tool, bison tool"
138if [ "x${NETSURF_GTK_MAJOR}" = "x3" ]; then
139 NS_GTK_GEN="gtk+ 3 toolkit library, librsvg2 library"
141 NS_GTK_GEN="gtk+ 2 toolkit library, librsvg2 library"
144# Generic OS package install
145# looks for package managers and tries to use them if present
148 if [ -x "/usr/bin/zypper" ]; then
150 elif [ -x "/usr/bin/apt-get" ]; then
152 elif [ -x "/usr/bin/dnf" ]; then
154 elif [ -x "/usr/bin/yum" ]; then
156 elif [ -x "/bin/pkgman" ]; then
158 elif [ -x "/opt/local/bin/port" ]; then
160 elif [ -x "/usr/sbin/pkg" ]; then
161 ns-freebsdpkg-install
163 echo "Unable to determine OS packaging system in use."
164 echo "Please ensure development packages are installed for:"
165 echo ${NS_DEV_GEN}"," ${NS_TOOL_GEN}"," ${NS_GTK_GEN}
169###############################################################################
171###############################################################################
173# find which command used to find everything else on path
174if [ -x /usr/bin/which ]; then
175 WHICH_CMD=/usr/bin/which
180# environment parameters
182# The system doing the building
183if [ "x${BUILD}" = "x" ]; then
184 BUILD_CC=$(${WHICH_CMD} cc)
186 BUILD=$(cc -dumpmachine)
188 echo "Unable to locate a compiler. Perhaps run ns-package-install"
193# Get the host build if unset
194if [ "x${HOST}" = "x" ]; then
195 if [ "x${TARGET_ABI}" = "x" ]; then
201 HOST_CC_LIST="/opt/netsurf/${HOST}/cross/bin/${HOST}-cc /opt/netsurf/${HOST}/cross/bin/${HOST}-gcc ${HOST}-cc ${HOST}-gcc"
202 for HOST_CC_V in $(echo ${HOST_CC_LIST});do
203 HOST_CC=$(${WHICH_CMD} ${HOST_CC_V})
204 if [ "x${HOST_CC}" != "x" ];then
208 if [ "x${HOST_CC}" = "x" ];then
209 echo "Unable to execute host compiler for HOST=${HOST}. is it set correctly?"
213 HOST_CC_MACHINE=$(${HOST_CC} -dumpmachine 2>/dev/null)
215 if [ "${HOST_CC_MACHINE}" != "${HOST}" ];then
216 echo "Compiler dumpmachine differs from HOST setting"
220 NS_ENV_CC="${HOST_CC}"
223 unset HOST_CC_LIST HOST_CC_V HOST_CC HOST_CC_MACHINE
226# set up a default target workspace
227if [ "x${TARGET_WORKSPACE}" = "x" ]; then
228 TARGET_WORKSPACE=${HOME}/dev-netsurf/workspace
231# set up default parallelism
232if [ "x${USE_CPUS}" = "x" ]; then
233 NCPUS=$(getconf _NPROCESSORS_ONLN 2>/dev/null || getconf NPROCESSORS_ONLN 2>/dev/null)
236 USE_CPUS="-j${NCPUS}"
239# The GTK version to build for (either 2 or 3 currently)
240if [ "x${NETSURF_GTK_MAJOR}" = "x" ]; then
247echo "TARGET_WORKSPACE=${TARGET_WORKSPACE}"
248echo "USE_CPUS=${USE_CPUS}"
250export PREFIX=${TARGET_WORKSPACE}/inst-${HOST}
251export BUILD_PREFIX=${TARGET_WORKSPACE}/inst-${BUILD}
252export PKG_CONFIG_PATH=${PREFIX}/lib/pkgconfig:${PKG_CONFIG_PATH}::
253export LD_LIBRARY_PATH=${LD_LIBRARY_PATH}:${PREFIX}/lib
254export PATH=${PATH}:${BUILD_PREFIX}/bin
255export NETSURF_GTK_MAJOR
260# NetSurf GIT repositories
261NS_GIT="git://git.netsurf-browser.org"
263# Buildsystem: everything depends on this
264NS_BUILDSYSTEM="buildsystem"
269BUILD_TARGET="${TARGET:-netsurf}"
271case "$BUILD_TARGET" in
273 NS_INTERNAL_LIBS="libparserutils"
277 NS_INTERNAL_LIBS="libwapcaplet libparserutils libhubbub"
281 NS_INTERNAL_LIBS="libwapcaplet libparserutils"
285 # internal libraries all frontends require (order is important)
286 NS_INTERNAL_LIBS="libwapcaplet libparserutils libhubbub libdom libcss libnsgif libnsbmp libutf8proc libnsutils libnspsl libnslog"
288 # add target specific libraries
291 # tools required to build the browser for haiku (beos)
293 # libraries required for the haiku target abi
294 NS_FRONTEND_LIBS="libsvgtiny"
297 # tools required to build the browser for OS X
299 # libraries required for the Darwin target abi
300 NS_FRONTEND_LIBS="libsvgtiny libnsfb"
302 arm-unknown-riscos|arm-riscos-gnueabi*)
303 # tools required to build the browser for RISC OS
305 # libraries required for the risc os target abi
306 NS_FRONTEND_LIBS="libsvgtiny librufl libpencil librosprite"
309 # tools required to build the browser for atari
311 # libraries required for the atari frontend
315 # default tools required to build the browser
317 # default additional internal libraries
318 NS_FRONTEND_LIBS="libsvgtiny"
320 m68k-unknown-amigaos)
321 # default tools required to build the browser
323 # default additional internal libraries
324 NS_FRONTEND_LIBS="libsvgtiny"
327 # tools required to build the browser for freebsd
329 # libraries required for the freebsd frontend
335 # default tools required to build the browser
337 # default additional internal libraries
338 NS_FRONTEND_LIBS="libsvgtiny libnsfb"
346################ Development helpers ################
348# git pull in all repos parameters are passed to git pull
351 for REPO in $(echo ${NS_BUILDSYSTEM} ${NS_INTERNAL_LIBS} ${NS_FRONTEND_LIBS} ${NS_TOOLS} ${BUILD_TARGET}) ; do
352 echo -n " GIT: Pulling ${REPO}: "
353 if [ -f "${TARGET_WORKSPACE}/${REPO}/.git/config" ]; then
354 (cd ${TARGET_WORKSPACE}/${REPO} && git pull $*; )
356 echo "Repository not present"
361# clone all repositories
369 -d | --deps-only) SKIP="${BUILD_TARGET}"
372 -s | --shallow) SHALLOW="--depth 1"
375 -*) echo "Error: Unknown option: $1" >&2
384 mkdir -p ${TARGET_WORKSPACE}
385 for REPO in $(echo ${NS_BUILDSYSTEM} ${NS_INTERNAL_LIBS} ${NS_FRONTEND_LIBS} ${NS_RISCOS_LIBS} ${NS_TOOLS} ${BUILD_TARGET}) ; do
386 [ "x${REPO}" != "x${SKIP}" ] || continue
387 echo -n " GIT: Cloning ${REPO}: "
388 if [ -f ${TARGET_WORKSPACE}/${REPO}/.git/config ]; then
389 echo "Repository already present"
391 (cd ${TARGET_WORKSPACE} && git clone ${SHALLOW} ${NS_GIT}/${REPO}.git; )
395 # put current env.sh in place in workspace
396 if [ "x$NS_BROWSER" = "x" ]; then
397 if [ ! -f "${TARGET_WORKSPACE}/env.sh" -a -f ${TARGET_WORKSPACE}/${NS_BROWSER}/docs/env.sh ]; then
398 cp ${TARGET_WORKSPACE}/${NS_BROWSER}/docs/env.sh ${TARGET_WORKSPACE}/env.sh
403# issues a make command to all libraries
406 for REPO in $(echo ${NS_BUILDSYSTEM} ${NS_INTERNAL_LIBS} ${NS_FRONTEND_LIBS}); do
407 echo " MAKE: make -C ${REPO} $USE_CPUS $*"
408 ${MAKE} -C ${TARGET_WORKSPACE}/${REPO} HOST=${HOST} $USE_CPUS $*
409 if [ $? -ne 0 ]; then
415# issues make command for all tools
418 for REPO in $(echo ${NS_BUILDSYSTEM} ${NS_TOOLS}); do
419 echo " MAKE: make -C ${REPO} $USE_CPUS $*"
420 ${MAKE} -C ${TARGET_WORKSPACE}/${REPO} PREFIX=${BUILD_PREFIX} HOST=${BUILD} $USE_CPUS $*
421 if [ $? -ne 0 ]; then
427# issues a make command for framebuffer libraries
430 echo " MAKE: make -C libnsfb $USE_CPUS $*"
431 ${MAKE} -C ${TARGET_WORKSPACE}/libnsfb HOST=${HOST} $USE_CPUS $*
434# pulls all repos and makes and installs the libraries and tools
439 ns-make-tools install
443# Passes appropriate flags to make
446 ${MAKE} $USE_CPUS "$@"