diff --git a/3rdparty/cmake/FindFUSE.cmake b/3rdparty/cmake/FindFUSE.cmake new file mode 100644 index 0000000..f9ed5fc --- /dev/null +++ b/3rdparty/cmake/FindFUSE.cmake @@ -0,0 +1,27 @@ +# Copyright (C) 2014 Johannes Schauer +# +# Permission is hereby granted, free of charge, to any person obtaining a copy +# of this software and associated documentation files (the "Software"), to deal +# in the Software without restriction, including without limitation the rights +# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +# copies of the Software, and to permit persons to whom the Software is +# furnished to do so, subject to the following conditions: +# +# The above copyright notice and this permission notice shall be included in +# all copies or substantial portions of the Software. + +find_path(FUSE_INCLUDE_DIRS NAMES "fuse/fuse.h" "fuse/fuse_common.h") +find_library(FUSE_LIBRARIES NAMES "fuse") +mark_as_advanced(FUSE_INCLUDE_DIRS FUSE_LIBRARIES) + +IF (FUSE_INCLUDE_DIRS) + file(STRINGS "${FUSE_INCLUDE_DIRS}/fuse/fuse_common.h" fuse_version_str REGEX "^#define[ \t]+FUSE_(MAJOR|MINOR)_VERSION[ \t]+.*") + string(REGEX REPLACE ".*#define[ \t]+FUSE_MAJOR_VERSION[ \t]+([0-9]+).*" "\\1" FUSE_VERSION_MAJOR "${fuse_version_str}") + string(REGEX REPLACE ".*#define[ \t]+FUSE_MINOR_VERSION[ \t]+([0-9]+).*" "\\1" FUSE_VERSION_MINOR "${fuse_version_str}") + unset(fuse_version_str) +endif() + +include(FindPackageHandleStandardArgs) +find_package_handle_standard_args(FUSE + REQUIRED_VARS FUSE_LIBRARIES FUSE_INCLUDE_DIRS + VERSION_VAR "${FUSE_VERSION_MAJOR}.${FUSE_VERSION_MINOR}") diff --git a/3rdparty/cmake/FindJansson.cmake b/3rdparty/cmake/FindJansson.cmake new file mode 100644 index 0000000..b149316 --- /dev/null +++ b/3rdparty/cmake/FindJansson.cmake @@ -0,0 +1,26 @@ +# Copyright (C) 2014 Johannes Schauer +# +# Permission is hereby granted, free of charge, to any person obtaining a copy +# of this software and associated documentation files (the "Software"), to deal +# in the Software without restriction, including without limitation the rights +# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +# copies of the Software, and to permit persons to whom the Software is +# furnished to do so, subject to the following conditions: +# +# The above copyright notice and this permission notice shall be included in +# all copies or substantial portions of the Software. + +find_path(JANSSON_INCLUDE_DIRS NAMES "jansson.h") +find_library(JANSSON_LIBRARIES NAMES "jansson") +mark_as_advanced(JANSSON_INCLUDE_DIRS JANSSON_LIBRARIES) + +if (JANSSON_INCLUDE_DIRS) + file(STRINGS "${JANSSON_INCLUDE_DIRS}/jansson.h" jansson_version_str REGEX "^#define[\t ]+JANSSON_VERSION[\t ]+\".*\"") + string(REGEX REPLACE "^#define[\t ]+JANSSON_VERSION[\t ]+\"([^\"]*)\".*" "\\1" JANSSON_VERSION_STRING "${jansson_ersion_str}") + unset(jansson_ersion_string) +endif() + +include(FindPackageHandleStandardArgs) +find_package_handle_standard_args(Jansson + REQUIRED_VARS JANSSON_LIBRARIES JANSSON_INCLUDE_DIRS + VERSION_VAR JANSSON_VERSION_STRING) diff --git a/CMakeLists.txt b/CMakeLists.txt index 900a814..a96711c 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -10,6 +10,23 @@ set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -std=c99 -Wall -Wextra -Werror") # the following is until we learn how to reorder the gcc arguments to correctly link on Ubuntu set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -Wl,--no-as-needed") +# ensure large file support (also necessary for fuse) +add_definitions("-D_FILE_OFFSET_BITS=64") + +find_package(OpenSSL REQUIRED) +include_directories(${OPENSSL_INCLUDE_DIR}) + +find_package(CURL REQUIRED) +include_directories(${CURL_INCLUDE_DIRS}) + +set(CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/3rdparty/cmake) + +find_package(FUSE 2.9 REQUIRED) +include_directories(${FUSE_INCLUDE_DIRS}) + +find_package(Jansson 2.6 REQUIRED) +include_directories(${JANSSON_INCLUDE_DIRS}) + add_library(mfapi SHARED mfapi/mfconn.c mfapi/file.c @@ -67,7 +84,7 @@ add_executable(mediafire-shell mfshell/config.c mfshell/options.c mfshell/commands/updates.c) -target_link_libraries(mediafire-shell curl ssl crypto jansson mfapi mfutils) +target_link_libraries(mediafire-shell ${CURL_LIBRARIES} ${OPENSSL_LIBRARIES} ${JANSSON_LIBRARIES} mfapi mfutils) enable_testing() @@ -76,8 +93,7 @@ add_executable(mediafire-fuse fuse/hashtbl.c fuse/filecache.c fuse/operations.c) -set_target_properties(mediafire-fuse PROPERTIES COMPILE_FLAGS "-D_FILE_OFFSET_BITS=64") -target_link_libraries(mediafire-fuse curl ssl fuse jansson mfapi mfutils) +target_link_libraries(mediafire-fuse ${CURL_LIBRARIES} ${OPENSSL_LIBRARIES} ${FUSE_LIBRARIES} ${JANSSON_LIBRARIES} mfapi mfutils) add_test(iwyu ${CMAKE_SOURCE_DIR}/tests/iwyu.py ${CMAKE_BINARY_DIR}) add_test(indent ${CMAKE_SOURCE_DIR}/tests/indent.sh ${CMAKE_SOURCE_DIR}) diff --git a/fuse/filecache.c b/fuse/filecache.c index 78f094e..bb6406a 100644 --- a/fuse/filecache.c +++ b/fuse/filecache.c @@ -21,7 +21,9 @@ #include #include #include +#ifdef __linux #include +#endif #include #include diff --git a/fuse/hashtbl.c b/fuse/hashtbl.c index a51178a..b164304 100644 --- a/fuse/hashtbl.c +++ b/fuse/hashtbl.c @@ -17,7 +17,11 @@ */ #define _POSIX_C_SOURCE 200809L // for strdup and struct timespec (in fuse.h) - // and S_IFDIR and S_IFREG +#define _XOPEN_SOURCE 700 // for S_IFDIR and S_IFREG (on linux, + // posix_c_source is enough but this is needed + // on freebsd) + +#define FUSE_USE_VERSION 30 #include #include @@ -32,7 +36,9 @@ #include #include #include +#ifdef __linux #include +#endif #include #include "hashtbl.h" diff --git a/fuse/main.c b/fuse/main.c index 8674f9c..926c796 100644 --- a/fuse/main.c +++ b/fuse/main.c @@ -29,7 +29,9 @@ #include #include #include +#ifdef __linux #include +#endif #include #include #include @@ -349,10 +351,12 @@ static void setup_conf_and_cache_dir(struct mediafirefs_context_private *ctx) /* EEXIST is okay, so only fail if it is something else */ if (mkdir(configdir, 0755) != 0 && errno != EEXIST) { perror("mkdir"); + fprintf(stderr, "cannot create %s\n", configdir); exit(1); } if (mkdir(cachedir, 0755) != 0 && errno != EEXIST) { perror("mkdir"); + fprintf(stderr, "cannot create %s\n", cachedir); exit(1); } @@ -371,6 +375,7 @@ static void setup_conf_and_cache_dir(struct mediafirefs_context_private *ctx) ctx->filecache = strdup_printf("%s/files", cachedir); if (mkdir(ctx->filecache, 0755) != 0 && errno != EEXIST) { perror("mkdir"); + fprintf(stderr, "cannot create %s\n", ctx->filecache); exit(1); } diff --git a/fuse/operations.c b/fuse/operations.c index fe78627..97e7f16 100644 --- a/fuse/operations.c +++ b/fuse/operations.c @@ -17,6 +17,9 @@ */ #define _POSIX_C_SOURCE 200809L // for strdup and struct timespec +#define _XOPEN_SOURCE 700 // for S_IFDIR and S_IFREG (on linux, + // posix_c_source is enough but this is needed + // on freebsd) #define FUSE_USE_VERSION 30 @@ -28,7 +31,9 @@ #include #include #include +#ifdef __linux #include +#endif #include #include #include diff --git a/mfshell/mfshell.c b/mfshell/mfshell.c index dc23e96..038fcbb 100644 --- a/mfshell/mfshell.c +++ b/mfshell/mfshell.c @@ -17,8 +17,12 @@ * */ +#ifdef __linux #define _POSIX_C_SOURCE 200809L // for strdup and getline #define _BSD_SOURCE // for strsep +#else +#define _WITH_GETLINE // on freebsd for getline +#endif #include #include diff --git a/tests/valgrind_shell.sh b/tests/valgrind_shell.sh index 04715a1..85575a5 100755 --- a/tests/valgrind_shell.sh +++ b/tests/valgrind_shell.sh @@ -19,8 +19,9 @@ esac cmd="valgrind --suppressions="${source_dir}/valgrind.supp" --fullpath-after="$source_dir" --tool=memcheck --leak-check=yes --show-reachable=yes --num-callers=20 --track-fds=yes --track-origins=yes --error-exitcode=1 --quiet" -if [ ! -f "./.mediafire-tools.conf" -a ! -f "~/.mediafire-tools.conf" ]; then +if [ ! -f "$XDG_CONFIG_HOME/mediafire-tools/config" -a ! -f ~/.config/mediafire-tools/config ]; then echo "no configuration file found" >&2 exit 1 fi + $cmd "${binary_dir}/mediafire-shell" -c "help; ls; changes"