NetSurf
env.sh
Go to the documentation of this file.
1 #!/bin/sh
2 #
3 # NetSurf Library, tool and browser development support script
4 #
5 # Copyright 2013-2017 Vincent Sanders <vince@netsurf-browser.org>
6 # Released under the MIT Licence
7 #
8 # This script allows NetSurf and its libraries to be built without
9 # requiring installation into a system.
10 #
11 # Usage: source env.sh
12 #
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
17 #
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
21 #
22 
23 ###############################################################################
24 # OS Package installation
25 ###############################################################################
26 
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"
32 else
33  NS_GTK_DEB="libgtk2.0-dev librsvg2-dev"
34 fi
35 
36 # apt get commandline to install necessary dev packages
37 ns-apt-get-install()
38 {
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"
44  else
45  NS_DEV_DEB="${NS_DEV_DEB} libssl-dev"
46  fi
47  sudo apt-get install $(echo ${NS_DEV_DEB} ${NS_TOOL_DEB} ${NS_GTK_DEB})
48 }
49 
50 
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"
56 else
57  NS_GTK_YUM_RPM="gtk2-devel librsvg2-devel"
58 fi
59 
60 # yum commandline to install necessary dev packages
61 ns-yum-install()
62 {
63  sudo yum -y install $(echo ${NS_DEV_YUM_RPM} ${NS_TOOL_YUM_RPM} ${NS_GTK_YUM_RPM})
64 }
65 
66 
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"
72 else
73  NS_GTK_DNF_RPM="gtk2-devel"
74 fi
75 
76 # dnf commandline to install necessary dev packages
77 ns-dnf-install()
78 {
79  sudo dnf install $(echo ${NS_DEV_DNF_RPM} ${NS_TOOL_DNF_RPM} ${NS_GTK_DNF_RPM})
80 }
81 
82 
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"
88 else
89  NS_GTK_ZYP_RPM="gtk2-devel"
90 fi
91 
92 # zypper commandline to install necessary dev packages
93 ns-zypper-install()
94 {
95  sudo zypper install -y $(echo ${NS_DEV_ZYP_RPM} ${NS_TOOL_ZYP_RPM} ${NS_GTK_ZYP_RPM})
96 }
97 
98 
99 # Packages for Haiku install
100 
101 # Haiku secondary arch suffix:
102 # empty for primary (gcc2 on x86) or "_x86" for gcc4 secondary.
103 HA=_x86
104 
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"
106 
107 # pkgman commandline to install necessary dev packages
108 ns-pkgman-install()
109 {
110  pkgman install $(echo ${NS_DEV_HPKG})
111 }
112 
113 
114 # MAC OS X
115 NS_DEV_MACPORT="git expat openssl curl libjpeg-turbo libpng"
116 
117 ns-macport-install()
118 {
119  PATH=/opt/local/bin:/opt/local/sbin:$PATH sudo /opt/local/bin/port install $(echo ${NS_DEV_MACPORT})
120 }
121 
122 
123 # packages for FreeBSD install
124 NS_DEV_FREEBSDPKG="gmake curl"
125 
126 # FreeBSD package install
127 ns-freebsdpkg-install()
128 {
129  pkg install $(echo ${NS_DEV_FREEBSDPKG})
130 }
131 
132 
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"
138 else
139  NS_GTK_GEN="gtk+ 2 toolkit library, librsvg2 library"
140 fi
141 
142 # Generic OS package install
143 # looks for package managers and tries to use them if present
144 ns-package-install()
145 {
146  if [ -x "/usr/bin/zypper" ]; then
147  ns-zypper-install
148  elif [ -x "/usr/bin/apt-get" ]; then
149  ns-apt-get-install
150  elif [ -x "/usr/bin/dnf" ]; then
151  ns-dnf-install
152  elif [ -x "/usr/bin/yum" ]; then
153  ns-yum-install
154  elif [ -x "/bin/pkgman" ]; then
155  ns-pkgman-install
156  elif [ -x "/opt/local/bin/port" ]; then
157  ns-macport-install
158  elif [ -x "/usr/sbin/pkg" ]; then
159  ns-freebsdpkg-install
160  else
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}
164  fi
165 }
166 
167 ###############################################################################
168 # Setup environment
169 ###############################################################################
170 
171 # find which command used to find everything else on path
172 if [ -x /usr/bin/which ]; then
173  WHICH_CMD=/usr/bin/which
174 else
175  WHICH_CMD=/bin/which
176 fi
177 
178 # environment parameters
179 
180 # The system doing the building
181 if [ "x${BUILD}" = "x" ]; then
182  BUILD_CC=$(${WHICH_CMD} cc)
183  if [ $? -eq 0 ];then
184  BUILD=$(cc -dumpmachine)
185  else
186  echo "Unable to locate a compiler. Perhaps run ns-package-install"
187  return 1
188  fi
189 fi
190 
191 # Get the host build if unset
192 if [ "x${HOST}" = "x" ]; then
193  if [ "x${TARGET_ABI}" = "x" ]; then
194  HOST=${BUILD}
195  else
196  HOST=${TARGET_ABI}
197  fi
198 else
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
203  break
204  fi
205  done
206  if [ "x${HOST_CC}" = "x" ];then
207  echo "Unable to execute host compiler for HOST=${HOST}. is it set correctly?"
208  return 1
209  fi
210 
211  HOST_CC_MACHINE=$(${HOST_CC} -dumpmachine 2>/dev/null)
212 
213  if [ "${HOST_CC_MACHINE}" != "${HOST}" ];then
214  echo "Compiler dumpmachine differes from HOST setting"
215  return 2
216  fi
217  unset HOST_CC_LIST HOST_CC_V HOST_CC HOST_CC_MACHINE
218 fi
219 
220 # set up a default target workspace
221 if [ "x${TARGET_WORKSPACE}" = "x" ]; then
222  TARGET_WORKSPACE=${HOME}/dev-netsurf/workspace
223 fi
224 
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)
228  NCPUS="${NCPUS:-1}"
229  NCPUS=$((NCPUS * 2))
230  USE_CPUS="-j${NCPUS}"
231 fi
232 
233 # The GTK version to build for (either 2 or 3 currently)
234 if [ "x${NETSURF_GTK_MAJOR}" = "x" ]; then
235  NETSURF_GTK_MAJOR=2
236 fi
237 
238 # report to user
239 echo "BUILD=${BUILD}"
240 echo "HOST=${HOST}"
241 echo "TARGET_WORKSPACE=${TARGET_WORKSPACE}"
242 echo "USE_CPUS=${USE_CPUS}"
243 
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
250 
251 # make tool
252 MAKE=make
253 
254 # NetSurf GIT repositories
255 NS_GIT="git://git.netsurf-browser.org"
256 
257 # Buildsystem: everything depends on this
258 NS_BUILDSYSTEM="buildsystem"
259 
260 # internal libraries all frontends require (order is important)
261 NS_INTERNAL_LIBS="libwapcaplet libparserutils libhubbub libdom libcss libnsgif libnsbmp libutf8proc libnsutils libnspsl libnslog"
262 
263 # The browser itself
264 NS_BROWSER="netsurf"
265 
266 
267 # add target specific libraries
268 case "${HOST}" in
269  i586-pc-haiku)
270  # tools required to build the browser for haiku (beos)
271  NS_TOOLS="nsgenbind"
272  # libraries required for the haiku target abi
273  NS_FRONTEND_LIBS="libsvgtiny"
274  ;;
275  *arwin*)
276  # tools required to build the browser for OS X
277  NS_TOOLS=""
278  # libraries required for the Darwin target abi
279  NS_FRONTEND_LIBS="libsvgtiny libnsfb"
280  ;;
281  arm-unknown-riscos)
282  # tools required to build the browser for RISC OS
283  NS_TOOLS="nsgenbind"
284  # libraries required for the risc os target abi
285  NS_FRONTEND_LIBS="libsvgtiny librufl libpencil librosprite"
286  ;;
287  *-atari-mint)
288  # tools required to build the browser for atari
289  NS_TOOLS=""
290  # libraries required for the atari frontend
291  NS_FRONTEND_LIBS=""
292  ;;
293  ppc-amigaos)
294  # default tools required to build the browser
295  NS_TOOLS="nsgenbind"
296  # default additional internal libraries
297  NS_FRONTEND_LIBS="libsvgtiny"
298  ;;
299  m68k-unknown-amigaos)
300  # default tools required to build the browser
301  NS_TOOLS="nsgenbind"
302  # default additional internal libraries
303  NS_FRONTEND_LIBS="libsvgtiny"
304  ;;
305  *-unknown-freebsd*)
306  # tools required to build the browser for freebsd
307  NS_TOOLS=""
308  # libraries required for the freebsd frontend
309  NS_FRONTEND_LIBS=""
310  # select gnu make
311  MAKE=gmake
312  ;;
313  *)
314  # default tools required to build the browser
315  NS_TOOLS="nsgenbind"
316  # default additional internal libraries
317  NS_FRONTEND_LIBS="libsvgtiny libnsfb"
318  ;;
319 esac
320 
321 export MAKE
322 
323 ################ Development helpers ################
324 
325 # git pull in all repos parameters are passed to git pull
326 ns-pull()
327 {
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 $*; )
332  else
333  echo "Repository not present"
334  fi
335  done
336 }
337 
338 # clone all repositories
339 ns-clone()
340 {
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"
346  else
347  (cd ${TARGET_WORKSPACE} && git clone ${NS_GIT}/${REPO}.git; )
348  fi
349  done
350 
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
354  fi
355 }
356 
357 # issues a make command to all libraries
358 ns-make-libs()
359 {
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
364  return $?
365  fi
366  done
367 }
368 
369 # issues make command for all tools
370 ns-make-tools()
371 {
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
376  return $?
377  fi
378  done
379 }
380 
381 # issues a make command for framebuffer libraries
382 ns-make-libnsfb()
383 {
384  echo " MAKE: make -C libnsfb $USE_CPUS $*"
385  ${MAKE} -C ${TARGET_WORKSPACE}/libnsfb HOST=${HOST} $USE_CPUS $*
386 }
387 
388 # pulls all repos and makes and installs the libraries and tools
389 ns-pull-install()
390 {
391  ns-pull $*
392 
393  ns-make-tools install
394  ns-make-libs install
395 }
396 
397 # Passes appropriate flags to make
398 ns-make()
399 {
400  ${MAKE} $USE_CPUS "$@"
401 }