2 eval 'exec perl -S $0 ${1+"$@"}'
5 #*************************************************************************
7 # This tool makes it easy to cleanly re-locate a
8 # build, eg. after you have copied or moved it to a new
9 # path. It tries to re-write all the hard-coded path logic
12 #*************************************************************************
14 # DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
16 # Copyright 2008 by Sun Microsystems, Inc.
18 # OpenOffice.org - a multi-platform office productivity suite
20 # $RCSfile: relocate,v $
24 # This file is part of OpenOffice.org.
26 # OpenOffice.org is free software: you can redistribute it and/or modify
27 # it under the terms of the GNU Lesser General Public License version 3
28 # only, as published by the Free Software Foundation.
30 # OpenOffice.org is distributed in the hope that it will be useful,
31 # but WITHOUT ANY WARRANTY; without even the implied warranty of
32 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
33 # GNU Lesser General Public License version 3 for more details
34 # (a copy is included in the LICENSE file that accompanied this code).
36 # You should have received a copy of the GNU Lesser General Public License
37 # version 3 along with OpenOffice.org. If not, see
38 # <http://www.openoffice.org/license.html>
39 # for a copy of the LGPLv3 License.
41 #*************************************************************************
45 my $build_dir = shift;
46 my ($dirhandle, $fname);
48 opendir ($dirhandle, $build_dir) || die "Can't open $build_dir";
49 while ($fname = readdir ($dirhandle)) {
50 $fname =~ /[Ss]et.sh$/ && last;
52 closedir ($dirhandle);
59 my ($old_fname, $function, $state) = @_;
60 my $tmp_fname = "$old_fname.new";
64 open ($old_file, $old_fname) || die "Can't open $old_fname: $!";
65 open ($new_file, ">$tmp_fname") || die "Can't open $tmp_fname: $!";
68 my $value = &$function($state, $_);
69 print $new_file $value;
72 close ($new_file) || die "Failed to close $tmp_fname: $!";
73 close ($old_file) || die "Failed to close $old_fname: $!";
75 rename $tmp_fname, $old_fname || die "Failed to replace $old_fname: $!";
80 my ($state, $value) = @_;
82 $value =~ s/$state->{'old_root'}/$state->{'new_root'}/g;
83 $value =~ s/$state->{'win32_old_root'}/$state->{'win32_new_root'}/g;
99 $state{'old_root'} = $old_root;
100 $state{'new_root'} = $new_root;
103 $tmp =~ s/\//\\\\\\\\\\\\\\\\/g;
104 $state{'win32_old_root'} = $tmp;
106 $tmp =~ s/\//\\\\\\\\/g;
107 $state{'win32_new_root'} = $tmp;
109 sed_file ("$new_root/$set", \&rewrite_value, \%state);
112 $tcsh_set =~ s/\.sh$//;
114 print " $tcsh_set\n";
116 sed_file ("$new_root/$tcsh_set", \&rewrite_value, \%state);
119 sub find_old_root($$)
121 my $new_root = shift;
123 my $fname = "$new_root/$set";
127 open ($file, $fname) || die "Can't open $fname: $!";
130 if (/\s*([^=]+)\s*=\s*\"([^\"]+)\"/) {
131 my ($name, $value) = ($1, $2);
133 if ($name eq 'SRC_ROOT') {
140 close ($file) || die "Failed to close $fname: $!";
145 sub rewrite_product_deps($$$)
147 my $new_root = shift;
148 my $product_path = shift;
149 my $old_root = shift;
151 my $path = "$new_root/$product_path/misc";
153 opendir ($misc_dir, $path) || return;
155 while ($name = readdir ($misc_dir)) {
156 # Should try re-writing these - but perhaps this would
157 # screw with timestamps ?
158 if ($name =~ m/\.dpcc$/ || $name =~ m/\.dpslo$/ || $name =~ m/\.dpobj$/) {
159 unlink ("$path/$name");
162 closedir ($misc_dir);
167 my $new_root = shift;
168 my $old_root = shift;
172 opendir ($top_dir, $new_root) || die "Can't open $new_root: $!";
174 while ($name = readdir ($top_dir)) {
176 opendir ($sub_dir, "$new_root/$name") || next;
178 while ($sub_name = readdir ($sub_dir)) {
179 if ($sub_name =~ /\.pro$/) {
185 rewrite_product_deps ($new_root, "$name/$sub_name", $old_root);
193 sub rewrite_bootstrap($$)
195 my $new_root = shift;
196 my $old_root = shift;
198 print " bootstrap\n";
201 $state{'old_root'} = $old_root;
202 $state{'new_root'} = $new_root;
204 my $rewrite = sub { my $state = shift; my $value = shift;
205 $value =~ s/$state->{'old_root'}/$state->{'new_root'}/g;
207 sed_file ("$new_root/bootstrap", $rewrite, \%state);
208 `chmod +x $new_root/bootstrap`;
212 if ($a eq '--help' || $a eq '-h') {
213 print "relocate: syntax\n";
214 print " relocate /path/to/new/ooo/source_root\n";
218 $OOO_BUILD = shift (@ARGV) || die "Pass path to relocated source tree";
219 substr ($OOO_BUILD, 0, 1) eq '/' || die "relocate requires absolute paths";
223 $set = sniff_set($OOO_BUILD) || die "Can't find env. set";
224 $OLD_ROOT = find_old_root($OOO_BUILD, $set);
226 print "Relocate: $OLD_ROOT -> $OOO_BUILD\n";
228 print "re-writing environment:\n";
230 rewrite_set($OOO_BUILD, $OLD_ROOT, $set);
231 rewrite_bootstrap($OOO_BUILD, $OLD_ROOT);
233 print "re-writing dependencies:\n";
235 rewrite_dpcc($OOO_BUILD, $OLD_ROOT);