cvs updates from Wed Dec 15 17:45:22 EST 2010
[tridge/bind9.git] / win32utils / updatelibxml2.pl
1 #!/usr/bin/perl
2 #
3 # Copyright (C) 2009, 2010  Internet Systems Consortium, Inc. ("ISC")
4 #
5 # Permission to use, copy, modify, and/or distribute this software for any
6 # purpose with or without fee is hereby granted, provided that the above
7 # copyright notice and this permission notice appear in all copies.
8 #
9 # THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
10 # REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
11 # AND FITNESS.  IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
12 # INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
13 # LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
14 # OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
15 # PERFORMANCE OF THIS SOFTWARE.
16
17 # $Id: updatelibxml2.pl,v 1.5 2010/08/13 23:47:04 tbox Exp $
18
19 # updatelibxml2.pl
20 # This script locates the latest version of libxml2 in the grandparent
21 # directory and updates the build scripts to use that version.
22 # Copied from updateopenssl.pl.
23 #
24 # Path and directory
25 $path = "..\\..\\";
26
27 # List of files that need to be updated with the actual version of the
28 # libxml2 directory
29 @filelist = ("SetupLibs.bat",
30              "../lib/dns/win32/libdns.mak",
31              "../lib/dns/win32/libdns.dsp",
32              "../bin/check/win32/checktool.dsp",
33              "../bin/check/win32/namedcheckconf.dsp",
34              "../bin/check/win32/namedcheckconf.mak",
35              "../bin/check/win32/namedcheckzone.dsp",
36              "../bin/check/win32/namedcheckzone.mak",
37              "../bin/confgen/win32/confgentool.dsp",
38              "../bin/confgen/win32/ddnsconfgen.dsp",
39              "../bin/confgen/win32/ddnsconfgen.mak",
40              "../bin/confgen/win32/rndcconfgen.dsp",
41              "../bin/confgen/win32/rndcconfgen.mak",
42              "../bin/dig/win32/dig.dsp",
43              "../bin/dig/win32/dig.mak",
44              "../bin/dig/win32/dighost.dsp",
45              "../bin/dig/win32/host.dsp",
46              "../bin/dig/win32/host.mak",
47              "../bin/dig/win32/nslookup.dsp",
48              "../bin/dig/win32/nslookup.mak",
49              "../bin/dnssec/win32/dnssectool.dsp",
50              "../bin/dnssec/win32/dsfromkey.dsp",
51              "../bin/dnssec/win32/dsfromkey.mak",
52              "../bin/dnssec/win32/keyfromlabel.dsp",
53              "../bin/dnssec/win32/keyfromlabel.mak",
54              "../bin/dnssec/win32/keygen.dsp",
55              "../bin/dnssec/win32/keygen.mak",
56              "../bin/dnssec/win32/revoke.dsp",
57              "../bin/dnssec/win32/revoke.mak",
58              "../bin/dnssec/win32/settime.dsp",
59              "../bin/dnssec/win32/settime.mak",
60              "../bin/dnssec/win32/signzone.dsp",
61              "../bin/dnssec/win32/signzone.mak",
62              "../bin/named/win32/named.dsp",
63              "../bin/named/win32/named.mak",
64              "../bin/nsupdate/win32/nsupdate.dsp",
65              "../bin/nsupdate/win32/nsupdate.mak",
66              "../bin/rndc/win32/rndc.dsp",
67              "../bin/rndc/win32/rndc.mak",
68              "../bin/tools/win32/journalprint.dsp",
69              "../bin/tools/win32/journalprint.mak",
70              "../lib/bind9/win32/libbind9.dsp",
71              "../lib/bind9/win32/libbind9.mak",
72              "../lib/dns/win32/libdns.dsp",
73              "../lib/dns/win32/libdns.mak",
74              "../lib/isc/win32/libisc.dsp",
75              "../lib/isc/win32/libisc.mak",
76              "../lib/isc/win32/libisc.def",
77              "../lib/isccc/win32/libisccc.dsp",
78              "../lib/isccc/win32/libisccc.mak",
79              "../lib/isccfg/win32/libisccfg.dsp",
80              "../lib/isccfg/win32/libisccfg.mak");
81
82 # Locate the libxml2 directory
83 $substr = getdirectory();
84 if ($substr eq 0) {
85      print "No directory found\n";
86 }
87 else {
88      print "Found $substr directory\n";
89 }
90
91 if ($substr ne 0) {
92    #Update the list of files
93    $ind = 0;
94    updateconfig(1);
95    foreach $file (@filelist) {
96       print "Updating file $file\n";
97       updatefile($file, $substr, 1);
98       $ind++;
99    }
100 }
101 else {
102    #Update the configuration to reflect libxml2 being absent
103    $ind = 0;
104    updateconfig(0);
105    foreach $file (@filelist) {
106       print "Updating file $file\n";
107       updatefile($file, $substr, 0);
108       $ind++;
109    }
110 }
111
112 # Function to find the libxml2 directory
113 sub getdirectory {
114     my(@namelist);
115     my($file, $name);
116     my($cnt);
117     opendir(DIR,$path) || return (0);
118     @namelist = grep (/^libxml2-[0-9]+\.[0-9]+\.[0-9]+[a-z]*$/i, readdir(DIR));
119     closedir(DIR);
120
121     # Make sure we have something
122     if (scalar(@namelist) == 0) {
123         return (0);
124     }
125     # Now see if we have a directory or just a file.
126     # Make sure we are case insensitive
127     foreach $file (sort {uc($a) cmp uc($b)} @namelist) {
128         if (-d $path.$file) {
129            $name = $file;
130         }
131     }
132
133     # If we have one use it otherwise report the error
134     # Note that we are only interested in the last one
135     # since the sort should have taken care of getting
136     # the latest
137     if (defined($name)) {
138         return ($name);
139     }
140     else {
141         return (0);
142     }
143 }
144
145 # function to replace the libxml2 directory name with the latest one
146 sub updatefile {
147         my($filename, $substr, $line);
148         my(@Lines);
149
150         $filename = $_[0];
151         $substr   = $_[1];
152         $havexml  = $_[2];
153
154         open (RFILE, $filename) || die "Can't open file $filename: $!";
155         @Lines = <RFILE>;
156         close (RFILE);
157
158         # Replace the string
159         foreach $line (@Lines) {
160            if ($havexml) {
161               $line =~ s/libxml2-[0-9]+\.[0-9]+\.[0-9]+[a-z]*/$substr/gi;
162               if ($filename =~ /\.mak$/) {
163                  $line =~ s/^# (LIBXML=.*\/libxml2\.lib.*)$/\1/;
164               } elsif ($filename =~ /\.dsp$/ ) {
165                  $line =~ s/^!MESSAGE (LIBXML=.*\/libxml2\.lib.*)$/\1/;
166                  $line =~ s/^!MESSAGE (# ADD LINK32 .*\/libxml2\.lib.*)$/\1/;
167               }
168               $line =~ s/^; (isc_socketmgr_renderxml)$/\1/;
169               $line =~ s/^; (isc_mem_renderxml)$/\1/;
170               $line =~ s/^; (isc_taskmgr_renderxml)$/\1/;
171            } else {
172               if ($filename =~ /\.mak$/) {
173                  $line =~ s/^(LIBXML=.*\/libxml2.lib.*)$/# \1/i;
174               } elsif ($filename =~ /\.dsp$/ ) {
175                  $line =~ s/^(# ADD LINK32 .*\/libxml2.lib.*)$/!MESSAGE \1/i;
176                  $line =~ s/^(LIBXML=.*\/libxml2.lib.*)$/!MESSAGE \1/i;
177               }
178               $line =~ s/^(isc_socketmgr_renderxml)$/; \1/;
179               $line =~ s/^(isc_mem_renderxml)$/; \1/;
180               $line =~ s/^(isc_taskmgr_renderxml)$/; \1/;
181            }
182         }
183
184         #update the file
185         open (RFILE, ">$filename") || die "Can't open file $filename: $!";
186         foreach $line (@Lines) {
187            print RFILE $line;
188         }
189         close(RFILE);
190 }
191
192 # update config.h to define or undefine HAVE_LIBXML2
193 sub updateconfig {
194    my($havexml, $substr, $line);
195    my(@Lines);
196
197    $havexml = $_[0];
198
199    open (RFILE, "../config.h") || die "Can't open config.h";
200    @Lines = <RFILE>;
201    close (RFILE);
202
203    foreach $line (@Lines) {
204       if ($havexml) {
205          $line =~ s/^.*#undef HAVE_LIBXML2.*$/define HAVE_LIBXML2 1/;
206       } else {
207          $line =~ s/^#define HAVE_LIBXML2 .*$/\/\* #undef HAVE_LIBXML2 \*\//;
208       }
209    }
210
211    open (RFILE, ">../config.h") || die "Can't open config.h";
212    print "Updating file ../config.h\n";
213    foreach $line (@Lines) {
214       print RFILE $line;
215    }
216    close(RFILE);
217 }