cdarke has asked for the wisdom of the Perl Monks concerning the following question:

This may have been dicussed in cb, but I missed it. Apologies for the diversion.

I have some Win32 modules that use a custom build step. In Makefile.PL I have a postamble subroutine with the custom steps in. I can compile using Visual Studio, and I can compile using gcc, but they require different options (specifically it is the /link or -shared options that are the problem). What I can't figure out it how to arrange things so that it builds a sensible Makefile for either compiler in use.

I can try loading gcc or cl.exe to see which is in the path, but (aside from it being ugly) the 'make' might run in a different environment to the Makefile.PL.

Suggestions will be gratefully recieved.
  • Comment on Makemaker on Win32 - different compiler options

Replies are listed 'Best First'.
Re: Makemaker on Win32 - different compiler options
by Corion (Patriarch) on May 12, 2008 at 09:58 UTC

    Don't try to guess by the things in $ENV{PATH} - use Config. $Config{cc} has whatever C compiler should be used, $Config{make} has whatever make program should be used.

    As you don't show any code, I can only give you vague and general hints. You will have to output different postambles depending on the type of make program (nmake, make, dmake), as they all use a different syntax. You will also have to set the CFLAGS variable depending on whether you need -shared or /link.

Re: Makemaker on Win32 - different compiler options
by syphilis (Archbishop) on May 13, 2008 at 08:38 UTC
    ... the 'make' might run in a different environment to the Makefile.PL

    I don't understand what you're getting at with that remark. Usually on Win32, you don't have to concern yourself with the flavour of make that's being used. If $Config{make} is dmake, then perl Makefile.PL will write a dmake-compatible makefile (and the same goes for nmake). Anybody who's using something other than dmake or nmake is "on their own".

    As you've found, you do need to concern yourself with the flavour of compiler that's being used. If you know how to code for both cl and gcc, and if you take Corion's advice of relying on $Config{cc}, then that problem should be solved. (Admittedly there are other compilers that can be used on Win32. I'd wait for bug reports from users of those compilers before concerning myself with them.)

    Cheers,
    Rob