Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw
 
PerlMonks  

Re^2: How to properly use ExtUtils::MakeMaker PL_FILES attribute?

by glasswalk3r (Friar)
on May 27, 2017 at 01:26 UTC ( [id://1191335]=note: print w/replies, xml ) Need Help??


in reply to Re: How to properly use ExtUtils::MakeMaker PL_FILES attribute?
in thread How to properly use ExtUtils::MakeMaker PL_FILES attribute?

I've yet to see a single module where it makes sense for it to be generated before the user tries to install it -- the author is supposed to do that before he uploads the distribution

See Linux::NFS::BigDir.

But, here's the secret, MyModuleGenerator(); WriteMakefile...

That will not work: I have declared prereqs that I need to generate the module. After Makefile.PL is executed, I should have them available and then the related code requires to have constant from C header files, which I can't (easily) figure out where they are (h2ph doesn't work properly).

So, short long story, I can't have Makefile.PL doing that for me (can't use or require something that is declared as a prereqs and is still not available).

I tried using the .PL file, but it is not generating the module (output) as implied here and it's running after the pm_to_lib.

I'm starting considering using Module::Build instead...

Alceu Rodrigues de Freitas Junior
---------------------------------
"You have enemies? Good. That means you've stood up for something, sometime in your life." - Sir Winston Churchill

Replies are listed 'Best First'.
Re^3: How to properly use ExtUtils::MakeMaker PL_FILES attribute?
by syphilis (Archbishop) on May 27, 2017 at 03:21 UTC
    I should have them available and then the related code requires to have constant from C header files, which I can't (easily) figure out where they are (h2ph doesn't work properly

    It's quite possible that I underestimate the complexity of the problem.
    1) Can't the PL file that generates the module place it in blib (creating the 'blib' directory if it's not already existent)?
    2) If the C header files are not found by default, then surely it's up to the user to make them locatable - eg by setting the relevant environment variable, or providing INC arg to Makefile.PL.

    Cheers,
    Rob
      1) Can't the PL file that generates the module place it in blib (creating the 'blib' directory if it's not already existent)?
      I tried that. The PL files (which I call build_my_module.PL from now on) is executed after the pm_to_files phase. I was able to open the related PM files, append information to it and close it, but this was too late since a copy (without the parts I need) was already put on 'blib'. I can write over there too, just will need to set right permissions, write, set read-only permissions again. But looks like a hack after all. I didn't get what the documentation says about "PL output is suppose to be used to the given parameter". Printing the output to STDOUT doesn't produce the expected results, and looking at the Makefile (which calls the script with a perl build_my_module.PL, returning data wouldn't do either. I'm explicit using open for that.
      2) If the C header files are not found by default, then surely it's up to the user to make them locatable - eg by setting the relevant environment variable, or providing INC arg to Makefile.PL.

      There is a long discussion about this on the CPAN Testers mailing list, but from it I have the following conclusions:

      1. These constants will change depending on processor architecture
      2. Best way to achieve the right header file is using the C compiler itself, since h2ph doesn't quite work (at least not in Ubuntu). So, to make it clear, I don't need the C compiler really, but I need it to grab me the correct constant value to use with syscall.

      Another possibility is to create a hash with the keys being the architecture and the values the related constants, but this is a hack and there is no telling when it is going to be broken.

      Alceu Rodrigues de Freitas Junior
      ---------------------------------
      "You have enemies? Good. That means you've stood up for something, sometime in your life." - Sir Winston Churchill
Re^3: How to properly use ExtUtils::MakeMaker PL_FILES attribute?
by Anonymous Monk on May 27, 2017 at 05:34 UTC

    can't use or require something that is declared as a prereqs and is still not available).

    Yes you can, thats what META files are for, you simply tell writemakefile the depends, when you make dist METAL files are generated, then when user try to install cpan/cpanp/cpanm notice from metal files what the "BUILD_REQUIRES" ...

      Yes you can, thats what META files are for, you simply tell writemakefile the depends, when you make dist METAL files are generated, then when user try to install cpan/cpanp/cpanm notice from metal files what the "BUILD_REQUIRES" ...

      Not sure if this would work, specially because the distribution already generates the mentioned files (see here). Check out this test result too. I made a stupid mistake when trying to avoid calling Inline at each call, I just need to execute it once and write the constant elsewhere. But doing that inside the Makefile.PL is not an option... I could have used require inside a eval block to trap the exception, but then the module wouldn't be created anyway. The cpan client will search and install dependencies right after the Makefile.PL is executed, but then it is too late to use it for the code generation.

      A ".PL" file (as described by ExtUtils::MakeMaker) would be the best option, if I could control when it will be executed...

      Alceu Rodrigues de Freitas Junior
      ---------------------------------
      "You have enemies? Good. That means you've stood up for something, sometime in your life." - Sir Winston Churchill
Re^3: How to properly use ExtUtils::MakeMaker PL_FILES attribute?
by Anonymous Monk on May 27, 2017 at 05:31 UTC

    See Linux::NFS::BigDir.

    Is that the module you're working on?

    How often in the past 20 years has that number you're fetching from the header changed? It should be easy to lookup

    Instead of generating a throwaway module so you can inline a constant, you should be generate a data file, using the "official" way for data files File::ShareDir / File::ShareDir::Install ...

      See Linux::NFS::BigDir. Is that the module you're working on?

      Yes, I'm the author of Linux::NFS::BigDir.

      How often in the past 20 years has that number you're fetching from the header changed? It should be easy to lookup

      If I could rely on h2ph, yes, but I can't. Linux distributions have a variation of locations there they think it the best way to keep C header files. On the other hand, they don't distribute broken C libraries, so it is safe to assume I can use it to get the constant.

      Instead of generating a throwaway module so you can inline a constant, you should be generate a data file, using the "official" way for data files File::ShareDir / File::ShareDir::Install

      That will probably give me a maintenance headache: we just need a new processor coming up or anything else that justify changing that constant.

      Alceu Rodrigues de Freitas Junior
      ---------------------------------
      "You have enemies? Good. That means you've stood up for something, sometime in your life." - Sir Winston Churchill

        If I could rely on h2ph, yes, but I can't. Linux distributions have a variation of locations there they think it the best way to keep C header files. On the other hand, they don't distribute broken C libraries, so it is safe to assume I can use it to get the constant.

        Um, no, thats not what I'm talking about. Header files are created by humans, they're source code. In big projects, like gui libraries, mfc, wxwidgets, header numbers do not change ever, for 5/10/15/20 years and more. New headers get added. Old numbers do not change.

        I'm not suggesting you use h2ph , I'm suggesting you use your eyes, track down every copy of the header file that ever existed, like in some kind of git repository, and compare the number today to the number it was 50 years ago

        Do it for all "official" source code repository that manages this header file

        Its like, you're not compiling/interfacing any c/xs code -- headers are just #define ... that stuff doesn't change :)

        That will probably give me a maintenance headache: we just need a new processor coming up or anything else that justify changing that constant.

        Hehe, um, no, that is not a maintenance headache, you just keep doing exactly what you're doing right this moment, except instead of Inline ... in Makefile.PL, only so you can insert sub CONSTANT(){12} into Foo.pm, all you do is have Foo.pm read from foo-dist/constant.txt when its loaded

        Its like h2ph, you require "constants.ph" or whatever, you don't inline the source of constants.ph into your module.pm

        Its like how much time you want to spend figuring out your makemaker for a single solitary constant

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1191335]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others having a coffee break in the Monastery: (4)
As of 2024-04-25 07:54 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found