1#!/usr/bin/env perl
2# *************************************************************
3#
4#  Licensed to the Apache Software Foundation (ASF) under one
5#  or more contributor license agreements.  See the NOTICE file
6#  distributed with this work for additional information
7#  regarding copyright ownership.  The ASF licenses this file
8#  to you under the Apache License, Version 2.0 (the
9#  "License"); you may not use this file except in compliance
10#  with the License.  You may obtain a copy of the License at
11#
12#    http://www.apache.org/licenses/LICENSE-2.0
13#
14#  Unless required by applicable law or agreed to in writing,
15#  software distributed under the License is distributed on an
16#  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17#  KIND, either express or implied.  See the License for the
18#  specific language governing permissions and limitations
19#  under the License.
20#
21# *************************************************************
22
23use File::Find;
24use File::Basename;
25
26# creates the help2 makefile for a given
27# directory including all help xhp files
28# in that and the subordinate directories
29# Only help files with the following
30#
31# status values are included:
32# PUBLISH DEPRECATED
33#
34# The following status values are
35# disregarded:
36# DRAFT FINAL STALLED
37
38$makefiletemplate = 'helpers/makefile.template';
39$linkmakefiletemplate = 'helpers/linkmakefile.template';
40$prj = "helpcontent2";
41$helpdirprefix = "$prj/source/";
42
43undef @sbasic;
44undef @scalc;
45undef @schart;
46undef @sdraw;
47undef @shared;
48undef @simpress;
49undef @smath;
50undef @swriter;
51
52$params = join "|", "",@ARGV,"";
53($params =~ /-dir/) ? ($startdir = $params) =~ (s/.*-dir=([^\|]*).*$/$1/gs) : (($startdir = `pwd`) =~ s/\n//gs);
54($startdir = $startdir."/source/text") if ($startdir =~ /$prj$/);
55($params =~ /-linkdir/) ? ($linkdir = $params) =~ (s/.*-linkdir=([^\|]*).*$/$1/gs) : (($linkdir = `pwd`) =~ s/\n//gs);
56($linkdir = $linkdir."/util") if ($linkdir =~ /$prj$/);
57$recursive = $params =~ /-recursive/ || 0;
58$all = $params =~ /-all/ || 0;
59
60if (open TMPL, $makefiletemplate) {
61	undef $/;
62	$tmpl = <TMPL>;
63	close TMPL;
64} else {
65	&terminate("Cannot open $makefiletemplate");
66}
67
68if (open LINKTMPL, $linkmakefiletemplate) {
69	undef $/;
70	$linktmpl = <LINKTMPL>;
71	close LINKTMPL;
72} else {
73	&terminate("Cannot open $linkmakefiletemplate");
74}
75
76print "Start Directory: $startdir\n";
77print "Link Directory : $linkdir\n";
78print "Recursive      : ". ($recursive ? "yes" : "no") . "\n";
79print "All files      : ". ($all ? "yes" : "no") . "\n";
80
81if ($recursive) {
82	find(sub{push @dirs, $File::Find::name if (-d and ($File::Find::name!~/\/CVS/));},$startdir);
83} else {
84	push @dirs, $startdir;
85}
86
87#print join "\n", @dirs;
88#die;
89
90for $d(@dirs) {
91	opendir DIR, $d;
92	@files = grep {/xhp$/} readdir DIR;
93	undef @files2;
94	closedir DIR;
95
96	($helpdir = $d) =~ s/.*\/$helpdirprefix/source\//gis;
97
98	($package = $helpdir) =~ s/^source\///gi;
99
100	($target = $package) =~ s/\//_/g; $target =~ s/_$//;
101	($module = $package) =~ s/^\/*text\/([^\/]+)\/*.*$/$1/;
102
103	for $f(@files) {
104		($n,$p,$e) = fileparse($f,".xhp");
105		if (not $all) {
106			if (open XML, $d.'/'.$f) {
107				undef $/;
108				($status = <XML>) =~ s/.*<topic[^>]*status="([^"]*)"[^>]*>.*$/$1/gs;
109				close XML;
110			} else {
111				die "Error: Cannot open ${d}/$f:$!\n";
112			}
113			if ($status =~ /(DEPRECATED|PUBLISH)/i) {
114				($p2=$package) =~ s,/,\$/,gis;
115				push @{$module}, $p2.'$/'.$n.'.xhp';
116				push @files2, '    '.$n.'.xhp ';
117			}
118		} else {
119			($p2=$package) =~ s,/,\$/,gis;
120			push @{$module}, $p2.'$/'.$n.'.xhp';
121			push @files2, '   '.$n.'.xhp ';
122		}
123	}
124
125	printf "%s: %4d files, %4d included in makefile -> ",$d,scalar @files,scalar @files2;
126
127	if (scalar @files2 > 0) { # don't write makefiles where there are no files to make
128		($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime(time);
129
130		$auth = "script";
131		$date = sprintf "%4d/%02d/%02d %02d:%02d:%02d",$year+1900,$mon,$mday,$hour,$min,$sec;
132		$prj = '..$/' x ((split "/", $helpdir) -1); $prj = $prj . "..";
133
134
135		$xhpfiles = join "\\\n", sort @files2;
136
137		($makefile = $tmpl) =~ s/%([^%]*)%/$$1/gise;
138
139		if (open(MK, ">$d/makefile.mk")) {
140			print MK $makefile;
141			close MK;
142			print "makefile created\n";
143		} else {
144			&terminate("Cannot write to ${d}/makefile.mk\n");
145		}
146	} else {
147		print "NO makefile created\n";
148	}
149}
150
151@sbasic = sort @sbasic;
152@schart = sort @schart;
153@scalc = sort @scalc;
154@shared = sort @shared;
155@sdraw = sort @sdraw;
156@simpress = sort @simpress;
157@smath = sort @smath;
158@swriter = sort @swriter;
159
160# now create the link makefiles
161
162#----------------------------------
163# sbasic
164	$module = "sbasic";
165
166	$linkaddedfiles = <<"LAF";
167   -add $module.cfg \$(PRJ)\$/source\$/auxiliary\$/LANGUAGE\$/$module.cfg \\
168   -add $module.tree \$(COMMONMISC)\$/LANGUAGE\$/$module.tree \\
169   -add $module.jar  \$(COMMONBIN)\$/xhp_${module}_LANGUAGE.zip
170LAF
171
172	$linkaddeddeps = <<"LAD";
173   \$(PRJ)\$/source\$/auxiliary\$/LANGUAGE\$/$module.cfg \\
174   \$(COMMONMISC)\$/LANGUAGE\$/$module.tree \\
175   \$(COMMONBIN)\$/xhp_${module}_LANGUAGE.zip
176LAD
177
178	$linklinkfiles = '';
179	for (@sbasic) {	$linklinkfiles = $linklinkfiles . "   $_ \\\n";	}
180	for (@shared) {	$linklinkfiles = $linklinkfiles . "   $_ \\\n";	}
181
182	$auth = "script";
183	$date = sprintf "%4d/%02d/%02d %02d:%02d:%02d",$year+1900,$mon,$mday,$hour,$min,$sec;
184	$prj = '..$/..' ;
185
186	($linkmakefile = $linktmpl) =~ s/%([^%]*)%/$$1/gise;
187	&writelinkmakefile($module,$linkmakefile);
188
189
190#-------------------------------------
191# scalc
192	$module = "scalc";
193
194	$linkaddedfiles = <<"LAF";
195   -add $module.cfg \$(PRJ)\$/source\$/auxiliary\$/LANGUAGE\$/$module.cfg \\
196   -add $module.tree \$(COMMONMISC)\$/LANGUAGE\$/$module.tree \\
197   -add $module.jar  \$(COMMONBIN)\$/xhp_${module}_LANGUAGE.zip
198LAF
199
200	$linkaddeddeps = <<"LAD";
201   \$(PRJ)\$/source\$/auxiliary\$/LANGUAGE\$/$module.cfg \\
202   \$(COMMONMISC)\$/LANGUAGE\$/$module.tree \\
203   \$(COMMONBIN)\$/xhp_${module}_LANGUAGE.zip
204LAD
205
206	$linklinkfiles = '';
207	for (@scalc)  { $linklinkfiles = $linklinkfiles . "   $_ \\\n";	}
208	for (@shared) {	$linklinkfiles = $linklinkfiles . "   $_ \\\n";	}
209	for (@schart) {	$linklinkfiles = $linklinkfiles . "   $_ \\\n";	}
210
211	$auth = "script";
212	$date = sprintf "%4d/%02d/%02d %02d:%02d:%02d",$year+1900,$mon,$mday,$hour,$min,$sec;
213	$prj = '..$/..' ;
214
215	($linkmakefile = $linktmpl) =~ s/%([^%]*)%/$$1/gise;
216	&writelinkmakefile($module,$linkmakefile);
217
218#--------------------------------
219# schart
220	$module = "schart";
221
222	$linkaddedfiles = <<"LAF";
223   -add $module.cfg \$(PRJ)\$/source\$/auxiliary\$/LANGUAGE\$/$module.cfg \\
224   -add $module.tree \$(COMMONMISC)\$/LANGUAGE\$/$module.tree \\
225   -add $module.jar  \$(COMMONBIN)\$/xhp_${module}_LANGUAGE.zip
226LAF
227
228	$linkaddeddeps = <<"LAD";
229   \$(PRJ)\$/source\$/auxiliary\$/LANGUAGE\$/$module.cfg \\
230   \$(COMMONMISC)\$/LANGUAGE\$/$module.tree \\
231   \$(COMMONBIN)\$/xhp_${module}_LANGUAGE.zip
232LAD
233
234	$linklinkfiles = '';
235
236	for (@shared) {	$linklinkfiles = $linklinkfiles . "   $_ \\\n";	}
237	for (@schart) {	$linklinkfiles = $linklinkfiles . "   $_ \\\n";	}
238
239
240	$auth = "script";
241	$date = sprintf "%4d/%02d/%02d %02d:%02d:%02d",$year+1900,$mon,$mday,$hour,$min,$sec;
242	$prj = '..$/..' ;
243
244	($linkmakefile = $linktmpl) =~ s/%([^%]*)%/$$1/gise;
245	&writelinkmakefile($module,$linkmakefile);
246
247#------------------------------
248# sdraw
249	$module = "sdraw";
250
251	$linkaddedfiles = <<"LAF";
252   -add $module.cfg \$(PRJ)\$/source\$/auxiliary\$/LANGUAGE\$/$module.cfg \\
253   -add $module.jar  \$(COMMONBIN)\$/xhp_${module}_LANGUAGE.zip
254LAF
255
256	$linkaddeddeps = <<"LAD";
257   \$(PRJ)\$/source\$/auxiliary\$/LANGUAGE\$/$module.cfg \\
258   \$(COMMONBIN)\$/xhp_${module}_LANGUAGE.zip
259LAD
260
261	$linklinkfiles = '';
262	for (@sdraw) {	$linklinkfiles = $linklinkfiles . "   $_ \\\n";	}
263	for (@simpress) {	$linklinkfiles = $linklinkfiles . "   $_ \\\n";	}
264	for (@shared) {	$linklinkfiles = $linklinkfiles . "   $_ \\\n";	}
265	for (@schart) {	$linklinkfiles = $linklinkfiles . "   $_ \\\n";	}
266
267	$auth = "script";
268	$date = sprintf "%4d/%02d/%02d %02d:%02d:%02d",$year+1900,$mon,$mday,$hour,$min,$sec;
269	$prj = '..$/..' ;
270
271	($linkmakefile = $linktmpl) =~ s/%([^%]*)%/$$1/gise;
272	&writelinkmakefile($module,$linkmakefile);
273
274#-------------------------------------
275# shared
276
277	$module = "shared";
278
279	$linkaddedfiles = <<"LAF";
280   -add $module.tree \$(COMMONMISC)\$/LANGUAGE\$/$module.tree \\
281   -add $module.jar  \$(COMMONBIN)\$/xhp_${module}_LANGUAGE.zip \\
282   -add default.css  \$(PRJ)\$/source\$/auxiliary\$/LANGUAGE\$/default.css \\
283   -add highcontrast1.css  \$(PRJ)\$/source\$/auxiliary\$/LANGUAGE\$/highcontrast1.css \\
284   -add highcontrast2.css  \$(PRJ)\$/source\$/auxiliary\$/LANGUAGE\$/highcontrast2.css \\
285   -add highcontrastwhite.css  \$(PRJ)\$/source\$/auxiliary\$/LANGUAGE\$/highcontrastwhite.css \\
286   -add highcontrastblack.css  \$(PRJ)\$/source\$/auxiliary\$/LANGUAGE\$/highcontrastblack.css \\
287   -add err.html  \$(COMMONMISC)\$/LANGUAGE\$/text\$/shared\$/05\$/err_html.xhp
288LAF
289
290	$linkaddeddeps = <<"LAD";
291   \$(COMMONMISC)\$/LANGUAGE\$/$module.tree \\
292   \$(COMMONBIN)\$/xhp_${module}_LANGUAGE.zip \\
293   \$(PRJ)\$/source\$/auxiliary\$/LANGUAGE\$/default.css \\
294   \$(PRJ)\$/source\$/auxiliary\$/LANGUAGE\$/highcontrast1.css \\
295   \$(PRJ)\$/source\$/auxiliary\$/LANGUAGE\$/highcontrast2.css \\
296   \$(PRJ)\$/source\$/auxiliary\$/LANGUAGE\$/highcontrastwhite.css \\
297   \$(PRJ)\$/source\$/auxiliary\$/LANGUAGE\$/highcontrastblack.css \\
298   \$(COMMONMISC)\$/LANGUAGE\$/text\$/shared\$/05\$/err_html.xhp
299LAD
300
301	$linklinkfiles = '';
302
303	$auth = "script";
304	$date = sprintf "%4d/%02d/%02d %02d:%02d:%02d",$year+1900,$mon,$mday,$hour,$min,$sec;
305	$prj = '..$/..' ;
306
307	($linkmakefile = $linktmpl) =~ s/%([^%]*)%/$$1/gise;
308	&writelinkmakefile($module,$linkmakefile);
309
310#-------------------------------
311# simpress
312	$module = "simpress";
313
314	$linkaddedfiles = <<"LAF";
315   -add $module.cfg \$(PRJ)\$/source\$/auxiliary\$/LANGUAGE\$/$module.cfg \\
316   -add $module.tree \$(COMMONMISC)\$/LANGUAGE\$/$module.tree \\
317   -add $module.jar  \$(COMMONBIN)\$/xhp_${module}_LANGUAGE.zip
318LAF
319
320	$linkaddeddeps = <<"LAD";
321   \$(PRJ)\$/source\$/auxiliary\$/LANGUAGE\$/$module.cfg \\
322   \$(COMMONMISC)\$/LANGUAGE\$/$module.tree \\
323   \$(COMMONBIN)\$/xhp_${module}_LANGUAGE.zip
324LAD
325
326	$linklinkfiles = '';
327
328	for (@sdraw) {	$linklinkfiles = $linklinkfiles . "   $_ \\\n";	}
329	for (@simpress) {	$linklinkfiles = $linklinkfiles . "   $_ \\\n";	}
330	for (@shared) {	$linklinkfiles = $linklinkfiles . "   $_ \\\n";	}
331	for (@schart) {	$linklinkfiles = $linklinkfiles . "   $_ \\\n";	}
332
333	$auth = "script";
334	$date = sprintf "%4d/%02d/%02d %02d:%02d:%02d",$year+1900,$mon,$mday,$hour,$min,$sec;
335	$prj = '..$/..' ;
336
337	($linkmakefile = $linktmpl) =~ s/%([^%]*)%/$$1/gise;
338	&writelinkmakefile($module,$linkmakefile);
339
340#-------------------------------------
341# smath
342	$module = "smath";
343
344	$linkaddedfiles = <<"LAF";
345   -add $module.cfg \$(PRJ)\$/source\$/auxiliary\$/LANGUAGE\$/$module.cfg \\
346   -add $module.tree \$(COMMONMISC)\$/LANGUAGE\$/$module.tree \\
347   -add $module.jar  \$(COMMONBIN)\$/xhp_${module}_LANGUAGE.zip
348LAF
349
350	$linkaddeddeps = <<"LAD";
351   \$(PRJ)\$/source\$/auxiliary\$/LANGUAGE\$/$module.cfg \\
352   \$(COMMONMISC)\$/LANGUAGE\$/$module.tree \\
353   \$(COMMONBIN)\$/xhp_${module}_LANGUAGE.zip
354LAD
355
356	$linklinkfiles = '';
357	for (@smath) {	$linklinkfiles = $linklinkfiles . "   $_ \\\n";	}
358	for (@shared) {	$linklinkfiles = $linklinkfiles . "   $_ \\\n";	}
359
360	$auth = "script";
361	$date = sprintf "%4d/%02d/%02d %02d:%02d:%02d",$year+1900,$mon,$mday,$hour,$min,$sec;
362	$prj = '..$/..' ;
363
364	($linkmakefile = $linktmpl) =~ s/%([^%]*)%/$$1/gise;
365	&writelinkmakefile($module,$linkmakefile);
366
367#-------------------------------
368# swriter
369	$module = "swriter";
370
371	$linkaddedfiles = <<"LAF";
372   -add $module.cfg \$(PRJ)\$/source\$/auxiliary\$/LANGUAGE\$/$module.cfg \\
373   -add $module.tree \$(COMMONMISC)\$/LANGUAGE\$/$module.tree \\
374   -add $module.jar  \$(COMMONBIN)\$/xhp_${module}_LANGUAGE.zip
375LAF
376
377	$linkaddeddeps = <<"LAD";
378   \$(PRJ)\$/source\$/auxiliary\$/LANGUAGE\$/$module.cfg \\
379   \$(COMMONMISC)\$/LANGUAGE\$/$module.tree \\
380   \$(COMMONBIN)\$/xhp_${module}_LANGUAGE.zip
381LAD
382
383	$linklinkfiles = '';
384	for (@swriter) {	$linklinkfiles = $linklinkfiles . "   $_ \\\n";	}
385	for (@shared) {	$linklinkfiles = $linklinkfiles . "   $_ \\\n";	}
386	for (@schart) {	$linklinkfiles = $linklinkfiles . "   $_ \\\n";	}
387	$auth = "script";
388	$date = sprintf "%4d/%02d/%02d %02d:%02d:%02d",$year+1900,$mon,$mday,$hour,$min,$sec;
389	$prj = '..$/..' ;
390
391	($linkmakefile = $linktmpl) =~ s/%([^%]*)%/$$1/gise;
392	&writelinkmakefile($module,$linkmakefile);
393
394#-------------------------------
395# sdatabase
396	$module = "sdatabase";
397
398	$linkaddedfiles = <<"LAF";
399   -add $module.cfg \$(PRJ)\$/source\$/auxiliary\$/LANGUAGE\$/$module.cfg \\
400   -add $module.jar  \$(COMMONBIN)\$/xhp_${module}_LANGUAGE.zip
401LAF
402
403	$linkaddeddeps = <<"LAD";
404   \$(PRJ)\$/source\$/auxiliary\$/LANGUAGE\$/$module.cfg \\
405   \$(COMMONBIN)\$/xhp_${module}_LANGUAGE.zip
406LAD
407
408	$linklinkfiles = '';
409	for (@shared) {	$linklinkfiles = $linklinkfiles . "   $_ \\\n";	}
410	$auth = "script";
411	$date = sprintf "%4d/%02d/%02d %02d:%02d:%02d",$year+1900,$mon,$mday,$hour,$min,$sec;
412	$prj = '..$/..' ;
413
414	($linkmakefile = $linktmpl) =~ s/%([^%]*)%/$$1/gise;
415
416	# remove zip1 targets
417	$linkmakefile =~ s,\n(ZIP1LIST=.*)\n,\nZIP1LIST=\$(LANGDIR)\$/text\$/shared\$/explorer\$/database\$/main.xhp\n,gi;
418	&writelinkmakefile($module,$linkmakefile);
419
420
421
422print "sbasic: $#sbasic\n";
423print "scalc : $#scalc\n";
424print "schart: $#schart\n";
425print "sdraw : $#sdraw\n";
426print "shared: $#shared\n";
427print "simpr : $#simpress\n";
428print "smath : $#smath\n";
429print "swrit : $#swriter\n";
430print "sdbase: $#sdatabase\n";
431
432sub terminate {
433	$err = shift;
434	print "$err\n\n";
435	$msg = <<"MSG";
436createmakefile.pl -dir=[directory name] -linkdir=[directory name] [-recursive] [-all]
437  -dir        Directory to start
438  -linkdir    Directory to write the link makefiles
439  -recursive  Write makefiles recursively
440  -all        include files with all status values
441MSG
442	die "$msg\n";
443}
444
445
446sub writelinkmakefile {
447	$module = shift;
448	$content = shift;
449	if (open(MK, ">$linkdir/$module/makefile.mk")) {
450		print MK $content;
451		close MK;
452	} else {
453		&terminate("Cannot write makefile to ${linkdir}/$module\n");
454	}
455}
456