3 # compile ldns for windows
4 cdir="$(echo ldns.win.$$)"
8 #configure="mingw32-configure"
9 #strip="i686-w64-mingw32-strip"
11 configure="mingw64-configure"
12 strip="x86_64-w64-mingw32-strip"
14 WINSSL="$HOME/Downloads/openssl-1.1.0h.tar.gz"
16 cross_flag_nonstatic=""
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.
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."
40 # Parse command line arguments
44 echo "Compile a zip file with static executables, and"
45 echo "dynamic library, static library, include dir and"
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"
54 echo " -wssl <file> Pass openssl.tar.gz file, use absolute path."
74 error_cleanup "Unrecognized argument -- $1"
83 CHECKOUT=$( (git status | head -n 1 | awk '{print$3}') || echo master)
85 CHECKOUT=$( (git status | head -n 1 | awk '{print$3}') || echo develop)
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
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
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"
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"
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"
139 sslflags="no-shared no-asm -DOPENSSL_NO_CAPIENG mingw"
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"
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"
151 ldnsinstall="$(pwd)/ldnsinstall"
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
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"
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"
169 # Build OpenSSL nonstatic
170 sslinstallnonstatic="$(pwd)/sslinstallnonstatic"
171 mkdir 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"
178 sslflags_nonstatic="shared no-asm -DOPENSSL_NO_CAPIENG mingw"
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"
189 # Build ldns nonstatic
190 ldnsinstallnonstatic="$(pwd)/ldnsinstall-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
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"
209 file="ldns-$version.zip"
211 info "Creating $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 .
224 cp ../ldns/Changelog .
225 info "copy static exe"
226 for x in "$installplace"/bin/* ; do
227 cp "$x" "$(basename "$x").exe"
229 # but the shell script stays a script file
230 mv ldns-config.exe ldns-config
234 cp "$installplace"/include/ldns/*.h include/ldns/.
237 cp "$installplace"/share/man/man1/* man1/.
240 cp "$installplace"/share/man/man3/* man3/.
243 for x in man1/*.1; do groff -man -Tascii -Z "$x" | grotty -cbu > cat1/"$(basename "$x" .1).txt"; done
246 for x in man3/*.3; do groff -man -Tascii -Z "$x" | grotty -cbu > cat3/"$(basename "$x" .3).txt"; done
248 info "$file contents"
249 # show contents of directory we are zipping up.
253 zip -r ../../"$file" LICENSE README libldns.a *.dll *.dll.a Changelog *.exe include man1 man3 cat1 cat3
255 (cd ../.. ; zip -T "$file" ) || error_cleanup "errors in zipfile $file"
258 # cleanup before exit