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-2017 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 #
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
23 #
24 
25 ###############################################################################
26 # OS Package installation
27 ###############################################################################
28 
29 # deb packages for dpkg based systems
30 NS_DEV_DEB="build-essential pkg-config git gperf libcurl3-dev libpng-dev libjpeg-dev"
31 NS_TOOL_DEB="flex bison libhtml-parser-perl"
32 if [ "x${NETSURF_GTK_MAJOR}" = "x3" ]; then
33  NS_GTK_DEB="libgtk-3-dev librsvg2-dev"
34 else
35  NS_GTK_DEB="libgtk2.0-dev librsvg2-dev"
36 fi
37 
38 # apt get commandline to install necessary dev packages
39 ns-apt-get-install()
40 {
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"
46  else
47  NS_DEV_DEB="${NS_DEV_DEB} libssl-dev"
48  fi
49  sudo apt-get install $(echo ${NS_DEV_DEB} ${NS_TOOL_DEB} ${NS_GTK_DEB})
50 }
51 
52 
53 # packages for yum installer RPM based systems (tested on fedora 20)
54 NS_DEV_YUM_RPM="git gcc pkgconfig expat-devel openssl-devel gperf libcurl-devel perl-Digest-MD5-File libjpeg-devel libpng-devel"
55 NS_TOOL_YUM_RPM="flex bison"
56 if [ "x${NETSURF_GTK_MAJOR}" = "x3" ]; then
57  NS_GTK_YUM_RPM="gtk3-devel librsvg2-devel"
58 else
59  NS_GTK_YUM_RPM="gtk2-devel librsvg2-devel"
60 fi
61 
62 # yum commandline to install necessary dev packages
63 ns-yum-install()
64 {
65  sudo yum -y install $(echo ${NS_DEV_YUM_RPM} ${NS_TOOL_YUM_RPM} ${NS_GTK_YUM_RPM})
66 }
67 
68 
69 # packages for dnf installer RPM based systems (tested on fedora 25)
70 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"
71 NS_TOOL_DNF_RPM="git flex bison ccache screen"
72 if [ "x${NETSURF_GTK_MAJOR}" = "x3" ]; then
73  NS_GTK_DNF_RPM="gtk3-devel"
74 else
75  NS_GTK_DNF_RPM="gtk2-devel"
76 fi
77 
78 # dnf commandline to install necessary dev packages
79 ns-dnf-install()
80 {
81  sudo dnf install $(echo ${NS_DEV_DNF_RPM} ${NS_TOOL_DNF_RPM} ${NS_GTK_DNF_RPM})
82 }
83 
84 
85 # packages for zypper installer RPM based systems (tested on openSUSE leap 42)
86 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"
87 NS_TOOL_ZYP_RPM="git flex bison gperf ccache screen"
88 if [ "x${NETSURF_GTK_MAJOR}" = "x3" ]; then
89  NS_GTK_ZYP_RPM="gtk3-devel"
90 else
91  NS_GTK_ZYP_RPM="gtk2-devel"
92 fi
93 
94 # zypper commandline to install necessary dev packages
95 ns-zypper-install()
96 {
97  sudo zypper install -y $(echo ${NS_DEV_ZYP_RPM} ${NS_TOOL_ZYP_RPM} ${NS_GTK_ZYP_RPM})
98 }
99 
100 
101 # Packages for Haiku install
102 
103 # Haiku secondary arch suffix:
104 # empty for primary (gcc2 on x86) or "_x86" for gcc4 secondary.
105 HA=_x86
106 
107 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"
108 
109 # pkgman commandline to install necessary dev packages
110 ns-pkgman-install()
111 {
112  pkgman install $(echo ${NS_DEV_HPKG})
113 }
114 
115 
116 # MAC OS X
117 NS_DEV_MACPORT="git expat openssl curl libjpeg-turbo libpng"
118 
119 ns-macport-install()
120 {
121  PATH=/opt/local/bin:/opt/local/sbin:$PATH sudo /opt/local/bin/port install $(echo ${NS_DEV_MACPORT})
122 }
123 
124 
125 # packages for FreeBSD install
126 NS_DEV_FREEBSDPKG="gmake curl"
127 
128 # FreeBSD package install
129 ns-freebsdpkg-install()
130 {
131  pkg install $(echo ${NS_DEV_FREEBSDPKG})
132 }
133 
134 
135 # generic for help text
136 NS_DEV_GEN="git, gcc, pkgconfig, expat library, openssl library, libcurl, perl, perl MD5 digest, libjpeg library, libpng library"
137 NS_TOOL_GEN="flex tool, bison tool"
138 if [ "x${NETSURF_GTK_MAJOR}" = "x3" ]; then
139  NS_GTK_GEN="gtk+ 3 toolkit library, librsvg2 library"
140 else
141  NS_GTK_GEN="gtk+ 2 toolkit library, librsvg2 library"
142 fi
143 
144 # Generic OS package install
145 # looks for package managers and tries to use them if present
146 ns-package-install()
147 {
148  if [ -x "/usr/bin/zypper" ]; then
149  ns-zypper-install
150  elif [ -x "/usr/bin/apt-get" ]; then
151  ns-apt-get-install
152  elif [ -x "/usr/bin/dnf" ]; then
153  ns-dnf-install
154  elif [ -x "/usr/bin/yum" ]; then
155  ns-yum-install
156  elif [ -x "/bin/pkgman" ]; then
157  ns-pkgman-install
158  elif [ -x "/opt/local/bin/port" ]; then
159  ns-macport-install
160  elif [ -x "/usr/sbin/pkg" ]; then
161  ns-freebsdpkg-install
162  else
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}
166  fi
167 }
168 
169 ###############################################################################
170 # Setup environment
171 ###############################################################################
172 
173 # find which command used to find everything else on path
174 if [ -x /usr/bin/which ]; then
175  WHICH_CMD=/usr/bin/which
176 else
177  WHICH_CMD=/bin/which
178 fi
179 
180 # environment parameters
181 
182 # The system doing the building
183 if [ "x${BUILD}" = "x" ]; then
184  BUILD_CC=$(${WHICH_CMD} cc)
185  if [ $? -eq 0 ];then
186  BUILD=$(cc -dumpmachine)
187  else
188  echo "Unable to locate a compiler. Perhaps run ns-package-install"
189  return 1
190  fi
191 fi
192 
193 # Get the host build if unset
194 if [ "x${HOST}" = "x" ]; then
195  if [ "x${TARGET_ABI}" = "x" ]; then
196  HOST=${BUILD}
197  else
198  HOST=${TARGET_ABI}
199  fi
200 else
201  HOST_CC_LIST="${HOST}-cc ${HOST}-gcc /opt/netsurf/${HOST}/cross/bin/${HOST}-cc /opt/netsurf/${HOST}/cross/bin/${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
205  break
206  fi
207  done
208  if [ "x${HOST_CC}" = "x" ];then
209  echo "Unable to execute host compiler for HOST=${HOST}. is it set correctly?"
210  return 1
211  fi
212 
213  HOST_CC_MACHINE=$(${HOST_CC} -dumpmachine 2>/dev/null)
214 
215  if [ "${HOST_CC_MACHINE}" != "${HOST}" ];then
216  echo "Compiler dumpmachine differes from HOST setting"
217  return 2
218  fi
219  unset HOST_CC_LIST HOST_CC_V HOST_CC HOST_CC_MACHINE
220 fi
221 
222 # set up a default target workspace
223 if [ "x${TARGET_WORKSPACE}" = "x" ]; then
224  TARGET_WORKSPACE=${HOME}/dev-netsurf/workspace
225 fi
226 
227 # set up default parallelism
228 if [ "x${USE_CPUS}" = "x" ]; then
229  NCPUS=$(getconf _NPROCESSORS_ONLN 2>/dev/null || getconf NPROCESSORS_ONLN 2>/dev/null)
230  NCPUS="${NCPUS:-1}"
231  NCPUS=$((NCPUS * 2))
232  USE_CPUS="-j${NCPUS}"
233 fi
234 
235 # The GTK version to build for (either 2 or 3 currently)
236 if [ "x${NETSURF_GTK_MAJOR}" = "x" ]; then
237  NETSURF_GTK_MAJOR=2
238 fi
239 
240 # report to user
241 echo "BUILD=${BUILD}"
242 echo "HOST=${HOST}"
243 echo "TARGET_WORKSPACE=${TARGET_WORKSPACE}"
244 echo "USE_CPUS=${USE_CPUS}"
245 
246 export PREFIX=${TARGET_WORKSPACE}/inst-${HOST}
247 export BUILD_PREFIX=${TARGET_WORKSPACE}/inst-${BUILD}
248 export PKG_CONFIG_PATH=${PREFIX}/lib/pkgconfig:${PKG_CONFIG_PATH}::
249 export LD_LIBRARY_PATH=${LD_LIBRARY_PATH}:${PREFIX}/lib
250 export PATH=${PATH}:${BUILD_PREFIX}/bin
251 export NETSURF_GTK_MAJOR
252 
253 # make tool
254 MAKE=make
255 
256 # NetSurf GIT repositories
257 NS_GIT="git://git.netsurf-browser.org"
258 
259 # Buildsystem: everything depends on this
260 NS_BUILDSYSTEM="buildsystem"
261 
262 # internal libraries all frontends require (order is important)
263 NS_INTERNAL_LIBS="libwapcaplet libparserutils libhubbub libdom libcss libnsgif libnsbmp libutf8proc libnsutils libnspsl libnslog"
264 
265 # The browser itself
266 NS_BROWSER="netsurf"
267 
268 
269 # add target specific libraries
270 case "${HOST}" in
271  i586-pc-haiku)
272  # tools required to build the browser for haiku (beos)
273  NS_TOOLS="nsgenbind"
274  # libraries required for the haiku target abi
275  NS_FRONTEND_LIBS="libsvgtiny"
276  ;;
277  *arwin*)
278  # tools required to build the browser for OS X
279  NS_TOOLS=""
280  # libraries required for the Darwin target abi
281  NS_FRONTEND_LIBS="libsvgtiny libnsfb"
282  ;;
283  arm-unknown-riscos)
284  # tools required to build the browser for RISC OS
285  NS_TOOLS="nsgenbind"
286  # libraries required for the risc os target abi
287  NS_FRONTEND_LIBS="libsvgtiny librufl libpencil librosprite"
288  ;;
289  *-atari-mint)
290  # tools required to build the browser for atari
291  NS_TOOLS=""
292  # libraries required for the atari frontend
293  NS_FRONTEND_LIBS=""
294  ;;
295  ppc-amigaos)
296  # default tools required to build the browser
297  NS_TOOLS="nsgenbind"
298  # default additional internal libraries
299  NS_FRONTEND_LIBS="libsvgtiny"
300  ;;
301  m68k-unknown-amigaos)
302  # default tools required to build the browser
303  NS_TOOLS="nsgenbind"
304  # default additional internal libraries
305  NS_FRONTEND_LIBS="libsvgtiny"
306  ;;
307  *-unknown-freebsd*)
308  # tools required to build the browser for freebsd
309  NS_TOOLS=""
310  # libraries required for the freebsd frontend
311  NS_FRONTEND_LIBS=""
312  # select gnu make
313  MAKE=gmake
314  ;;
315  *)
316  # default tools required to build the browser
317  NS_TOOLS="nsgenbind"
318  # default additional internal libraries
319  NS_FRONTEND_LIBS="libsvgtiny libnsfb"
320  ;;
321 esac
322 
323 export MAKE
324 
325 ################ Development helpers ################
326 
327 # git pull in all repos parameters are passed to git pull
328 ns-pull()
329 {
330  for REPO in $(echo ${NS_BUILDSYSTEM} ${NS_INTERNAL_LIBS} ${NS_FRONTEND_LIBS} ${NS_TOOLS} ${NS_BROWSER}) ; do
331  echo -n " GIT: Pulling ${REPO}: "
332  if [ -f "${TARGET_WORKSPACE}/${REPO}/.git/config" ]; then
333  (cd ${TARGET_WORKSPACE}/${REPO} && git pull $*; )
334  else
335  echo "Repository not present"
336  fi
337  done
338 }
339 
340 # clone all repositories
341 ns-clone()
342 {
343  mkdir -p ${TARGET_WORKSPACE}
344  for REPO in $(echo ${NS_BUILDSYSTEM} ${NS_INTERNAL_LIBS} ${NS_FRONTEND_LIBS} ${NS_RISCOS_LIBS} ${NS_TOOLS} ${NS_BROWSER}) ; do
345  echo -n " GIT: Cloning ${REPO}: "
346  if [ -f ${TARGET_WORKSPACE}/${REPO}/.git/config ]; then
347  echo "Repository already present"
348  else
349  (cd ${TARGET_WORKSPACE} && git clone ${NS_GIT}/${REPO}.git; )
350  fi
351  done
352 
353  # put current env.sh in place in workspace
354  if [ ! -f "${TARGET_WORKSPACE}/env.sh" -a -f ${TARGET_WORKSPACE}/${NS_BROWSER}/docs/env.sh ]; then
355  cp ${TARGET_WORKSPACE}/${NS_BROWSER}/docs/env.sh ${TARGET_WORKSPACE}/env.sh
356  fi
357 }
358 
359 # issues a make command to all libraries
360 ns-make-libs()
361 {
362  for REPO in $(echo ${NS_BUILDSYSTEM} ${NS_INTERNAL_LIBS} ${NS_FRONTEND_LIBS}); do
363  echo " MAKE: make -C ${REPO} $USE_CPUS $*"
364  ${MAKE} -C ${TARGET_WORKSPACE}/${REPO} HOST=${HOST} $USE_CPUS $*
365  if [ $? -ne 0 ]; then
366  return $?
367  fi
368  done
369 }
370 
371 # issues make command for all tools
372 ns-make-tools()
373 {
374  for REPO in $(echo ${NS_BUILDSYSTEM} ${NS_TOOLS}); do
375  echo " MAKE: make -C ${REPO} $USE_CPUS $*"
376  ${MAKE} -C ${TARGET_WORKSPACE}/${REPO} PREFIX=${BUILD_PREFIX} HOST=${BUILD} $USE_CPUS $*
377  if [ $? -ne 0 ]; then
378  return $?
379  fi
380  done
381 }
382 
383 # issues a make command for framebuffer libraries
384 ns-make-libnsfb()
385 {
386  echo " MAKE: make -C libnsfb $USE_CPUS $*"
387  ${MAKE} -C ${TARGET_WORKSPACE}/libnsfb HOST=${HOST} $USE_CPUS $*
388 }
389 
390 # pulls all repos and makes and installs the libraries and tools
391 ns-pull-install()
392 {
393  ns-pull $*
394 
395  ns-make-tools install
396  ns-make-libs install
397 }
398 
399 # Passes appropriate flags to make
400 ns-make()
401 {
402  ${MAKE} $USE_CPUS "$@"
403 }