2 eval 'exec perl -S $0 ${1+"$@"}'
5 #*************************************************************************
7 # This app makes it easy to link a live build
8 # set into an install set. Then your devel iteration
9 # is: 'build', execute.
11 #*************************************************************************
13 # DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
15 # Copyright 2008 by Sun Microsystems, Inc.
17 # OpenOffice.org - a multi-platform office productivity suite
19 # $RCSfile: linkoo,v $
23 # This file is part of OpenOffice.org.
25 # OpenOffice.org is free software: you can redistribute it and/or modify
26 # it under the terms of the GNU Lesser General Public License version 3
27 # only, as published by the Free Software Foundation.
29 # OpenOffice.org is distributed in the hope that it will be useful,
30 # but WITHOUT ANY WARRANTY; without even the implied warranty of
31 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
32 # GNU Lesser General Public License version 3 for more details
33 # (a copy is included in the LICENSE file that accompanied this code).
35 # You should have received a copy of the GNU Lesser General Public License
36 # version 3 along with OpenOffice.org. If not, see
37 # <http://www.openoffice.org/license.html>
38 # for a copy of the LGPLv3 License.
40 #*************************************************************************
42 # ends up in program/ooenv
43 ( $moz_lib = `pkg-config --variable=libdir mozilla-nss` ) =~ tr/\n/:/;
45 java_path=`../basis-link/ure-link/bin/javaldx`
46 export LD_LIBRARY_PATH=".:$java_path:' . $moz_lib . '$LD_LIBRARY_PATH"
48 export PATH=".:../basis-link/program:../basis-link/ure-link/bin:$PATH"
49 export GNOME_DISABLE_CRASH_DIALOG=1
50 export STAR_RESOURCEPATH=`pwd`/../basis-link/program/resource
51 # debugging assistance
52 export OOO_FORCE_SYSALLOC=1
53 export MALLOC_CHECK_=2
54 export OOO_DISABLE_RECOVERY=1
55 export SAL_ALLOW_LINKOO_SYMLINKS=1
58 $program_dir = 'basis-link/program';
59 $brand_program_dir = 'program';
60 $ure_misc_dir = 'basis-link/ure-link/share/misc';
62 $program_dir = 'openoffice.org/basis-link/MacOS' if ($ENV{OS} eq 'MACOSX'); # FIXME probably wrong
64 my @exceptions = ( 'cppuhelper', 'configmgr2', 'sunjavaplugin', 'libjvmfwk' );
67 $program_dir => '\.so',
68 $program_dir . '/resource' => '\.res$',
69 $program_dir . '/classes' => '\.jar$',
70 'basis-link/share/config' => '\.zip$',
71 # 'share/uno_packages' => '\.zip$'
74 # strangely enough, OSX has those small differences...
75 $replaceable{$program_dir} = '\.dylib$' if ($ENV{OS} eq 'MACOSX');
77 @search_dirs = ( 'lib', 'bin', 'class' );
79 @known_duplicates = ( 'db.jar', 'libi18n' );
83 my $build_dir = shift;
84 my ($dirhandle, $fname);
85 my ($target, $libver, $lang) = ( 'unxlngi4.pro', '680', 'en-US' ); # defaults
87 opendir ($dirhandle, $build_dir) || die "Can't open $build_dir";
88 while ($fname = readdir ($dirhandle)) {
89 $fname =~ /Set.sh$/ || next;
92 open ($file, "$build_dir/$fname") || die "Can't open $build_dir/$fname";
94 /\s*(\S+)\s*=\s*\"(\S+)\"/ || next;
105 closedir ($dirhandle);
107 print "Sniffed target: $target, $libver\n";
109 return ($target, $libver, $lang);
112 sub build_installed_list($)
117 for my $suffix (keys %replaceable) {
118 my $dirname = "$path/$suffix";
120 my $pattern = $replaceable{$suffix};
121 if (opendir ($dirhandle, $dirname)) {
122 while (my $fname = readdir ($dirhandle)) {
123 $fname =~ m/$pattern/ || next;
126 for $pattern (@exceptions) {
127 $fname =~ /$pattern/ || next;
130 $files{$fname} = $dirname if !$skip;
132 closedir ($dirhandle);
134 print "Couldn't find '$dirname': skipping\n";
140 sub check_create_linked($)
143 my $linked_dir = "$path/linked";
144 if (! -d $linked_dir) {
145 mkdir $linked_dir || die "Can't make $linked_dir: $!";
153 my $src_name = shift;
154 my $dest_name = shift;
155 my $dont_check_link = shift;
157 if (-l "$dest/$dest_name" ) {
158 my $link = readlink ("$dest/$dest_name");
159 if ($link =~ /^\//) { # Absolute path
162 unlink ("$dest/$dest_name");
163 symlink ("$src/$src_name", "$dest/$dest_name") || die "Failed to symlink: $!";
164 print " [$dest_name]";
166 print "re-make link $src/$src_name => $dest/$dest_name\n";
169 print "skipping symbolic link $dest/$dest_name -> $link\n";
172 check_create_linked ($dest);
174 # move / write the link
175 rename ("$dest/$dest_name", "$dest/linked/$dest_name") ||
176 defined $dont_check_link || die "Failed rename of $dest/$dest_name: $!";
178 symlink ("$src/$src_name", "$dest/$dest_name") || die "Failed to symlink: $!";
181 print "move / symlink $src/$src_name => $dest/$dest_name\n";
186 sub scan_and_link_files($$$)
188 my $build_path = shift;
189 my $installed_files = shift;
194 opendir ($dirh_toplevel, $build_path) || die "Can't open '$build_path': $!";
195 while (my $subdir = readdir ($dirh_toplevel)) {
196 $subdir =~ m/\./ && next; # eg. vcl.old,
197 my $test = "$build_path/$subdir/$target";
199 push @modules, $test;
201 closedir ($dirh_toplevel);
203 # FIXME: re-implement the $product functionality
206 for $module (@modules) {
207 for $elem (@search_dirs) {
209 my $module_path = "$module/$elem";
210 if (opendir ($dirh_module, $module_path)) {
211 while (my $file = readdir($dirh_module)) {
212 if (defined $installed_files->{$file}) {
213 if (defined $build_files{$file}) {
215 for my $regexp (@known_duplicates) {
216 if ($file =~ m/$regexp/) {
221 print "Unknown duplicate file '$file' in: '" .
222 $build_files{$file} . "' vs '" .
223 $module_path . "' in module $module\n";
227 $build_files{$file} = $module_path;
231 closedir ($dirh_module);
235 for my $file (keys %build_files) {
236 my $src = $build_files{$file};
237 my $dest = $installed_files->{$file};
239 do_link ($src, $dest, $file, $file);
247 my $name = 'librecentfile.so';
248 my $src = "$OOO_BUILD/shell/$TARGET/lib/$name";
249 my $dest = "$OOO_BUILD/sfx2/$TARGET/lib/$name";
251 if ($doit eq 'undo') {
253 print " unlink $name\n";
257 $doit eq 'do' || die;
259 print " link $name\n";
267 print "Special iso.res case: ";
268 my $ooo_res="$OOO_INSTALL/" . $brand_program_dir . "/resource/ooo".$LIBVER.$LANG.".res";
269 my $star_res="$OOO_INSTALL/" . $brand_program_dir . "/resource/iso".$LIBVER.$LANG.".res";
270 if (-l $ooo_res && -l $star_res) {
272 print "link $ooo_res to $star_res";
275 symlink ($ooo_res, $star_res);
282 # Hack for (renamed) types.rdb (types.db)
283 sub link_oovbaapi_rdb()
285 print "oovbaapi.rdb case:";
286 my $src = "$OOO_BUILD/oovbaapi/$TARGET/ucr";
287 my $dest = "$OOO_INSTALL/" . $program_dir;
288 do_link ($src, $dest, 'oovbaapi.db', 'oovbaapi.rdb');
293 print "Types.rdb case:";
294 my $src = "$OOO_BUILD/offapi/$TARGET/ucr";
295 my $dest = "$OOO_INSTALL/" . $ure_misc_dir;
296 do_link ($src, $dest, 'types.db', 'types.rdb');
300 # link installed files back into src tree:
301 sub link_soffice_bin_files()
304 my $src = "$OOO_INSTALL/" . $brand_program_dir;
306 print "soffice files";
307 $dest = "$OOO_BUILD/desktop/$TARGET/bin";
308 do_link ($src, $dest, 'soffice', 'soffice.bin', 1);
309 do_link ($src, $dest, 'bootstraprc', 'bootstraprc', 1);
310 do_link ($src, $dest, 'intro.bmp', 'intro.bmp', 1);
311 do_link ("$OOO_INSTALL", "$OOO_BUILD/desktop/$TARGET", 'share', 'share', 1);
313 $dest = "$OOO_BUILD/configmgr/$TARGET/lib";
314 do_link ($src, $dest, 'configmgrrc', 'configmgrrc', 1);
324 if ($a =~ /--product/) {
326 } elsif ($a =~ /--dry-run/) {
328 } elsif (($a eq '--help') || ($a eq '-h')) {
332 } elsif (!defined $OOO_INSTALL) {
334 } elsif (!defined $OOO_BUILD) {
337 print "Unknown argument '$a'\n";
342 if (!defined $OOO_BUILD && defined $ENV{SRC_ROOT}) {
343 $OOO_BUILD = $ENV{SRC_ROOT};
346 if ($usage || !defined $OOO_INSTALL || !defined $OOO_BUILD) {
347 printf "Usage: linkoo </path/to/ooo/install> [</path/to/ooo/build/tree>] [--product] [--dry-run]\n";
351 substr ($OOO_INSTALL, 0, 1) eq '/' || die "linkoo requires absolute paths ($OOO_INSTALL does not qualify)";
352 substr ($OOO_BUILD, 0, 1) eq '/' || die "linkoo requires absolute paths ($OOO_BUILD does not qualify)";
354 -d $OOO_INSTALL || die "No such directory $OOO_INSTALL";
355 -w $OOO_INSTALL || die "You need write access to $OOO_INSTALL";
356 -d $OOO_BUILD || die "No such directory $OOO_BUILD";
357 -d "$OOO_INSTALL/" . $program_dir . "/resource" || die "$OOO_INSTALL doesn't look like an OO install";
359 ($TARGET, $LIBVER, $LANG) = sniff_target ($OOO_BUILD);
363 my $installed_files = build_installed_list ($OOO_INSTALL);
365 scan_and_link_files ($OOO_BUILD, $installed_files, $TARGET);
369 link_soffice_bin_files();
371 if (!-f "$OOO_INSTALL/" . $brand_program_dir . "/ooenv") {
372 print "Creating '$OOO_INSTALL/", $brand_program_dir, "/ooenv'\n";
373 open ($ooenv, ">$OOO_INSTALL/" . $brand_program_dir . "/ooenv") || die "Can't open $OOO_INSTALL/" . $brand_program_dir . "/ooenv: $!";
374 print $ooenv $env_script;
375 print $ooenv "# testtool\nexport SRC_ROOT=$OOO_BUILD\n";
381 print "\nlinkoo finished, please don't forget to source ooenv before ./soffice.\n";