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

[MacPerl] Should h2xs work for MacPerl? [LONG PRELUDE!]



Howdy:

  In my continuing effort to learn how to compile XS's for MacPerl, I think
I have figured out the following:

A) I know of four ways in which C code can be used from within Perl:

   1) Perl in general and MacPerl specifically know how to access
dynamically linked libraries, and C compilers in general can generate them.
Thus, I assume if you really, really know what you are doing, you can write
a dynamic library module in C entirely by hand that will have the proper
interface to be called from Perl.  Any Perl script that wants to call this
library, however, will have to know all about it.  If you wrote such a
thing for general use, you probably would write a module in Perl (.pm)
which knew about your custom library so that normal mortals could access
your library in standard Perl ways via that module.

One might expect that the above process could and should be automated, and
it has been:

   2) There is a package called SWIG which automates this this process.
All I know about it is what I have read in "Advanced Perl Programming".

   3) There is a similar package is called XS.  The most important thing
about XS, to my mind, is that it is the standard form for C extensions used
in CPAN.  More about XS below.

   4) In MacPerl, there is at least one more option: the HyperCard-derived
.XFCN.  As I understand it, MacPerl specifically (e.g. this is a Mac only
feature not present in Perl in general) has the hooks to call an .XFCN, in
the same way HyperCard does.  The disadvantage of using an .XFCN is that it
is a Mac only solution.  The advantage of this is that there is a huge
number of extremely useful .XFCN files out there.  (BTW, the butler.pm
package which receives periodic mention here is built on top of an .XFCN
which is part of the Butler package.)

Because the XS system is the Perl, CPAN standard, that is what I am
currently trying to learn.

B) I think I know of two ways to use the XS system.

   1) The Perl MakeMaker system, given at least three files (Makefile.PL,
foobar.xs, and foobar.pm, and maybe some header and c files), will build
the appropriate dynamic library on your system.  My understanding is that
this is what you will find on CPAN, making this an invaluable approach to
have working.  On many Unix systems (including my RedHat Linux computer)
this works right out of the box.  On a Mac, it appears still to be deep
magic.  One path I am taking is to figure out how to make this work.
Fortunately, an intrepid pioneer has gone ahead of me; Arved Sandstrom, and
he is helping me on my journey.

   2) The XS package actually consists of (at least) two programs: h2xs,
which given a header file for a C program, will create foobar.xs.  xsubpp
will take that file and create the foobar.pm file and the c code for the
glue needed to match your C code to perl.  This is the approach used when
you DEVELOP an XS, and I am also pursuing this path, which brings me to my
question:

I can't get h2xs (which looks like a shell script that mostly calls a Perl
script) to run on a Mac.  Is that expected?  If so, is there a solution out
there, or should I roll my own?

THANKS!

-David-

p.s. Arved and I have talked about creating a beginners guide to XS on the
Mac.  Thus, any corrections to the above will be gratefully accepted.

David Steffen, Ph.D.
President, Biomedical Computing, Inc. <http://www.biomedcomp.com/>
Phone: (713) 610-9770 FAX: (713) 610-9769 E-mail: steffen@biomedcomp.com



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