Support DLL builds + Fix C RTL variants
authorTanzinul Islam <tanzinul.islam@gmail.com>
Sun, 6 Dec 2020 23:04:45 +0000 (23:04 +0000)
committerDmitry Belyavskiy <beldmit@gmail.com>
Mon, 19 Apr 2021 09:05:54 +0000 (11:05 +0200)
We need to generate a import library without the version in the
filename. MSVC's `link.exe` accommodates this with the [`/implib:`
option][1], while C++Builder needs a separate run of [`implib.exe`][2].
Also fix the variants of the [C runtime library and startup objects][3].

[1]: https://docs.microsoft.com/en-us/cpp/build/reference/implib-name-import-library?view=msvc-160
[2]: http://docwiki.embarcadero.com/RADStudio/Sydney/en/IMPLIB.EXE,_the_Import_Library_Tool_for_Win32
[3]: http://docwiki.embarcadero.com/RADStudio/Sydney/en/Static_Runtime_Libraries

Reviewed-by: Richard Levitte <levitte@openssl.org>
Reviewed-by: Dmitry Belyavskiy <beldmit@gmail.com>
(Merged from https://github.com/openssl/openssl/pull/13540)

Configurations/10-main.conf
Configurations/50-cppbuilder.conf
Configurations/windows-makefile.tmpl
NOTES-WINDOWS.md
crypto/build.info

index 518e8c77f4d89b41aaad46a33987757160dc4fd7..3d6fbba5e41db3f9b999d6122ff01e77167fbbf2 100644 (file)
@@ -1300,6 +1300,8 @@ my %targets = (
         shared_defflag   => '',
         shared_ldflag    => "/dll",
         shared_target    => "win-shared", # meaningless except it gives Configure a hint
+        lddefflag        => "/def:",
+        ld_implib_flag   => "/implib:",
         thread_scheme    => "winthreads",
         dso_scheme       => "win32",
         perl_platform    => 'Windows::MSVC',
index 334672e1a3c41d19bcfee70ab4c999ecff1100db..cb293afcb9589a6fcf5c82724581c4fd17f32daa 100644 (file)
@@ -3,34 +3,46 @@ my %targets = (
         inherit_from     => [ "BASE_Windows" ],
         sys_id           => "WIN32",
         bn_ops           => "BN_LLONG",
-        dso_scheme       => "win32",
         thread_scheme    => "winthreads",
         cc               => "bcc32c",
         defines          => add("WIN32_LEAN_AND_MEAN", "OPENSSL_SYS_WIN32",
                                 "L_ENDIAN", "DSO_WIN32", "_stricmp=stricmp",
                                 "_strnicmp=strnicmp", "_malloca=malloc",
                                 "_freea=free", "_setmode=setmode"),
-        cflags           => picker(default => "-q -c -tWC -tWM",
+        cflags           => picker(default => add("-q -c",
+                                                  threads("-tM"),
+                                                  shared("-tR")),
                                    debug   => "-Od -v -vi- -D_DEBUG",
                                    release => "-O2"),
+        bin_cflags       => "-tWC",
+        lib_cflags       => shared("-tWD -D_WINDLL -D_DLL"),
         coutflag         => "-o",
         LD               => "ilink32",
-        bin_lflags       => combine(picker(default => "-ap -Tpe -x -Gn -q",
-                                           debug   => '-j"$(BDS)\lib\win32c\debug" ' .
-                                                      '-L"$(BDS)\lib\win32c\debug"',
-                                           release => '-j"$(BDS)\lib\win32c\release" ' .
-                                                      '-L"$(BDS)\lib\win32c\release"'),
-                                    "wildargs.obj"),
+        LDFLAGS          => picker(default => "-ap -x -Gn -q",
+                                   debug   => '-j"$(BDS)\lib\win32c\debug" ' .
+                                              '-L"$(BDS)\lib\win32c\debug" -v',
+                                   release => '-j"$(BDS)\lib\win32c\release" ' .
+                                              '-L"$(BDS)\lib\win32c\release"'),
+        bin_lflags       => "-Tpe c0x32.obj wildargs.obj",
         ldoutflag        => ",",
         ldpostoutflag    => ",,",
         ld_resp_delim    => " +\n",
         ex_libs          => add(sub {
-            my @ex_libs = ("cw32mt.lib", "import32.lib");
+            my @ex_libs = ("import32.lib",
+                           ($disabled{shared}
+                            ? ($disabled{threads} ? "cw32.lib" : "cw32mt.lib")
+                            : ($disabled{threads} ? "cw32i.lib" : "cw32mti.lib")));
             push @ex_libs, ("crypt32.lib", "ws2_32.lib") unless $disabled{sock};
             return join(" ", @ex_libs);
         }),
         AR               => "tlib",
         ARFLAGS          => "/P256 /N /u",
         ar_resp_delim    => " &\n",
+        shared_target    => "win-shared",
+        shared_ldflag    => "-Tpd c0d32.obj",
+        dso_lflags       => "-Tpd c0d32.obj",
+        lddefflag        => ",",
+        ld_implib_rule   => 'implib $< $**',
+        dso_scheme       => "win32",
     }
 );
index bf214b0ee20a0778401962ea4a9ab67fac655aa3..1e3d63f8d10f067e2e24cf455b76af2234b10c54 100644 (file)
@@ -860,18 +860,22 @@ EOF
      my $deps = join(" ", @objs, @defs, @deps);
      my $import = platform->sharedlib_import($lib);
      my $dll =  platform->sharedlib($lib);
-     my $shared_def = join("", map { " /def:$_" } @defs);
+     my $shared_def = join("", map { " $target{lddefflag}$_" } @defs);
+     my $implib_rule = $target{ld_implib_rule} || "";
+     my $implib_flag = $target{ld_implib_flag}
+                       ? "$target{ld_implib_flag}$import"
+                       : "";
      return <<"EOF"
 # The import library may look like a static library, but it is not.
 # We MUST make the import library depend on the DLL, in case someone
 # mistakenly removes the latter.
 $import: $dll
+       $implib_rule
 $dll: $deps
        IF EXIST $full.manifest DEL /F /Q $full.manifest
        IF EXIST \$@ DEL /F /Q \$@
-       \$(LD) \$(LDFLAGS) \$(LIB_LDFLAGS) \\
-               /implib:$import \$(LDOUTFLAG)$dll$shared_def @<< || (DEL /Q \$(\@B).* $import; EXIT 1)
-$objs$target{ld_resp_delim}$linklibs\$(LIB_EX_LIBS)
+       \$(LD) \$(LDFLAGS) \$(LIB_LDFLAGS) @<< $implib_flag || (DEL /Q \$(\@B).* $import; EXIT 1)
+$objs$target{ld_resp_delim}\$(LDOUTFLAG)$dll$target{ldpostoutflag}$target{ld_resp_delim}$linklibs\$(LIB_EX_LIBS)$shared_def
 <<
        IF EXIST $dll.manifest \\
           \$(MT) \$(MTFLAGS) \$(MTINFLAG)$dll.manifest \$(MTOUTFLAG)$dll
@@ -897,13 +901,12 @@ EOF
      my $objs = join($target{ld_resp_delim}, @objs);
      my $linklibs = join("", map { "$_$target{ld_resp_delim}" } @deps);
      my $deps = join(" ", @objs, @defs, @deps);
-     my $shared_def = join("", map { " /def:$_" } @defs);
+     my $shared_def = join("", map { " $target{lddefflag}$_" } @defs);
      return <<"EOF";
 $dso: $deps
        IF EXIST $dso.manifest DEL /F /Q $dso.manifest
-       \$(LD) \$(LDFLAGS) \$(DSO_LDFLAGS) \\
-               \$(LDOUTFLAG)$dso$shared_def @<< || (DEL /Q \$(\@B).* $dso_n.*; EXIT 1)
-$objs$target{ld_resp_delim}$linklibs \$(DSO_EX_LIBS)
+       \$(LD) \$(LDFLAGS) \$(DSO_LDFLAGS) @<< || (DEL /Q \$(\@B).* $dso_n.*; EXIT 1)
+$objs$target{ld_resp_delim}\$(LDOUTFLAG)$dso$target{ldpostoutflag}$target{ld_resp_delim}$linklibs \$(DSO_EX_LIBS)$shared_def
 <<
        IF EXIST $dso.manifest \\
           \$(MT) \$(MTFLAGS) \$(MTINFLAG)$dso.manifest \$(MTOUTFLAG)$dso
index 95682f205c38b0ddb197160c5b800eb3a00cc2fa..7ca8de299ebfdba3307e45d0f56c2cd6345487b0 100644 (file)
@@ -127,8 +127,8 @@ Native builds using Embarcadero C++Builder
 =========================================
 
 This toolchain (a descendant of Turbo/Borland C++) is an alternative to MSVC.
-OpenSSL currently includes an experimental 32-bit static-build configuration
-targeting the Clang-based compiler (bcc32c.exe) in v10.3.3 Community Edition.
+OpenSSL currently includes an experimental 32-bit configuration targeting the
+Clang-based compiler (bcc32c.exe) in v10.3.3 Community Edition.
 <https://www.embarcadero.com/products/cbuilder/starter>
 
  1. Install Perl.
@@ -140,12 +140,14 @@ targeting the Clang-based compiler (bcc32c.exe) in v10.3.3 Community Edition.
 
  4. make -N
 
- 5. Build your program against this OpenSSL:
+ 5. make -N test
+
+ 6. Build your program against this OpenSSL:
     * Set your include search path to the "include" subdirectory of OpenSSL.
     * Set your library search path to the OpenSSL source directory.
 
-Note that this is very experimental. Support for 64-bit, dynamic library, and
-other Configure options is still pending.
+Note that this is very experimental. Support for 64-bit and other Configure
+options is still pending.
 
 Native builds using MinGW
 =========================
index 3b78431f809ef41884d05f95c3ccd11eb6c01c59..3e1c295aeadf18d9ac2a7a664834a4c9ac509b36 100644 (file)
@@ -131,6 +131,6 @@ INCLUDE[armv4cpuid.o]=.
 GENERATE[s390xcpuid.S]=s390xcpuid.pl
 INCLUDE[s390xcpuid.o]=.
 
-IF[{- $config{target} =~ /^(?:Cygwin|mingw|VC-)/ -}]
+IF[{- $config{target} =~ /^(?:Cygwin|mingw|VC-|BC-)/ -}]
   SHARED_SOURCE[../libcrypto]=dllmain.c
 ENDIF