From d21eb039fee34bd1551c6caa1d3690856016f5f3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Hugo=20Beauz=C3=A9e-Luyssen?= Date: Thu, 5 Jan 2017 17:29:28 +0100 Subject: [PATCH 1/6] configure.ac: Allow the programs to be disabled In case one only wants the libflac to be built --- configure.ac | 3 +++ src/flac/Makefile.am | 13 +++++++++---- src/metaflac/Makefile.am | 8 ++++++-- 3 files changed, 18 insertions(+), 6 deletions(-) diff --git a/configure.ac b/configure.ac index 3d18bb91..21e1ecb9 100644 --- a/configure.ac +++ b/configure.ac @@ -400,6 +400,9 @@ AC_ARG_ENABLE([examples], AS_HELP_STRING([--disable-examples], [Don't build and install examples])) AM_CONDITIONAL([EXAMPLES], [test "x$enable_examples" != "xno"]) +AC_ARG_ENABLE([bin], AC_HELP_STRING([--disable-bin], [Do not build the flac program])) +AM_CONDITIONAL([HAS_BIN], [test "${enable_bin}" != "no"]) + dnl check for i18n(internationalization); these are from libiconv/gettext AM_ICONV AM_LANGINFO_CODESET diff --git a/src/flac/Makefile.am b/src/flac/Makefile.am index fe6fa489..af6c45cb 100644 --- a/src/flac/Makefile.am +++ b/src/flac/Makefile.am @@ -16,10 +16,6 @@ # with this program; if not, write to the Free Software Foundation, Inc., # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. -bin_PROGRAMS = flac - -AM_CFLAGS = @OGG_CFLAGS@ -AM_CPPFLAGS = -I$(top_builddir) -I$(srcdir)/include -I$(top_srcdir)/include EXTRA_DIST = \ Makefile.lite \ Makefile.lite.iffscan \ @@ -31,6 +27,13 @@ EXTRA_DIST = \ iffscan.vcxproj \ iffscan.vcxproj.filters +if HAS_BIN + +bin_PROGRAMS = flac + +AM_CFLAGS = @OGG_CFLAGS@ +AM_CPPFLAGS = -I$(top_builddir) -I$(srcdir)/include -I$(top_srcdir)/include + flac_SOURCES = \ analyze.c \ decode.c \ @@ -64,3 +67,5 @@ flac_LDADD = \ -lm CLEANFILES = flac.exe + +endif diff --git a/src/metaflac/Makefile.am b/src/metaflac/Makefile.am index ec201ddf..5c50f59a 100644 --- a/src/metaflac/Makefile.am +++ b/src/metaflac/Makefile.am @@ -16,8 +16,6 @@ # with this program; if not, write to the Free Software Foundation, Inc., # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. -bin_PROGRAMS = metaflac - AM_CFLAGS = @OGG_CFLAGS@ AM_CPPFLAGS = -I$(top_builddir) -I$(srcdir)/include -I$(top_srcdir)/include EXTRA_DIST = \ @@ -26,6 +24,10 @@ EXTRA_DIST = \ metaflac.vcxproj \ metaflac.vcxproj.filters +if HAS_BIN + +bin_PROGRAMS = metaflac + metaflac_SOURCES = \ main.c \ operations.c \ @@ -58,3 +60,5 @@ metaflac_LDADD = \ @LTLIBICONV@ CLEANFILES = metaflac.exe + +endif -- GitLab From e253c641f057d8788bfc465e421ba4c7f0ec5220 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Hugo=20Beauz=C3=A9e-Luyssen?= Date: Thu, 5 Jan 2017 17:38:02 +0100 Subject: [PATCH 2/6] configure.ac: Allow bench to be disabled --- configure.ac | 3 +++ microbench/Makefile.am | 4 ++++ 2 files changed, 7 insertions(+) diff --git a/configure.ac b/configure.ac index 21e1ecb9..d80434e5 100644 --- a/configure.ac +++ b/configure.ac @@ -403,6 +403,9 @@ AM_CONDITIONAL([EXAMPLES], [test "x$enable_examples" != "xno"]) AC_ARG_ENABLE([bin], AC_HELP_STRING([--disable-bin], [Do not build the flac program])) AM_CONDITIONAL([HAS_BIN], [test "${enable_bin}" != "no"]) +AC_ARG_ENABLE([benchmark], AC_HELP_STRING([--disable-benchmark], [Do not build the flac benchmark])) +AM_CONDITIONAL([FLaC__HAS_BENCHMARK], [test "${enable_benchmark}" != "no"]) + dnl check for i18n(internationalization); these are from libiconv/gettext AM_ICONV AM_LANGINFO_CODESET diff --git a/microbench/Makefile.am b/microbench/Makefile.am index 9ab6a040..9c960691 100644 --- a/microbench/Makefile.am +++ b/microbench/Makefile.am @@ -33,8 +33,12 @@ AM_CPPFLAGS = -I$(top_srcdir)/include -I$(top_srcdir)/src/libFLAC/include noinst_HEADERS = util.h +if FLaC__HAS_BENCHMARK + noinst_PROGRAMS = benchmark_residual benchmark_residual_SOURCES = benchmark_residual.c util.c benchmark_residual_LDADD = @LIB_CLOCK_GETTIME@ + +endif -- GitLab From 09c4d365d2d1b37e819f71aa2ef4eda0e6fd4fe4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Hugo=20Beauz=C3=A9e-Luyssen?= Date: Thu, 5 Jan 2017 18:29:10 +0100 Subject: [PATCH 3/6] win_utf8_io: Avoid forbidden functions when building for WinRT/UWP --- src/share/win_utf8_io/win_utf8_io.c | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/share/win_utf8_io/win_utf8_io.c b/src/share/win_utf8_io/win_utf8_io.c index bbb6a74a..a382df4c 100644 --- a/src/share/win_utf8_io/win_utf8_io.c +++ b/src/share/win_utf8_io/win_utf8_io.c @@ -34,6 +34,7 @@ #endif #include +#include #include "share/win_utf8_io.h" #include "share/windows_unicode_filenames.h" @@ -182,11 +183,13 @@ size_t strlen_utf8(const char *str) int win_get_console_width(void) { int width = 80; +#if WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_DESKTOP) CONSOLE_SCREEN_BUFFER_INFO csbi; HANDLE hOut = GetStdHandle(STD_OUTPUT_HANDLE); if(hOut != INVALID_HANDLE_VALUE && hOut != NULL) if (GetConsoleScreenBufferInfo(hOut, &csbi) != 0) width = csbi.dwSize.X; +#endif return width; } @@ -194,6 +197,7 @@ int win_get_console_width(void) static int wprint_console(FILE *stream, const wchar_t *text, size_t len) { +#if WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_DESKTOP) DWORD out; int ret; @@ -220,6 +224,11 @@ static int wprint_console(FILE *stream, const wchar_t *text, size_t len) if (ret < 0) return ret; return len; +#else + (void)stream; + OutputDebugStringW(text); + return len; +#endif } int printf_utf8(const char *format, ...) -- GitLab From 22b0d9a1dd4d05b23c822363d4a4f53632f6a6b8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Hugo=20Beauz=C3=A9e-Luyssen?= Date: Fri, 18 Jan 2019 16:04:56 +0100 Subject: [PATCH 4/6] configure.ac: Don't force __MSVCRT_VERSION__ Doing so results in build failures depending on the crt version the toolchain uses. --- configure.ac | 1 - 1 file changed, 1 deletion(-) diff --git a/configure.ac b/configure.ac index d80434e5..706ea6b0 100644 --- a/configure.ac +++ b/configure.ac @@ -208,7 +208,6 @@ AC_SUBST(OBJ_FORMAT) os_is_windows=no case "$host" in *mingw*) - CPPFLAGS="-D__MSVCRT_VERSION__=0x0601 $CPPFLAGS" os_is_windows=yes ;; esac -- GitLab From 011b5e574377af70cd08f5ce7b73e3956284a4bf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Hugo=20Beauz=C3=A9e-Luyssen?= Date: Fri, 18 Jan 2019 16:31:41 +0100 Subject: [PATCH 5/6] share: Don't use CreateFileA when building for WinRT/UWP As this function is forbidden there --- src/share/win_utf8_io/win_utf8_io.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/share/win_utf8_io/win_utf8_io.c b/src/share/win_utf8_io/win_utf8_io.c index a382df4c..b1ac255c 100644 --- a/src/share/win_utf8_io/win_utf8_io.c +++ b/src/share/win_utf8_io/win_utf8_io.c @@ -154,7 +154,11 @@ int get_utf8_argv(int *argc, char ***argv) HANDLE WINAPI CreateFile_utf8(const char *lpFileName, DWORD dwDesiredAccess, DWORD dwShareMode, LPSECURITY_ATTRIBUTES lpSecurityAttributes, DWORD dwCreationDisposition, DWORD dwFlagsAndAttributes, HANDLE hTemplateFile) { if (!flac_internal_get_utf8_filenames()) { +#if WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_DESKTOP) return CreateFileA(lpFileName, dwDesiredAccess, dwShareMode, lpSecurityAttributes, dwCreationDisposition, dwFlagsAndAttributes, hTemplateFile); +#else + return INVALID_HANDLE_VALUE; +#endif } else { wchar_t *wname; HANDLE handle = INVALID_HANDLE_VALUE; -- GitLab From 2bf53afb57bb3337976929704a793f26ee37060b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Hugo=20Beauz=C3=A9e-Luyssen?= Date: Fri, 18 Jan 2019 16:40:03 +0100 Subject: [PATCH 6/6] Move grabbag__file_are_same to the only file it's used in This function doesn't compile when targetting WinRT/UWP (as it uses forbidden function). Since the function is only used in the flac program, it makes sense to move the function there, as executable are not built for that platform. --- include/share/grabbag/file.h | 4 ---- src/flac/main.c | 42 +++++++++++++++++++++++++++++++++++- src/share/grabbag/file.c | 37 ------------------------------- 3 files changed, 41 insertions(+), 42 deletions(-) diff --git a/include/share/grabbag/file.h b/include/share/grabbag/file.h index b3f41484..5b3b4091 100644 --- a/include/share/grabbag/file.h +++ b/include/share/grabbag/file.h @@ -47,10 +47,6 @@ const char *grabbag__file_get_basename(const char *srcpath); */ FLAC__bool grabbag__file_change_stats(const char *filename, FLAC__bool read_only); -/* returns true iff stat() succeeds for both files and they have the same device and inode. */ -/* on windows, uses GetFileInformationByHandle() to compare */ -FLAC__bool grabbag__file_are_same(const char *f1, const char *f2); - /* attempts to make writable before unlinking */ FLAC__bool grabbag__file_remove_file(const char *filename); diff --git a/src/flac/main.c b/src/flac/main.c index be072a3d..27c8eaa2 100644 --- a/src/flac/main.c +++ b/src/flac/main.c @@ -29,6 +29,7 @@ #include #include #include +#include #if !defined _MSC_VER && !defined __MINGW32__ /* unlink is in stdio.h in VC++ */ @@ -71,6 +72,7 @@ static void show_help(void); static void show_explain(void); static void format_mistake(const char *infilename, FileFormat wrong, FileFormat right); +static FLAC__bool file_are_same(const char *f1, const char *f2); static int encode_file(const char *infilename, FLAC__bool is_first_file, FLAC__bool is_last_file); static int decode_file(const char *infilename); @@ -1682,6 +1684,44 @@ void format_mistake(const char *infilename, FileFormat wrong, FileFormat right) flac__utils_printf(stderr, 1, "WARNING: %s is not a%s file; treating as a%s file\n", infilename, ff[wrong], ff[right]); } +FLAC__bool file_are_same(const char *f1, const char *f2) +{ +#if defined _WIN32 && !defined __CYGWIN__ + /* see + * http://www.hydrogenaudio.org/forums/index.php?showtopic=49439&pid=444300&st=0 + * http://msdn.microsoft.com/library/default.asp?url=/library/en-us/fileio/fs/getfileinformationbyhandle.asp + * http://msdn.microsoft.com/library/default.asp?url=/library/en-us/fileio/fs/by_handle_file_information_str.asp + * http://msdn.microsoft.com/library/default.asp?url=/library/en-us/fileio/fs/createfile.asp + * apparently both the files have to be open at the same time for the comparison to work + */ + FLAC__bool same = false; + BY_HANDLE_FILE_INFORMATION info1, info2; + HANDLE h1, h2; + BOOL ok = 1; + h1 = CreateFile_utf8(f1, GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL); + h2 = CreateFile_utf8(f2, GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL); + if(h1 == INVALID_HANDLE_VALUE || h2 == INVALID_HANDLE_VALUE) + ok = 0; + ok &= GetFileInformationByHandle(h1, &info1); + ok &= GetFileInformationByHandle(h2, &info2); + if(ok) + same = + info1.dwVolumeSerialNumber == info2.dwVolumeSerialNumber && + info1.nFileIndexHigh == info2.nFileIndexHigh && + info1.nFileIndexLow == info2.nFileIndexLow + ; + if(h1 != INVALID_HANDLE_VALUE) + CloseHandle(h1); + if(h2 != INVALID_HANDLE_VALUE) + CloseHandle(h2); + return same; +#else + struct flac_stat_s s1, s2; + return f1 && f2 && flac_stat(f1, &s1) == 0 && flac_stat(f2, &s2) == 0 && s1.st_ino == s2.st_ino && s1.st_dev == s2.st_dev; +#endif +} + + int encode_file(const char *infilename, FLAC__bool is_first_file, FLAC__bool is_last_file) { FILE *encode_infile; @@ -1924,7 +1964,7 @@ int encode_file(const char *infilename, FLAC__bool is_first_file, FLAC__bool is_ encode_options.error_on_compression_fail = option_values.error_on_compression_fail; /* if infilename and outfilename point to the same file, we need to write to a temporary file */ - if(encode_infile != stdin && grabbag__file_are_same(infilename, outfilename)) { + if(encode_infile != stdin && file_are_same(infilename, outfilename)) { static const char *tmp_suffix = ".tmp,fl-ac+en'c"; size_t dest_len = strlen(outfilename) + strlen(tmp_suffix) + 1; /*@@@@ still a remote possibility that a file with this filename exists */ diff --git a/src/share/grabbag/file.c b/src/share/grabbag/file.c index 2c67bebf..634424ee 100644 --- a/src/share/grabbag/file.c +++ b/src/share/grabbag/file.c @@ -115,43 +115,6 @@ FLAC__bool grabbag__file_change_stats(const char *filename, FLAC__bool read_only return true; } -FLAC__bool grabbag__file_are_same(const char *f1, const char *f2) -{ -#if defined _WIN32 && !defined __CYGWIN__ - /* see - * http://www.hydrogenaudio.org/forums/index.php?showtopic=49439&pid=444300&st=0 - * http://msdn.microsoft.com/library/default.asp?url=/library/en-us/fileio/fs/getfileinformationbyhandle.asp - * http://msdn.microsoft.com/library/default.asp?url=/library/en-us/fileio/fs/by_handle_file_information_str.asp - * http://msdn.microsoft.com/library/default.asp?url=/library/en-us/fileio/fs/createfile.asp - * apparently both the files have to be open at the same time for the comparison to work - */ - FLAC__bool same = false; - BY_HANDLE_FILE_INFORMATION info1, info2; - HANDLE h1, h2; - BOOL ok = 1; - h1 = CreateFile_utf8(f1, GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL); - h2 = CreateFile_utf8(f2, GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL); - if(h1 == INVALID_HANDLE_VALUE || h2 == INVALID_HANDLE_VALUE) - ok = 0; - ok &= GetFileInformationByHandle(h1, &info1); - ok &= GetFileInformationByHandle(h2, &info2); - if(ok) - same = - info1.dwVolumeSerialNumber == info2.dwVolumeSerialNumber && - info1.nFileIndexHigh == info2.nFileIndexHigh && - info1.nFileIndexLow == info2.nFileIndexLow - ; - if(h1 != INVALID_HANDLE_VALUE) - CloseHandle(h1); - if(h2 != INVALID_HANDLE_VALUE) - CloseHandle(h2); - return same; -#else - struct flac_stat_s s1, s2; - return f1 && f2 && flac_stat(f1, &s1) == 0 && flac_stat(f2, &s2) == 0 && s1.st_ino == s2.st_ino && s1.st_dev == s2.st_dev; -#endif -} - FLAC__bool grabbag__file_remove_file(const char *filename) { return grabbag__file_change_stats(filename, /*read_only=*/false) && 0 == flac_unlink(filename); -- GitLab