Provide defined value for $TODO only where test is still failing.
[perl.git] / symbian / config.pl
1 #!/usr/bin/perl -w
2
3 # Copyright (c) 2004-2005 Nokia.  All rights reserved.
4 # This utility is licensed under the same terms as Perl itself.
5
6 use strict;
7 use lib "symbian";
8
9 print "Configuring...\n";
10 print "Configuring with: Perl version $] ($^X)\n";
11
12 do "sanity.pl" or die $@;
13
14 my %VERSION = %{ do "version.pl" or die $@ };
15
16 printf "Configuring for:  Perl version $VERSION{REVISION}.%03d%03d\n",
17   $VERSION{VERSION}, $VERSION{SUBVERSION};
18
19 my $VERSION = "$VERSION{REVISION}$VERSION{VERSION}$VERSION{SUBVERSION}";
20 my $R_V_SV  = "$VERSION{REVISION}.$VERSION{VERSION}.$VERSION{SUBVERSION}";
21
22 my ($SYMBIAN_ROOT, $SYMBIAN_VERSION, $SDK_NAME, $SDK_VARIANT, $SDK_VERSION) =
23     @{ do "sdk.pl" or die $@ };
24 my %PORT = %{ do "port.pl" or die $@ };
25
26 if ($SYMBIAN_ROOT eq 'C:\Symbian\Series60_1_2_CW') {
27     ( $SYMBIAN_VERSION, $SDK_VERSION ) = qw(6.1 1.2);
28 }
29
30 my $WIN = $ENV{WIN} ; # 'wins', 'winscw' (from sdk.pl)
31 my $ARM = 'thumb';    # 'thumb', 'armv5'
32 my $S60SDK = $ENV{S60SDK}; # qw(1.2 2.0 2.1 2.6) (from sdk.pl)
33     if ($SDK_VARIANT eq 'S60' && $S60SDK =~ /^5\./) {
34         $ARM = 'armv5';    # 'thumb', 'armv5' # Configuration for S60 5th Edition SDK v1.0
35     }
36 my $S80SDK = $ENV{S80SDK}; # qw(2.0) (from sdk.pl)
37 my $S90SDK = $ENV{S90SDK}; # qw(1.1) (from sdk.pl)
38 my $UIQSDK = $ENV{UIQSDK}; # qw(2.0 2.1) (from sdk.pl)
39
40 my $UREL = $ENV{UREL}; # from sdk.pl
41 $UREL =~ s/-ARM-/$ARM/;
42 my $UARM = $ENV{UARM}; # from sdk.pl
43
44 die "$0: SDK not recognized\n"
45   if !defined($SYMBIAN_VERSION) ||
46      !defined($SDK_VERSION) ||
47      (!defined($S60SDK) && !defined($S80SDK) && !defined($S90SDK) && !defined($UIQSDK));
48
49 die "$0: does not know which Windows compiler to use\n"
50     unless defined $WIN;
51
52 print "Symbian $SYMBIAN_VERSION SDK $SDK_VARIANT $SDK_VERSION ($WIN) installed at $SYMBIAN_ROOT\n";
53
54 my $CWD = do "cwd.pl" or die $@;
55 print "Build directory $CWD\n";
56
57 die "$0: '+' in cwd does not work with Series 60 SDK 1.2\n"
58     if defined $S60SDK && $S60SDK eq '1.2' && $CWD =~ /\+/;
59
60 my @unclean;
61 my @mmp;
62
63 sub create_mmp {
64     my ( $target, $type, @x ) = @_;
65     my $miniperl = $target eq 'miniperl';
66     my $perl     = $target eq 'perl';
67     my $mmp        = "$target.mmp";
68     my $targetpath = $miniperl
69       || $perl ? "TARGETPATH\t\\System\\Apps\\Perl" : "";
70     if ( open( my $fh, '>', $mmp ) ) {
71         print "\t$mmp\n";
72         push @mmp,     $mmp;
73         push @unclean, $mmp;
74         print $fh <<__EOF__;
75 TARGET          $target.$type
76 TARGETTYPE      $type
77 __EOF__
78         if ($SDK_VARIANT eq 'S60' && $S60SDK =~ /^5\./) {
79             print $fh "UID\t0 0xEA3E9181\n" if $miniperl;
80             print $fh "UID\t0 0xED04DD86\n" if $perl;
81             print $fh "UID\t0x1000008d 0xE8667302\n" unless $miniperl || $perl; 
82             print $fh "CAPABILITY\tNONE\n";
83         } else {
84             print $targetpath; 
85             print $fh "EPOCHEAPSIZE\t1024 8388608"; 
86             print $fh "EPOCSTACKSIZE\t65536"; 
87         }
88         print $fh <<__EOF__;
89 EXPORTUNFROZEN
90 SRCDBG
91 __EOF__
92         if ($SDK_VARIANT eq 'S60') {
93             print $fh "MACRO\t__SERIES60__\n";
94             print $fh "MACRO\t__SERIES60_1X__\n" if $S60SDK =~ /^1\./;
95             print $fh "MACRO\t__SERIES60_2X__\n" if $S60SDK =~ /^2\./;
96             print $fh "MACRO\t__SERIES60_3X__\n" if $S60SDK =~ /^5\./; 
97         }
98         if ($SDK_VARIANT eq 'S80') {
99             print $fh "MACRO\t__SERIES80__\n";
100             print $fh "MACRO\t__SERIES80_1X__\n" if $S80SDK =~ /^1\./;
101             print $fh "MACRO\t__SERIES80_2X__\n" if $S80SDK =~ /^2\./;
102         }
103         if ($SDK_VARIANT eq 'S90') {
104             print $fh "MACRO\t__SERIES90__\n";
105         }
106         if ($SDK_VARIANT eq 'UIQ') {
107             print $fh "MACRO\t__UIQ__\n";
108             print $fh "MACRO\t__UIQ_1X__\n" if $UIQSDK =~ /^1\./;
109             print $fh "MACRO\t__UIQ_2X__\n" if $UIQSDK =~ /^2\./;
110         }
111         my ( @c, %c );
112         @c = map  { glob } qw(*.c);       # Find the .c files.
113         @c = map  { lc } @c;              # Lowercase the names.
114         @c = grep { !/malloc\.c/ } @c;    # Use the system malloc.
115         @c = grep { !/main\.c/ } @c;      # main.c must be explicit.
116         push @c, map { lc } @x;
117         @c = map { s:^\.\./::; $_ } @c;    # Remove the leading ../
118         @c = map { $c{$_}++ } @c;          # Uniquefy.
119         @c = sort keys %c;                 # Beautify.
120
121         for (@c) {
122             print $fh "SOURCE\t\t$_\n";
123         }
124         print $fh <<__EOF__;
125 SOURCEPATH      $CWD
126 USERINCLUDE     $CWD
127 USERINCLUDE     $CWD\\ext\\DynaLoader
128 USERINCLUDE     $CWD\\symbian
129 SYSTEMINCLUDE   \\epoc32\\include\\libc
130 SYSTEMINCLUDE   \\epoc32\\include
131 LIBRARY         euser.lib
132 LIBRARY         estlib.lib
133 LIBRARY         eikcore.lib
134 LIBRARY         cone.lib
135 LIBRARY         efsrv.lib
136 __EOF__
137         if ( $miniperl || $perl || $type eq 'dll' ) {
138             print $fh <<__EOF__;
139 LIBRARY         charconv.lib
140 LIBRARY         hal.lib
141 LIBRARY         estor.lib
142 __EOF__
143         }
144         if ($SDK_VARIANT =~ /^S[689]0$/) {
145             print $fh <<__EOF__;
146 LIBRARY         commonengine.lib
147 __EOF__
148         }
149         if (defined $S60SDK) {
150             print $fh <<__EOF__;
151 LIBRARY         avkon.lib
152 LIBRARY         commondialogs.lib 
153 __EOF__
154         }
155         if ((defined $S80SDK) or (defined $S90SDK)) {
156             print $fh <<__EOF__;
157 LIBRARY         eikctl.lib
158 LIBRARY         eikcoctl.lib
159 LIBRARY         eikdlg.lib
160 LIBRARY         ckndlg.lib
161 __EOF__
162         }
163         if (defined $UIQSDK) {
164             print $fh <<__EOF__;
165 LIBRARY         eikctl.lib
166 LIBRARY         eikcoctl.lib
167 LIBRARY         eikdlg.lib
168 LIBRARY         qikctl.lib
169 __EOF__
170         }
171         if ( $type eq 'exe' ) {
172             print $fh <<__EOF__;
173 STATICLIBRARY   ecrt0.lib
174 __EOF__
175         }
176         if ($miniperl) {
177             print $fh <<__EOF__;
178 MACRO           PERL_MINIPERL
179 __EOF__
180         }
181         if ($perl) {
182             print $fh <<__EOF__;
183 MACRO           PERL_PERL
184 __EOF__
185         }
186         print $fh <<__EOF__;
187 MACRO           PERL_CORE
188 MACRO           MULTIPLICITY
189 MACRO           PERL_IMPLICIT_CONTEXT
190 __EOF__
191         unless ( $miniperl || $perl ) {
192             print $fh <<__EOF__;
193 MACRO           PERL_GLOBAL_STRUCT
194 MACRO           PERL_GLOBAL_STRUCT_PRIVATE
195 __EOF__
196     }
197         unless ($miniperl || $perl ) {
198             if ($SDK_VARIANT eq 'S60' && $S60SDK =~ /^5\./) {
199                 print $fh "START RESOURCE\tsymbian\\PerlUi.rss\nEND\n";
200             } else {
201                 print $fh "RESOURCE\tsymbian\\PerlUi.rss";
202             }
203         }
204         close $fh;
205     }
206     else {
207         warn "$0: failed to open $mmp for writing: $!\n";
208     }
209 }
210
211 sub create_bld_inf {
212     if ( open( BLD_INF, '>', 'bld.inf' ) ) {
213         print "\tbld.inf\n";
214         push @unclean, "bld.inf";
215         print BLD_INF <<__EOF__;
216 PRJ_PLATFORMS
217 ${WIN} ${ARM}
218 PRJ_MMPFILES
219 __EOF__
220         for (@mmp) { print BLD_INF $_, "\n" }
221         close BLD_INF;
222     }
223     else {
224         warn "$0: failed to open bld.inf for writing: $!\n";
225     }
226 }
227
228 my %config;
229
230 sub load_config_sh {
231     if ( open( CONFIG_SH, '<', 'symbian/config.sh' ) ) {
232         while (<CONFIG_SH>) {
233             if (/^(\w+)=['"]?(.*?)["']?$/) {
234                 my ( $var, $val ) = ( $1, $2 );
235                 $val =~ s/x.y.z/$R_V_SV/gi;
236                 $val =~ s/thumb/$ARM/gi;
237                 $val = "C:$val" if (defined($S90SDK) and ($val =~ /^(\/|\\\\)system[\/\\]/i));
238                 $val = "'$SYMBIAN_VERSION'" if $var eq 'osvers';
239                 $val = "'$SDK_VERSION'"     if $var eq 'sdkvers';
240                 $config{$var} = $val;
241             }
242         }
243         close CONFIG_SH;
244     }
245     else {
246         warn "$0: failed to open symbian\\config.sh for reading: $!\n";
247     }
248 }
249
250 sub create_config_h {
251     load_config_sh();
252     if ( open( CONFIG_H, '>', 'config.h' ) ) {
253         print "\tconfig.h\n";
254         push @unclean, "config.h";
255         if ( open( CONFIG_H_SH, '<', 'config_h.SH' ) ) {
256             while (<CONFIG_H_SH>) {
257                 last if /\#ifndef _config_h_/;
258             }
259             print CONFIG_H <<__EOF__;
260 /*
261  * Package name      : perl
262  * Source directory  : .
263  * Configuration time: 
264  * Configured by     : 
265  * Target system     : symbian
266  */
267
268 #ifndef _config_h_
269 __EOF__
270             while (<CONFIG_H_SH>) {
271                 last if /!GROK!THIS/;
272                 s/\$(\w+)/exists $config{$1} ? $config{$1} : (warn "$0: config.sh missing '$1'\n", "")/eg;
273                 s/^#undef\s+(\S+).+/#undef $1/g;
274                 s:\Q/**/::;
275                 print CONFIG_H;
276             }
277             close CONFIG_H_SH;
278         }
279         else {
280             warn "$0: failed to open ../config_h.SH for reading: $!\n";
281         }
282         close CONFIG_H;
283     }
284     else {
285         warn "$0: failed to open config.h for writing: $!\n";
286     }
287 }
288
289 sub create_DynaLoader_cpp {
290     print "\text\\DynaLoader\\DynaLoader.cpp\n";
291     system(
292 q[xsubpp ext\DynaLoader\dl_symbian.xs >ext\DynaLoader\DynaLoader.cpp]
293       ) == 0
294       or die "$0: creating DynaLoader.cpp failed: $!\n";
295     push @unclean, 'ext\DynaLoader\DynaLoader.cpp';
296
297 }
298
299 sub create_symbian_port_h {
300     print "\tsymbian\\symbian_port.h\n";
301     if ( open( SYMBIAN_PORT_H, '>', 'symbian/symbian_port.h' ) ) {
302         my ($sdkmajor, $sdkminor);
303         if ($SDK_VARIANT eq 'S60') {
304             $S60SDK =~ /^(\d+)\.(\d+)$/;
305             ($sdkmajor, $sdkminor) = ($1, $2);
306         }
307         if ($SDK_VARIANT eq 'S80') {
308             $S80SDK =~ /^(\d+)\.(\d+)$/;
309             ($sdkmajor, $sdkminor) = ($1, $2);
310         }
311         if ($SDK_VARIANT eq 'S90') {
312             $S90SDK =~ /^(\d+)\.(\d+)$/;
313             ($sdkmajor, $sdkminor) = ($1, $2);
314         }
315         if ($SDK_VARIANT eq 'UIQ') {
316             $UIQSDK =~ /^(\d+)\.(\d+)$/;
317             ($sdkmajor, $sdkminor) = ($1, $2);
318         }
319         print SYMBIAN_PORT_H <<__EOF__;
320 /* Copyright (c) 2004-2005, Nokia.  All rights reserved. */
321
322 #ifndef __symbian_port_h__
323 #define __symbian_port_h__
324
325 #define PERL_SYMBIANPORT_MAJOR $PORT{dll}->{MAJOR}
326 #define PERL_SYMBIANPORT_MINOR $PORT{dll}->{MINOR}
327 #define PERL_SYMBIANPORT_PATCH $PORT{dll}->{PATCH}
328
329 #define PERL_SYMBIANSDK_FLAVOR  L"$SDK_VARIANT"
330 #define PERL_SYMBIANSDK_MAJOR   $sdkmajor
331 #define PERL_SYMBIANSDK_MINOR   $sdkminor
332
333 #endif /* #ifndef __symbian_port_h__ */
334 __EOF__
335         close(SYMBIAN_PORT_H);
336         push @unclean, 'symbian\symbian_port.h';
337     }
338     else {
339         warn "$0: failed to open symbian/symbian_port.h for writing: $!\n";
340     }
341 }
342
343 sub create_perlmain_c {
344     print "\tperlmain.c\n";
345     system(
346 q[perl -ne "print qq[    char *file = __FILE__;\n] if /dXSUB_SYS/;print unless /PERL_UNUSED_CONTEXT/;print qq[    newXS(\"DynaLoader::boot_DynaLoader\", boot_DynaLoader, file);\n] if /dXSUB_SYS/;print qq[EXTERN_C void boot_DynaLoader (pTHX_ CV* cv);\n] if /Do not delete this line/" miniperlmain.c > perlmain.c]
347       ) == 0
348       or die "$0: Creating perlmain.c failed: $!\n";
349     push @unclean, 'perlmain.c';
350 }
351
352 sub create_PerlApp_pkg {
353     print "\tsymbian\\PerlApp.pkg\n";
354     if ( open( PERLAPP_PKG, '>', 'symbian\\PerlApp.pkg' ) ) {
355         my $ProductId =
356             defined $S60SDK ?
357 qq[;Supports Series 60 v0.9\n(0x101F6F88), 0, 0, 0, {"Series60ProductID"}\n] :
358             defined $S80SDK ?
359 qq[;Supports Series 80 v2.0\n(0x101F8ED2), 0, 0, 0, {"Series80ProductID"}\n] :
360             defined $S90SDK ?
361 qq[;Supports Series 90 v1.1\n(0x101FBE05), 0, 0, 0, {"Series90ProductID"}\n] :
362             defined $UIQSDK && $SDK_VERSION =~  /^(\d)\.(\d)$/ ?
363 qq[;Supports UIQ v2.1\n(0x101F617B), $1, $2, 0, {"UIQ21ProductID"}\n] :
364             ";Supports Series NN";
365         my $APPS = $UREL;
366         if (($SDK_VARIANT eq 'S60' && $SDK_VERSION ne '1.2' || $WIN eq 'winscw') || defined $S80SDK || defined $S90SDK) { # Do only if not in S60 1.2 VC.
367             $APPS =~ s!\\epoc32\\release\\(.+)\\$UARM$!\\epoc32\\data\\z\\system\\apps\\PerlApp!i;
368         }
369         # TODO: in S60 3.0 there will be no more recognizers.
370         my $mdl = qq["$UREL\\PerlRecog.mdl"-"!:\\system\\recogs\\PerlRecog.mdl";];
371         my $AIF = $SDK_VARIANT =~ /^S[689]0/ ? qq["$APPS\\PerlApp.aif"-"!:\\system\\apps\\PerlApp\\PerlApp.aif"] : "";
372         print PERLAPP_PKG <<__EOF__;
373 ; !!!!!!   DO NOT EDIT THIS FILE   !!!!!!
374 ; This file is built by symbian\\config.pl.
375 ; Any changes made here will be lost!
376 ;
377 ; PerlApp.pkg
378 ;
379 ; Note that the demo_pl needs to be run to create the demo .pl scripts.
380 ;
381 ; Languages
382 &EN;
383
384 ; Standard SIS file header
385 #{"PerlApp"},(0x102015F6),0,2,0
386
387 $ProductId
388
389 ; Files
390 "$UREL\\PerlApp.APP"-"!:\\system\\apps\\PerlApp\\PerlApp.app"
391 $mdl
392 "$APPS\\PerlApp.rsc"-"!:\\system\\apps\\PerlApp\\PerlApp.rsc"
393 $AIF
394 __EOF__
395         if ( open( DEMOS, '-|', "perl symbian\\demo_pl list" ) ) {
396             while (<DEMOS>) {
397                 chomp;
398                 if (defined $S90SDK) {
399                     print PERLAPP_PKG qq["$_"-"!:\\Mydocs\\Perl\\$_"\n];
400                 } else {
401                     print PERLAPP_PKG qq["$_"-"!:\\Perl\\$_"\n];
402                 }
403             }
404             close(DEMOS);
405         }
406         close(PERLAPP_PKG);
407     }
408     else {
409         die "$0: symbian\\PerlApp.pkg: $!\n";
410     }
411     push @unclean, 'symbian\PerlApp.pkg';
412 }
413
414 print "Creating...\n";
415 create_mmp(
416     'miniperl',             'exe',
417     'miniperlmain.c',       'symbian\symbian_stubs.c',
418     'symbian\PerlBase.cpp',
419     'symbian\PerlUi.cpp',
420     'symbian\PerlUtil.cpp',
421     'symbian\symbian_utils.cpp',
422 );
423 create_mmp(
424     "perl",                      'exe',
425     'perlmain.c',                'symbian\symbian_stubs.c',
426     'symbian\symbian_utils.cpp',
427     'symbian\PerlBase.cpp',
428     'symbian\PerlUi.cpp',
429     'symbian\PerlUtil.cpp',
430     'ext\DynaLoader\DynaLoader.cpp',
431 );
432
433 create_mmp(
434     "perl$VERSION",              'dll',
435     'symbian\symbian_dll.cpp',   'symbian\symbian_stubs.c',
436     'symbian\symbian_utils.cpp',
437     'symbian\PerlBase.cpp',
438     'symbian\PerlUi.cpp',
439     'symbian\PerlUtil.cpp',
440     'ext\DynaLoader\DynaLoader.cpp',
441 );
442
443 create_bld_inf();
444 create_config_h();
445 create_perlmain_c();
446 create_symbian_port_h();
447 create_DynaLoader_cpp();
448 create_PerlApp_pkg();
449
450 if ( open( PERLAPP_MMP, '>', 'symbian/PerlApp.mmp' ) ) {
451     my @MACRO;
452     my @LIB;
453     push @MACRO, 'PERL_IMPLICIT_CONTEXT';
454     push @MACRO, 'MULTIPLICITY';
455     if (defined $S60SDK) {
456         push @MACRO, '__SERIES60__';
457         push @MACRO, '__SERIES60_1X__' if $S60SDK =~ /^1\./;
458         push @MACRO, '__SERIES60_2X__' if $S60SDK =~ /^2\./;
459         push @LIB, <<__EOF__;
460 LIBRARY         avkon.lib
461 LIBRARY         commondialogs.lib 
462 __EOF__
463     }
464     if (defined $S80SDK) {
465         push @MACRO, '__SERIES80__';
466         push @MACRO, '__SERIES80_1X__' if $S80SDK =~ /^1\./;
467         push @MACRO, '__SERIES80_2X__' if $S80SDK =~ /^2\./;
468         push @LIB, <<__EOF__;
469 LIBRARY         eikctl.lib
470 LIBRARY         eikcoctl.lib
471 LIBRARY         eikdlg.lib
472 LIBRARY         ckndlg.lib
473 __EOF__
474     }
475     if (defined $S90SDK) {
476         push @MACRO, '__SERIES90__';
477         push @LIB, <<__EOF__;
478 LIBRARY         eikctl.lib
479 LIBRARY         eikcoctl.lib
480 LIBRARY         eikdlg.lib
481 LIBRARY         ckndlg.lib
482 __EOF__
483     }
484     if (defined $UIQSDK) {
485         push @MACRO, '__UIQ__';
486         push @MACRO, '__UIQ_1X__' if $UIQSDK =~ /^1\./;
487         push @MACRO, '__UIQ_2X__' if $UIQSDK =~ /^2\./;
488         push @LIB, <<__EOF__;
489 LIBRARY         eikctl.lib
490 LIBRARY         eikcoctl.lib
491 LIBRARY         eikdlg.lib
492 LIBRARY         qikctl.lib
493 __EOF__
494     }
495     print PERLAPP_MMP <<__EOF__;
496 // !!!!!!   DO NOT EDIT THIS FILE   !!!!!!
497 // This file is built by symbian\\config.pl.
498 // Any changes made here will be lost!
499 TARGET            PerlApp.app
500 TARGETTYPE        app
501 UID               0x100039CE 0x102015F6
502 TARGETPATH        \\system\\apps\\PerlApp
503 SRCDBG
504 EXPORTUNFROZEN
505 SOURCEPATH        .
506 SOURCE            PerlApp.cpp 
507
508 USERINCLUDE       .
509 USERINCLUDE       ..
510 USERINCLUDE       \\symbian\\perl\\$R_V_SV\\include
511
512 SYSTEMINCLUDE     \\epoc32\\include
513 SYSTEMINCLUDE     \\epoc32\\include\\libc
514
515 LIBRARY           apparc.lib
516 LIBRARY           bafl.lib
517 LIBRARY           charconv.lib 
518 LIBRARY           cone.lib
519 LIBRARY           efsrv.lib
520 LIBRARY           eikcore.lib
521 LIBRARY           estlib.lib 
522 LIBRARY           euser.lib
523 LIBRARY           perl$VERSION.lib
524 @LIB
525 RESOURCE          perlapp.rss
526 __EOF__
527     if (@MACRO) {
528         for my $macro (@MACRO) {
529             print PERLAPP_MMP <<__EOF__;
530 MACRO             $macro
531 __EOF__
532         }
533     }
534     if ($SDK_VARIANT =~ /^S[689]0$/) {
535         print PERLAPP_MMP <<__EOF__;
536 AIF               PerlApp.aif . PerlAppAif.rss 
537 __EOF__
538     }
539     close(PERLAPP_MMP);
540     push @unclean, 'symbian\PerlApp.mmp';
541 }
542 else {
543     warn "$0: failed to create symbian\\PerlApp.mmp";
544 }
545
546 if ( open( MAKEFILE, '>', 'Makefile' ) ) {
547     my $perl = "perl$VERSION";
548     my $windef1 = "$SYMBIAN_ROOT\\Epoc32\\Build$CWD\\$perl\\$WIN\\$perl.def";
549     my $windef2 = "..\\BWINS\\${perl}u.def";
550     my $armdef1 = "$SYMBIAN_ROOT\\Epoc32\\Build$CWD\\$perl\\$ARM\\$perl.def";
551     my $armdef2 = "..\\BMARM\\${perl}u.def";
552     my $MF = $WIN eq 'wins' ? 'vc6' : $WIN eq 'winscw' ? 'cw_ide' : "UNKNOWN";
553     print "\tMakefile\n";
554     print MAKEFILE <<__EOF__;
555 help:
556         \@echo === Perl for Symbian ===
557         \@echo Useful targets:
558         \@echo all win arm clean
559         \@echo perldll.sis perlext.sis perlsdk.zip
560
561 WIN     = ${WIN}
562 ARM     = ${ARM}
563
564 all:    build
565
566 build:  rename_makedef build_${WIN} build_arm
567
568 @unclean: symbian\\config.pl
569         perl symbian\\config.pl
570
571 build_${WIN}:   abld.bat perldll_${WIN}
572
573 build_vc6:      abld.bat perldll_wins
574
575 build_vc7:      abld.bat perldll_wins
576
577 build_cw:       abld.bat perldll_winscw
578
579 build_arm:      abld.bat perl_arm miniperl_arm perldll_arm
580
581 miniperl_win miniperl_${WIN}:   miniperl.mmp abld.bat rename_makedef
582         abld build ${WIN} udeb miniperl
583
584 miniperl_arm:   miniperl.mmp abld.bat rename_makedef
585         abld build \$(ARM) $UARM miniperl
586
587 miniperl:       miniperl_${WIN} miniperl_arm
588
589 perl:   perl_${WIN} perl_arm
590
591 perl_win perl_${WIN}:   perl.mmp abld.bat rename_makedef
592         abld build ${WIN} perl
593
594 perl_arm:       perl.mmp abld.bat rename_makedef
595         abld build \$(ARM) $UARM perl
596
597 perldll_win perldll_${WIN}: perl${VERSION}_${WIN} freeze_${WIN} perl${VERSION}_${WIN}
598
599 perl${VERSION}_win perl${VERSION}_${WIN}:       perl$VERSION.mmp abld.bat rename_makedef
600         abld build ${WIN} perl$VERSION
601
602 perldll_arm: perl${VERSION}_arm freeze_arm perl${VERSION}_arm
603
604 perl${VERSION}_arm:     perl$VERSION.mmp abld.bat rename_makedef
605         abld build \$(ARM) $UARM perl$VERSION
606
607 perldll perl$VERSION:   perldll_${WIN} perldll_arm
608
609 win ${WIN}:     miniperl_${WIN} perl_${WIN} perldll_${WIN}
610
611 thumb arm:      miniperl_arm perl_arm perldll_arm
612
613 rename_makedef:
614         -ren makedef.pl nomakedef.pl
615
616 # Symbian SDK has a makedef.pl of its own,
617 # and we don't need Perl's.
618 rerename_makedef:
619         -ren nomakedef.pl makedef.pl
620
621 symbian\\PerlUi.rss: symbian\\PerlUi$SDK_VARIANT.rss
622         copy symbian\\PerlUi$SDK_VARIANT.rss symbian\\PerlUi.rss
623
624 abld.bat abld: bld.inf symbian\\PerlUi.rss
625         bldmake bldfiles
626
627 vc6:    win.mf vc6.mf build_vc6
628
629 vc7:    win.mf vc7.mf build_vc7
630
631 cw:     win.mf cw.mf build_cw
632
633 ${WIN}_miniperl.mf: abld.bat symbian\\config.pl
634         abld makefile ${MF} miniperl
635         echo > ${WIN}_miniperl.mf
636
637 ${WIN}_perl.mf: abld.bat symbian\\config.pl
638         abld makefile ${MF} perl
639         echo > ${WIN}_perl.mf
640
641 ${WIN}_${VERSION}.mf: abld.bat symbian\\config.pl
642         abld makefile ${MF} perl${VERSION}
643         echo > ${WIN}_${VERSION}.mf
644
645 symbian\\${WIN}.mf:
646         cd symbian; make ${WIN}.mf
647
648 ${WIN}.mf: ${WIN}_miniperl.mf ${WIN}_perl.mf ${WIN}_${VERSION}.mf symbian\\${WIN}.mf
649
650 arm_miniperl.mf: abld.bat symbian\\config.pl
651         echo > arm_miniperl.mf
652
653 arm_perl.mf: abld.bat symbian\\config.pl
654         echo > arm_perl.mf
655
656 arm_${VERSION}.mf: abld.bat symbian\\config.pl
657         echo > arm_${VERSION}.mf
658
659 arm.mf: arm_miniperl.mf arm_perl.mf arm_${VERSION}.mf
660
661 win.mf:  vc6.mf cw.mf
662         echo > win.mf
663
664 vc6.mf: abld.bat symbian\\config.pl
665         abld makefile vc6
666         echo > vc6.mf
667
668 vc7.mf: abld.bat symbian\\config.pl
669         abld makefile vc7
670         echo > vc7.mf
671
672 cw.mf: abld.bat symbian\\config.pl
673         abld makefile cw_ide
674         echo > cw.mf
675
676 PM  = lib\\Config.pm lib\\Cross.pm lib\\lib.pm ext\\DynaLoader\\DynaLoader.pm ext\\DynaLoader\\XSLoader.pm ext\\Errno\\Errno.pm
677 POD = lib\\Config.pod
678
679 pm:     \$(PM)
680
681 XLIB    = -Ixlib\\symbian
682
683 XSBOPT  = --win=\$(WIN) --arm=\$(ARM)
684
685 lib\\Config.pm:
686         copy symbian\\config.sh config.sh
687 __EOF__
688     if (defined $S90SDK) {
689         print MAKEFILE <<__EOF__;
690         perl -pi.bak -e "s:x\\.y\\.z+:$R_V_SV:g; s!='(\\\\\\\\system)!='C:\\1!" config.sh
691 __EOF__
692     } else {
693         print MAKEFILE <<__EOF__;
694         perl -pi.bak -e "s:x\\.y\\.z+:$R_V_SV:g" config.sh
695 __EOF__
696     };
697     print MAKEFILE <<__EOF__;
698         perl \$(XLIB) configpm --cross=symbian
699         copy xlib\\symbian\\Config.pm lib\\Config.pm
700         perl -pi.bak -e "s:x\\.y\\.z:$R_V_SV:g" lib\\Config.pm
701         perl -pi.bak -e "s:5\\.\\d+\\.\\d+:$R_V_SV:g" lib\\Config.pm
702         -perl -pi.bak -e "s:x\\.y\\.z:$R_V_SV:g" xlib\\symbian\\Config_heavy.pl
703
704 lib\\lib.pm:
705         perl lib\\lib_pm.PL
706
707 ext\\DynaLoader\\DynaLoader.pm:
708         -del /f ext\\DynaLoader\\DynaLoader.pm
709         perl -Ixlib\\symbian ext\\DynaLoader\\DynaLoader_pm.PL
710         perl -pi.bak -e "s/__END__//" DynaLoader.pm
711         copy /y DynaLoader.pm ext\\DynaLoader\\DynaLoader.pm
712         -del /f DynaLoader.pm DynaLoader.pm.bak
713
714 ext\\DynaLoader\\XSLoader.pm:
715         perl \$(XLIB) symbian\\xsbuild.pl \$(XSBOPT) XSLoader
716
717 ext\\Errno\\Errno.pm:
718         perl \$(XLIB) symbian\\xsbuild.pl \$(XSBOPT) Errno
719
720 miniperlexe.sis:        miniperl_arm symbian\\makesis.pl
721         perl \$(XLIB) symbian\\makesis.pl miniperl
722
723 perlexe.sis:    perl_arm symbian\\makesis.pl
724         perl \$(XLIB) symbian\\makesis.pl perl
725
726
727 allsis: all miniperlexe.sis perlexe.sis perldll.sis perllib.sis perlext.sis perlapp.sis
728
729 perldll.sis perl$VERSION.sis:   perldll_arm pm symbian\\makesis.pl
730         perl \$(XLIB) symbian\\makesis.pl perl${VERSION}dll
731
732 perl${VERSION}lib.sis perllib.sis:      \$(PM)
733         perl \$(XLIB) symbian\\makesis.pl perl${VERSION}lib
734
735 perl${VERSION}ext.sis perlext.sis:      perldll_arm buildext_sis
736         perl symbian\\makesis.pl perl${VERSION}ext
737
738 EXT =   Compress::Raw::Zlib Cwd Data::Dumper Devel::Peek Digest::MD5 Errno Fcntl File::Glob Filter::Util::Call IO List::Util MIME::Base64 PerlIO::scalar PerlIO::via SDBM_File Socket Storable Time::HiRes XSLoader attributes
739
740 buildext: perldll symbian\\xsbuild.pl lib\\Config.pm
741         perl \$(XLIB) symbian\\xsbuild.pl \$(XSBOPT) \$(EXT)
742
743 buildextcpp: perldll symbian\\xsbuild.pl lib\\Config.pm
744         perl \$(XLIB) symbian\\xsbuild.pl --csuffix .cpp \$(XSBOPT) \$(EXT)
745
746 buildext_sis: perldll.sis symbian\\xsbuild.pl lib\\Config.pm
747         perl \$(XLIB) symbian\\xsbuild.pl \$(XSBOPT) --sis \$(EXT)
748
749 buildextcpp_sis: perldll.sis symbian\\xsbuild.pl lib\\Config.pm
750         perl \$(XLIB) symbian\\xsbuild.pl --csuffix .cpp \$(XSBOPT) --sis \$(EXT)
751
752 cleanext: symbian\\xsbuild.pl
753         perl \$(XLIB) symbian\\xsbuild.pl \$(XSBOPT) --clean \$(EXT)
754
755 distcleanext: symbian\\xsbuild.pl
756         perl \$(XLIB) symbian\\xsbuild.pl \$(XSBOPT) --distclean \$(EXT)
757
758 sis makesis:    miniperl perl perldll pm buildext perlapp.sis
759         perl \$(XLIB) symbian\\makesis.pl
760
761 APIDIR = \\Symbian\\perl\\$R_V_SV
762
763 sdkinstall:
764         -mkdir \\Symbian\\perl
765         -mkdir \\Symbian\\perl\\$R_V_SV
766         -mkdir \$(APIDIR)\\include
767         -mkdir \$(APIDIR)\\include\\symbian
768         -mkdir \$(APIDIR)\\lib
769         -mkdir \$(APIDIR)\\lib\\ExtUtils
770         -mkdir \$(APIDIR)\\pod
771         -mkdir \$(APIDIR)\\bin
772         -mkdir \$(BINDIR)
773         copy /y *.h   \$(APIDIR)\\include
774         -copy /y *.inc \$(APIDIR)\\include
775         copy /y lib\\ExtUtils\\xsubpp  \$(APIDIR)\\lib\\ExtUtils
776         copy /y lib\\ExtUtils\\typemap \$(APIDIR)\\lib\\ExtUtils
777         copy /y lib\\ExtUtils\\ParseXS.pm \$(APIDIR)\\lib\\ExtUtils
778         copy /y symbian\\xsbuild.pl    \$(APIDIR)\\bin
779         copy /y symbian\\sisify.pl     \$(APIDIR)\\bin
780         copy /y symbian\\PerlBase.h    \$(APIDIR)\\include
781         copy /y symbian\\PerlUi.h      \$(APIDIR)\\include
782         copy /y symbian\\PerlUtil.h    \$(APIDIR)\\include
783         copy /y symbian\\symbian*.h    \$(APIDIR)\\include\\symbian
784         copy /y symbian\\PerlBase.pod  \$(APIDIR)\\pod
785         copy /y symbian\\PerlUtil.pod  \$(APIDIR)\\pod
786
787 RELDIR  = $SYMBIAN_ROOT\\epoc32\\release
788 RELWIN = \$(RELDIR)\\\$(WIN)\\udeb
789 RELARM = \$(RELDIR)\\\$(ARM)\\$UARM
790 SDKZIP = perl${VERSION}sdk.zip
791
792
793 \$(SDKZIP) perlsdk.zip: perldll sdkinstall
794         -del /f perl${VERSION}sdk.zip
795         zip -r perl${VERSION}sdk.zip \$(RELWIN)\\perl$VERSION.* \$(RELARM)\\perl$VERSION.* \$(APIDIR)
796         \@echo perl${VERSION}sdk.zip created.
797
798 PERLSIS = perl${VERSION}.SIS perl${VERSION}lib.SIS perl${VERSION}ext.SIS
799 ALLSIS  = \$(PERLSIS) perlapp.sis
800 ETC     = README.symbian symbian\\PerlBase.pod symbian\\PerlUtil.pod symbian\\sisify.pl symbian\\TODO
801
802 perl${VERSION}dist.zip perldist.zip: \$(ALLSIS) \$(SDKZIP) \$(ETC)
803         -del /f perl${VERSION}dist.zip
804         zip -r perl${VERSION}dist.zip \$(ALLSIS) \$(SDKZIP) \$(ETC)
805
806 perlapp:        sdkinstall perlapp_${WIN} perlapp_arm
807
808 perlapp_arm_minimal sisify_hex perlappmin.hex perlrscmin.hex:   sdkinstall config.h
809         cd symbian; make perlapp_arm USERDEFS=-DCreatePerlAppMinimal
810         perl symbian\\hexdump.pl
811
812 perlapp_win perlapp_${WIN}: config.h
813         cd symbian; make perlapp_${WIN}
814
815 perlapp_arm: config.h
816         cd symbian; make perlapp_arm
817
818 perlapp_arm_clean:
819         cd symbian; make clean
820
821 perlapp_demo_extract:
822         cd symbian; make perlapp_demo_extract
823
824 perlapp.sis: perlapp_arm
825         cd symbian; make perlapp.sis
826
827 perlapp.zip:
828         cd symbian; zip perlapp.zip PerlApp.* PerlRecog.* PerlBase.* PerlUtil.* demo_pl
829
830 zip:    perlsdk.zip perlapp.zip
831
832 freeze: freeze_${WIN} freeze_arm
833
834 freeze_${WIN}:
835         abld freeze ${WIN} perl$VERSION
836
837 freeze_arm:
838         abld freeze \$(ARM) perl$VERSION
839
840 defrost:        defrost_${WIN} defrost_arm
841
842 defrost_${WIN}:
843         -del /f $windef1
844         -del /f $windef2
845
846 defrost_arm:
847         -del /f $armdef1
848         -del /f $armdef2
849
850 clean_${WIN}: abld.bat
851         abld clean ${WIN}
852
853 clean_arm: abld.bat
854         abld clean \$(ARM)
855
856 clean:  clean_${WIN} clean_arm rerename_makedef
857         -del /f \$(PM)
858         -del /f \$(POD)
859         -del /f lib\\Config.pm.bak
860         -del /f xlib\\symbian\\Config_heavy.pl
861         -rmdir /s /q xlib
862         -del /f config.sh
863         -del /f DynaLoader.pm ext\\DynaLoader\\DynaLoader.pm
864         -del /f ext\\DynaLoader\\Makefile
865         -del /f ext\\SDBM_File\\sdbm\\Makefile
866         -del /f symbian\\*.lst
867         -del /f abld.bat @unclean *.pkg *.sis *.zip
868         -del /f symbian\\abld.bat symbian\\*.sis symbian\\*.zip
869         -del /f symbian\\perl5*.pkg symbian\\miniperl.pkg
870         -del arm_*.mf ${WIN}_*.mf vc*.mf cw*.mf
871         -del symbian\\Makefile
872         -del symbian\\PerlUi.rss symbian\\PerlApp.rss
873         -del perlappmin.hex perlrscmin.hex
874         -perl symbian\\xsbuild.pl \$(XSBOPT) --clean \$(EXT)
875         -rmdir /s /q perl${VERSION}_Data
876         -cd symbian; make clean
877
878 reallyclean: abld.bat
879         abld reallyclean
880
881 distclean: defrost reallyclean clean
882         -perl symbian\\xsbuild.pl \$(XSBOPT) --distclean \$(EXT)
883         -del /f config.h config.sh.bak symbian\\symbian_port.h
884         -del /f Makefile symbian\\PerlApp.mmp
885         -del /f BMARM\\*.def
886         -del /f *.cwlink *.resources *.pref
887         -del /f perl${VERSION}.xml perl${VERSION}.mcp uid.cpp
888         -rmdir /s /q BMARM
889         cd symbian; make distclean
890         -del /f symbian\\Makefile
891 __EOF__
892     close MAKEFILE;
893 }
894 else {
895     warn "$0: failed to create Makefile: $!\n";
896 }
897
898 if ( open( MAKEFILE, '>', 'symbian/Makefile')) {
899     my $wrap = defined $S60SDK && $S60SDK eq '1.2' && $WIN ne '${WIN}cw';
900     my $ABLD = $wrap ? 'perl b.pl': 'abld';
901     print "\tsymbian/Makefile\n";
902     my $MF = $WIN eq 'wins' ? 'vc6' : $WIN eq 'winscw' ? 'cw_ide' : "UNKNOWN";
903     print MAKEFILE <<__EOF__;
904 WIN = $WIN
905 ARM = $ARM
906 ABLD = $ABLD
907 MF = $MF
908
909 abld.bat:
910         bldmake bldfiles
911
912 perlapp_${WIN}: abld.bat ..\\config.h PerlApp.h PerlApp.cpp
913         copy PerlUi$SDK_VARIANT.rss PerlApp.rss
914         bldmake bldfiles
915         \$(ABLD) build ${WIN} udeb
916
917 perlapp_arm: ..\\config.h PerlApp.h PerlApp.cpp
918         copy PerlUi$SDK_VARIANT.rss PerlApp.rss
919         bldmake bldfiles
920         \$(ABLD) build ${ARM} $UARM
921
922 $MF:
923         abld makefile $MF
924
925 win.mf:
926         bldmake bldfiles
927         abld makefile $MF
928
929 perlapp_demo_extract:
930         perl demo_pl extract
931
932 perlapp.sis: perlapp_arm perlapp_demo_extract
933         -del /f perlapp.SIS
934         makesis perlapp.pkg
935         copy /y perlapp.SIS ..\\perlapp.SIS
936
937 clean:
938         -perl demo_pl cleanup
939         -del /f perlapp.sis
940         -del /f b.pl
941         -del PerlApp.rss
942         abld clean $WIN
943         abld clean thumb
944         -del Makefile
945
946 distclean: clean
947         -del /f *.cwlink *.resources *.pref
948         -del /f PerlApp.xml PerlApp.mcp uid.cpp
949         -rmdir /s /q PerlApp_Data
950         -del /f abld.bat
951 __EOF__
952     close(MAKEFILE);
953     if ($wrap) {
954         if ( open( B_PL, '>', 'symbian/b.pl')) {
955             print B_PL <<'__EOF__';
956 # abld.pl wrapper.
957
958 # nmake doesn't like MFLAGS and MAKEFLAGS being set to -w and w.
959 delete $ENV{MFLAGS};
960 delete $ENV{MAKEFLAGS};
961
962 system("abld @ARGV");
963 __EOF__
964             close(B_PL);
965         } else {
966             warn "$0: failed to create symbian/b.pl: $!\n";
967         }
968     }
969 } else {
970     warn "$0: failed to create symbian/Makefile: $!\n";
971 }
972
973 print "Deleting...\n";
974 for my $config (
975                 # Do not delete config.h here.
976                 "config.sh",
977                 "lib\\Config.pm",
978                 "xlib\\symbian\\Config.pm",
979                 "xlib\\symbian\\Config_heavy.pl",
980                 "symbian\\PerlUi.rss",
981                 "symbian\\PerlApp.rss",
982                 ) {
983     print "\t$config\n";
984     unlink($config);
985 }
986
987 print <<__EOM__;
988 Configuring done.
989 Now you can run:
990     make all
991     make allsis
992 __EOM__
993
994 1;    # Happy End.