diff --git a/CMakeLists.txt b/CMakeLists.txt index bf2c8e4a..92920e36 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -77,10 +77,10 @@ option ( enable-readline "compile readline lib line editing (if it is available) option ( enable-threads "enable multi-threading support (such as parallel voice synthesis)" on ) # Platform specific options -if ( CMAKE_SYSTEM MATCHES "Linux" ) +if ( CMAKE_SYSTEM MATCHES "Linux|FreeBSD|DragonFly" ) option ( enable-lash "compile LASH support (if it is available)" on ) option ( enable-alsa "compile ALSA support (if it is available)" on ) -endif ( CMAKE_SYSTEM MATCHES "Linux" ) +endif ( CMAKE_SYSTEM MATCHES "Linux|FreeBSD|DragonFly" ) if ( CMAKE_SYSTEM MATCHES "Darwin" ) option ( enable-coreaudio "compile CoreAudio support (if it is available)" on ) @@ -95,7 +95,7 @@ if ( CMAKE_SYSTEM MATCHES "OS2" ) endif ( CMAKE_SYSTEM MATCHES "OS2" ) # Initialize the library directory name suffix. -if (NOT MINGW AND NOT MSVC) +if (NOT MINGW AND NOT MSVC AND NOT CMAKE_SYSTEM_NAME MATCHES "FreeBSD|DragonFly") if ( CMAKE_SIZEOF_VOID_P EQUAL 8 ) set ( _init_lib_suffix "64" ) else ( CMAKE_SIZEOF_VOID_P EQUAL 8 ) @@ -465,6 +465,10 @@ else(NOT enable-pkgconfig) # Mandatory libraries: glib and gthread pkg_check_modules ( GLIB REQUIRED glib-2.0>=2.6.5 gthread-2.0>=2.6.5 ) + if ( GLIB_VERSION VERSION_LESS "2.26" ) + message ( WARNING "Your version of glib is very old. This may cause problems with fluidsynth's sample cache on Windows. Consider updating to glib 2.26 or newer!" ) + endif ( GLIB_VERSION VERSION_LESS "2.26" ) + include ( UnsetPkgConfig ) # Optional features diff --git a/cmake_admin/DefaultDirs.cmake b/cmake_admin/DefaultDirs.cmake index 6fe45fa1..0110bac7 100644 --- a/cmake_admin/DefaultDirs.cmake +++ b/cmake_admin/DefaultDirs.cmake @@ -53,7 +53,11 @@ set (INFO_INSTALL_DIR "share/info" CACHE STRING "The info install dir") mark_as_advanced (INFO_INSTALL_DIR) # MAN_INSTALL_DIR - the man pages install dir -set (MAN_INSTALL_DIR "share/man/man1" CACHE STRING "The man pages install dir") +if ( CMAKE_SYSTEM_NAME MATCHES "FreeBSD|DragonFly") + set (MAN_INSTALL_DIR "man/man1" CACHE STRING "The man pages install dir") +else() + set (MAN_INSTALL_DIR "share/man/man1" CACHE STRING "The man pages install dir") +endif() mark_as_advanced (MAN_INSTALL_DIR) # SYSCONF_INSTALL_DIR - the config file install dir diff --git a/src/bindings/fluid_filerenderer.c b/src/bindings/fluid_filerenderer.c index 6882a4b9..8afc89fb 100644 --- a/src/bindings/fluid_filerenderer.c +++ b/src/bindings/fluid_filerenderer.c @@ -298,7 +298,7 @@ new_fluid_file_renderer(fluid_synth_t *synth) sf_command(dev->sndfile, SFC_SET_NORM_FLOAT, NULL, SF_TRUE); #else - dev->file = fopen(filename, "wb"); + dev->file = FLUID_FOPEN(filename, "wb"); if(dev->file == NULL) { diff --git a/src/bindings/fluid_rtkit.c b/src/bindings/fluid_rtkit.c index d0e96cfd..282a4014 100644 --- a/src/bindings/fluid_rtkit.c +++ b/src/bindings/fluid_rtkit.c @@ -32,7 +32,7 @@ #include "fluid_rtkit.h" -#if defined(__linux__) || defined(__APPLE__) +#if defined(__linux__) || defined(__APPLE__) || defined(__FreeBSD__) || defined(__DragonFly__) #ifndef _GNU_SOURCE #define _GNU_SOURCE @@ -42,10 +42,17 @@ #include #include +#if defined(__FreeBSD__) || defined(__DragonFly__) +#include +#endif static pid_t _gettid(void) { +#if defined(__FreeBSD__) || defined(__DragonFly__) + return pthread_getthreadid_np(); +#else return (pid_t) syscall(SYS_gettid); +#endif } static int translate_error(const char *name) diff --git a/src/gentables/CMakeLists.txt b/src/gentables/CMakeLists.txt index 64ec7b44..638f299c 100644 --- a/src/gentables/CMakeLists.txt +++ b/src/gentables/CMakeLists.txt @@ -4,6 +4,12 @@ cmake_minimum_required(VERSION 3.1) # which hopefully will be the host compiler unset(ENV{CC}) +# also unset $CFLAGS to avoid passing any cross compilation flags to the host compiler +unset(ENV{CFLAGS}) + +# linker flags as well +unset(ENV{LDFLAGS}) + project (gentables C) set ( CMAKE_BUILD_TYPE Debug ) diff --git a/src/midi/fluid_midi.c b/src/midi/fluid_midi.c index 1a394f81..fb71a822 100644 --- a/src/midi/fluid_midi.c +++ b/src/midi/fluid_midi.c @@ -92,17 +92,23 @@ static int fluid_midi_file_get_division(fluid_midi_file *midifile); */ int fluid_is_midifile(const char *filename) { - FILE *fp = FLUID_FOPEN(filename, "rb"); + FILE *fp; uint32_t id; int retcode = FALSE; do { - if(fp == NULL) + if(!fluid_file_test(filename, G_FILE_TEST_IS_REGULAR)) { return retcode; } - + + // file seems to exist and is a regular file or a symlink to such + if((fp = FLUID_FOPEN(filename, "rb")) == NULL) + { + return retcode; + } + if(FLUID_FREAD(&id, sizeof(id), 1, fp) != 1) { break; diff --git a/src/sfloader/fluid_sffile.c b/src/sfloader/fluid_sffile.c index 302eea72..b5a641b6 100644 --- a/src/sfloader/fluid_sffile.c +++ b/src/sfloader/fluid_sffile.c @@ -334,17 +334,23 @@ static int fluid_sffile_read_wav(SFData *sf, unsigned int start, unsigned int en */ int fluid_is_soundfont(const char *filename) { - FILE *fp = FLUID_FOPEN(filename, "rb"); + FILE *fp; uint32_t fcc; int retcode = FALSE; do { - if(fp == NULL) + if(!fluid_file_test(filename, G_FILE_TEST_IS_REGULAR)) { return retcode; } - + + // file seems to exist and is a regular file or a symlink to such + if((fp = FLUID_FOPEN(filename, "rb")) == NULL) + { + return retcode; + } + if(FLUID_FREAD(&fcc, sizeof(fcc), 1, fp) != 1) { break; diff --git a/src/sfloader/fluid_sfont.c b/src/sfloader/fluid_sfont.c index 548a80ab..d0ce264d 100644 --- a/src/sfloader/fluid_sfont.c +++ b/src/sfloader/fluid_sfont.c @@ -24,7 +24,27 @@ void *default_fopen(const char *path) { - return FLUID_FOPEN(path, "rb"); + FILE* handle; + + if(!fluid_file_test(path, G_FILE_TEST_EXISTS)) + { + FLUID_LOG(FLUID_ERR, "fluid_sfloader_load(): Unable to load non-existent file. ('%s')", path); + return NULL; + } + + if(!fluid_file_test(path, G_FILE_TEST_IS_REGULAR)) + { + FLUID_LOG(FLUID_ERR, "fluid_sfloader_load(): Refusing to load non-regular file! ('%s')", path); + return NULL; + } + + if((handle = FLUID_FOPEN(path, "rb")) == NULL) + { + FLUID_LOG(FLUID_ERR, "fluid_sfloader_load(): Specified file does not exists or insufficient permissions to open it! ('%s')", path); + return NULL; + } + + return handle; } int default_fclose(void *handle) diff --git a/src/utils/fluid_sys.h b/src/utils/fluid_sys.h index 72b32302..10f7d12b 100644 --- a/src/utils/fluid_sys.h +++ b/src/utils/fluid_sys.h @@ -374,25 +374,26 @@ fluid_istream_t fluid_socket_get_istream(fluid_socket_t sock); fluid_ostream_t fluid_socket_get_ostream(fluid_socket_t sock); /* File access */ +#define fluid_stat(_filename, _statbuf) g_stat((_filename), (_statbuf)) #if !GLIB_CHECK_VERSION(2, 26, 0) /* GStatBuf has not been introduced yet, manually typedef to what they had at that time: * https://github.com/GNOME/glib/blob/e7763678b56e3be073cc55d707a6e92fc2055ee0/glib/gstdio.h#L98-L115 */ #if defined(WIN32) || HAVE_WINDOWS_H // somehow reliably mock G_OS_WIN32?? - #if defined (_MSC_VER) && !defined(_WIN64) - typedef struct _stat32 fluid_stat_buf_t; - #else - typedef struct _stat fluid_stat_buf_t; - #endif + // Any effort from our side to reliably mock GStatBuf on Windows is in vain. E.g. glib-2.16 is broken as it uses struct stat rather than struct _stat32 on Win x86. + // Disable it (the user has been warned by cmake). + #undef fluid_stat + #define fluid_stat(_filename, _statbuf) (-1) + typedef struct _fluid_stat_buf_t{int st_mtime;} fluid_stat_buf_t; #else - /* posix, OS/2, etc. */ - typedef struct stat fluid_stat_buf_t; + /* posix, OS/2, etc. */ + typedef struct stat fluid_stat_buf_t; #endif #else typedef GStatBuf fluid_stat_buf_t; #endif -#define fluid_stat(_filename, _statbuf) g_stat((_filename), (_statbuf)) +#define fluid_file_test g_file_test /* Profiling */ #if WITH_PROFILING