3 # NetSurf Library, tool and browser development support script
5 # Copyright 2013-2017 Vincent Sanders <vince@netsurf-browser.org>
6 # Released under the MIT Licence
8 # This script allows NetSurf and its libraries to be built without
9 # requiring installation into a system.
11 # Usage: source env.sh
13 # Controlling variables
14 # HOST sets the target architecture for library builds
15 # BUILD sets the building machines architecture
16 # TARGET_WORKSPACE is the workspace directory to keep the sandboxes
18 # The use of HOST and BUILD here is directly comprable to the GCC
19 # usage as described at:
20 # http://gcc.gnu.org/onlinedocs/gccint/Configure-Terms.html
23 ###############################################################################
24 # OS Package installation
25 ###############################################################################
27 # deb packages for dpkg based systems
28 NS_DEV_DEB="build-essential pkg-config git gperf libcurl3-dev libpng-dev libjpeg-dev"
29 NS_TOOL_DEB="flex bison libhtml-parser-perl"
30 if [ "x${NETSURF_GTK_MAJOR}" = "x3" ]; then
31 NS_GTK_DEB="libgtk-3-dev librsvg2-dev"
33 NS_GTK_DEB="libgtk2.0-dev librsvg2-dev"
36 # apt get commandline to install necessary dev packages
39 LIBCURL_OPENSSL_CONFLICTS="$(/usr/bin/apt-cache show libcurl4-openssl-dev | grep Conflicts | grep -o libssl1.0-dev)"
40 if [ "x${LIBCURL_OPENSSL_CONFLICTS}" != "x" ]; then
41 NS_DEV_DEB="${NS_DEV_DEB} libssl-dev"
42 elif /usr/bin/apt-cache show libssl1.0-dev >/dev/null 2>&1; then
43 NS_DEV_DEB="${NS_DEV_DEB} libssl1.0-dev"
45 NS_DEV_DEB="${NS_DEV_DEB} libssl-dev"
47 sudo apt-get install $(echo ${NS_DEV_DEB} ${NS_TOOL_DEB} ${NS_GTK_DEB})
51 # packages for yum installer RPM based systems (tested on fedora 20)
52 NS_DEV_YUM_RPM="git gcc pkgconfig expat-devel openssl-devel gperf libcurl-devel perl-Digest-MD5-File libjpeg-devel libpng-devel"
53 NS_TOOL_YUM_RPM="flex bison"
54 if [ "x${NETSURF_GTK_MAJOR}" = "x3" ]; then
55 NS_GTK_YUM_RPM="gtk3-devel librsvg2-devel"
57 NS_GTK_YUM_RPM="gtk2-devel librsvg2-devel"
60 # yum commandline to install necessary dev packages
63 sudo yum -y install $(echo ${NS_DEV_YUM_RPM} ${NS_TOOL_YUM_RPM} ${NS_GTK_YUM_RPM})
67 # packages for dnf installer RPM based systems (tested on fedora 25)
68 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"
69 NS_TOOL_DNF_RPM="git flex bison ccache screen"
70 if [ "x${NETSURF_GTK_MAJOR}" = "x3" ]; then
71 NS_GTK_DNF_RPM="gtk3-devel"
73 NS_GTK_DNF_RPM="gtk2-devel"
76 # dnf commandline to install necessary dev packages
79 sudo dnf install $(echo ${NS_DEV_DNF_RPM} ${NS_TOOL_DNF_RPM} ${NS_GTK_DNF_RPM})
83 # packages for zypper installer RPM based systems (tested on openSUSE leap 42)
84 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"
85 NS_TOOL_ZYP_RPM="git flex bison gperf ccache screen"
86 if [ "x${NETSURF_GTK_MAJOR}" = "x3" ]; then
87 NS_GTK_ZYP_RPM="gtk3-devel"
89 NS_GTK_ZYP_RPM="gtk2-devel"
92 # zypper commandline to install necessary dev packages
95 sudo zypper install -y $(echo ${NS_DEV_ZYP_RPM} ${NS_TOOL_ZYP_RPM} ${NS_GTK_ZYP_RPM})
99 # Packages for Haiku install
101 # Haiku secondary arch suffix:
102 # empty for primary (gcc2 on x86) or "_x86" for gcc4 secondary.
105 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"
107 # pkgman commandline to install necessary dev packages
110 pkgman install $(echo ${NS_DEV_HPKG})
115 NS_DEV_MACPORT="git expat openssl curl libjpeg-turbo libpng"
119 PATH=/opt/local/bin:/opt/local/sbin:$PATH sudo /opt/local/bin/port install $(echo ${NS_DEV_MACPORT})
123 # packages for FreeBSD install
124 NS_DEV_FREEBSDPKG="gmake curl"
126 # FreeBSD package install
127 ns-freebsdpkg-install()
129 pkg install $(echo ${NS_DEV_FREEBSDPKG})
133 # generic for help text
134 NS_DEV_GEN="git, gcc, pkgconfig, expat library, openssl library, libcurl, perl, perl MD5 digest, libjpeg library, libpng library"
135 NS_TOOL_GEN="flex tool, bison tool"
136 if [ "x${NETSURF_GTK_MAJOR}" = "x3" ]; then
137 NS_GTK_GEN="gtk+ 3 toolkit library, librsvg2 library"
139 NS_GTK_GEN="gtk+ 2 toolkit library, librsvg2 library"
142 # Generic OS package install
143 # looks for package managers and tries to use them if present
146 if [ -x "/usr/bin/zypper" ]; then
148 elif [ -x "/usr/bin/apt-get" ]; then
150 elif [ -x "/usr/bin/dnf" ]; then
152 elif [ -x "/usr/bin/yum" ]; then
154 elif [ -x "/bin/pkgman" ]; then
156 elif [ -x "/opt/local/bin/port" ]; then
158 elif [ -x "/usr/sbin/pkg" ]; then
159 ns-freebsdpkg-install
161 echo "Unable to determine OS packaging system in use."
162 echo "Please ensure development packages are installed for:"
163 echo ${NS_DEV_GEN}"," ${NS_TOOL_GEN}"," ${NS_GTK_GEN}
167 ###############################################################################
169 ###############################################################################
171 # find which command used to find everything else on path
172 if [ -x /usr/bin/which ]; then
173 WHICH_CMD=/usr/bin/which
178 # environment parameters
180 # The system doing the building
181 if [ "x${BUILD}" = "x" ]; then
182 BUILD_CC=$(${WHICH_CMD} cc)
184 BUILD=$(cc -dumpmachine)
186 echo "Unable to locate a compiler. Perhaps run ns-package-install"
191 # Get the host build if unset
192 if [ "x${HOST}" = "x" ]; then
193 if [ "x${TARGET_ABI}" = "x" ]; then
199 HOST_CC_LIST="${HOST}-cc ${HOST}-gcc /opt/netsurf/${HOST}/cross/bin/${HOST}-cc /opt/netsurf/${HOST}/cross/bin/${HOST}-gcc"
200 for HOST_CC_V in $(echo ${HOST_CC_LIST});do
201 HOST_CC=$(${WHICH_CMD} ${HOST_CC_V})
202 if [ "x${HOST_CC}" != "x" ];then
206 if [ "x${HOST_CC}" = "x" ];then
207 echo "Unable to execute host compiler for HOST=${HOST}. is it set correctly?"
211 HOST_CC_MACHINE=$(${HOST_CC} -dumpmachine 2>/dev/null)
213 if [ "${HOST_CC_MACHINE}" != "${HOST}" ];then
214 echo "Compiler dumpmachine differes from HOST setting"
217 unset HOST_CC_LIST HOST_CC_V HOST_CC HOST_CC_MACHINE
220 # set up a default target workspace
221 if [ "x${TARGET_WORKSPACE}" = "x" ]; then
222 TARGET_WORKSPACE=${HOME}/dev-netsurf/workspace
225 # set up default parallelism
226 if [ "x${USE_CPUS}" = "x" ]; then
227 NCPUS=$(getconf _NPROCESSORS_ONLN 2>/dev/null || getconf NPROCESSORS_ONLN 2>/dev/null)
230 USE_CPUS="-j${NCPUS}"
233 # The GTK version to build for (either 2 or 3 currently)
234 if [ "x${NETSURF_GTK_MAJOR}" = "x" ]; then
239 echo "BUILD=${BUILD}"
241 echo "TARGET_WORKSPACE=${TARGET_WORKSPACE}"
242 echo "USE_CPUS=${USE_CPUS}"
244 export PREFIX=${TARGET_WORKSPACE}/inst-${HOST}
245 export BUILD_PREFIX=${TARGET_WORKSPACE}/inst-${BUILD}
246 export PKG_CONFIG_PATH=${PREFIX}/lib/pkgconfig:${PKG_CONFIG_PATH}::
247 export LD_LIBRARY_PATH=${LD_LIBRARY_PATH}:${PREFIX}/lib
248 export PATH=${PATH}:${BUILD_PREFIX}/bin
249 export NETSURF_GTK_MAJOR
254 # NetSurf GIT repositories
255 NS_GIT="git://git.netsurf-browser.org"
257 # Buildsystem: everything depends on this
258 NS_BUILDSYSTEM="buildsystem"
260 # internal libraries all frontends require (order is important)
261 NS_INTERNAL_LIBS="libwapcaplet libparserutils libhubbub libdom libcss libnsgif libnsbmp libutf8proc libnsutils libnspsl libnslog"
267 # add target specific libraries
270 # tools required to build the browser for haiku (beos)
272 # libraries required for the haiku target abi
273 NS_FRONTEND_LIBS="libsvgtiny"
276 # tools required to build the browser for OS X
278 # libraries required for the Darwin target abi
279 NS_FRONTEND_LIBS="libsvgtiny libnsfb"
282 # tools required to build the browser for RISC OS
284 # libraries required for the risc os target abi
285 NS_FRONTEND_LIBS="libsvgtiny librufl libpencil librosprite"
288 # tools required to build the browser for atari
290 # libraries required for the atari frontend
294 # default tools required to build the browser
296 # default additional internal libraries
297 NS_FRONTEND_LIBS="libsvgtiny"
299 m68k-unknown-amigaos)
300 # default tools required to build the browser
302 # default additional internal libraries
303 NS_FRONTEND_LIBS="libsvgtiny"
306 # tools required to build the browser for freebsd
308 # libraries required for the freebsd frontend
314 # default tools required to build the browser
316 # default additional internal libraries
317 NS_FRONTEND_LIBS="libsvgtiny libnsfb"
323 ################ Development helpers ################
325 # git pull in all repos parameters are passed to git pull
328 for REPO in $(echo ${NS_BUILDSYSTEM} ${NS_INTERNAL_LIBS} ${NS_FRONTEND_LIBS} ${NS_TOOLS} ${NS_BROWSER}) ; do
329 echo -n " GIT: Pulling ${REPO}: "
330 if [ -f "${TARGET_WORKSPACE}/${REPO}/.git/config" ]; then
331 (cd ${TARGET_WORKSPACE}/${REPO} && git pull $*; )
333 echo "Repository not present"
338 # clone all repositories
341 mkdir -p ${TARGET_WORKSPACE}
342 for REPO in $(echo ${NS_BUILDSYSTEM} ${NS_INTERNAL_LIBS} ${NS_FRONTEND_LIBS} ${NS_RISCOS_LIBS} ${NS_TOOLS} ${NS_BROWSER}) ; do
343 echo -n " GIT: Cloning ${REPO}: "
344 if [ -f ${TARGET_WORKSPACE}/${REPO}/.git/config ]; then
345 echo "Repository already present"
347 (cd ${TARGET_WORKSPACE} && git clone ${NS_GIT}/${REPO}.git; )
351 # put current env.sh in place in workspace
352 if [ ! -f "${TARGET_WORKSPACE}/env.sh" -a -f ${TARGET_WORKSPACE}/${NS_BROWSER}/docs/env.sh ]; then
353 cp ${TARGET_WORKSPACE}/${NS_BROWSER}/docs/env.sh ${TARGET_WORKSPACE}/env.sh
357 # issues a make command to all libraries
360 for REPO in $(echo ${NS_BUILDSYSTEM} ${NS_INTERNAL_LIBS} ${NS_FRONTEND_LIBS}); do
361 echo " MAKE: make -C ${REPO} $USE_CPUS $*"
362 ${MAKE} -C ${TARGET_WORKSPACE}/${REPO} HOST=${HOST} $USE_CPUS $*
363 if [ $? -ne 0 ]; then
369 # issues make command for all tools
372 for REPO in $(echo ${NS_BUILDSYSTEM} ${NS_TOOLS}); do
373 echo " MAKE: make -C ${REPO} $USE_CPUS $*"
374 ${MAKE} -C ${TARGET_WORKSPACE}/${REPO} PREFIX=${BUILD_PREFIX} HOST=${BUILD} $USE_CPUS $*
375 if [ $? -ne 0 ]; then
381 # issues a make command for framebuffer libraries
384 echo " MAKE: make -C libnsfb $USE_CPUS $*"
385 ${MAKE} -C ${TARGET_WORKSPACE}/libnsfb HOST=${HOST} $USE_CPUS $*
388 # pulls all repos and makes and installs the libraries and tools
393 ns-make-tools install
397 # Passes appropriate flags to make
400 ${MAKE} $USE_CPUS "$@"