Sync usage with man page.
[netbsd-mini2440.git] / external / bsd / bind / dist / win32utils / updatelibxml2.pl
blob5f409ee0d198cc033d3294f8525c63afd4d3bae9
1 #!/usr/bin/perl
3 # Copyright (C) 2009 Internet Systems Consortium, Inc. ("ISC")
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.
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.
17 # Id: updatelibxml2.pl,v 1.3 2009/07/19 04:50:15 each Exp
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.
24 # Path and directory
25 $path = "..\\..\\";
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 "../lib/bind9/win32/libbind9.dsp",
69 "../lib/bind9/win32/libbind9.mak",
70 "../lib/dns/win32/libdns.dsp",
71 "../lib/dns/win32/libdns.mak",
72 "../lib/isc/win32/libisc.dsp",
73 "../lib/isc/win32/libisc.mak",
74 "../lib/isc/win32/libisc.def",
75 "../lib/isccc/win32/libisccc.dsp",
76 "../lib/isccc/win32/libisccc.mak",
77 "../lib/isccfg/win32/libisccfg.dsp",
78 "../lib/isccfg/win32/libisccfg.mak");
80 # Locate the libxml2 directory
81 $substr = getdirectory();
82 if ($substr eq 0) {
83 print "No directory found\n";
85 else {
86 print "Found $substr directory\n";
89 if ($substr ne 0) {
90 #Update the list of files
91 $ind = 0;
92 updateconfig(1);
93 foreach $file (@filelist) {
94 print "Updating file $file\n";
95 updatefile($file, $substr, 1);
96 $ind++;
99 else {
100 #Update the configuration to reflect libxml2 being absent
101 $ind = 0;
102 updateconfig(0);
103 foreach $file (@filelist) {
104 print "Updating file $file\n";
105 updatefile($file, $substr, 0);
106 $ind++;
110 # Function to find the libxml2 directory
111 sub getdirectory {
112 my(@namelist);
113 my($file, $name);
114 my($cnt);
115 opendir(DIR,$path) || return (0);
116 @namelist = grep (/^libxml2-[0-9]+\.[0-9]+\.[0-9]+[a-z]*$/i, readdir(DIR));
117 closedir(DIR);
119 # Make sure we have something
120 if (scalar(@namelist) == 0) {
121 return (0);
123 # Now see if we have a directory or just a file.
124 # Make sure we are case insensitive
125 foreach $file (sort {uc($a) cmp uc($b)} @namelist) {
126 if (-d $path.$file) {
127 $name = $file;
131 # If we have one use it otherwise report the error
132 # Note that we are only interested in the last one
133 # since the sort should have taken care of getting
134 # the latest
135 if (defined($name)) {
136 return ($name);
138 else {
139 return (0);
143 # function to replace the libxml2 directory name with the latest one
144 sub updatefile {
145 my($filename, $substr, $line);
146 my(@Lines);
148 $filename = $_[0];
149 $substr = $_[1];
150 $havexml = $_[2];
152 open (RFILE, $filename) || die "Can't open file $filename: $!";
153 @Lines = <RFILE>;
154 close (RFILE);
156 # Replace the string
157 foreach $line (@Lines) {
158 if ($havexml) {
159 $line =~ s/libxml2-[0-9]+\.[0-9]+\.[0-9]+[a-z]*/$substr/gi;
160 if ($filename =~ /\.mak$/) {
161 $line =~ s/^# (LIBXML=.*\/libxml2\.lib.*)$/\1/;
162 } elsif ($filename =~ /\.dsp$/ ) {
163 $line =~ s/^!MESSAGE (LIBXML=.*\/libxml2\.lib.*)$/\1/;
164 $line =~ s/^!MESSAGE (# ADD LINK32 .*\/libxml2\.lib.*)$/\1/;
166 $line =~ s/^; (isc_socketmgr_renderxml)$/\1/;
167 $line =~ s/^; (isc_mem_renderxml)$/\1/;
168 $line =~ s/^; (isc_taskmgr_renderxml)$/\1/;
169 } else {
170 if ($filename =~ /\.mak$/) {
171 $line =~ s/^(LIBXML=.*\/libxml2.lib.*)$/# \1/i;
172 } elsif ($filename =~ /\.dsp$/ ) {
173 $line =~ s/^(# ADD LINK32 .*\/libxml2.lib.*)$/!MESSAGE \1/i;
174 $line =~ s/^(LIBXML=.*\/libxml2.lib.*)$/!MESSAGE \1/i;
176 $line =~ s/^(isc_socketmgr_renderxml)$/; \1/;
177 $line =~ s/^(isc_mem_renderxml)$/; \1/;
178 $line =~ s/^(isc_taskmgr_renderxml)$/; \1/;
182 #update the file
183 open (RFILE, ">$filename") || die "Can't open file $filename: $!";
184 foreach $line (@Lines) {
185 print RFILE $line;
187 close(RFILE);
190 # update config.h to define or undefine HAVE_LIBXML2
191 sub updateconfig {
192 my($havexml, $substr, $line);
193 my(@Lines);
195 $havexml = $_[0];
197 open (RFILE, "../config.h") || die "Can't open config.h";
198 @Lines = <RFILE>;
199 close (RFILE);
201 foreach $line (@Lines) {
202 if ($havexml) {
203 $line =~ s/^.*#undef HAVE_LIBXML2.*$/define HAVE_LIBXML2 1/;
204 } else {
205 $line =~ s/^#define HAVE_LIBXML2 .*$/\/\* #undef HAVE_LIBXML2 \*\//;
209 open (RFILE, ">../config.h") || die "Can't open config.h";
210 print "Updating file ../config.h\n";
211 foreach $line (@Lines) {
212 print RFILE $line;
214 close(RFILE);