Debian Codegraph @

compile/Compile.pod

raw
1
2 =head1 NAME
3
4 Tk/compile - making executables from perl/Tk scripts
5
6 =for category Other Modules and Languages
7
8 =head1 SYNOPSIS
9
10 cd .../Tk800.013/compile
11 make PROG=...path/to/script
12
13 =head1 DESCRIPTION
14
15 This directory is for experimenting with compiling Tk apps. to executables.
16 You need perl5.00556 (or later?) to have the right hooks in perl itself.
17
18 This has only been tested on Solaris 2.6 (but I doubt version makes
19 much difference), and RedHat Linux 5.1 both with gcc. As far as I am aware
20 other C compilers should work if 'Makefile' is tweaked appropriately.
21 The Makefile is for GNU make as it uses $(shell ...).
22 The Makefile could be converted to a script (contributions welcome), but having
23 a makefile makes it easier for me to debug the stages.
24
25 =head2 Instructions
26
27 build and install perl5.005_56 (suggest not as your _main_ perl).
28 build and install Tk800.013 with perl5.005_56
29
30 cd to this directory
31 Copy the script you want to compile to trial.pl
32 ( make PROG=.../script will do that )
33 type 'make'
34
35 wait ...
36
37 type 'trial' to test the executable.
38
39 copy 'trial' to your path.
40
41 =head2 How it Works
42
43 The script is "invoked" with two modules ahead of it on the command line
44 and with perl's -c flag to "just compile". The most important of the
45 modules is Malcolm Beatie's -MO=C "Compile" module. This installs an END {}
46 block so that when perl has finished parsing the script the "C backend" gets
47 control.
48
49 The other command line module is -MPreLoad (in this directory)
50 this supplies another END {} block (which is run before Malcolm's), and
51 overrides AutoLoader::import to pass the END {} block a list of modules
52 that "use AutoLoader". The END {} block then loads _all_ the subs that
53 module could load.
54
55 When Malcolm's END {} block gets control it then writes C code to build
56 the same data structures that perl has just built. (This takes a long time
57 and writes a large file - ../tiny takes 1:20 minutes and builds 3.5M of C).
58 Lots of messages get written at the start - expect 'bootstrap' to be
59 redefined a few times.
60
61 This C code (with version of B::C module in 5.00556) has one function
62 which is very large. This stresses the C compiler, so makefile runs a perl
63 script "splitfunc" which breaks that function down into smaller ones.
64
65 Then C code is compiled to an object file.
66 This takes a long time (tiny takes 3:07 minutes).
67 Beware enabling optimization or debug on this compile, it will
68 take even longer.
69
70 Another perl script is run to find the shared objects which where
71 loaded by DynaLoader (B::C module has listed them as comments in the C file).
72 We also hunt down the DynaLoader.a library (just in case script will load
73 something at run time).
74
75 Then all the above i.e. object files, shared objects, dynaloader are linked
76 with libperl to produce the final executable.
77
78 tiny builds a 2.7M executable (stripped).
79 Note though that due to fact that B::C and PreLoad include "everything"
80 from modules, larger apps don't grow in proportion (ptked is 5M stripped).
81
82 =head2 Restrictions on Scripts
83
84 What gets compiled into the script is what gets built by perl up to,
85 but stopping short of running the main script. This means that body of "use'd"
86 modules is run, but "required" modules are not. The built executable
87 is still (supposed to be) capable of loading other code (including binary
88 modules), but will use "compiled-in" paths to do so.
89
90 So 'use Tk::widgets (...)' to load the widgets your script needs.
91
92 Only AutoLoader is handled by PreLoad. In particular SelfLoader will not work
93 as DATA handle is lost between compile and running executable.
94
95 B::C's handing of initialized variables is still patchy. Thus if modules
96 set global variables at "compile" time their values may be lost
97 by time executable is run.
98
99 =head2 Showing Off
100
101 This file is being edited by compiled ptked on Linux.
102
103
104
105
106