[Date Prev][Date Next][Thread Prev][Thread Next] [Search] [Date Index] [Thread Index]

Re: [MacPerl] Re: Generic XS from CPAN build



On Fri, 5 Feb 1999, Geoffrey C Kinnel wrote:

> Does compiling an XS require MPW? I have CodeWarrior 10 and was thinking
> I could contribute something to the MacPerl community by compiling
> things here and there on occasion. We can't let Arved and Chris do all
> the work :).
> 
No, it doesn't require MPW. Because you have CW10 you may have to fiddle
stuff a bit, but I can't see that you won't be able to track the following
procedure and get something working. I only started with Metrowerks at
Pro2; before that I had Think C.

**********************************************************************
Making a MacPerl shared library (XS extension) in the CW IDE

This is a first cut at outlining procedures for using the Codewarrior IDE 
to build extensions for MacPerl. This is very much work in progress. I 
normally use MPW myself.

Rather than cut our teeth on a CPAN module to start, let's take a look at 
Example 1 in CookBook A of Dean Roehrich's XS stuff (this is available on 
CPAN). We know these work - we might not know that about an arbitrary CPAN 
XS build, and there's no point in getting into porting. For convenience 
stick the CookBook folder in "HD:MacPerl_Src:perl:ext".

I've included a script which you can save as a droplet. Change the 2 
hardcoded paths to reflect the name of your hard drive. All you need to do 
is drag the XS file on to this droplet, and it'll run xsubpp for you, 
producing the C source in the same folder. Right now it's slightly 
hardwired to add the typemap that comes with the CookBook stuff.

Create a new project (I'm using IDE 3.1 and the 2.1.1 compilers).  The
most convenient place to put it is in the Ex1 folder in CookBookA, since that's 
what we're doing at the moment.  A C or C++ Standard Console project under 
MacOS is a good starting point.

Replace HelloWorld with the C file you generated with xsubpp. Create a new 
group if you like; in any case, add PerlStub from the "perl" folder in the 
source tree. All the other libraries should be OK (if possibly overkill
for this particular example). 

Access Paths: add the perl folder (i.e. HD:MacPerl_Src:perl) to your user 
paths. Add sfio:include and GUSI:include to your system paths (these are 
also in MacPerl_Src). There may be adjustments to the system paths after 
I've had time to really look, but this works.

Build Target: shared library
C/C++ Language: check "map NL to CR"
PPC Linker: I always go for Normal linking

When you run the first time, set the PPC PEF to use an .exp file for
Export Symbols. After the first run, open this file, and edit it to remove 
everything except the bootstrap (I had been leaving in the XS symbols
also. But based on Matthias' info this is unnecessary). Then rerun the
project. (The MPW build procedure does all of this for you with
ExtUtils:MkSymlists. Hint, hint).

Another good reason to use MPW is to avoid the detail work of installing 
your new library so you can test it. Rename your library to Ex1, 
and make folders and copy files so you have

:Ex1:lib:Ex1.pm
:Ex1:lib:MacPPC:auto:Ex1:Ex1

To test, set Preferences for MacPerl so that user paths (for @INC) include 
the lib folder you just set up in the CookBookA:Ex1 folder. In any case, 
if you've done everything right, running test1.t in the t folder should 
give you 9 OK's. Well, it did for me... :-)

CFM notes: I'll try to hack something together over the next few days. The 
gist of it is basically going to be like it is for PPC, though.

-----------------------------------------------------------------
#!perl

# AH Sandstrom 1999
# wrapper for xsubpp
# This is beta: I welcome comments, suggestions and witticisms

use File::Basename;
use IO::File;
use Carp;
use lib 'Tallinn:MacPerl_Src:perl:lib';

fileparse_set_fstype("MacOS");
my ($name,$path,$suffix) = fileparse($ARGV[0],q!.xs!);
chdir $path;
@options = ();

# extra typemap just because of this example
$other_map = "::perlobject.map";
push(@options, ('-typemap',$other_map)) if (-f $other_map);
push(@options, '-noprototypes');
@ARGV = ($name.$suffix);
unshift(@ARGV, @options);

# create temporary file
$srcfile = new IO::File;
die "Can't open $srcfile" unless ($srcfile->open(">xstmp.c"));

# xsubpp output is to stdout
$oldfh = select($srcfile);

# no overwhelming reason for wrapping this in eval, but it doesn't hurt.
# The name is wrapped in quotes to prevent a .pm suffix from being added.
$xsubpp = "Tallinn:MacPerl_Src:perl:lib:ExtUtils:xsubpp";
unless (eval "require \"$xsubpp\"") {
   die "Couldn't run xsubpp: $@";
}

END {
   # xsubpp calls exit(), so this code needs to be in END
   select($oldfh);
   $newfile = $name.".c";
   rename("xstmp.c",$newfile);
}



***** Want to unsubscribe from this list?
***** Send mail with body "unsubscribe" to mac-perl-request@iis.ee.ethz.ch