From: Vadim Konovalov Date: Fri, 31 Aug 2007 08:56:47 +0000 (+0200) Subject: Add Win32 makefile option to link all extensions statically X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=a1f2e7199166cd131cf3ae57c774868eaa6d61aa;p=p5sagit%2Fp5-mst-13.2.git Add Win32 makefile option to link all extensions statically Subject: [PATCH-at31768] RE: [PATCH at 31761] RE: MakeMaker + static misbehaviour From: "Konovalov, Vadim Vladimirovich (Vadim)** CTR **" Message-ID: (with a couple of tweaks to comments in Makefile, exclusion of one more module (Hash/Utils) from the "all static" build option, plus the same changes in makefile.mk) p4raw-id: //depot/perl@31784 --- diff --git a/win32/FindExt.pm b/win32/FindExt.pm index 298b44f..b2386b1 100644 --- a/win32/FindExt.pm +++ b/win32/FindExt.pm @@ -1,6 +1,6 @@ package FindExt; -our $VERSION = '1.01'; +our $VERSION = '1.02'; use strict; use warnings; @@ -20,12 +20,18 @@ sub getcwd { return $ENV{'PWD'} = $_; } -sub set_static_extensions -{ +sub set_static_extensions { # adjust results of scan_ext, and also save # statics in case scan_ext hasn't been called yet. + # if '*' is passed then all XS extensions are static + # (with possible exclusions) %static = (); - for (@_) { + my @list = @_; + if ($_[0] eq '*') { + my %excl = map {$_=>1} map {m/^!(.*)$/} @_[1 .. $#_]; + @list = grep {!exists $excl{$_}} keys %ext; + } + for (@list) { $static{$_} = 1; $ext{$_} = 'static' if $ext{$_} && $ext{$_} eq 'dynamic'; } diff --git a/win32/Makefile b/win32/Makefile index 57426ab..0c479df 100644 --- a/win32/Makefile +++ b/win32/Makefile @@ -169,13 +169,22 @@ CRYPT_SRC = fcrypt.c # # set this to additionally provide a statically linked perl-static.exe. # Note that dynamic loading will not work with this perl, so you must -# include required modules statically using STATIC_EXT variable below. -# A static library perl59s.lib will also be created. +# include required modules statically using the STATIC_EXT or ALL_STATIC +# variables below. A static library perl59s.lib will also be created. # Ordinary perl.exe is not affected by this option. # #BUILD_STATIC = define # +# in addition to BUILD_STATIC the option ALL_STATIC makes *every* +# extension get statically built +# This will result in a very large perl executable, but the main purpose +# is to have proper linking set so as to be able to create miscellaneous +# executables with different built-in extensions +# +#ALL_STATIC = define + +# # # set the install locations of the compiler include/libraries # Running VCVARS32.BAT is *required* when using Visual C. @@ -784,9 +793,18 @@ PERLDLL_OBJ = $(PERLDLL_OBJ) $(WIN32_OBJ) $(DLL_OBJ) SETARGV_OBJ = setargv$(o) !ENDIF -# specify static extensions here +!IF "$(ALL_STATIC)" == "define" +# some exclusions, unfortunately, until fixed: +# - Win32 extension contains overlapped symbols with win32.c (BUG!) +# - MakeMaker isn't capable enough for SDBM_File (smaller bug) +# - Encode (encoding search algorithm relies on shared library?) +# - Hash/Util (fails various tests when linked statically) +STATIC_EXT = * !Win32 !SDBM_File !Encode !Hash/Util +!ELSE +# specify static extensions here, for example: #STATIC_EXT = Cwd Compress/Raw/Zlib STATIC_EXT = Win32CORE +!ENDIF DYNALOADER = $(EXTDIR)\DynaLoader\DynaLoader @@ -822,8 +840,8 @@ CFG_VARS = \ # Top targets # -all : .\config.h $(GLOBEXE) $(MINIMOD) $(CONFIGPM) $(UNIDATAFILES) $(PERLEXE) \ - $(X2P) MakePPPort Extensions $(PERLSTATIC) +all : .\config.h $(GLOBEXE) $(MINIMOD) $(CONFIGPM) $(UNIDATAFILES) MakePPPort \ + $(PERLEXE) $(X2P) Extensions $(PERLSTATIC) @echo Everything is up to date. '$(MAKE_BARE) test' to run test suite. ..\regnodes.h : ..\regcomp.sym ..\regcomp.pl ..\regexp.h @@ -1011,7 +1029,7 @@ $(PERLEXE): $(PERLDLL) $(CONFIGPM) $(PERLEXE_OBJ) $(PERLEXE_RES) $(PERLEXESTATIC): $(PERLSTATICLIB) $(CONFIGPM) $(PERLEXEST_OBJ) $(PERLEXE_RES) $(LINK32) -subsystem:console -out:$@ -stack:0x1000000 $(LINK_FLAGS) \ - @Extensions_static $(PERLSTATICLIB) \ + @Extensions_static $(PERLSTATICLIB) /PDB:NONE \ $(LIBFILES) $(PERLEXEST_OBJ) $(SETARGV_OBJ) $(PERLEXE_RES) $(EMBED_EXE_MANI) diff --git a/win32/buildext.pl b/win32/buildext.pl index 7578669..ea5f57f 100644 --- a/win32/buildext.pl +++ b/win32/buildext.pl @@ -63,8 +63,7 @@ if ($opts{'list-static-libs'} || $opts{'create-perllibst-h'}) { print $fh "#ifdef STATIC2\n",(map {" EXTERN_C void boot_$_ (pTHX_ CV* cv);\n"} @statics1),"#undef STATIC2\n#endif\n"; print $fh "#ifdef STATIC3\n",(map {" newXS(\"$statics2[$_]::bootstrap\", boot_$statics1[$_], file);\n"} 0 .. $#statics),"#undef STATIC3\n#endif\n"; close $fh; - } - else { + } else { my %extralibs; for (@statics) { open my $fh, "<..\\lib\\auto\\$_\\extralibs.ld" or die "can't open <..\\lib\\auto\\$_\\extralibs.ld: $!"; @@ -76,17 +75,14 @@ if ($opts{'list-static-libs'} || $opts{'create-perllibst-h'}) { exit(0); } -my $here = getcwd(); +(my $here = getcwd()) =~ s{/}{\\}g; my $perl = $^X; -$here =~ s,/,\\,g; -if ($perl =~ m#^\.\.#) - { - $perl = "$here\\$perl"; - } +if ($perl =~ m#^\.\.#) { + $perl = "$here\\$perl"; +} (my $topdir = $perl) =~ s/\\[^\\]+$//; # miniperl needs to find perlglob and pl2bat $ENV{PATH} = "$topdir;$topdir\\win32\\bin;$ENV{PATH}"; -#print "PATH=$ENV{PATH}\n"; my $pl2bat = "$topdir\\win32\\bin\\pl2bat"; unless (-f "$pl2bat.bat") { my @args = ($perl, ("$pl2bat.pl") x 2); @@ -100,7 +96,7 @@ my $dmod = -M $dep; my $dir = shift; chdir($dir) || die "Cannot cd to $dir\n"; my $targ = shift; -(my $ext = getcwd()) =~ s,/,\\,g; +(my $ext = getcwd()) =~ s{/}{\\}g; my $code; FindExt::scan_ext($ext); FindExt::set_static_extensions(split ' ', $Config{static_ext}) if $ext ne "ext"; diff --git a/win32/makefile.mk b/win32/makefile.mk index df032e1..fc0a2f7 100644 --- a/win32/makefile.mk +++ b/win32/makefile.mk @@ -187,13 +187,22 @@ CRYPT_SRC *= fcrypt.c # # set this to additionally provide a statically linked perl-static.exe. # Note that dynamic loading will not work with this perl, so you must -# include required modules statically using STATIC_EXT variable below. -# A static library perl59s.lib will also be created. +# include required modules statically using the STATIC_EXT or ALL_STATIC +# variables below. A static library perl59s.lib will also be created. # Ordinary perl.exe is not affected by this option. # #BUILD_STATIC *= define # +# in addition to BUILD_STATIC the option ALL_STATIC makes *every* +# extension get statically built +# This will result in a very large perl executable, but the main purpose +# is to have proper linking set so as to be able to create miscellaneous +# executables with different built-in extensions +# +#ALL_STATIC *= define + +# # set the install locations of the compiler include/libraries # Running VCVARS32.BAT is *required* when using Visual C. # Some versions of Visual C don't define MSVCDIR in the environment, @@ -940,9 +949,18 @@ PERLDLL_OBJ += $(WIN32_OBJ) $(DLL_OBJ) SETARGV_OBJ = setargv$(o) .ENDIF -# specify static extensions here +.IF "$(ALL_STATIC)" == "define" +# some exclusions, unfortunately, until fixed: +# - Win32 extension contains overlapped symbols with win32.c (BUG!) +# - MakeMaker isn't capable enough for SDBM_File (smaller bug) +# - Encode (encoding search algorithm relies on shared library?) +# - Hash/Util (fails various tests when linked statically) +STATIC_EXT = * !Win32 !SDBM_File !Encode !Hash/Util +.ELSE +# specify static extensions here, for example: #STATIC_EXT = Cwd Compress/Raw/Zlib STATIC_EXT = Win32CORE +.ENDIF DYNALOADER = $(EXTDIR)\DynaLoader\DynaLoader @@ -1010,8 +1028,8 @@ ODBCCP32_DLL = $(windir)\system\odbccp32.dll # all : CHECKDMAKE .\config.h $(GLOBEXE) $(MINIPERL) $(MK2) \ - $(RIGHTMAKE) $(MINIMOD) $(CONFIGPM) $(UNIDATAFILES) $(PERLEXE) \ - $(X2P) MakePPPort Extensions $(PERLSTATIC) + $(RIGHTMAKE) $(MINIMOD) $(CONFIGPM) $(UNIDATAFILES) MakePPPort \ + $(PERLEXE) $(X2P) Extensions $(PERLSTATIC) ..\regnodes.h : ..\regcomp.sym ..\regcomp.pl ..\regexp.h cd .. && regcomp.pl && cd win32 @@ -1341,7 +1359,7 @@ $(PERLEXESTATIC): $(PERLSTATICLIB) $(CONFIGPM) $(PERLEXEST_OBJ) $(PERLEXE_RES) $(PERLEXE_RES) $(LKPOST)) .ELSE $(LINK32) -subsystem:console -out:$@ -stack:0x1000000 $(BLINK_FLAGS) \ - @Extensions_static $(PERLSTATICLIB) \ + @Extensions_static $(PERLSTATICLIB) /PDB:NONE \ $(LIBFILES) $(PERLEXEST_OBJ) $(SETARGV_OBJ) $(PERLEXE_RES) $(EMBED_EXE_MANI) .ENDIF