I think the ideal way would be to have the bootstrap statement in your .pm file simply load the appropriate .dll/.so. That is, the bootstrap statement already knows where to look and what to look for depending upon which platform it is invoked on.

So, if you can make the build process only attempt to build the platform specific .xs file and put it into the right place, and if all platforms present the same interface, then the whole thing get taken care of at extension build times and there is nothing more to do.

It would certainly move a heap of messy platform-conditional stuff out of the sources. Of course, it can also create a maintanence problem with code duplication, but on the basis that only the performance critical or "only possible in C" code should be done in XS with the rest done in the .PM file, the duplication would be minimal.

Whether there is anything in the existing makefile generation processors to cater for this I'm not sure, but at the simplest of levels it could be something along the lines of having a module.xs.w32 and module.xs.nix and just copying or renaming the appropriate one to module.xs when setting up the blib.

Alternatively, since compilers already know how to do platform specific selection at compile time, it might be better to have a single module.xs and platform specific includes. It also eliminates the need for common code duplication:

// module.xs ... #if defined(WIN32) # include "module.win32"; #elseif define(MAC) # include "module.mac" #else # include "module.unix" #endif ...

Same make file; same .xs file; same .pm file; same bootstrap. Just the contents of the .dll/.so changes?

Somebody will point out that #include is for header files, and include files should be named .h, and having executable code in include files is frowned upon; but XS is a different langauge to C and it can set what rules it decides upon.


Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
"Science is about questioning the status quo. Questioning authority".
In the absence of evidence, opinion is indistinguishable from prejudice.
"Too many [] have been sedated by an oppressive environment of political correctness and risk aversion."

In reply to Re: Splitting an extension based on OS by BrowserUk
in thread Splitting an extension based on OS by syphilis

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.