use ifdef instead of if for __linux__ and BSD
[oweals/gnunet.git] / bootstrap
1 #!/bin/sh
2 # This file is in the public domain.
3
4 # We can't set -eu because we encounter warnings which
5 # result in stops, whereas the warnings can for now be
6 # safely ignored.
7 # set -eu
8
9 cleanup()
10 {
11     echo "Removing folder 'libltdl'..."
12     rm -rf libltdl
13 }
14
15 # This is more portable than `which' but comes with
16 # the caveat of not(?) properly working on busybox's ash:
17 existence()
18 {
19     command -v "$1" >/dev/null 2>&1
20 }
21
22 check_uncrustify()
23 {
24     if existence uncrustify; then
25         echo "Installing uncrustify hook and configuration"
26         ln -fs contrib/build-common/conf/uncrustify.cfg uncrustify.cfg 2> /dev/null
27         ln -fs contrib/build-common/conf/uncrustify_precommit .git/hooks/pre-commit 2> /dev/null
28     else
29         echo "Uncrustify not detected, hook not installed."
30         echo "Please install uncrustify if you plan on doing development"
31     fi
32 }
33
34 # yapf can be a suffixed binary, don't change the essential logic
35 # of this if you change it.
36 check_yapf()
37 {
38     if existence yapf || \
39        existence yapf3.0 || \
40        existence yapf3.1 || \
41        existence yapf3.2 || \
42        existence yapf3.3 || \
43        existence yapf3.4 || \
44        existence yapf3.5 || \
45        existence yapf3.6 || \
46        existence yapf3.7 || \
47        existence yapf3.8 || \
48        existence yapf3.9 || \
49        existence yapf4.0; then
50         echo "Installing yapf symlink"
51         ln -fs contrib/build-common/conf/.style.yapf .style.yapf 2> /dev/null
52     else
53         echo "yapf not detected, please install yapf if you plan on contributing python code"
54     fi
55 }
56
57 check_libtool()
58 {
59     echo "checking for libtoolize / libtool... "
60
61     if existence libtool || \
62        existence libtoolize || \
63        existence glibtoolize || \
64        existence slibtool; then
65         autoreconf -if
66         . "bin/pogen.sh"
67     else
68         echo "*** No libtoolize (libtool) or libtool found, please install it ***" >&2;
69         exit 1
70     fi
71 }
72
73 submodules()
74 {
75     # Try to update the submodule. Since bootstrap
76     # is also invoked by distributors, we must
77     # ignore any failing of this function as we
78     # could have no outgoing network connection
79     # in a restricted environment.
80     if ! git --version >/dev/null; then
81         echo "git not installed, skipping submodule update"
82     else
83         git submodule update --init || true
84         git submodule update --recursive --remote || true
85         git submodule sync || true
86     fi
87 }
88
89 main()
90 {
91     cleanup
92     submodules
93     check_uncrustify
94     check_yapf
95     check_libtool
96 }
97
98 main "$@"