diff options
Diffstat (limited to 'vcpkg/ports/libmagic')
19 files changed, 986 insertions, 0 deletions
diff --git a/vcpkg/ports/libmagic/0001-Use-libtre.patch b/vcpkg/ports/libmagic/0001-Use-libtre.patch new file mode 100644 index 0000000..a1080d5 --- /dev/null +++ b/vcpkg/ports/libmagic/0001-Use-libtre.patch @@ -0,0 +1,53 @@ +From e6e59f41c082be94c4fef007e276b1dffe7dc240 Mon Sep 17 00:00:00 2001 +From: Long Nguyen <nguyen.long.908132@gmail.com> +Date: Sat, 8 May 2021 19:28:01 +0700 +Subject: [PATCH 01/14] Use libtre + +--- + configure.ac | 2 +- + src/Makefile.am | 2 +- + src/file.h | 2 +- + 3 files changed, 3 insertions(+), 3 deletions(-) + +diff --git a/configure.ac b/configure.ac +index 02eac8f..b05c334 100644 +--- a/configure.ac ++++ b/configure.ac +@@ -185,7 +185,7 @@ if test "$enable_libseccomp" != "no"; then + AC_CHECK_LIB(seccomp, seccomp_init) + fi + if test "$MINGW" = 1; then +- AC_CHECK_LIB(gnurx,regexec,,AC_MSG_ERROR([libgnurx is required to build file(1) with MinGW])) ++ AC_SEARCH_LIBS(tre_regexec,tre,,AC_MSG_ERROR([libtre is required to build file(1) with MinGW])) + fi + + dnl See if we are cross-compiling +diff --git a/src/Makefile.am b/src/Makefile.am +index 3f67f2c..34781b9 100644 +--- a/src/Makefile.am ++++ b/src/Makefile.am +@@ -13,7 +13,7 @@ libmagic_la_SOURCES = buffer.c magic.c apprentice.c softmagic.c ascmagic.c \ + file_opts.h elfclass.h mygetopt.h cdf.c cdf_time.c readcdf.c cdf.h + libmagic_la_LDFLAGS = -no-undefined -version-info 1:0:0 + if MINGW +-MINGWLIBS = -lgnurx -lshlwapi ++MINGWLIBS = -lshlwapi + else + MINGWLIBS = + endif +diff --git a/src/file.h b/src/file.h +index c548e97..299ac0c 100644 +--- a/src/file.h ++++ b/src/file.h +@@ -79,7 +79,7 @@ + #include <stdio.h> /* Include that here, to make sure __P gets defined */ + #include <errno.h> + #include <fcntl.h> /* For open and flags */ +-#include <regex.h> ++#include <tre/regex.h> + #include <time.h> + #include <sys/types.h> + #ifndef WIN32 +-- +2.29.2.windows.2 + diff --git a/vcpkg/ports/libmagic/0002-Change-zlib-lib-name-to-match-CMake-output.patch b/vcpkg/ports/libmagic/0002-Change-zlib-lib-name-to-match-CMake-output.patch new file mode 100644 index 0000000..e70c202 --- /dev/null +++ b/vcpkg/ports/libmagic/0002-Change-zlib-lib-name-to-match-CMake-output.patch @@ -0,0 +1,39 @@ +From 2fa43ece9ec7564e1fbb9867bb5852b834643aa4 Mon Sep 17 00:00:00 2001 +From: Long Nguyen <nguyen.long.908132@gmail.com> +Date: Sat, 8 May 2021 19:36:11 +0700 +Subject: [PATCH 02/14] Change zlib lib name to match CMake output + +--- + configure.ac | 6 +++--- + 1 file changed, 3 insertions(+), 3 deletions(-) + +diff --git a/configure.ac b/configure.ac +index b05c334..dd4063c 100644 +--- a/configure.ac ++++ b/configure.ac +@@ -173,7 +173,7 @@ AC_REPLACE_FUNCS(getopt_long asprintf vasprintf strlcpy strlcat getline ctime_r + + dnl Checks for libraries + if test "$enable_zlib" != "no"; then +- AC_CHECK_LIB(z, gzopen) ++ AC_SEARCH_LIBS(gzopen, [z zlib zlibd], have_zlib="yes", have_zlib="no") + fi + if test "$enable_bzlib" != "no"; then + AC_CHECK_LIB(bz2, BZ2_bzCompressInit) +@@ -193,11 +193,11 @@ AM_CONDITIONAL(IS_CROSS_COMPILE, test "$cross_compiling" = yes) + + dnl Final sanity checks + if test "$enable_zlib" = "yes"; then +- if test "$ac_cv_header_zlib_h$ac_cv_lib_z_gzopen" != "yesyes"; then ++ if test "$ac_cv_header_zlib_h$have_zlib" != "yesyes"; then + AC_MSG_ERROR([zlib support requested but not found]) + fi + fi +-if test "$ac_cv_header_zlib_h$ac_cv_lib_z_gzopen" = "yesyes"; then ++if test "$ac_cv_header_zlib_h$have_zlib" = "yesyes"; then + AC_DEFINE([ZLIBSUPPORT], 1, [Enable zlib compression support]) + fi + if test "$enable_bzlib" = "yes"; then +-- +2.29.2.windows.2 + diff --git a/vcpkg/ports/libmagic/0003-Fix-WIN32-macro-checks.patch b/vcpkg/ports/libmagic/0003-Fix-WIN32-macro-checks.patch new file mode 100644 index 0000000..7b88b1f --- /dev/null +++ b/vcpkg/ports/libmagic/0003-Fix-WIN32-macro-checks.patch @@ -0,0 +1,31 @@ +diff --git a/src/file.h b/src/file.h +index a67e8ff..9115c5b 100644 +--- a/src/file.h ++++ b/src/file.h +@@ -82,7 +82,7 @@ + #include <tre/regex.h> + #include <time.h> + #include <sys/types.h> +-#ifndef WIN32 ++#ifndef _WIN32 + #include <sys/param.h> + #endif + /* Do this here and now, because struct stat gets re-defined on solaris */ +@@ -99,7 +99,7 @@ + #define MAGIC "/etc/magic" + #endif + +-#if defined(__EMX__) || defined (WIN32) ++#if defined(__EMX__) || defined (_WIN32) + #define PATHSEP ';' + #else + #define PATHSEP ':' +@@ -108,7 +108,7 @@ + #define file_private static + + #if HAVE_VISIBILITY +-# if defined(WIN32) ++# if defined(_WIN32) + # define file_public __declspec(dllexport) + # ifndef file_protected + # define file_protected diff --git a/vcpkg/ports/libmagic/0004-Typedef-POSIX-types-on-Windows.patch b/vcpkg/ports/libmagic/0004-Typedef-POSIX-types-on-Windows.patch new file mode 100644 index 0000000..a152984 --- /dev/null +++ b/vcpkg/ports/libmagic/0004-Typedef-POSIX-types-on-Windows.patch @@ -0,0 +1,29 @@ +From eb3dde2954dacd86ec7490540eb9b7e3530b917b Mon Sep 17 00:00:00 2001 +From: Long Nguyen <nguyen.long.908132@gmail.com> +Date: Sat, 8 May 2021 20:12:55 +0700 +Subject: [PATCH 04/14] Typedef POSIX types on Windows + +--- + src/file.h | 6 ++++++ + 1 file changed, 6 insertions(+) + +diff --git a/src/file.h b/src/file.h +index 2c365a6..0332506 100644 +--- a/src/file.h ++++ b/src/file.h +@@ -425,6 +425,12 @@ struct cont { + + #define MAGIC_SETS 2 + ++#ifdef _MSC_VER ++#include <BaseTsd.h> ++typedef int mode_t; ++typedef SSIZE_T ssize_t; ++#endif ++ + struct magic_set { + struct mlist *mlist[MAGIC_SETS]; /* list of regular entries */ + struct cont c; +-- +2.29.2.windows.2 + diff --git a/vcpkg/ports/libmagic/0005-Include-dirent.h-for-S_ISREG-and-S_ISDIR.patch b/vcpkg/ports/libmagic/0005-Include-dirent.h-for-S_ISREG-and-S_ISDIR.patch new file mode 100644 index 0000000..afcb658 --- /dev/null +++ b/vcpkg/ports/libmagic/0005-Include-dirent.h-for-S_ISREG-and-S_ISDIR.patch @@ -0,0 +1,25 @@ +From a8f8fbfc2736419c65992cbf24de963c3b1f3107 Mon Sep 17 00:00:00 2001 +From: Long Nguyen <nguyen.long.908132@gmail.com> +Date: Sat, 8 May 2021 22:07:55 +0700 +Subject: [PATCH 05/14] Include dirent.h for S_ISREG and S_ISDIR + +--- + src/file.h | 1 + + 1 file changed, 1 insertion(+) + +diff --git a/src/file.h b/src/file.h +index 0332506..4aa9f60 100644 +--- a/src/file.h ++++ b/src/file.h +@@ -88,7 +88,8 @@ + /* Do this here and now, because struct stat gets re-defined on solaris */ + #include <sys/stat.h> + #include <stdarg.h> ++#include <dirent.h> + #include <locale.h> + #if defined(HAVE_XLOCALE_H) + #include <xlocale.h> + #endif +-- +2.29.2.windows.2 + diff --git a/vcpkg/ports/libmagic/0006-Remove-Wrap-POSIX-headers.patch b/vcpkg/ports/libmagic/0006-Remove-Wrap-POSIX-headers.patch new file mode 100644 index 0000000..169561d --- /dev/null +++ b/vcpkg/ports/libmagic/0006-Remove-Wrap-POSIX-headers.patch @@ -0,0 +1,189 @@ +From b20c8e62851f3cb53083a3e7811518092f98dc26 Mon Sep 17 00:00:00 2001 +From: Long Nguyen <nguyen.long.908132@gmail.com> +Date: Sat, 8 May 2021 22:47:32 +0700 +Subject: [PATCH 06/14] Remove/Wrap POSIX headers + +--- + src/buffer.c | 2 ++ + src/cdf.c | 2 ++ + src/dprintf.c | 2 ++ + src/file.c | 1 - + src/getline.c | 2 ++ + src/is_csv.c | 2 ++ + src/is_json.c | 2 ++ + src/magic.c | 2 ++ + src/memtest.c | 2 ++ + src/mygetopt.h | 2 ++ + src/pread.c | 2 ++ + src/readcdf.c | 2 ++ + 12 files changed, 22 insertions(+), 1 deletion(-) + +diff --git a/src/buffer.c b/src/buffer.c +index 227015a..f3d8efa 100644 +--- a/src/buffer.c ++++ b/src/buffer.c +@@ -31,7 +31,9 @@ FILE_RCSID("@(#)$File: buffer.c,v 1.8 2020/02/16 15:52:49 christos Exp $") + #endif /* lint */ + + #include "magic.h" ++#ifdef HAVE_UNISTD_H + #include <unistd.h> ++#endif + #include <string.h> + #include <stdlib.h> + #include <sys/stat.h> +diff --git a/src/cdf.c b/src/cdf.c +index bb81d63..dc9ec56 100644 +--- a/src/cdf.c ++++ b/src/cdf.c +@@ -43,7 +43,9 @@ FILE_RCSID("@(#)$File: cdf.c,v 1.116 2019/08/26 14:31:39 christos Exp $") + #include <err.h> + #endif + #include <stdlib.h> ++#ifdef HAVE_UNISTD_H + #include <unistd.h> ++#endif + #include <string.h> + #include <time.h> + #include <ctype.h> +diff --git a/src/dprintf.c b/src/dprintf.c +index 027a64f..873c547 100644 +--- a/src/dprintf.c ++++ b/src/dprintf.c +@@ -32,7 +32,9 @@ FILE_RCSID("@(#)$File: dprintf.c,v 1.2 2018/09/09 20:33:28 christos Exp $") + #endif /* lint */ + + #include <assert.h> ++#ifdef HAVE_UNISTD_H + #include <unistd.h> ++#endif + #include <stdio.h> + #include <stdarg.h> + +diff --git a/src/file.c b/src/file.c +index 87b9ab1..2889f8a 100644 +--- a/src/file.c ++++ b/src/file.c +@@ -38,7 +38,6 @@ FILE_RCSID("@(#)$File: file.c,v 1.189 2021/02/05 21:33:49 christos Exp $") + #include "magic.h" + + #include <stdlib.h> +-#include <unistd.h> + #include <string.h> + #ifdef RESTORE_TIME + # if (__COHERENT__ >= 0x420) +diff --git a/src/getline.c b/src/getline.c +index b00de01..c2d41ca 100644 +--- a/src/getline.c ++++ b/src/getline.c +@@ -33,7 +33,9 @@ + #if !HAVE_GETLINE + #include <stdlib.h> + #include <stdio.h> ++#ifdef HAVE_UNISTD_H + #include <unistd.h> ++#endif + #include <errno.h> + #include <string.h> + +diff --git a/src/is_csv.c b/src/is_csv.c +index 937ab5f..2f704c5 100644 +--- a/src/is_csv.c ++++ b/src/is_csv.c +@@ -166,7 +166,9 @@ file_is_csv(struct magic_set *ms, const struct buffer *b, int looks_text) + #include <sys/stat.h> + #include <stdio.h> + #include <fcntl.h> ++#ifdef HAVE_UNISTD_H + #include <unistd.h> ++#endif + #include <stdlib.h> + #include <stdint.h> + #include <err.h> +diff --git a/src/is_json.c b/src/is_json.c +index 0b12438..997a276 100644 +--- a/src/is_json.c ++++ b/src/is_json.c +@@ -436,7 +436,9 @@ file_is_json(struct magic_set *ms, const struct buffer *b) + #include <sys/stat.h> + #include <stdio.h> + #include <fcntl.h> ++#ifdef HAVE_UNISTD_H + #include <unistd.h> ++#endif + #include <stdlib.h> + #include <stdint.h> + #include <err.h> +diff --git a/src/magic.c b/src/magic.c +index 81a0840..e9aeafa 100644 +--- a/src/magic.c ++++ b/src/magic.c +@@ -39,7 +39,9 @@ FILE_RCSID("@(#)$File: magic.c,v 1.114 2021/02/05 21:33:49 christos Exp $") + #include "magic.h" + + #include <stdlib.h> ++#ifdef HAVE_UNISTD_H + #include <unistd.h> ++#endif + #include <string.h> + #ifdef QUICK + #include <sys/mman.h> +diff --git a/src/memtest.c b/src/memtest.c +index f9506f6..ea50242 100644 +--- a/src/memtest.c ++++ b/src/memtest.c +@@ -34,7 +34,9 @@ + #include <stdlib.h> + #include <err.h> + #include <fcntl.h> ++#ifdef HAVE_UNISTD_H + #include <unistd.h> ++#endif + #include <dlfcn.h> + #include <magic.h> + +diff --git a/src/mygetopt.h b/src/mygetopt.h +index d766762..b8e044c 100644 +--- a/src/mygetopt.h ++++ b/src/mygetopt.h +@@ -39,7 +39,9 @@ + #ifndef _GETOPT_H_ + #define _GETOPT_H_ + ++#ifdef HAVE_UNISTD_H + #include <unistd.h> ++#endif + + /* + * Gnu like getopt_long() and BSD4.4 getsubopt()/optreset extensions +diff --git a/src/pread.c b/src/pread.c +index 3ab52d1..fc48d84 100644 +--- a/src/pread.c ++++ b/src/pread.c +@@ -3,7 +3,9 @@ + FILE_RCSID("@(#)$File: pread.c,v 1.5 2022/09/24 20:30:13 christos Exp $") + #endif /* lint */ + #include <fcntl.h> ++#ifdef HAVE_UNISTD_H + #include <unistd.h> ++#endif + + ssize_t + pread(int fd, void *buf, size_t len, off_t off) { +diff --git a/src/readcdf.c b/src/readcdf.c +index 7622c7b..977cb75 100644 +--- a/src/readcdf.c ++++ b/src/readcdf.c +@@ -31,7 +31,9 @@ FILE_RCSID("@(#)$File: readcdf.c,v 1.74 2019/09/11 15:46:30 christos Exp $") + + #include <assert.h> + #include <stdlib.h> ++#ifdef HAVE_UNISTD_H + #include <unistd.h> ++#endif + #include <string.h> + #include <time.h> + #include <ctype.h> +-- +2.29.2.windows.2 + diff --git a/vcpkg/ports/libmagic/0007-Substitute-unistd-macros-for-MSVC.patch b/vcpkg/ports/libmagic/0007-Substitute-unistd-macros-for-MSVC.patch new file mode 100644 index 0000000..726fbde --- /dev/null +++ b/vcpkg/ports/libmagic/0007-Substitute-unistd-macros-for-MSVC.patch @@ -0,0 +1,30 @@ +From 1106d1523ed44bcbcca90fc1fe9fa9400777d8fe Mon Sep 17 00:00:00 2001 +From: Long Nguyen <nguyen.long.908132@gmail.com> +Date: Sun, 9 May 2021 10:28:49 +0700 +Subject: [PATCH 07/14] Substitute unistd macros for MSVC + +--- + src/file.h | 7 +++++++ + 1 file changed, 7 insertions(+) + +diff --git a/src/file.h b/src/file.h +index 4aa9f60..5da838c 100644 +--- a/src/file.h ++++ b/src/file.h +@@ -85,6 +85,13 @@ + #ifndef _WIN32 + #include <sys/param.h> + #endif ++#ifdef _MSC_VER ++#include <io.h> ++#define R_OK 4 ++#define W_OK 2 ++#define X_OK R_OK ++#define F_OK 0 ++#endif + /* Do this here and now, because struct stat gets re-defined on solaris */ + #include <sys/stat.h> + #include <stdarg.h> +-- +2.29.2.windows.2 + diff --git a/vcpkg/ports/libmagic/0008-Add-FILENO-defines.patch b/vcpkg/ports/libmagic/0008-Add-FILENO-defines.patch new file mode 100644 index 0000000..dea5080 --- /dev/null +++ b/vcpkg/ports/libmagic/0008-Add-FILENO-defines.patch @@ -0,0 +1,26 @@ +From e449e3fb47aee00f0d82782183cc7fd6b446d27b Mon Sep 17 00:00:00 2001 +From: Long Nguyen <nguyen.long.908132@gmail.com> +Date: Sun, 9 May 2021 13:24:42 +0700 +Subject: [PATCH 08/14] Add FILENO defines + +--- + src/file.h | 3 +++ + 1 file changed, 3 insertions(+) + +diff --git a/src/file.h b/src/file.h +index 5da838c..ccfe0da 100644 +--- a/src/file.h ++++ b/src/file.h +@@ -91,6 +91,9 @@ + #define W_OK 2 + #define X_OK R_OK + #define F_OK 0 ++#define STDIN_FILENO _fileno(stdin) ++#define STDOUT_FILENO _fileno(stdout) ++#define STDERR_FILENO _fileno(stderr) + #endif + /* Do this here and now, because struct stat gets re-defined on solaris */ + #include <sys/stat.h> +-- +2.29.2.windows.2 + diff --git a/vcpkg/ports/libmagic/0010-Properly-check-for-the-presence-of-bitmasks.patch b/vcpkg/ports/libmagic/0010-Properly-check-for-the-presence-of-bitmasks.patch new file mode 100644 index 0000000..e241f5e --- /dev/null +++ b/vcpkg/ports/libmagic/0010-Properly-check-for-the-presence-of-bitmasks.patch @@ -0,0 +1,118 @@ +From a6bc98ce25cd9d9dba896e93ed441ff162f6793b Mon Sep 17 00:00:00 2001 +From: Long Nguyen <nguyen.long.908132@gmail.com> +Date: Sun, 9 May 2021 17:43:20 +0700 +Subject: [PATCH 10/14] Properly check for the presence of bitmasks + +--- + src/fsmagic.c | 24 ++++++++++++------------ + 1 file changed, 12 insertions(+), 12 deletions(-) + +diff --git a/src/fsmagic.c b/src/fsmagic.c +index 5204f20..7244841 100644 +--- a/src/fsmagic.c ++++ b/src/fsmagic.c +@@ -66,7 +66,7 @@ FILE_RCSID("@(#)$File: fsmagic.c,v 1.81 2019/07/16 13:30:32 christos Exp $") + # define minor(dev) ((dev) & 0xff) + #endif + #undef HAVE_MAJOR +-#ifdef S_IFLNK ++#if S_IFLNK != 0 + file_private int + bad_link(struct magic_set *ms, int err, char *buf) + { +@@ -108,7 +108,7 @@ file_fsmagic(struct magic_set *ms, const char *fn, struct stat *sb) + int ret, did = 0; + int mime = ms->flags & MAGIC_MIME; + int silent = ms->flags & (MAGIC_APPLE|MAGIC_EXTENSION); +-#ifdef S_IFLNK ++#if S_IFLNK != 0 + char buf[BUFSIZ+4]; + ssize_t nch; + struct stat tstatbuf; +@@ -122,7 +122,7 @@ file_fsmagic(struct magic_set *ms, const char *fn, struct stat *sb) + * Fstat is cheaper but fails for files you don't have read perms on. + * On 4.2BSD and similar systems, use lstat() to identify symlinks. + */ +-#ifdef S_IFLNK ++#if S_IFLNK != 0 + if ((ms->flags & MAGIC_SYMLINK) == 0) + ret = lstat(fn, sb); + else +@@ -171,17 +171,17 @@ file_fsmagic(struct magic_set *ms, const char *fn, struct stat *sb) + + ret = 1; + if (!mime && !silent) { +-#ifdef S_ISUID ++#if S_ISUID != 0 + if (sb->st_mode & S_ISUID) + if (file_printf(ms, "%ssetuid", COMMA) == -1) + return -1; + #endif +-#ifdef S_ISGID ++#if S_ISGID != 0 + if (sb->st_mode & S_ISGID) + if (file_printf(ms, "%ssetgid", COMMA) == -1) + return -1; + #endif +-#ifdef S_ISVTX ++#if S_ISVTX != 0 + if (sb->st_mode & S_ISVTX) + if (file_printf(ms, "%ssticky", COMMA) == -1) + return -1; +@@ -197,7 +197,7 @@ file_fsmagic(struct magic_set *ms, const char *fn, struct stat *sb) + } else if (file_printf(ms, "%sdirectory", COMMA) == -1) + return -1; + break; +-#ifdef S_IFCHR ++#if S_IFCHR != 0 + case S_IFCHR: + /* + * If -s has been specified, treat character special files +@@ -232,7 +232,7 @@ file_fsmagic(struct magic_set *ms, const char *fn, struct stat *sb) + } + break; + #endif +-#ifdef S_IFBLK ++#if S_IFBLK != 0 + case S_IFBLK: + /* + * If -s has been specified, treat block special files +@@ -268,7 +268,7 @@ file_fsmagic(struct magic_set *ms, const char *fn, struct stat *sb) + break; + #endif + /* TODO add code to handle V7 MUX and Blit MUX files */ +-#ifdef S_IFIFO ++#if S_IFIFO != 0 + case S_IFIFO: + if((ms->flags & MAGIC_DEVICES) != 0) + break; +@@ -280,7 +280,7 @@ file_fsmagic(struct magic_set *ms, const char *fn, struct stat *sb) + return -1; + break; + #endif +-#ifdef S_IFDOOR ++#if S_IFDOOR != 0 + case S_IFDOOR: + if (mime) { + if (handle_mime(ms, mime, "door") == -1) +@@ -290,7 +290,7 @@ file_fsmagic(struct magic_set *ms, const char *fn, struct stat *sb) + return -1; + break; + #endif +-#ifdef S_IFLNK ++#if S_IFLNK != 0 + case S_IFLNK: + if ((nch = readlink(fn, buf, BUFSIZ-1)) <= 0) { + if (ms->flags & MAGIC_ERROR) { +@@ -378,7 +378,7 @@ file_fsmagic(struct magic_set *ms, const char *fn, struct stat *sb) + } + break; + #endif +-#ifdef S_IFSOCK ++#if S_IFSOCK != 0 + #ifndef __COHERENT__ + case S_IFSOCK: + if (mime) { +-- +2.29.2.windows.2 + diff --git a/vcpkg/ports/libmagic/0011-Remove-pipe-related-functions-in-funcs.c.patch b/vcpkg/ports/libmagic/0011-Remove-pipe-related-functions-in-funcs.c.patch new file mode 100644 index 0000000..13c24fa --- /dev/null +++ b/vcpkg/ports/libmagic/0011-Remove-pipe-related-functions-in-funcs.c.patch @@ -0,0 +1,30 @@ +From 15b0f505ff9eefd41b74ffdd4230355e933263ca Mon Sep 17 00:00:00 2001 +From: Long Nguyen <nguyen.long.908132@gmail.com> +Date: Sun, 9 May 2021 17:45:50 +0700 +Subject: [PATCH 11/14] Remove pipe related functions in funcs.c + +--- + src/funcs.c | 2 ++ + 1 file changed, 2 insertions(+) + +diff --git a/src/funcs.c b/src/funcs.c +index b926625..b585486 100644 +--- a/src/funcs.c ++++ b/src/funcs.c +@@ -888,5 +888,6 @@ + } + ++#ifndef _WIN32 + file_protected int + file_pipe_closexec(int *fds) + { +@@ -914,5 +915,6 @@ + #endif + } ++#endif + + file_protected char * + file_strtrim(char *str) +-- +2.29.2.windows.2 + diff --git a/vcpkg/ports/libmagic/0012-Convert-MSYS2-paths-to-Windows-paths.patch b/vcpkg/ports/libmagic/0012-Convert-MSYS2-paths-to-Windows-paths.patch new file mode 100644 index 0000000..728fe77 --- /dev/null +++ b/vcpkg/ports/libmagic/0012-Convert-MSYS2-paths-to-Windows-paths.patch @@ -0,0 +1,24 @@ +From f0139ced57c1579450f3d09b6e3ae0159aae031b Mon Sep 17 00:00:00 2001 +From: Long Nguyen <nguyen.long.908132@gmail.com> +Date: Mon, 10 May 2021 08:43:28 +0700 +Subject: [PATCH 12/14] Convert MSYS2 paths to Windows paths + +--- + src/Makefile.am | 3 +++ + 1 file changed, 3 insertions(+) + +diff --git a/src/Makefile.am b/src/Makefile.am +index 34781b9..26f853f 100644 +--- a/src/Makefile.am ++++ b/src/Makefile.am +@@ -1,4 +1,7 @@ + MAGIC = $(pkgdatadir)/magic ++if MINGW ++MAGIC != cygpath -m -a -l '$(MAGIC)' ++endif + lib_LTLIBRARIES = libmagic.la + nodist_include_HEADERS = magic.h + +-- +2.29.2.windows.2 + diff --git a/vcpkg/ports/libmagic/0013-Check-for-backslash-in-argv-0-on-Windows.patch b/vcpkg/ports/libmagic/0013-Check-for-backslash-in-argv-0-on-Windows.patch new file mode 100644 index 0000000..77777fc --- /dev/null +++ b/vcpkg/ports/libmagic/0013-Check-for-backslash-in-argv-0-on-Windows.patch @@ -0,0 +1,42 @@ +From 3f10c7d31627b64b068b84ba72e706991f672560 Mon Sep 17 00:00:00 2001 +From: Long Nguyen <nguyen.long.908132@gmail.com> +Date: Fri, 14 May 2021 08:14:05 +0700 +Subject: [PATCH 13/14] Check for backslash in argv[0] on Windows + +--- + magic/Makefile.am | 2 +- + src/file.c | 5 +++++ + 2 files changed, 6 insertions(+), 1 deletion(-) + +diff --git a/magic/Makefile.am b/magic/Makefile.am +index 0eb5865..170bbab 100644 +--- a/magic/Makefile.am ++++ b/magic/Makefile.am +@@ -353,7 +353,7 @@ ${MAGIC}: $(EXTRA_DIST) $(FILE_COMPILE_DEP) + @(if expr "${FILE_COMPILE}" : '.*/.*' > /dev/null; then \ + echo "Using ${FILE_COMPILE} to generate ${MAGIC}" > /dev/null; \ + else \ +- v=$$(${FILE_COMPILE} --version | sed -e s/file-// -e q); \ ++ v=$$(${FILE_COMPILE} --version | sed -e s/file${EXEEXT}-// -e q); \ + if [ "$$v" != "${PACKAGE_VERSION}" ]; then \ + echo "Cannot use the installed version of file ($$v) to"; \ + echo "cross-compile file ${PACKAGE_VERSION}"; \ +diff --git a/src/file.c b/src/file.c +index 2889f8a..12a604b 100644 +--- a/src/file.c ++++ b/src/file.c +@@ -200,6 +200,11 @@ main(int argc, char *argv[]) + _wildcard(&argc, &argv); + #endif + ++#ifdef _WIN32 ++ if ((progname = strrchr(argv[0], '\\')) != NULL) ++ progname++; ++ else ++#endif + if ((progname = strrchr(argv[0], '/')) != NULL) + progname++; + else +-- +2.29.2.windows.2 + diff --git a/vcpkg/ports/libmagic/0015-MSYS2-Remove-ioctl-call.patch b/vcpkg/ports/libmagic/0015-MSYS2-Remove-ioctl-call.patch new file mode 100644 index 0000000..13fe3cf --- /dev/null +++ b/vcpkg/ports/libmagic/0015-MSYS2-Remove-ioctl-call.patch @@ -0,0 +1,27 @@ +# From https://github.com/msys2/MINGW-packages/commit/3a51faadb8bacf06c7b7fd84b2ea80775d1a8b0d + +# this is an advanced patch to fix building v5.38 +# see for details +# this patch should be removed with the next version +diff --git a/src/compress.c b/src/compress.c +index 33ce2bc..f172eda 100644 +--- a/src/compress.c ++++ b/src/compress.c +@@ -407,7 +407,7 @@ + sread(int fd, void *buf, size_t n, int canbepipe __attribute__((__unused__))) + { + ssize_t rv; +-#if defined(FIONREAD) && !defined(__MINGW32__) ++#if defined(FIONREAD) && !defined(__MINGW32__) && !defined(WIN32) + int t = 0; + #endif + size_t rn = n; +@@ -418,7 +418,7 @@ + if (fd == STDIN_FILENO) + goto nocheck; + +-#if defined(FIONREAD) && !defined(__MINGW32__) ++#if defined(FIONREAD) && !defined(__MINGW32__) && !defined(WIN32) + if (canbepipe && (ioctl(fd, FIONREAD, &t) == -1 || t == 0)) { + #ifdef FD_ZERO + ssize_t cnt; diff --git a/vcpkg/ports/libmagic/0016-Fix-file_famagic-function.patch b/vcpkg/ports/libmagic/0016-Fix-file_famagic-function.patch new file mode 100644 index 0000000..5eaba92 --- /dev/null +++ b/vcpkg/ports/libmagic/0016-Fix-file_famagic-function.patch @@ -0,0 +1,40 @@ +diff --git a/src/fsmagic.c b/src/fsmagic.c +index 7244841..2c553c1 100644 +--- a/src/fsmagic.c ++++ b/src/fsmagic.c +@@ -66,7 +66,7 @@ # define major(dev) (((dev) >> 8) & 0xff) + # define minor(dev) ((dev) & 0xff) + #endif + #undef HAVE_MAJOR +-#if S_IFLNK != 0 ++#if S_IFLNK != 0 && ! defined(_WIN32) + file_private int + bad_link(struct magic_set *ms, int err, char *buf) + { +@@ -108,7 +108,7 @@ file_fsmagic(struct magic_set *ms, const char *fn, struct stat *sb) + int ret, did = 0; + int mime = ms->flags & MAGIC_MIME; + int silent = ms->flags & (MAGIC_APPLE|MAGIC_EXTENSION); +-#if S_IFLNK != 0 ++#if S_IFLNK != 0 && ! defined(_WIN32) + char buf[BUFSIZ+4]; + ssize_t nch; + struct stat tstatbuf; +@@ -122,7 +122,7 @@ file_fsmagic(struct magic_set *ms, const char *fn, struct stat *sb) + * Fstat is cheaper but fails for files you don't have read perms on. + * On 4.2BSD and similar systems, use lstat() to identify symlinks. + */ +-#if S_IFLNK != 0 ++#if S_IFLNK != 0 && ! defined(_WIN32) + if ((ms->flags & MAGIC_SYMLINK) == 0) + ret = lstat(fn, sb); + else +@@ -290,7 +290,7 @@ file_fsmagic(struct magic_set *ms, const char *fn, struct stat *sb) + return -1; + break; + #endif +-#if S_IFLNK != 0 ++#if S_IFLNK != 0 && ! defined(_WIN32) + case S_IFLNK: + if ((nch = readlink(fn, buf, BUFSIZ-1)) <= 0) { + if (ms->flags & MAGIC_ERROR) { diff --git a/vcpkg/ports/libmagic/0017-Change-bzlib-name-to-match-CMake-output.patch b/vcpkg/ports/libmagic/0017-Change-bzlib-name-to-match-CMake-output.patch new file mode 100644 index 0000000..ba26f6c --- /dev/null +++ b/vcpkg/ports/libmagic/0017-Change-bzlib-name-to-match-CMake-output.patch @@ -0,0 +1,27 @@ +diff --git a/configure.ac b/configure.ac +index 8b54efda..d043fb06 100644 +--- a/configure.ac ++++ b/configure.ac +@@ -191,7 +191,7 @@ if test "$enable_zlib" != "no"; then + AC_SEARCH_LIBS(gzopen, [z zlib zlibd], have_zlib="yes", have_zlib="no") + fi + if test "$enable_bzlib" != "no"; then +- AC_CHECK_LIB(bz2, BZ2_bzCompressInit) ++ AC_SEARCH_LIBS(BZ2_bzCompressInit, [bz2 bz2d], have_bzlib="yes", have_bzlib="no") + fi + if test "$enable_xzlib" != "no"; then + AC_CHECK_LIB(lzma, lzma_stream_decoder) +@@ -222,11 +222,11 @@ if test "$ac_cv_header_zlib_h$have_zlib" = "yesyes"; then + AC_DEFINE([ZLIBSUPPORT], 1, [Enable zlib compression support]) + fi + if test "$enable_bzlib" = "yes"; then +- if test "$ac_cv_header_bzlib_h$ac_cv_lib_bz2_BZ2_bzCompressInit" != "yesyes"; then ++ if test "$ac_cv_header_bzlib_h$have_bzlib" != "yesyes"; then + AC_MSG_ERROR([bzlib support requested but not found]) + fi + fi +-if test "$ac_cv_header_bzlib_h$ac_cv_lib_bz2_BZ2_bzCompressInit" = "yesyes"; then ++if test "$ac_cv_header_bzlib_h$have_bzlib" = "yesyes"; then + AC_DEFINE([BZLIBSUPPORT], 1, [Enable bzlib compression support]) + fi + if test "$enable_xzlib" = "yes"; then diff --git a/vcpkg/ports/libmagic/portfile.cmake b/vcpkg/ports/libmagic/portfile.cmake new file mode 100644 index 0000000..d04f65c --- /dev/null +++ b/vcpkg/ports/libmagic/portfile.cmake @@ -0,0 +1,105 @@ +if(VCPKG_TARGET_IS_WINDOWS) + set(PATCHES + "0001-Use-libtre.patch" + "0002-Change-zlib-lib-name-to-match-CMake-output.patch" + "0003-Fix-WIN32-macro-checks.patch" + "0004-Typedef-POSIX-types-on-Windows.patch" + "0005-Include-dirent.h-for-S_ISREG-and-S_ISDIR.patch" + "0006-Remove-Wrap-POSIX-headers.patch" + "0007-Substitute-unistd-macros-for-MSVC.patch" + "0008-Add-FILENO-defines.patch" + "0010-Properly-check-for-the-presence-of-bitmasks.patch" + "0011-Remove-pipe-related-functions-in-funcs.c.patch" + "0012-Convert-MSYS2-paths-to-Windows-paths.patch" + "0013-Check-for-backslash-in-argv-0-on-Windows.patch" + "0015-MSYS2-Remove-ioctl-call.patch" + "0016-Fix-file_famagic-function.patch" + "0017-Change-bzlib-name-to-match-CMake-output.patch" + ) +endif() + +vcpkg_from_github( + OUT_SOURCE_PATH SOURCE_PATH + REPO file/file + REF FILE5_46 + SHA512 fb8157ee8065feaf57412ccdeee57cd8fc853b54ac49b0ddc818eeb1ca3555a7cfd25dea08996503f7c565dcba8c57fd7e4dc5fe3452872c617f5612a94a8f0e + HEAD_REF master + PATCHES ${PATCHES} +) + +if(VCPKG_TARGET_IS_WINDOWS) + set(VCPKG_C_FLAGS "${VCPKG_C_FLAGS} -D_CRT_SECURE_NO_WARNINGS -D_CRT_NONSTDC_NO_WARNINGS") + set(VCPKG_CXX_FLAGS "${VCPKG_CXX_FLAGS} -D_CRT_SECURE_NO_WARNINGS -D_CRT_NONSTDC_NO_WARNINGS") +endif() + +if(VCPKG_TARGET_IS_WINDOWS AND VCPKG_LIBRARY_LINKAGE STREQUAL "static") + set(VCPKG_C_FLAGS "${VCPKG_C_FLAGS} -DBUILD_AS_WINDOWS_STATIC_LIBARAY") + set(VCPKG_CXX_FLAGS "${VCPKG_CXX_FLAGS} -DBUILD_AS_WINDOWS_STATIC_LIBARAY") +endif() + +set(FEATURE_OPTIONS) + +macro(enable_feature feature switch) + if("${feature}" IN_LIST FEATURES) + list(APPEND FEATURE_OPTIONS "--enable-${switch}") + set(has_${feature} 1) + else() + list(APPEND FEATURE_OPTIONS "--disable-${switch}") + set(has_${feature} 0) + endif() +endmacro() + +enable_feature("bzip2" "bzlib") +enable_feature("zlib" "zlib") +enable_feature("lzma" "xzlib") +enable_feature("zstd" "zstdlib") + +vcpkg_configure_make( + AUTOCONFIG + SOURCE_PATH "${SOURCE_PATH}" + OPTIONS + ${FEATURE_OPTIONS} + "--disable-lzlib" + "--disable-libseccomp" +) + +if(VCPKG_CROSSCOMPILING) + vcpkg_add_to_path(PREPEND "${CURRENT_HOST_INSTALLED_DIR}/tools/libmagic/bin") +elseif(VCPKG_TARGET_IS_WINDOWS AND VCPKG_LIBRARY_LINKAGE STREQUAL dynamic) + set(EXTRA_ARGS "ADD_BIN_TO_PATH") +endif() + +vcpkg_install_make(${EXTRA_ARGS}) +vcpkg_copy_tool_dependencies("${CURRENT_PACKAGES_DIR}/tools/${PORT}/bin") +vcpkg_copy_tool_dependencies("${CURRENT_PACKAGES_DIR}/tools/${PORT}/debug/bin") +vcpkg_fixup_pkgconfig() + +if(VCPKG_LIBRARY_LINKAGE STREQUAL static) + file(REMOVE_RECURSE "${CURRENT_PACKAGES_DIR}/bin" "${CURRENT_PACKAGES_DIR}/debug/bin") +endif() + +if(VCPKG_TARGET_IS_WINDOWS) + if(NOT VCPKG_BUILD_TYPE OR VCPKG_BUILD_TYPE STREQUAL "release") + file(MAKE_DIRECTORY "${CURRENT_PACKAGES_DIR}/tools/${PORT}/share/misc") + file(COPY "${CURRENT_PACKAGES_DIR}/share/${PORT}/misc/magic.mgc" DESTINATION "${CURRENT_PACKAGES_DIR}/tools/${PORT}/share/misc") + endif() + if(NOT VCPKG_BUILD_TYPE OR VCPKG_BUILD_TYPE STREQUAL "debug") + file(MAKE_DIRECTORY "${CURRENT_PACKAGES_DIR}/tools/${PORT}/debug/share/misc") + file(COPY "${CURRENT_PACKAGES_DIR}/share/${PORT}/misc/magic.mgc" DESTINATION "${CURRENT_PACKAGES_DIR}/tools/${PORT}/debug/share/misc") + endif() +endif() + +file(REMOVE_RECURSE "${CURRENT_PACKAGES_DIR}/debug/include") +file(REMOVE_RECURSE "${CURRENT_PACKAGES_DIR}/debug/share") +file(REMOVE_RECURSE "${CURRENT_PACKAGES_DIR}/share/${PORT}/man5") + +include(CMakePackageConfigHelpers) +configure_package_config_file( + "${CMAKE_CURRENT_LIST_DIR}/unofficial-${PORT}-config.cmake.in" + "${CURRENT_PACKAGES_DIR}/share/unofficial-${PORT}/unofficial-${PORT}-config.cmake" + INSTALL_DESTINATION "share/unofficial-${PORT}" +) + +# Handle copyright and usage +vcpkg_install_copyright(FILE_LIST "${SOURCE_PATH}/COPYING") +file(INSTALL "${CMAKE_CURRENT_LIST_DIR}/usage" DESTINATION "${CURRENT_PACKAGES_DIR}/share/${PORT}") diff --git a/vcpkg/ports/libmagic/unofficial-libmagic-config.cmake.in b/vcpkg/ports/libmagic/unofficial-libmagic-config.cmake.in new file mode 100644 index 0000000..9de6058 --- /dev/null +++ b/vcpkg/ports/libmagic/unofficial-libmagic-config.cmake.in @@ -0,0 +1,93 @@ +@PACKAGE_INIT@
+
+include(CMakeFindDependencyMacro)
+
+if("@VCPKG_LIBRARY_LINKAGE@" STREQUAL "static")
+ if(WIN32)
+ find_dependency(unofficial-tre)
+ endif()
+
+ if(@has_zlib@)
+ find_dependency(ZLIB)
+ endif()
+
+ if(@has_bzip2@)
+ find_dependency(BZip2)
+ endif()
+
+ if(@has_lzma@)
+ find_dependency(LibLZMA)
+ endif()
+
+ if(@has_zstd@)
+ find_dependency(zstd)
+ endif()
+endif()
+
+# Compute the installation prefix relative to this file.
+get_filename_component(_IMPORT_PREFIX "${CMAKE_CURRENT_LIST_FILE}" PATH)
+get_filename_component(_IMPORT_PREFIX "${_IMPORT_PREFIX}" PATH)
+get_filename_component(_IMPORT_PREFIX "${_IMPORT_PREFIX}" PATH)
+if(_IMPORT_PREFIX STREQUAL "/")
+ set(_IMPORT_PREFIX "")
+endif()
+
+if("@VCPKG_LIBRARY_LINKAGE@" STREQUAL "static")
+ add_library(unofficial::libmagic::libmagic STATIC IMPORTED)
+else()
+ add_library(unofficial::libmagic::libmagic SHARED IMPORTED)
+endif()
+
+set_target_properties(unofficial::libmagic::libmagic PROPERTIES
+ INTERFACE_INCLUDE_DIRECTORIES "${_IMPORT_PREFIX}/include"
+)
+
+if("@VCPKG_LIBRARY_LINKAGE@" STREQUAL "static")
+ set_target_properties(unofficial::libmagic::libmagic PROPERTIES
+ INTERFACE_LINK_LIBRARIES
+ "\$<LINK_ONLY:$<$<BOOL:${WIN32}>:unofficial::tre::tre;shlwapi>>"
+ "\$<LINK_ONLY:$<@has_zlib@:ZLIB::ZLIB>>"
+ "\$<LINK_ONLY:$<@has_bzip2@:BZip2::BZip2>>"
+ "\$<LINK_ONLY:$<@has_lzma@:LibLZMA::LibLZMA>>"
+ "\$<LINK_ONLY:$<@has_zstd@:zstd::libzstd>"
+ )
+endif()
+
+macro(add_library_config config prefix)
+ set_property(TARGET unofficial::libmagic::libmagic APPEND PROPERTY IMPORTED_CONFIGURATIONS ${config})
+ if("@VCPKG_LIBRARY_LINKAGE@" STREQUAL "static")
+ set_target_properties(unofficial::libmagic::libmagic PROPERTIES
+ IMPORTED_LOCATION_${config} "${_IMPORT_PREFIX}/${prefix}lib/@VCPKG_TARGET_STATIC_LIBRARY_PREFIX@magic@VCPKG_TARGET_STATIC_LIBRARY_SUFFIX@"
+ IMPORTED_LINK_INTERFACE_LANGUAGES_${config} "C"
+ )
+ else()
+ if(WIN32)
+ set(library_dir "${_IMPORT_PREFIX}/${prefix}bin/")
+ set(soversion_suffix "-1")
+ set_target_properties(unofficial::libmagic::libmagic PROPERTIES
+ IMPORTED_IMPLIB_${config} "${_IMPORT_PREFIX}/${prefix}/lib/@VCPKG_TARGET_IMPORT_LIBRARY_PREFIX@magic@VCPKG_TARGET_IMPORT_LIBRARY_SUFFIX@"
+ )
+ else()
+ set(library_dir "${_IMPORT_PREFIX}/${prefix}lib/")
+ endif()
+ set_target_properties(unofficial::libmagic::libmagic PROPERTIES
+ IMPORTED_LOCATION_${config} "${library_dir}@VCPKG_TARGET_SHARED_LIBRARY_PREFIX@magic${soversion_suffix}@VCPKG_TARGET_SHARED_LIBRARY_SUFFIX@"
+ )
+ unset(soversion_suffix)
+ unset(library_dir)
+ endif()
+endmacro()
+
+if("@VCPKG_BUILD_TYPE@" STREQUAL "" OR "@VCPKG_BUILD_TYPE@" STREQUAL "debug")
+ add_library_config(DEBUG "debug/")
+endif()
+
+if("@VCPKG_BUILD_TYPE@" STREQUAL "" OR "@VCPKG_BUILD_TYPE@" STREQUAL "release")
+ add_library_config(RELEASE "")
+endif()
+
+set_and_check(unofficial-libmagic_DICTIONARY "${_IMPORT_PREFIX}/share/libmagic/misc/magic.mgc")
+
+unset(_IMPORT_PREFIX)
+
+check_required_components(unofficial-libmagic)
diff --git a/vcpkg/ports/libmagic/usage b/vcpkg/ports/libmagic/usage new file mode 100644 index 0000000..3f7bb80 --- /dev/null +++ b/vcpkg/ports/libmagic/usage @@ -0,0 +1,6 @@ +libmagic provides CMake targets:
+
+ find_package(unofficial-libmagic REQUIRED)
+ target_link_libraries(main PRIVATE unofficial::libmagic::libmagic)
+
+The magic.mgc file can be accessed from the unofficial-libmagic_DICTIONARY variable.
diff --git a/vcpkg/ports/libmagic/vcpkg.json b/vcpkg/ports/libmagic/vcpkg.json new file mode 100644 index 0000000..a7357d6 --- /dev/null +++ b/vcpkg/ports/libmagic/vcpkg.json @@ -0,0 +1,52 @@ +{ + "name": "libmagic", + "version": "5.46", + "port-version": 2, + "description": "This library can be used to classify files according to magic number tests.", + "homepage": "https://github.com/file/file", + "license": "BSD-2-Clause", + "dependencies": [ + { + "name": "dirent", + "platform": "windows" + }, + { + "name": "getopt", + "platform": "windows" + }, + { + "name": "libmagic", + "host": true + }, + { + "name": "tre", + "platform": "windows | mingw" + } + ], + "features": { + "bzip2": { + "description": "Enable bzip2 support", + "dependencies": [ + "bzip2" + ] + }, + "lzma": { + "description": "Enable lzma support", + "dependencies": [ + "liblzma" + ] + }, + "zlib": { + "description": "Enable zlib support", + "dependencies": [ + "zlib" + ] + }, + "zstd": { + "description": "Enable zstd support", + "dependencies": [ + "zstd" + ] + } + } +} |