Re: XS_FILES, H_FILES, C_FILES Makefile target
On Thu, Aug 01, 2002 at 06:22:08PM +0800, Stas Bekman wrote: do we have some place where this trick (technique) can be documented? I'll submit a patch. or should we start something like perlmmtut.pod? where this kind of tricks can go to? Starting ExtUtils::MakeMaker::FAQ would be nice. -- Michael G. Schwern [EMAIL PROTECTED]http://www.pobox.com/~schwern/ Perl Quality Assurance [EMAIL PROTECTED] Kwalitee Is Job One Consistency? I'm sorry, Sir, but you obviously chose the wrong door. -- Jarkko Hietaniemi in [EMAIL PROTECTED]
Re: XS_FILES, H_FILES, C_FILES Makefile target
Michael G Schwern wrote: On Thu, Aug 01, 2002 at 06:22:08PM +0800, Stas Bekman wrote: do we have some place where this trick (technique) can be documented? I'll submit a patch. or should we start something like perlmmtut.pod? where this kind of tricks can go to? Starting ExtUtils::MakeMaker::FAQ would be nice. Please find the attached FAQ.pod. __ Stas BekmanJAm_pH -- Just Another mod_perl Hacker http://stason.org/ mod_perl Guide --- http://perl.apache.org mailto:[EMAIL PROTECTED] http://use.perl.org http://apacheweek.com http://modperlbook.org http://apache.org http://ticketmaster.com package ExtUtils::MakeMaker::FAQ; our $VERSION = '0.01'; 1; __END__ =head1 NAME ExtUtils::MakeMaker::FAQ - Frequently Asked Questions About MakeMaker =head1 SYNOPSIS =head1 DESCRIPTION Document tips and tricks for CExtUtils::MakeMaker. =head1 How to Make Two and More XS files Coexist In The Same Directory? Sometimes you need to have two and more XS files in the same package. One way to go is to put them into separate directories, but sometimes this is not the most suitable solution. The following technique allows you to put two (and more) XS files in the same directory. Let's assume that we have a package CCool::Foo, which includes CCool::Foo and CCool::Bar modules each having a separate XS file. First we use the following IMakefile.PL: use ExtUtils::MakeMaker; WriteMakefile( NAME = 'Cool::Foo', VERSION_FROM = 'Foo.pm', OBJECT = q/$(O_FILES)/, # ... other attrs ... ); Notice the COBJECT attribute. MakeMaker generates the following variables in IMakefile: # Handy lists of source code files: XS_FILES= Bar.xs \ Foo.xs C_FILES = Bar.c \ Foo.c O_FILES = Bar.o \ Foo.o Therefore we can use the CO_FILES variable to tell MakeMaker to use these objects into the shared library. That's pretty much it. Now write IFoo.pm and IFoo.xs, IBar.pm and IBar.xs, where IFoo.pm bootstraps the shared library and IBar.pm simply loading IFoo.pm. The only issue left is to how to bootstrap IBar.xs. This is done from IFoo.xs: MODULE = Cool::Foo PACKAGE = Cool::Foo BOOT: # boot the second XS file boot_Cool__Bar(aTHX_ cv); If you have more than two files, this is the place where you should boot extra XS files from. The following four files sum up all the details discussed so far. Foo.pm: --- package Cool::Foo; require DynaLoader; our @ISA = qw(DynaLoader); our $VERSION = '0.01'; bootstrap Cool::Foo $VERSION; 1; Bar.pm: --- package Cool::Bar; use Cool::Foo; # bootstraps Bar.xs 1; Foo.xs: --- #include EXTERN.h #include perl.h #include XSUB.h MODULE = Cool::Foo PACKAGE = Cool::Foo BOOT: # boot the second XS file boot_Cool__Bar(aTHX_ cv); MODULE = Cool::Foo PACKAGE = Cool::Foo PREFIX = cool_foo_ void cool_foo_perl_rules() CODE: fprintf(stderr, Cool::Foo says: Perl Rules\n); Bar.xs: --- #include EXTERN.h #include perl.h #include XSUB.h MODULE = Cool::Bar PACKAGE = Cool::Bar PREFIX = cool_bar_ void cool_bar_perl_rules() CODE: fprintf(stderr, Cool::Bar says: Perl Rules\n); And of course a very basic test: test.pl: use Test; BEGIN { plan tests = 1 }; use Cool::Foo; use Cool::Bar; Cool::Foo::perl_rules(); Cool::Bar::perl_rules(); ok 1; This tip has been brought to you by Nick Ing-Simmons and Stas Bekman. =head1 AUTHOR =head1 SEE ALSO perl(3) =cut
Re: XS_FILES, H_FILES, C_FILES Makefile target
Stas Bekman [EMAIL PROTECTED] writes: Multiple .xs files in a directory used to at least sort-of-work. The problem was that you needed a custom BOOT: {} section in at least one to load the others. The problem is before the loading. How do you write Makefile.PL so it'll create the right rules for Makefile to do all the xs2c conversion. You don't need to do anything: nick@bactrian 1010$ cd /tmp/Thing nick@bactrian 1011$ touch Foo.xs Bar.xs nick@bactrian 1012$ perl -MExtUtils::MakeMaker -e 'WriteMakefile()' Warning: Guessing NAME [Thing] from current directory name. Writing Makefile for Thing Gives: # Handy lists of source code files: XS_FILES= Bar.xs \ Foo.xs C_FILES = Bar.c \ Foo.c O_FILES = Bar.o \ Foo.o So all you need is the normal OBJECT = '$(O_FILES)' that anything with multiple .o files needs. I know that you need to override some My:: methods, but this is a big kludge as I couldn't find any module doing that (which is how I usually learn about MM untold magic) and the docs weren't tell me :( So I thought that the XS attribute is the perfect fit for doing the work for you. You provide a hash in the form .xs = .c and voila Makemaker does the right thing. __ Stas BekmanJAm_pH -- Just Another mod_perl Hacker http://stason.org/ mod_perl Guide --- http://perl.apache.org mailto:[EMAIL PROTECTED] http://use.perl.org http://apacheweek.com http://modperlbook.org http://apache.org http://ticketmaster.com -- Nick Ing-Simmons http://www.ni-s.u-net.com/
Re: XS_FILES, H_FILES, C_FILES Makefile target
Stas Bekman [EMAIL PROTECTED] writes: So all you need is the normal OBJECT = '$(O_FILES)' that anything with multiple .o files needs. yay, why things are always so simple when somebody tells you how ;) I've added : BOOT: # boot the second XS file boot_Bar(); boot_Bar() is an XS() so it expects some args I think boot_Bar(aTHX_ cv); Will suffice - it will pass wrong CV *, but that is unlikely to matter. However for MULTIPLICITY (or threads) the aTHX_ will ensure a my_perl is passed. to Foo.xs and it all worked! Thanks Nick! do we have some place where this trick (technique) can be documented? I'll submit a patch. or should we start something like perlmmtut.pod? where this kind of tricks can go to? __ Stas BekmanJAm_pH -- Just Another mod_perl Hacker http://stason.org/ mod_perl Guide --- http://perl.apache.org mailto:[EMAIL PROTECTED] http://use.perl.org http://apacheweek.com http://modperlbook.org http://apache.org http://ticketmaster.com -- Nick Ing-Simmons http://www.ni-s.u-net.com/
Re: XS_FILES, H_FILES, C_FILES Makefile target
Nick Ing-Simmons wrote: Stas Bekman [EMAIL PROTECTED] writes: So all you need is the normal OBJECT = '$(O_FILES)' that anything with multiple .o files needs. yay, why things are always so simple when somebody tells you how ;) I've added : BOOT: # boot the second XS file boot_Bar(); boot_Bar() is an XS() so it expects some args I think boot_Bar(aTHX_ cv); Will suffice - it will pass wrong CV *, but that is unlikely to matter. However for MULTIPLICITY (or threads) the aTHX_ will ensure a my_perl is passed. Hmm, funny but it did work without this addition with ithreads-enabled perl. But I've added the args as you've suggested. Thanks Nick! __ Stas BekmanJAm_pH -- Just Another mod_perl Hacker http://stason.org/ mod_perl Guide --- http://perl.apache.org mailto:[EMAIL PROTECTED] http://use.perl.org http://apacheweek.com http://modperlbook.org http://apache.org http://ticketmaster.com
Re: XS_FILES, H_FILES, C_FILES Makefile target
Nick Ing-Simmons wrote: Stas Bekman [EMAIL PROTECTED] writes: Hi Michael, As discussed at OSC I'm sending a heads-up on XS, C and H, MM attributes, which currently do nothing but create the corresponding *_FILES targets in Makefile, used in the cleanup. Would be great if the XS attribute would actually allow supporting of more than one .xs file in each directory. Multiple .xs files in a directory used to at least sort-of-work. The problem was that you needed a custom BOOT: {} section in at least one to load the others. The problem is before the loading. How do you write Makefile.PL so it'll create the right rules for Makefile to do all the xs2c conversion. I know that you need to override some My:: methods, but this is a big kludge as I couldn't find any module doing that (which is how I usually learn about MM untold magic) and the docs weren't tell me :( So I thought that the XS attribute is the perfect fit for doing the work for you. You provide a hash in the form .xs = .c and voila Makemaker does the right thing. __ Stas BekmanJAm_pH -- Just Another mod_perl Hacker http://stason.org/ mod_perl Guide --- http://perl.apache.org mailto:[EMAIL PROTECTED] http://use.perl.org http://apacheweek.com http://modperlbook.org http://apache.org http://ticketmaster.com
XS_FILES, H_FILES, C_FILES Makefile target
Hi Michael, As discussed at OSC I'm sending a heads-up on XS, C and H, MM attributes, which currently do nothing but create the corresponding *_FILES targets in Makefile, used in the cleanup. Would be great if the XS attribute would actually allow supporting of more than one .xs file in each directory. Thanks. __ Stas BekmanJAm_pH -- Just Another mod_perl Hacker http://stason.org/ mod_perl Guide --- http://perl.apache.org mailto:[EMAIL PROTECTED] http://use.perl.org http://apacheweek.com http://modperlbook.org http://apache.org http://ticketmaster.com