]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - contrib/ldns/makewin.sh
ntp: import ntp-4.2.8p17
[FreeBSD/FreeBSD.git] / contrib / ldns / makewin.sh
1 #!/usr/bin/env bash
2
3 # compile ldns for windows
4 cdir="$(echo ldns.win.$$)"
5 tmpdir=$(pwd)
6 mkdir "$cdir"
7 cd "$cdir"
8 #configure="mingw32-configure"
9 #strip="i686-w64-mingw32-strip"
10 #warch="i686"
11 configure="mingw64-configure"
12 strip="x86_64-w64-mingw32-strip"
13 warch="x86_64"
14 WINSSL="$HOME/Downloads/openssl-1.1.0h.tar.gz"
15 cross_flag=""
16 cross_flag_nonstatic=""
17 RC="no"
18 SNAPSHOT="no"
19 CHECKOUT=""
20 # the destination is a zipfile in the start directory ldns-a.b.c.zip
21 # the start directory is a git repository, and it is copied to build from.
22
23 info () {
24         echo "info: $1"
25 }
26
27 error_cleanup () {
28         echo "$1"
29         cd "$tmpdir"
30         rm -rf "$cdir"
31         exit 1
32 }
33
34 replace_text () {
35     (cp "$1" "$1".orig && \
36         sed -e "s/$2/$3/g" < "$1".orig > "$1" && \
37         rm "$1".orig) || error_cleanup "Replacement for $1 failed."
38 }
39
40 # Parse command line arguments
41 while [ "$1" ]; do
42     case "$1" in
43         "-h")
44                 echo "Compile a zip file with static executables, and"
45                 echo "dynamic library, static library, include dir and"
46                 echo "manual pages."
47                 echo ""
48                 echo "  -h              This usage information."
49                 echo "  -s              snapshot, current date appended to version"
50                 echo "  -rc <nr>        release candidate, the number is added to version"
51                 echo "                  ldns-<version>rc<nr>."
52                 echo "  -c <tag/br>     Checkout this tag or branch, (defaults to current"
53                 echo "                  branch)."
54                 echo "  -wssl <file>    Pass openssl.tar.gz file, use absolute path."
55                 echo ""
56                 exit 1
57                 ;;
58         "-c")
59                 CHECKOUT="$2"
60                 shift
61                 ;;
62         "-s")
63                 SNAPSHOT="yes"
64                 ;;
65         "-rc")
66                 RC="$2"
67                 shift
68                 ;;
69         "-wssl")
70                 WINSSL="$2"
71                 shift
72                 ;;
73         *)
74                 error_cleanup "Unrecognized argument -- $1"
75                 ;;
76     esac
77     shift
78 done
79 if [ -z "$CHECKOUT" ]
80 then
81         if [ "$RC" = "no" ]
82         then
83                 CHECKOUT=$( (git status | head -n 1 | awk '{print$3}') || echo master)
84         else
85                 CHECKOUT=$( (git status | head -n 1 | awk '{print$3}') || echo develop)
86         fi
87 fi
88
89 # this script creates a temp directory $cdir.
90 # this directory contains subdirectories:
91 # ldns/ : ldns source compiled
92 # openssl-a.b.c/ : the openSSL source compiled
93 # ldnsinstall/ : install of ldns here.
94 # sslinstall/ : install of ssl here.
95 # file/ : directory to gather the components of the zipfile distribution
96 # ldns-nonstatic/ : ldns source compiled nonstatic
97 # ldnsinstall-nonstatic/ : install of ldns nonstatic compile
98 # openssl-nonstatic/ : nonstatic openssl source compiled
99 # sslinstall-nonstatic/ : install of nonstatic openssl compile
100
101 info "exporting source into $cdir/ldns"
102 git clone git://git.nlnetlabs.nl/ldns/ ldns || error_cleanup "git command failed"
103 (cd ldns; git checkout "$CHECKOUT") || error_cleanup "Could not checkout $CHECKOUT"
104 #svn export . $cdir/ldns
105 info "exporting source into $cdir/ldns-nonstatic"
106 git clone git://git.nlnetlabs.nl/ldns/ ldns-nonstatic || error_cleanup "git command failed"
107 (cd ldns-nonstatic; git checkout "$CHECKOUT") || error_cleanup "Could not checkout $CHECKOUT"
108 #svn export . $cdir/ldns-nonstatic
109
110 # Fix up the version number if necessary
111 (cd ldns; if test ! -f install-sh -a -f ../../install-sh; then cp ../../install-sh . ; fi; libtoolize -ci; autoreconf -fi)
112 version=$(./ldns/configure --version | head -1 | awk '{ print $3 }') || \
113     error_cleanup "Cannot determine version number."
114 info "LDNS version: $version"
115 if [ "$RC" != "no" ]; then
116         info "Building LDNS release candidate $RC."
117         version2="${version}-rc$RC"
118         info "Version number: $version2"
119         replace_text "ldns/configure.ac" "AC_INIT(ldns, $version" "AC_INIT(ldns, $version2"
120         replace_text "ldns-nonstatic/configure.ac" "AC_INIT(ldns, $version" "AC_INIT(ldns, $version2"
121         version="$version2"
122 fi
123 if [ "$SNAPSHOT" = "yes" ]; then
124         info "Building LDNS snapshot."
125         version2="${version}_$(date +%Y%m%d)"
126         info "Snapshot version number: $version2"
127         replace_text "ldns/configure.ac" "AC_INIT(ldns, $version" "AC_INIT(ldns, $version2"
128         replace_text "ldns-nonstatic/configure.ac" "AC_INIT(ldns, $version" "AC_INIT(ldns, $version2"
129         version="$version2"
130 fi
131
132 # Build OpenSSL
133 gzip -cd "$WINSSL" | tar xf - || error_cleanup "tar unpack of $WINSSL failed"
134 sslinstall="$(pwd)/sslinstall"
135 cd openssl-* || error_cleanup "no openssl-X dir in tarball"
136 if test $configure = "mingw64-configure"; then
137         sslflags="no-shared no-asm -DOPENSSL_NO_CAPIENG mingw64"
138 else
139         sslflags="no-shared no-asm -DOPENSSL_NO_CAPIENG mingw"
140 fi
141 info "winssl: Configure $sslflags"
142 CC="${warch}-w64-mingw32-gcc" AR="${warch}-w64-mingw32-ar" RANLIB="${warch}-w64-mingw32-ranlib" WINDRES="${warch}-w64-mingw32-windres" ./Configure --prefix="$sslinstall" "$sslflags" || error_cleanup "OpenSSL Configure failed"
143 info "winssl: make"
144 make || error_cleanup "make failed for $WINSSL"
145 info "winssl: make install_sw"
146 make install_sw || error_cleanup "OpenSSL install failed"
147 cross_flag="$cross_flag --with-ssl=$sslinstall"
148 cd ..
149
150 # Build ldns
151 ldnsinstall="$(pwd)/ldnsinstall"
152 cd ldns
153 info "ldns: autoconf"
154 # cp install-sh because one at ../.. means libtoolize won't install it for us.
155 if test ! -f install-sh -a -f ../../install-sh; then cp ../../install-sh . ; fi
156 libtoolize -ci
157 autoreconf -fi
158 ldns_flag="--with-examples --with-drill"
159 info "ldns: Configure $cross_flag $ldns_flag"
160 $configure "$cross_flag" "$ldns_flag" || error_cleanup "ldns configure failed"
161 info "ldns: make"
162 make || error_cleanup "ldns make failed"
163 # do not strip debug symbols, could be useful for stack traces
164 # $strip lib/*.dll || error_cleanup "cannot strip ldns dll"
165 make doc || error_cleanup "ldns make doc failed"
166 DESTDIR=$ldnsinstall make install || error_cleanup "ldns make install failed"
167 cd ..
168
169 # Build OpenSSL nonstatic
170 sslinstallnonstatic="$(pwd)/sslinstallnonstatic"
171 mkdir openssl-nonstatic
172 cd openssl-nonstatic
173 # remove openssl-a.b.c/ and put in openssl-nonstatic directory
174 gzip -cd "$WINSSL" | tar xf - --strip-components=1 || error_cleanup "tar unpack of $WINSSL failed"
175 if test "$configure" = "mingw64-configure"; then
176         sslflags_nonstatic="shared no-asm -DOPENSSL_NO_CAPIENG mingw64"
177 else
178         sslflags_nonstatic="shared no-asm -DOPENSSL_NO_CAPIENG mingw"
179 fi
180 info "winsslnonstatic: Configure $sslflags_nonstatic"
181 CC="${warch}-w64-mingw32-gcc" AR="${warch}-w64-mingw32-ar" RANLIB="${warch}-w64-mingw32-ranlib" WINDRES="${warch}-w64-mingw32-windres" ./Configure --prefix="$sslinstallnonstatic" "$sslflags_nonstatic" || error_cleanup "OpenSSL Configure failed"
182 info "winsslnonstatic: make"
183 make || error_cleanup "make failed for $WINSSL"
184 info "winsslnonstatic: make install_sw"
185 make install_sw || error_cleanup "OpenSSL install failed"
186 cross_flag_nonstatic="$cross_flag_nonstatic --with-ssl=$sslinstallnonstatic"
187 cd ..
188
189 # Build ldns nonstatic
190 ldnsinstallnonstatic="$(pwd)/ldnsinstall-nonstatic"
191 cd ldns-nonstatic
192 info "ldnsnonstatic: autoconf"
193 # cp install-sh because one at ../.. means libtoolize won't install it for us.
194 if test ! -f install-sh -a -f ../../install-sh; then cp ../../install-sh . ; fi
195 libtoolize -ci
196 autoreconf -fi
197 ldns_flag_nonstatic="--with-examples --with-drill"
198 info "ldnsnonstatic: Configure $cross_flag_nonstatic $ldns_flag_nonstatic"
199 $configure "$cross_flag_nonstatic" "$ldns_flag_nonstatic" || error_cleanup "ldns configure failed"
200 info "ldnsnonstatic: make"
201 make || error_cleanup "ldns make failed"
202 # do not strip debug symbols, could be useful for stack traces
203 # $strip lib/*.dll || error_cleanup "cannot strip ldns dll"
204 make doc || error_cleanup "ldns make doc failed"
205 DESTDIR=$ldnsinstallnonstatic make install || error_cleanup "ldns make install failed"
206 cd ..
207
208 # create zipfile
209 file="ldns-$version.zip"
210 rm -f "$file"
211 info "Creating $file"
212 mkdir file
213 cd file
214 installplace="$ldnsinstall/usr/$warch-w64-mingw32/sys-root/mingw"
215 installplacenonstatic="$ldnsinstallnonstatic/usr/$warch-w64-mingw32/sys-root/mingw"
216 cp "$installplace"/lib/libldns.a .
217 cp "$installplacenonstatic"/lib/libldns.dll.a .
218 cp "$installplacenonstatic"/bin/*.dll .
219 cp "$sslinstallnonstatic"/lib/*.dll.a .
220 cp "$sslinstallnonstatic"/bin/*.dll .
221 cp "$sslinstallnonstatic"/lib/engines-*/*.dll .
222 cp ../ldns/LICENSE .
223 cp ../ldns/README .
224 cp ../ldns/Changelog .
225 info "copy static exe"
226 for x in "$installplace"/bin/* ; do
227         cp "$x" "$(basename "$x").exe"
228 done
229 # but the shell script stays a script file
230 mv ldns-config.exe ldns-config
231 info "copy include"
232 mkdir include
233 mkdir include/ldns
234 cp "$installplace"/include/ldns/*.h include/ldns/.
235 info "copy man1"
236 mkdir man1
237 cp "$installplace"/share/man/man1/* man1/.
238 info "copy man3"
239 mkdir man3
240 cp "$installplace"/share/man/man3/* man3/.
241 info "create cat1"
242 mkdir cat1
243 for x in man1/*.1; do groff -man -Tascii -Z "$x" | grotty -cbu > cat1/"$(basename "$x" .1).txt"; done
244 info "create cat3"
245 mkdir cat3
246 for x in man3/*.3; do groff -man -Tascii -Z "$x" | grotty -cbu > cat3/"$(basename "$x" .3).txt"; done
247 rm -f "../../$file"
248 info "$file contents"
249 # show contents of directory we are zipping up.
250 du -s ./*
251 # zip it
252 info "zip $file"
253 zip -r ../../"$file" LICENSE README libldns.a *.dll *.dll.a Changelog *.exe include man1 man3 cat1 cat3
254 info "Testing $file"
255 (cd ../.. ; zip -T "$file" ) || error_cleanup "errors in zipfile $file"
256 cd ..
257
258 # cleanup before exit
259 cd "$tmpdir"
260 rm -rf "$cdir"
261 echo "done"
262 # display
263 ls -lG "$file"