|
| 1 | +<?php |
| 2 | + |
| 3 | +/** |
| 4 | + * ██╗ ██╗██████╗ ███████╗██╗██████╗ |
| 5 | + * ██║ ██║██╔══██╗╚══███╔╝██║██╔══██╗ |
| 6 | + * ██║ ██║██████╔╝ ███╔╝ ██║██████╔╝ |
| 7 | + * ██║ ██║██╔══██╗ ███╔╝ ██║██╔═══╝ |
| 8 | + * ███████╗██║██████╔╝███████╗██║██║ |
| 9 | + * ╚══════╝╚═╝╚═════╝ ╚══════╝╚═╝╚═╝ |
| 10 | + */ |
| 11 | + |
| 12 | + |
| 13 | +$path = ARCH_PATH . $lib->name . '-' . $lib->version . '\\'; |
| 14 | +$ziplog = LOG . 'libzip.log'; |
| 15 | + |
| 16 | + |
| 17 | +// Verify if libzip is installed |
| 18 | +if (is_dir($path) && is_file($path . 'build\lib\libzip_a.lib') && is_file(DEPS_PATH . 'lib\libzip_a.lib')) { |
| 19 | + draw_status($lib->name . '-' . $lib->version, "installed", Green); |
| 20 | + return; |
| 21 | +} |
| 22 | + |
| 23 | + |
| 24 | +// Download and unzip libzip |
| 25 | +$tmpfile = TMP.pathinfo($lib->download_url, PATHINFO_BASENAME); |
| 26 | +if(!download_file($lib->download_url, $tmpfile, pathinfo($tmpfile, PATHINFO_BASENAME))) exit_error(); |
| 27 | +if(!unzip($tmpfile, ARCH_PATH)) exit_error(); |
| 28 | +if(!is_dir($path)) exit_error("Can't find unzip results"); |
| 29 | + |
| 30 | + |
| 31 | +// Copy libraries |
| 32 | +if(!@copy(DEPS_PATH . 'lib\zlib_a.lib', DEPS_PATH . 'lib\zlib.lib')) exit_error("Can't copy zlib.lib"); |
| 33 | +if(!@copy(DEPS_PATH . 'lib\libbz2_a.lib', DEPS_PATH . 'lib\libbz2.lib')) exit_error("Can't copy libbz2.lib"); |
| 34 | +if(!@copy(DEPS_PATH . 'lib\liblzma_a.lib', DEPS_PATH . 'lib\liblzma.lib')) exit_error("Can't copy liblzma.lib"); |
| 35 | +if(!@copy(DEPS_PATH . 'lib\libzstd.lib', DEPS_PATH . 'lib\zstd.lib')) exit_error("Can't copy zstd.lib"); |
| 36 | + |
| 37 | + |
| 38 | +// Patch CMakeLists |
| 39 | +$cmakelists = $path . 'lib\CMakeLists.txt'; |
| 40 | +$contents = file_get_contents($cmakelists); |
| 41 | +$contents = str_replace('if(HAVE_LIBBZ2)', 'if(HAVE_LIBBZ2)' . RN . ' add_compile_definitions(LZMA_API_STATIC)', $contents); |
| 42 | +file_put_contents($cmakelists, $contents); |
| 43 | + |
| 44 | + |
| 45 | +// Configure libzip |
| 46 | +$label = "Configure " . $lib->name . '-' . $lib->version; |
| 47 | +draw_line($label, "running", Yellow); |
| 48 | +$bat = '@echo off'.RN; |
| 49 | +$bat .= 'cd ' . escapeshellarg($path).RN; |
| 50 | +$bat .= 'mkdir build-win'.RN; |
| 51 | +$bat .= 'cd build-win'.RN; |
| 52 | +$bat .= 'set PATH=%PATH%;' . ARCH_PATH . 'deps'.RN; |
| 53 | +$bat .= 'cmake -G "Visual Studio 16 2019" BUILD_SHARED_LIBS=OFF ..'.RN; |
| 54 | +$batfile = TMP . 'build_libzip.bat'; |
| 55 | +file_put_contents($batfile, $bat); |
| 56 | +$ret = shell_exec_vs16($batfile); |
| 57 | +file_put_contents($ziplog, $ret); |
| 58 | + |
| 59 | + |
| 60 | +// Verify if the solution works |
| 61 | +if(!is_file($path . 'build-win\libzip.sln')) draw_status($label, "failed", Red, true, 'SEE: ' . $ziplog); |
| 62 | +else draw_status($label, "complete", Green); |
| 63 | + |
| 64 | + |
| 65 | +// Patch solution file to enable full static library |
| 66 | +$prjfile = $path . 'build-win\lib\zip.vcxproj'; |
| 67 | +$contents = file_get_contents($prjfile); |
| 68 | +$contents = str_replace('<ConfigurationType>DynamicLibrary</ConfigurationType>', '<ConfigurationType>StaticLibrary</ConfigurationType>', $contents); |
| 69 | +$contents = str_replace('>.dll<', '>.lib<', $contents); |
| 70 | +$addlibs = '<Lib><AdditionalDependencies>' . DEPS_PATH . 'lib\liblzma.lib;' . DEPS_PATH . 'lib\zstd.lib' . ';%(AdditionalDependencies)</AdditionalDependencies></Lib>'; |
| 71 | +$contents = preg_replace('#<ProjectReference>\s+<LinkLibraryDependencies>false</LinkLibraryDependencies>\s+</ProjectReference>#msi', '<ProjectReference><LinkLibraryDependencies>true</LinkLibraryDependencies></ProjectReference>'. $addlibs, $contents); |
| 72 | +file_put_contents($prjfile, $contents); |
| 73 | + |
| 74 | + |
| 75 | +// Compile libzip |
| 76 | +$label = "Compile " . $lib->name . '-' . $lib->version; |
| 77 | +draw_line($label, "running", Yellow); |
| 78 | +$bat = '@echo off'.RN; |
| 79 | +$bat .= 'cd ' . escapeshellarg($path . 'build-win').RN; |
| 80 | +$bat .= 'DEVENV libzip.sln /rebuild "Release|x64" /project zip'.RN; |
| 81 | +$batfile = TMP . 'build_libzip.bat'; |
| 82 | +file_put_contents($batfile, $bat); |
| 83 | +$ret = shell_exec_vs16($batfile); |
| 84 | +file_put_contents($ziplog, $ret, FILE_APPEND); |
| 85 | + |
| 86 | + |
| 87 | +// Verify if the build works |
| 88 | +if(!is_file($path . 'build-win\lib\Release\zip.lib')) draw_status($label, "failed", Red, true, 'SEE: ' . $ziplog); |
| 89 | +else draw_status($label, "complete", Green); |
| 90 | + |
| 91 | + |
| 92 | +// Install libzip |
| 93 | +$label = "Install " . $lib->name . '-' . $lib->version; |
| 94 | +draw_line($label, "running", Yellow); |
| 95 | +$builddir = $path . 'build\\'; |
| 96 | + |
| 97 | +$files[$path . 'build-win\lib\Release\zip.lib'] = 'lib\libzip_a.lib'; |
| 98 | +$files[$path . 'build-win\zipconf.h'] = 'include\zipconf.h'; |
| 99 | +$files[$path . 'lib\zip.h'] = 'include\zip.h'; |
| 100 | + |
| 101 | +if(!create_build($builddir, $files)) draw_status($label, "failed", Red, true); |
| 102 | +if(!install_deps($builddir)) draw_status($label, "failed", Red, true); |
| 103 | +else draw_status($label, "complete", Green); |
| 104 | + |
| 105 | +delete_parent_deps($lib->name); |
| 106 | + |
| 107 | + |
| 108 | +// Delete temp libraries |
| 109 | +unlink(DEPS_PATH . 'lib\zlib.lib'); |
| 110 | +unlink(DEPS_PATH . 'lib\libbz2.lib'); |
| 111 | +unlink(DEPS_PATH . 'lib\liblzma.lib'); |
| 112 | +unlink(DEPS_PATH . 'lib\zstd.lib'); |
0 commit comments