[DO-971] ffmpeg recipe with requirements (!9)

Co-authored-by: aleksandr.vodyanov <aleksandr.vodyanov@avroid.tech>
Reviewed-on: https://git.avroid.tech/Conan/conan_build/pulls/9
This commit is contained in:
Aleksandr Vodyanov
2024-12-25 17:47:28 +03:00
parent e58f90de0e
commit 39afe6a1dd
212 changed files with 9263 additions and 0 deletions

View File

@@ -0,0 +1,17 @@
sources:
"3.100":
url: "https://nexus.avroid.tech/repository/all-raw-proxy-sourceforge_net/projects/lame/files/lame/3.100/lame-3.100.tar.gz"
sha256: "ddfe36cab873794038ae2c1210557ad34857a4b6bdc515785d1da9e175b1da1e"
patches:
"3.100":
- patch_file: "patches/6410.patch"
patch_type: "backport"
patch_description: "bug tracker item #487: v3.100 breaks Windows compatibility"
patch_source: "https://sourceforge.net/p/lame/svn/commit_browser -- [r6410]"
- patch_file: "patches/6416.patch"
patch_type: "backport"
patch_description: "lame patches ticket #75: Fix for completing svn-r6410"
patch_source: "https://sourceforge.net/p/lame/svn/commit_browser -- [r6410]"
- patch_file: "patches/android.patch"
patch_type: "portability"
patch_description: "Add __ANDROID__ test to one bit"

View File

@@ -0,0 +1,152 @@
from conan import ConanFile
from conan.tools.apple import fix_apple_shared_install_name
from conan.tools.env import VirtualBuildEnv
from conan.tools.files import apply_conandata_patches, chdir, copy, export_conandata_patches, get, rename, replace_in_file, rm, rmdir
from conan.tools.gnu import Autotools, AutotoolsToolchain
from conan.tools.layout import basic_layout
from conan.tools.microsoft import is_msvc, NMakeToolchain
import os
import shutil
required_conan_version = ">=1.55.0"
class LibMP3LameConan(ConanFile):
name = "libmp3lame"
url = "https://github.com/conan-io/conan-center-index"
description = "LAME is a high quality MPEG Audio Layer III (MP3) encoder licensed under the LGPL."
homepage = "http://lame.sourceforge.net"
topics = "multimedia", "audio", "mp3", "decoder", "encoding", "decoding"
license = "LGPL-2.0"
settings = "os", "arch", "compiler", "build_type"
options = {
"shared": [True, False],
"fPIC": [True, False],
}
default_options = {
"shared": False,
"fPIC": True,
}
@property
def _is_clang_cl(self):
return str(self.settings.compiler) in ["clang"] and str(self.settings.os) in ['Windows']
@property
def _settings_build(self):
return getattr(self, "settings_build", self.settings)
def export_sources(self):
export_conandata_patches(self)
def config_options(self):
if self.settings.os == "Windows":
del self.options.fPIC
def configure(self):
if self.options.shared:
self.options.rm_safe("fPIC")
self.settings.rm_safe("compiler.cppstd")
self.settings.rm_safe("compiler.libcxx")
def layout(self):
basic_layout(self, src_folder="src")
def build_requirements(self):
if not is_msvc(self) and not self._is_clang_cl:
#self.tool_requires("gnu-config/cci.20210814")
if self._settings_build.os == "Windows":
self.win_bash = True
if not self.conf.get("tools.microsoft.bash:path", check_type=str):
self.tool_requires("msys2/cci.latest")
def source(self):
get(self, **self.conan_data["sources"][self.version], strip_root=True)
def generate(self):
if is_msvc(self) or self._is_clang_cl:
tc = NMakeToolchain(self)
tc.generate()
else:
env = VirtualBuildEnv(self)
env.generate()
tc = AutotoolsToolchain(self)
tc.configure_args.append("--disable-frontend")
if self.settings.compiler == "clang" and self.settings.arch in ["x86", "x86_64"]:
tc.extra_cxxflags.extend(["-mmmx", "-msse"])
tc.generate()
def _build_vs(self):
with chdir(self, self.source_folder):
shutil.copy2("configMS.h", "config.h")
# Honor vc runtime
replace_in_file(self, "Makefile.MSVC", "CC_OPTS = $(CC_OPTS) /MT", "")
# Do not hardcode LTO
replace_in_file(self, "Makefile.MSVC", " /GL", "")
replace_in_file(self, "Makefile.MSVC", " /LTCG", "")
replace_in_file(self, "Makefile.MSVC", "ADDL_OBJ = bufferoverflowU.lib", "")
command = "nmake -f Makefile.MSVC comp=msvc"
if self._is_clang_cl:
compilers_from_conf = self.conf.get("tools.build:compiler_executables", default={}, check_type=dict)
buildenv_vars = VirtualBuildEnv(self).vars()
cl = compilers_from_conf.get("c", buildenv_vars.get("CC", "clang-cl"))
link = buildenv_vars.get("LD", "lld-link")
replace_in_file(self, "Makefile.MSVC", "CC = cl", f"CC = {cl}")
replace_in_file(self, "Makefile.MSVC", "LN = link", f"LN = {link}")
# what is /GAy? MSDN doesn't know it
# clang-cl: error: no such file or directory: '/GAy'
# https://docs.microsoft.com/en-us/cpp/build/reference/ga-optimize-for-windows-application?view=msvc-170
replace_in_file(self, "Makefile.MSVC", "/GAy", "/GA")
if self.settings.arch == "x86_64":
replace_in_file(self, "Makefile.MSVC", "MACHINE = /machine:I386", "MACHINE =/machine:X64")
command += " MSVCVER=Win64 asm=yes"
elif self.settings.arch == "armv8":
replace_in_file(self, "Makefile.MSVC", "MACHINE = /machine:I386", "MACHINE =/machine:ARM64")
command += " MSVCVER=Win64"
else:
command += " asm=yes"
command += " libmp3lame.dll" if self.options.shared else " libmp3lame-static.lib"
self.run(command)
def _build_autotools(self):
for gnu_config in [
self.conf.get("user.gnu-config:config_guess", check_type=str),
self.conf.get("user.gnu-config:config_sub", check_type=str),
]:
if gnu_config:
copy(self, os.path.basename(gnu_config), src=os.path.dirname(gnu_config), dst=self.source_folder)
autotools = Autotools(self)
autotools.configure()
autotools.make()
def build(self):
apply_conandata_patches(self)
replace_in_file(self, os.path.join(self.source_folder, "include", "libmp3lame.sym"), "lame_init_old\n", "")
if is_msvc(self) or self._is_clang_cl:
self._build_vs()
else:
self._build_autotools()
def package(self):
copy(self, pattern="LICENSE", src=self.source_folder, dst=os.path.join(self.package_folder,"licenses"))
if is_msvc(self) or self._is_clang_cl:
copy(self, pattern="*.h", src=os.path.join(self.source_folder, "include"), dst=os.path.join(self.package_folder,"include", "lame"))
name = "libmp3lame.lib" if self.options.shared else "libmp3lame-static.lib"
copy(self, name, src=os.path.join(self.source_folder, "output"), dst=os.path.join(self.package_folder,"lib"))
if self.options.shared:
copy(self, pattern="*.dll", src=os.path.join(self.source_folder, "output"), dst=os.path.join(self.package_folder,"bin"))
rename(self, os.path.join(self.package_folder, "lib", name),
os.path.join(self.package_folder, "lib", "mp3lame.lib"))
else:
autotools = Autotools(self)
autotools.install()
rmdir(self, os.path.join(self.package_folder, "share"))
rm(self, "*.la", os.path.join(self.package_folder, "lib"))
fix_apple_shared_install_name(self)
def package_info(self):
self.cpp_info.libs = ["mp3lame"]
if self.settings.os in ["Linux", "FreeBSD"]:
self.cpp_info.system_libs = ["m"]

