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