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