|
1 | 1 | #!/usr/bin/perl -w
|
2 | 2 | # -*- mode: perl; -*-
|
3 |
| -# $Id: libtool_win32.pl,v 1.10 2023/12/26 17:01:00 cvsuser Exp $ |
| 3 | +# $Id: libtool_win32.pl,v 1.11 2025/02/01 19:57:27 cvsuser Exp $ |
4 | 4 | # libtool emulation for WIN32 builds.
|
5 | 5 | #
|
6 | 6 | # **Warning**
|
|
18 | 18 | # $(D_LIB)/%.lo: %.cpp
|
19 | 19 | # $(LIBTOOL) --mode=compile $(CXX) $(CXXFLAGS) -o $(D_OBJ)/$@ -c $<
|
20 | 20 | #
|
21 |
| -# Copyright Adam Young 2012 - 2023 |
| 21 | +# Copyright Adam Young 2012 - 2025 |
22 | 22 | # All rights reserved.
|
23 | 23 | #
|
24 | 24 | # This file is part of the Midnight Commander.
|
|
362 | 362 | my $cl_ltcg = 0;
|
363 | 363 | my $cl_debug = undef;
|
364 | 364 | my $cl_runtime = 'MT';
|
| 365 | + my $targetarch = ''; |
365 | 366 | my $gcc_debugger = 0;
|
366 |
| - my $x64 = 0; |
367 | 367 | my @OBJECTS;
|
368 | 368 | my @RESOURCES;
|
369 | 369 | my @EXPORTS;
|
|
374 | 374 | my @STUFF;
|
375 | 375 |
|
376 | 376 | $cc = 'gcc' if ('g++' eq $cc); # alises
|
377 |
| - if ('cl' eq $cc) { |
378 |
| - if (defined $ENV{'LIB'}) { # x64 toolchain selection (TODO: option) |
379 |
| - $x64 = 1 if ($ENV{'LIB'} =~ /amd64/); |
| 377 | + if ($cc eq 'cl') { |
| 378 | + if (defined $ENV{'VSCMD_ARG_TGT_ARCH'} && $ENV{'VSCMD_ARG_TGT_ARCH'} eq "x64") { |
| 379 | + $targetarch = 'x64'; |
380 | 380 | }
|
381 | 381 | }
|
382 | 382 |
|
|
773 | 773 | }
|
774 | 774 |
|
775 | 775 | MSVCRuntimeX64($cl_runtime, \@LIBRARIES)
|
776 |
| - if ($x64 && $cl_runtime); |
| 776 | + if ($targetarch eq 'x64' && $cl_runtime); |
777 | 777 |
|
778 | 778 | Verbose "libraries:";
|
779 | 779 | foreach(@LIBRARIES) { Verbose "\t$_"; }
|
|
869 | 869 | #
|
870 | 870 | if (defined $ENV{'VCToolsInstallDir'}) { # 2010 plus
|
871 | 871 | my $toolbase = $ENV{'VCToolsInstallDir'};
|
872 |
| - if ($x64) { |
873 |
| - Error("link: x64 linker needed"); |
874 |
| - } else { |
875 |
| - $cmd = "\"${toolbase}\\bin\\Hostx86\\x86\\link\" @STUFF \@$cmdfile"; |
876 |
| - } |
| 872 | + my $toolarch = "Hostx86\\x86"; |
| 873 | + |
| 874 | + $toolarch = "Hostx64\\x64" # x86 or x64 |
| 875 | + if ($targetarch eq 'x64'); |
| 876 | + |
| 877 | + $cmd = "\"${toolbase}\\bin\\${toolarch}\\link\" \@$cmdfile"; |
877 | 878 |
|
878 | 879 | } elsif (defined $ENV{'VCINSTALLDIR'}) { # 2008
|
879 | 880 | my $toolbase = $ENV{'VCINSTALLDIR'};
|
880 |
| - if ($x64) { |
881 |
| - $cmd = "\"${toolbase}\\bin\\amd64\\link\" @STUFF \@$cmdfile"; |
882 |
| - } else { |
883 |
| - $cmd = "\"${toolbase}\\bin\\link\" @STUFF \@$cmdfile"; |
884 |
| - } |
| 881 | + $cmd = "\"${toolbase}\\bin\\link\" \@$cmdfile"; |
885 | 882 |
|
886 |
| - } else { # default |
887 |
| - if ($x64) { |
888 |
| - Error("link: x64 linker needed"); |
889 |
| - } else { |
890 |
| - $cmd = "link @STUFF \@$cmdfile"; |
891 |
| - } |
| 883 | + } else { # default |
| 884 | + $cmd = "link \@$cmdfile"; |
892 | 885 | }
|
893 | 886 |
|
894 | 887 | open(CMD, ">${cmdfile}") or
|
895 | 888 | die "cannot create <${$cmdfile}>: $!\n";
|
896 | 889 |
|
| 890 | + print CMD "/MACHINE:${targetarch}\n" |
| 891 | + if ($targetarch); # ARM|ARM64|ARM64X|EBC|X64|X86 |
| 892 | + |
897 | 893 | if ($linktype eq 'dll') {
|
898 | 894 | print CMD "/DLL\n";
|
899 | 895 | print CMD "/SUBSYSTEM:WINDOWS\n";
|
900 |
| - if ($x64) { # cdecl |
| 896 | + if ($targetarch eq 'x64') { # cdecl |
901 | 897 | print CMD "/ENTRY:_DllMainCRTStartup"."\n";
|
902 | 898 | } else { # STDCALL
|
903 | 899 | print CMD "/ENTRY:_DllMainCRTStartup\@12"."\n";
|
|
908 | 904 | print CMD "/SUBSYSTEM:CONSOLE\n";
|
909 | 905 | print CMD "/OUT:${output}\n";
|
910 | 906 | }
|
911 |
| - |
912 |
| - print CMD "/MACHINE:X64\n" |
913 |
| - if ($x64); |
914 | 907 | print CMD "/MANIFEST\n";
|
915 | 908 | print CMD "/NXCOMPAT\n";
|
916 | 909 | print CMD "/DYNAMICBASE\n";
|
|
929 | 922 | print CMD "/LTCG\n"
|
930 | 923 | if ($cl_ltcg);
|
931 | 924 | print CMD "/IGNORE:4197\n" # FIXME: warning LNK4197: export 'XXXe' specified multiple times; using first specification
|
932 |
| - if ($x64); |
| 925 | + if ($targetarch eq 'x64'); |
933 | 926 |
|
934 | 927 | foreach(@OBJECTS) {
|
935 | 928 | print CMD true_object($_)."\n";
|
|
1130 | 1123 | print LA "dll=${dllpath}\n";
|
1131 | 1124 | print LA "pdb=${pdbpath}\n" if ($pdbpath);
|
1132 | 1125 | print LA "manifest=${manifestpath}\n" if ($manifestpath);
|
| 1126 | + print LA "targetarch=${targetarch}\n" if ($targetarch); |
1133 | 1127 | print LA "[objects]\n";
|
1134 | 1128 | foreach(@OBJECTS) {
|
1135 | 1129 | print LA true_object($_)."\n";
|
|
0 commit comments