Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??

First things first

The code is the major thing. The code is what the reader should try running* and try reading in order to understand the issues that I've addressed. The following links are current as of Wed Jan 16 11:08:42 UTC 2008 and point to different kinds of archives of the same source code kit, a tarball and a zipfile:

Please check the website containing directory first for more recent updates before downloading the files above, would be my advice.

* Try running $ perl Makefile.PL verbose — use the verbose flag.

Required Reading

The CPAN module Request Tracker (RT) ticket connected to this coding effort is bug 32123.

Background on ExtUtils::MakeMaker

Documentation for the release of EUMM's MM_Unix.pm current as of this writing: ExtUtils/MM_Unix.pm

In all that follows, EUMM (a.k.a EU::MM) is used as a widely-known abbreviation for the ExtUtils::MakeMaker namespace and its sub-modules.

The notion at work in EUMM is code generation, where the type of "code" being emitted is the declarative syntax understood by `make'. The job of creating a Makefile was divided up into discreet methods, each of which would be responsible for a single section of the final Makefile. When "overrides" are mentioned, I am referring to the fact that about 60% of the methods for producing sections of Makefile were designed to be "overridden" so that special-case platforms (like ms windows) could be accommodated, or other special case scenarios could be achieved. The default methods live, appropriately, in the namespace ExtUtils::MM_Unix; this could be seen as "appropriate" since Unix is where Perl was born, and is such a (in many ways) standardized and widely-deployed family of OSes (as the famous footnote in the Camel puts it: "Assuming that you agree that Unix is both standard and fashionable" ;-).

In the ExtUtils/MM_Unix.pm module documentation mentioned above, a symbol (o) next to the name of the method is used to indicate that the method is one of the overridable ones. Methods lacking this mark do not have the automatic support for overriding; they were assumed to be doing parts of the Makefile text that would be invariant.

ExtUtils::MakeMaker Issues Addressed in this Work

The dlltool conundrum on mswin32.mingw

I was focused in this effort on the case wherein the platform OS is MS Windows and the "subplatform" is defined by the GNU toolset provided by the volunteer MinGW project, which includes the GNU Compiler Collection (GCC). Another example of a subplatform of MS Windows would be the VisualStudio 2008 from Microsoft. GCC, being free (in both senses) and standard across many types of systems, is a particularly attractive choice for those not employed at a workplace that provides and enforces the use of a proprietary commercial C compiler toolchain.

When the default EUMM -based Makefile.PL is run in the case of a C extension module like XML::Parser::Expat (the backend to XML::Parser), there is a section of Makefile code "emitted" by the method named ExtUtils::MM_Win32::dynamic_lib. This section of Makefile text includes a make rule (recipe) for building the dynamic lib (relocateable object code) or DLL which implements the C part of the extension. The rule will cause make to do the invocation of a program called dlltool which hasn't been required for most uses of mingw for many years now. It's obsolete code that targets a generation of mingw which is, in F/LOSS terms, practically ancient history.

One improvement I sought in writing the reworked build support for XML::Parser was the elimination of the baroque, little-understood, time consuming and unneeded invocation of dlltool in favor of a cleaner, up to date and more understandable direct creation of the DLL through invoking gcc. This way of calling gcc is much more congruent with the operation of gcc on Unix-like platforms that are familiar to many users with some background in compiling C code — like GNU/Linux.

The override that does the change to this method dynamic_lib() is located (at present) in the file hints/mswin32.pl in the source kit tree you'll get when you unpack one of the archives listed above. But please note that this way of overridding this method is not customary or best!. It was done in this way and in this file due to the particular unique process I went though of writing the overall refactoring, and may be moved out and done in a different (and better) way later.

Here's the excerpt from that file: the code that implements the overridden method (with comments as they appear in the source):

package ExtUtils::MM_Win32; # clobber this one with extreme prejudice because of the gawd-awfu +l bs # it is, for thinking that mingw gcc is still this clunky. sub dynamic_lib { my($self, %attribs) = @_; return '' unless $self->needs_linking(); #might be because + of a subdir return '' unless $self->has_link_code; my($otherldflags) = $attribs{OTHERLDFLAGS}; my($inst_dynamic_dep) = $attribs{INST_DYNAMIC_DEP} || ""; my($ldfrom) = '$(LDFROM)'; my $tabchar = "\t"; my(@m); my $dllname = $self->{BASEEXT} . "." . $self->{DLEXT}; $dllname =~ /(....)(.{0,4})/; my $baseaddr = unpack("n", $1 ^ $2); $otherldflags .= sprintf("-Wl,--image-base,0x%x0000 ", $ba +seaddr); push(@m,' # This section creates the dynamically loadable $(INST_DYNAMIC) # (ms windows DLL file) from $(OBJECT) and possibly $(MYEXTLIB). OTHERLDFLAGS =' .($otherldflags ? " $otherldflags" : "") +.' INST_DYNAMIC_DEP =' .($inst_dynamic_dep ? " $inst_dynamic_dep" : "") +.' $(INST_DYNAMIC): $(OBJECT) $(MYEXTLIB) $(BOOTSTRAP) \ $(INST_ARCHAUTODIR)$(DFSEP).exists \ $(PERL_ARCHIVE) $(INST_DYNAMIC_DEP) '); push(@m, $tabchar, q{$(CC) -o $@ $(LDDLFLAGS) } . $ldfrom ." \\\n" . q{ $(OTHERLDFLAGS) $(MYEXTLIB) $(PERL_ARCHIVE) $(LDLO +ADLIBS) } ); # return our assembled Makefile text: join('',@m); } # END of sub

One thing of note is that the sub above is just Perl. Where there are strings that look like Makefile text, they are just Perl scalar strings. There is no "source filtering" or other eldritch magic going on here, merely using Perl to manipulated text, something that Perl is reputed to be rather good at ;-).

The override imposed on this section-builder method replaces an invocation that looks like this:

dlltool --def Expat.def --output-exp dll.exp
(a first invocation of dlltool, echo'd by make, followed by the commandline dlltool echos)
g++ -o ..\blib\arch\auto\XML\Parser\Expat\Expat.dll -Wl,--base-file -Wl,dll.base -mdll -s -LE:/perls/Strawberry_Perl_510_0/perl/lib/CORE -LE:/StPerl_Bundled_mingw/lib Expat.o -Wl,--image-base,0x31560000  C:\strawberry\perl\lib\CORE\libperl510.a E:\StPerl_Bundled_mingw\lib\libexpat.a E:\StPerl_Bundled_mingw\lib\libmsvcrt.a E:\StPerl_Bundled_mingw\lib\libmoldname.a E:\StPerl_Bundled_mingw\lib\libkernel32.a E:\StPerl_Bundled_mingw\lib\libuser32.a E:\StPerl_Bundled_mingw\lib\libgdi32.a E:\StPerl_Bundled_mingw\lib\libwinspool.a E:\StPerl_Bundled_mingw\lib\libcomdlg32.a E:\StPerl_Bundled_mingw\lib\libadvapi32.a E:\StPerl_Bundled_mingw\lib\libshell32.a E:\StPerl_Bundled_mingw\lib\libole32.a E:\StPerl_Bundled_mingw\lib\liboleaut32.a E:\StPerl_Bundled_mingw\lib\libnetapi32.a E:\StPerl_Bundled_mingw\lib\libuuid.a E:\StPerl_Bundled_mingw\lib\libws2_32.a E:\StPerl_Bundled_mingw\lib\libmpr.a E:\StPerl_Bundled_mingw\lib\libwinmm.a E:\StPerl_Bundled_mingw\lib\libversion.a E:\StPerl_Bundled_mingw\lib\libodbc32.a E:\StPerl_Bundled_mingw\lib\libodbccp32.a dll.exp dlltool --def Expat.def --base-file dll.base --output-exp dll.exp
(a second invocation of dlltool, echo'd by make, followed by the commandline dlltool echos)
g++ -o ..\blib\arch\auto\XML\Parser\Expat\Expat.dll -mdll -s -LE:/perls/Strawberry_Perl_510_0/perl/lib/CORE -LE:/StPerl_Bundled_mingw/lib Expat.o -Wl,--image-base,0x31560000  C:\strawberry\perl\lib\CORE\libperl510.a E:\StPerl_Bundled_mingw\lib\libexpat.a E:\StPerl_Bundled_mingw\lib\libmsvcrt.a E:\StPerl_Bundled_mingw\lib\libmoldname.a E:\StPerl_Bundled_mingw\lib\libkernel32.a E:\StPerl_Bundled_mingw\lib\libuser32.a E:\StPerl_Bundled_mingw\lib\libgdi32.a E:\StPerl_Bundled_mingw\lib\libwinspool.a E:\StPerl_Bundled_mingw\lib\libcomdlg32.a E:\StPerl_Bundled_mingw\lib\libadvapi32.a E:\StPerl_Bundled_mingw\lib\libshell32.a E:\StPerl_Bundled_mingw\lib\libole32.a E:\StPerl_Bundled_mingw\lib\liboleaut32.a E:\StPerl_Bundled_mingw\lib\libnetapi32.a E:\StPerl_Bundled_mingw\lib\libuuid.a E:\StPerl_Bundled_mingw\lib\libws2_32.a E:\StPerl_Bundled_mingw\lib\libmpr.a E:\StPerl_Bundled_mingw\lib\libwinmm.a E:\StPerl_Bundled_mingw\lib\libversion.a E:\StPerl_Bundled_mingw\lib\libodbc32.a E:\StPerl_Bundled_mingw\lib\libodbccp32.a dll.expwith one that looks like this:
gcc -o blib\arch\auto\XML\Parser\Expat\Expat.dll -mdll -s -LE:/perls/S +trawberry_Perl_510_0/perl/lib/CORE -LE:/StPerl_Bundled_mingw/lib -O2 +-mconsole -Wl,-export-all-symbols,-output-def,XML_Parser_Expat.def,-o +ut-implib,XML_Parser_Expat.dll.a Expat.o \ -Wl,--image-base,0x35130000 C:\strawberry\perl\lib\CORE/libperl510.a + e:/stperl_bundled_mingw/lib/libexpat.a e:/StPerl_Bundled_mingw/lib/l +ibgdi32.a e:/StPerl_Bundled_mingw/lib/libwinspool.a e:/StPerl_Bundled +_mingw/lib/libcomdlg32.a e:/StPerl_Bundled_mingw/lib/libole32.a e:/St +Perl_Bundled_mingw/lib/liboleaut32.a e:/StPerl_Bundled_mingw/lib/libn +etapi32.a e:/StPerl_Bundled_mingw/lib/libuuid.a e:/StPerl_Bundled_min +gw/lib/libws2_32.a e:/StPerl_Bundled_mingw/lib/libmpr.a e:/StPerl_Bun +dled_mingw/lib/libwinmm.a e:/StPerl_Bundled_mingw/lib/libversion.a e: +/StPerl_Bundled_mingw/lib/libodbc32.a e:/StPerl_Bundled_mingw/lib/lib +odbccp32.a Creating library file: XML_Parser_Expat.dll.a

I've inserted extra newlines in a couple of places in a futile attempt to make this console output more parseable to the human eye. But notice that the operations called for in the second instance involve less text and a single invocation of gcc.


Future elaboration

There might be more discussion of this patch later. At the time that I started writing this meditation I was not interested enough in teaching anyone anything due to the fatigue I'm experiencing after combining the coding effort with the effort to stay in touch with some of the other Perl authors involved. Such efforts included trying to contact a certain person at a known hangout (#p5p at irc - perl -org) and encountering the borderline psychosis so common among the current set of p5p personalities ... so please vote according to your displeasure at not finding more content here or at having the social club you identify with being insulted (or at neither of the above).


    Soren A / somian / perlspinr / Intrepid

-- 
Words can be slippery, so consider carefully who speaks as well as what is said; know as much as you can about the total context of the speaker's participation in a forum over time, before deciding that you fully comprehend the intention behind those words. If in doubt, ask for clarification before you 'flame'.

In reply to UnBefuzzling XML::Parser: an adventure with EU::MM method overrides by Intrepid

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



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others cooling their heels in the Monastery: (4)
As of 2024-04-20 00:55 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found