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