diff options
author | Nirbheek Chauhan <nirbheek@centricular.com> | 2020-06-09 18:29:15 +0530 |
---|---|---|
committer | Nirbheek Chauhan <nirbheek@centricular.com> | 2020-06-12 23:44:47 +0530 |
commit | 7b3dd464eb4aedc2f37b7271d47b7f911df8ba80 (patch) | |
tree | de05f07fe5a835efe8f5c4568782fc4ae6c42667 | |
parent | 63abc835a83fcd4f1b066df548364e3d9c5f9a3e (diff) |
openssl.recipe: Add support for building with MSVC
Supports both regular Win32 and WinRT/UWP.
Part-of: <https://gitlab.freedesktop.org/gstreamer/cerbero/-/merge_requests/505>
4 files changed, 272 insertions, 69 deletions
diff --git a/recipes/openssl.recipe b/recipes/openssl.recipe index 00c652c9..e7df103a 100644 --- a/recipes/openssl.recipe +++ b/recipes/openssl.recipe @@ -18,85 +18,126 @@ class Recipe(recipe.Recipe): allow_parallel_build = False # Configure script is perl, not shell config_sh_needs_shell = False + # Can build for MSVC and UWP + can_msvc = True - patches = ['openssl/0001-Load-ca-certificate.crt-from-PREFIX-etc-ssl-on-macOS.patch'] + patches = [ + # Portable prefix with SSL certs + 'openssl/0001-Load-ca-certificate.crt-from-PREFIX-etc-ssl-on-macOS.patch', + # MSVC and UWP support + 'openssl/0001-windows-makefile.tmpl-Generate-and-install-pkgconfig.patch', + 'openssl/0002-windows-makefile.tmpl-Fix-ONECORE-build.patch', + 'openssl/0003-windows-makefile.tmpl-Do-not-prefix-import-libraries.patch' + ] files_bins = ['openssl'] files_libs = ['libcrypto', 'libssl'] files_devel = ['include/openssl', 'lib/pkgconfig/openssl.pc', 'lib/pkgconfig/libssl.pc', 'lib/pkgconfig/libcrypto.pc'] - def prepare(self): + def _get_openssl_platform(self): # map platforms if self.config.target_platform == Platform.IOS: if self.config.target_arch == Architecture.ARMv7: - self.openssl_platform = 'BSD-generic32' - elif self.config.target_arch == Architecture.ARMv7S: - self.openssl_platform = 'BSD-generic32' - elif self.config.target_arch == Architecture.X86: - self.openssl_platform = 'BSD-generic32' - elif self.config.target_arch == Architecture.X86_64: - self.openssl_platform = 'BSD-generic64' - elif self.config.target_arch == Architecture.ARM64: - self.openssl_platform = 'BSD-generic64' - else: - raise InvalidRecipeError(self, "Unknown iOS platform") - elif self.config.target_platform == Platform.ANDROID: - if self.config.target_arch == Architecture.ARM: - self.openssl_platform = 'android-arm' - elif self.config.target_arch == Architecture.ARMv7: - self.openssl_platform = 'android-arm' - elif self.config.target_arch == Architecture.ARM64: - self.openssl_platform = 'android-arm64' - elif self.config.target_arch == Architecture.X86: - self.openssl_platform = 'android-x86' - elif self.config.target_arch == Architecture.X86_64: - self.openssl_platform = 'android-x86_64' - else: - raise InvalidRecipeError(self, "Unknown Android platform") - + return 'BSD-generic32' + if self.config.target_arch == Architecture.ARMv7S: + return 'BSD-generic32' + if self.config.target_arch == Architecture.X86: + return 'BSD-generic32' + if self.config.target_arch == Architecture.X86_64: + return 'BSD-generic64' + if self.config.target_arch == Architecture.ARM64: + return 'BSD-generic64' + raise InvalidRecipeError(self, "Unknown iOS platform") + if self.config.target_platform == Platform.ANDROID: self.make += ['CROSS_SYSROOT=' + self.config.sysroot] - elif self.config.target_platform == Platform.DARWIN: + if self.config.target_arch == Architecture.ARM: + return 'android-arm' + if self.config.target_arch == Architecture.ARMv7: + return 'android-arm' + if self.config.target_arch == Architecture.ARM64: + return 'android-arm64' if self.config.target_arch == Architecture.X86: - self.openssl_platform = 'darwin-i386-cc' - elif self.config.target_arch == Architecture.X86_64: - self.openssl_platform = 'darwin64-x86_64-cc' - else: - raise InvalidRecipeError(self, "Unknown macOS platform") - elif self.config.target_platform == Platform.LINUX: + return 'android-x86' + if self.config.target_arch == Architecture.X86_64: + return 'android-x86_64' + raise InvalidRecipeError(self, "Unknown Android platform") + if self.config.target_platform == Platform.DARWIN: if self.config.target_arch == Architecture.X86: - self.openssl_platform = 'linux-elf' - elif self.config.target_arch == Architecture.X86_64: - self.openssl_platform = 'linux-x86_64' - elif self.config.target_arch == Architecture.ARM: - self.openssl_platform = 'linux-armv4' - elif self.config.target_arch == Architecture.ARMv7: - self.openssl_platform = 'linux-armv4' - elif self.config.target_arch == Architecture.ARM64: - self.openssl_platform = 'linux-aarch64' - else: - raise InvalidRecipeError(self, "Unknown Linux platform") - elif self.config.target_platform == Platform.WINDOWS: + return 'darwin-i386-cc' + if self.config.target_arch == Architecture.X86_64: + return 'darwin64-x86_64-cc' + raise InvalidRecipeError(self, "Unknown macOS platform") + if self.config.target_platform == Platform.LINUX: if self.config.target_arch == Architecture.X86: - self.openssl_platform = 'mingw' - elif self.config.target_arch == Architecture.X86_64: - self.openssl_platform = 'mingw64' + return 'linux-elf' + if self.config.target_arch == Architecture.X86_64: + return 'linux-x86_64' + if self.config.target_arch == Architecture.ARM: + return 'linux-armv4' + if self.config.target_arch == Architecture.ARMv7: + return 'linux-armv4' + if self.config.target_arch == Architecture.ARM64: + return 'linux-aarch64' + raise InvalidRecipeError(self, "Unknown Linux platform") + if self.config.target_platform == Platform.WINDOWS: + if self.using_uwp(): + if self.config.target_arch == Architecture.X86: + return 'VC-WIN32-ONECORE' + if self.config.target_arch == Architecture.X86_64: + return 'VC-WIN64A-ONECORE' + if self.config.target_arch == Architecture.ARM: + return 'VC-WIN32-ARM' + if self.config.target_arch == Architecture.ARMv7: + return 'VC-WIN32-ARM' + if self.config.target_arch == Architecture.ARM64: + return 'VC-WIN64-ARM' + elif self.using_msvc(): + if self.config.target_arch == Architecture.X86: + return 'VC-WIN32' + if self.config.target_arch == Architecture.X86_64: + return 'VC-WIN64A' else: - raise InvalidRecipeError(self, "Unknown Windows platform") - cflags = self.get_env('CFLAGS') + '-fPIC -DOPENSSL_PIC' - ldflags = self.get_env('LDFLAGS') + '-fPIC' - ranlib = self.get_env('RANLIB') - ar = self.get_env('AR') - # Need to add CFLAGS to CC because CFLAG is not used everywhere in the - # build, and we can't pass arguments via Configure because on Darwin, - # Configure reads the `-arch x86_64` as meaning that you want to use - # `x86_64` as the platform, and errors out about a redefined platform. - cc = self.get_env('CC') + ' ' + self.get_env('CFLAGS') - ld = self.get_env('LD') + ' ' + self.get_env('LDFLAGS') - # NOTE: CFLAG and LDFLAG are not typos! - self.make += ['AR=' + ar, 'RANLIB=' + ranlib, 'CC=' + cc, 'LD=' + ld, - 'CFLAG=' + cflags, 'LDFLAG=' + ldflags] - self.make_install = ['make', 'install_sw', 'RANLIB=' + ranlib] + if self.config.target_arch == Architecture.X86: + return 'mingw' + if self.config.target_arch == Architecture.X86_64: + return 'mingw64' + raise InvalidRecipeError(self, "Unknown Windows platform") + raise InvalidRecipeError(self, "Unknown target platform {}" + .format(self.config.target_platform)) + + def prepare(self): + self.openssl_platform = self._get_openssl_platform() + cflags = self.get_env('CFLAGS') + ldflags = self.get_env('LDFLAGS') + + if self.using_msvc(): + # Gets converted to C:/MinGW/msys/1.0/utf-8 by MSYS somehow, so + # just remove it. We only need this for gstreamer sources anyway. + cflags = cflags.replace('/utf-8', '') + # If we don't unset these, they override values set by openssl's makefile + self.set_env('CFLAGS') + self.set_env('CPPFLAGS') + self.set_env('CXXFLAGS') + self.set_env('LDFLAGS') + # Building with MSVC uses nmake, not make + self.make = ['nmake', 'CFLAG=' + cflags, 'LDFLAG=' + ldflags] + self.make_install = ['nmake', 'install_sw'] + else: + cflags += '-fPIC -DOPENSSL_PIC' + ldflags += '-fPIC' + ranlib = self.get_env('RANLIB') + ar = self.get_env('AR') + # Need to add CFLAGS to CC because CFLAG is not used everywhere in the + # build, and we can't pass arguments via Configure because on Darwin, + # Configure reads the `-arch x86_64` as meaning that you want to use + # `x86_64` as the platform, and errors out about a redefined platform. + cc = self.get_env('CC') + ' ' + self.get_env('CFLAGS') + ld = self.get_env('LD') + ' ' + self.get_env('LDFLAGS') + # NOTE: CFLAG and LDFLAG are not typos! + self.make += ['AR=' + ar, 'RANLIB=' + ranlib, 'CC=' + cc, 'LD=' + ld, + 'CFLAG=' + cflags, 'LDFLAG=' + ldflags] + self.make_install = ['make', 'install_sw', 'RANLIB=' + ranlib] # We probably don't need and can't use the tools on these platforms if self.config.target_platform in (Platform.IOS, Platform.ANDROID): @@ -108,12 +149,17 @@ class Recipe(recipe.Recipe): # mingw-perl that was downloaded and installed by bootstrap. openssl_path = os.path.join(self.config.mingw_perl_prefix, 'bin') self.prepend_env('PATH', openssl_path, sep=';') - # Ensure that Perl's Filei/Spec.pm uses forward-slashes. These vars - # are automatically set by the MSYS terminal, but they might get - # overriden by something, which will cause Perl to use backward - # slashes and fail `Configurations/unix-checker.pm` on configure. + # Ensure that our Perl's File/Spec.pm uses backward slashes when + # building for MSVC and forward-slashes when building for MinGW. + # The vars for the MinGW case are automatically set by the MSYS + # terminal, but they might get overriden by something, which will + # cause Perl to use backward slashes and fail + # `Configurations/unix-checker.pm` on configure. self.set_env('MSYSTEM', 'MINGW32') - self.set_env('TERM', 'cygwin') + if self.using_msvc(): + self.set_env('TERM', 'dumb') + else: + self.set_env('TERM', 'cygwin') @modify_environment diff --git a/recipes/openssl/0001-windows-makefile.tmpl-Generate-and-install-pkgconfig.patch b/recipes/openssl/0001-windows-makefile.tmpl-Generate-and-install-pkgconfig.patch new file mode 100644 index 00000000..723dd2d1 --- /dev/null +++ b/recipes/openssl/0001-windows-makefile.tmpl-Generate-and-install-pkgconfig.patch @@ -0,0 +1,95 @@ +From 96881a7b26d569b08dc5847204856ebb5fc532f9 Mon Sep 17 00:00:00 2001 +From: Nirbheek Chauhan <nirbheek@centricular.com> +Date: Tue, 9 Jun 2020 15:14:32 +0530 +Subject: [PATCH] windows-makefile.tmpl: Generate and install pkgconfig files + +Copied from unix-makefile.tmpl +--- + Configurations/windows-makefile.tmpl | 50 +++++++++++++++++++++++++++- + 1 file changed, 49 insertions(+), 1 deletion(-) + +diff --git a/Configurations/windows-makefile.tmpl b/Configurations/windows-makefile.tmpl +index 8ef70b8..bc1e199 100644 +--- a/Configurations/windows-makefile.tmpl ++++ b/Configurations/windows-makefile.tmpl +@@ -314,7 +314,7 @@ PROCESSOR= {- $config{processor} -} + {- dependmagic('build_programs'); -}: build_programs_nodep + + build_generated: $(GENERATED_MANDATORY) +-build_libs_nodep: $(LIBS) {- join(" ",map { shlib_import($_) } @{$unified_info{libraries}}) -} ++build_libs_nodep: libcrypto.pc libssl.pc openssl.pc $(LIBS) {- join(" ",map { shlib_import($_) } @{$unified_info{libraries}}) -} + build_engines_nodep: $(ENGINES) + build_programs_nodep: $(PROGRAMS) $(SCRIPTS) + +@@ -371,6 +371,7 @@ clean: libclean + -del /Q /S /F engines\*.lib engines\*.exp + -del /Q /S /F apps\*.lib apps\*.rc apps\*.res apps\*.exp + -del /Q /S /F test\*.exp ++ -del /Q /S /F openssl.pc libcrypto.pc libssl.pc + -rmdir /Q /S test\test-runs + + distclean: clean +@@ -426,6 +427,14 @@ install_dev: install_runtime_libs + @"$(PERL)" "$(SRCDIR)\util\copy.pl" $(INSTALL_LIBS) "$(libdir)" + @if "$(SHLIBS)"=="" \ + "$(PERL)" "$(SRCDIR)\util\copy.pl" ossl_static.pdb "$(libdir)" ++ @ : {- output_on() if $disabled{shared}; "" -} ++ @$(PERL) $(SRCDIR)\util\mkdir-p.pl "$(DESTDIR)$(libdir)\pkgconfig" ++ @$(ECHO) "install libcrypto.pc -> $(DESTDIR)$(libdir)\pkgconfig\libcrypto.pc" ++ @"$(PERL)" "$(SRCDIR)\util\copy.pl" libcrypto.pc "$(DESTDIR)$(libdir)\pkgconfig" ++ @$(ECHO) "install libssl.pc -> $(DESTDIR)$(libdir)\pkgconfig\libssl.pc" ++ @"$(PERL)" "$(SRCDIR)\util\copy.pl" libssl.pc "$(DESTDIR)$(libdir)\pkgconfig" ++ @$(ECHO) "install openssl.pc -> $(DESTDIR)$(libdir)\pkgconfig\openssl.pc" ++ @"$(PERL)" "$(SRCDIR)\util\copy.pl" openssl.pc "$(DESTDIR)$(libdir)\pkgconfig" + + uninstall_dev: + +@@ -472,6 +481,45 @@ install_html_docs: + uninstall_html_docs: + + # Building targets ################################################### ++# ++libcrypto.pc libssl.pc openssl.pc: configdata.pm ++libcrypto.pc: ++ @$(ECHO) "prefix=$(INSTALLTOP)" > libcrypto.pc ++ @$(ECHO) "exec_prefix=$${prefix}" >> libcrypto.pc ++ @$(ECHO) "libdir=$${exec_prefix}/$(LIBDIR)" >> libcrypto.pc ++ @$(ECHO) "includedir=$${prefix}/include" >> libcrypto.pc ++ @$(ECHO) "enginesdir=$${libdir}/engines-{- $sover_dirname -}" >> libcrypto.pc ++ @$(ECHO) "" >> libcrypto.pc ++ @$(ECHO) "Name: OpenSSL-libcrypto" >> libcrypto.pc ++ @$(ECHO) "Description: OpenSSL cryptography library" >> libcrypto.pc ++ @$(ECHO) "Version: $(VERSION)" >> libcrypto.pc ++ @$(ECHO) "Libs: -L$${libdir} -lcrypto" >> libcrypto.pc ++ @$(ECHO) "Libs.private: $(LIB_EX_LIBS)" >> libcrypto.pc ++ @$(ECHO) "Cflags: -I$${includedir}" >> libcrypto.pc ++ ++libssl.pc: ++ @$(ECHO) "prefix=$(INSTALLTOP)" > libssl.pc ++ @$(ECHO) "exec_prefix=$${prefix}" >> libssl.pc ++ @$(ECHO) "libdir=$${exec_prefix}/$(LIBDIR)" >> libssl.pc ++ @$(ECHO) "includedir=$${prefix}/include" >> libssl.pc ++ @$(ECHO) "" >> libssl.pc ++ @$(ECHO) "Name: OpenSSL-libssl" >> libssl.pc ++ @$(ECHO) "Description: Secure Sockets Layer and cryptography libraries" >> libssl.pc ++ @$(ECHO) "Version: $(VERSION)" >> libssl.pc ++ @$(ECHO) "Requires.private: libcrypto" >> libssl.pc ++ @$(ECHO) "Libs: -L$${libdir} -lssl" >> libssl.pc ++ @$(ECHO) "Cflags: -I$${includedir}" >> libssl.pc ++ ++openssl.pc: ++ @$(ECHO) "prefix=$(INSTALLTOP)" > openssl.pc ++ @$(ECHO) "exec_prefix=$${prefix}" >> openssl.pc ++ @$(ECHO) "libdir=$${exec_prefix}/$(LIBDIR)" >> openssl.pc ++ @$(ECHO) "includedir=$${prefix}/include" >> openssl.pc ++ @$(ECHO) "" >> openssl.pc ++ @$(ECHO) "Name: OpenSSL" >> openssl.pc ++ @$(ECHO) "Description: Secure Sockets Layer and cryptography libraries and tools" >> openssl.pc ++ @$(ECHO) "Version: $(VERSION)" >> openssl.pc ++ @$(ECHO) "Requires: libssl libcrypto" >> openssl.pc + + configdata.pm: "$(SRCDIR)\Configure" {- join(" ", map { '"'.$_.'"' } @{$config{build_file_templates}}, @{$config{build_infos}}, @{$config{conf_files}}) -} + @$(ECHO) "Detected changed: $?" +-- +2.27.0.windows.1 + diff --git a/recipes/openssl/0002-windows-makefile.tmpl-Fix-ONECORE-build.patch b/recipes/openssl/0002-windows-makefile.tmpl-Fix-ONECORE-build.patch new file mode 100644 index 00000000..8a254fc5 --- /dev/null +++ b/recipes/openssl/0002-windows-makefile.tmpl-Fix-ONECORE-build.patch @@ -0,0 +1,34 @@ +From 5c5959292e59650051418a7db487ac07ef701700 Mon Sep 17 00:00:00 2001 +From: Nirbheek Chauhan <nirbheek@centricular.com> +Date: Tue, 9 Jun 2020 18:21:10 +0530 +Subject: [PATCH 2/3] windows-makefile.tmpl: Fix ONECORE build + +setargv.obj is not buildable: + +``` + link /nologo /debug /subsystem:console /opt:ref /NODEFAULTLIB:kernel32.lib /nologo /debug /out:apps\openssl.exe @C:/Users/nirbheek/AppData/Local/Temp\nm76E2.tmp +LINK : fatal error LNK1181: cannot open input file 'setargv.obj' +NMAKE : fatal error U1077: '"c:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.25.28610\bin\HostX64\x64\link.EXE"' : return code '0x49d' +Stop. +NMAKE : fatal error U1077: '"c:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.25.28610\bin\HostX64\x64\nmake.exe"' : return code '0x2' +Stop. +``` +--- + Configurations/windows-makefile.tmpl | 1 - + 1 file changed, 1 deletion(-) + +diff --git a/Configurations/windows-makefile.tmpl b/Configurations/windows-makefile.tmpl +index ca05fa4..e573f58 100644 +--- a/Configurations/windows-makefile.tmpl ++++ b/Configurations/windows-makefile.tmpl +@@ -752,7 +752,6 @@ $bin$exeext: $deps + IF EXIST $bin$exeext.manifest DEL /F /Q $bin$exeext.manifest + \$(LD) \$(LDFLAGS) \$(BIN_LDFLAGS) \$(LDOUTFLAG)$bin$exeext @<< + $objs +-setargv.obj + $linklibs\$(BIN_EX_LIBS) + << + IF EXIST $bin$exeext.manifest \\ +-- +2.27.0.windows.1 + diff --git a/recipes/openssl/0003-windows-makefile.tmpl-Do-not-prefix-import-libraries.patch b/recipes/openssl/0003-windows-makefile.tmpl-Do-not-prefix-import-libraries.patch new file mode 100644 index 00000000..8dbc3dc7 --- /dev/null +++ b/recipes/openssl/0003-windows-makefile.tmpl-Do-not-prefix-import-libraries.patch @@ -0,0 +1,28 @@ +From 1802e7c87fd9a6ba76e04b32ba258079ee94b2d4 Mon Sep 17 00:00:00 2001 +From: Nirbheek Chauhan <nirbheek@centricular.com> +Date: Tue, 9 Jun 2020 18:55:35 +0530 +Subject: [PATCH 3/3] windows-makefile.tmpl: Do not prefix import libraries + with 'lib' + +We want ssl.lib and crypto.lib, which matches libssl.dll.a and +libcrypto.dll.a since all of them can be found by GCC with -lfoo +--- + Configurations/windows-makefile.tmpl | 2 +- + 1 file changed, 1 insertion(+), 1 deletion(-) + +diff --git a/Configurations/windows-makefile.tmpl b/Configurations/windows-makefile.tmpl +index e573f58..c70f821 100644 +--- a/Configurations/windows-makefile.tmpl ++++ b/Configurations/windows-makefile.tmpl +@@ -48,7 +48,7 @@ + sub shlib_import { + my $lib = shift; + return () if $disabled{shared} || $lib =~ /\.a$/; +- return $lib . $shlibextimport; ++ return substr($lib, 3) . $shlibextimport; + } + + sub dso { +-- +2.27.0.windows.1 + |