View File

@@ -0,0 +1,77 @@
--- a/frontend/parse.c
+++ b/frontend/parse.c
@@ -70,8 +70,10 @@
#ifdef HAVE_ICONV
#include <iconv.h>
#include <errno.h>
+#ifdef HAVE_LANGINFO
#include <locale.h>
#include <langinfo.h>
+#endif
#endif
#if defined _ALLOW_INTERNAL_OPTIONS
@@ -146,6 +148,18 @@
return n;
}
+static char*
+currentCharacterEncoding()
+{
+#ifdef HAVE_LANGINFO
+ char* cur_code = nl_langinfo(CODESET);
+#else
+ char* env_lang = getenv("LANG");
+ char* xxx_code = env_lang == NULL ? NULL : strrchr(env_lang, '.');
+ char* cur_code = xxx_code == NULL ? "" : xxx_code+1;
+#endif
+ return cur_code;
+}
static size_t
currCharCodeSize(void)
@@ -153,7 +167,7 @@
size_t n = 1;
char dst[32];
char* src = "A";
- char* cur_code = nl_langinfo(CODESET);
+ char* cur_code = currentCharacterEncoding();
iconv_t xiconv = iconv_open(cur_code, "ISO_8859-1");
if (xiconv != (iconv_t)-1) {
for (n = 0; n < 32; ++n) {
@@ -181,7 +195,7 @@
size_t const n = l*4;
dst = calloc(n+4, 4);
if (dst != 0) {
- char* cur_code = nl_langinfo(CODESET);
+ char* cur_code = currentCharacterEncoding();
iconv_t xiconv = iconv_open(cur_code, "ISO_8859-1");
if (xiconv != (iconv_t)-1) {
char* i_ptr = src;
@@ -205,7 +219,7 @@
size_t const n = l*4;
dst = calloc(n+4, 4);
if (dst != 0) {
- char* cur_code = nl_langinfo(CODESET);
+ char* cur_code = currentCharacterEncoding();
iconv_t xiconv = iconv_open(cur_code, "UTF-16LE");
if (xiconv != (iconv_t)-1) {
char* i_ptr = (char*)src;
@@ -231,7 +245,7 @@
size_t const n = l*4;
dst = calloc(n+4, 4);
if (dst != 0) {
- char* cur_code = nl_langinfo(CODESET);
+ char* cur_code = currentCharacterEncoding();
iconv_t xiconv = iconv_open("ISO_8859-1//TRANSLIT", cur_code);
if (xiconv != (iconv_t)-1) {
char* i_ptr = (char*)src;
@@ -257,7 +271,7 @@
size_t const n = (l+1)*4;
dst = calloc(n+4, 4);
if (dst != 0) {
- char* cur_code = nl_langinfo(CODESET);
+ char* cur_code = currentCharacterEncoding();
iconv_t xiconv = iconv_open("UTF-16LE//TRANSLIT", cur_code);
dst[0] = 0xff;
dst[1] = 0xfe;

View File

@@ -0,0 +1,39 @@
--- a/configure.in
+++ b/configure.in
@@ -421,6 +421,7 @@
AC_CHECK_LIB(termcap, initscr, HAVE_TERMCAP="termcap")
AC_CHECK_LIB(curses, initscr, HAVE_TERMCAP="curses")
AC_CHECK_LIB(ncurses, initscr, HAVE_TERMCAP="ncurses")
+AC_CHECK_HEADERS(langinfo.h, AC_CHECK_FUNCS(nl_langinfo))
AM_ICONV
--- a/frontend/parse.c
+++ b/frontend/parse.c
@@ -70,7 +70,7 @@
#ifdef HAVE_ICONV
#include <iconv.h>
#include <errno.h>
-#ifdef HAVE_LANGINFO
+#ifdef HAVE_LANGINFO_H
#include <locale.h>
#include <langinfo.h>
#endif
@@ -151,7 +151,7 @@
static char*
currentCharacterEncoding()
{
-#ifdef HAVE_LANGINFO
+#ifdef HAVE_LANGINFO_H
char* cur_code = nl_langinfo(CODESET);
#else
char* env_lang = getenv("LANG");
@@ -1527,7 +1527,7 @@
enum TextEncoding id3_tenc = TENC_LATIN1;
#endif
-#ifdef HAVE_ICONV
+#ifdef HAVE_LANGINFO_H
setlocale(LC_CTYPE, "");
#endif
inPath[0] = '\0';

View File

@@ -0,0 +1,11 @@
--- a/libmp3lame/util.c
+++ b/libmp3lame/util.c
@@ -911,7 +911,7 @@
mask &= ~(_EM_OVERFLOW | _EM_ZERODIVIDE | _EM_INVALID);
_FPU_SETCW(mask);
}
-# elif defined(__linux__)
+# elif defined(__linux__) && !defined(__ANDROID__)
{
# include <fpu_control.h>

View File

@@ -0,0 +1,7 @@
cmake_minimum_required(VERSION 3.1)
project(test_package LANGUAGES C)
find_package(libmp3lame REQUIRED CONFIG)
add_executable(${PROJECT_NAME} test_package.c)
target_link_libraries(${PROJECT_NAME} PRIVATE libmp3lame::libmp3lame)

View File

@@ -0,0 +1,26 @@
from conan import ConanFile
from conan.tools.build import can_run
from conan.tools.cmake import cmake_layout, CMake
import os
class TestPackageConan(ConanFile):
settings = "os", "arch", "compiler", "build_type"
generators = "CMakeDeps", "CMakeToolchain", "VirtualRunEnv"
test_type = "explicit"
def layout(self):
cmake_layout(self)
def requirements(self):
self.requires(self.tested_reference_str)
def build(self):
cmake = CMake(self)
cmake.configure()
cmake.build()
def test(self):
if can_run(self):
bin_path = os.path.join(self.cpp.build.bindirs[0], "test_package")
self.run(bin_path, env="conanrun")

View File

@@ -0,0 +1,10 @@
#include <lame/lame.h>
#include <stdio.h>
#include <stdlib.h>
int main()
{
printf("%s\n", get_lame_version());
return EXIT_SUCCESS;
}