make everything work on freebsd

This commit is contained in:
josch
2014-12-09 09:07:47 +01:00
parent c8a0f2a942
commit 5bd9e418c4
9 changed files with 97 additions and 5 deletions

27
3rdparty/cmake/FindFUSE.cmake vendored Normal file
View File

@@ -0,0 +1,27 @@
# Copyright (C) 2014 Johannes Schauer <j.schauer@email.de>
#
# 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}")

26
3rdparty/cmake/FindJansson.cmake vendored Normal file
View File

@@ -0,0 +1,26 @@
# Copyright (C) 2014 Johannes Schauer <j.schauer@email.de>
#
# 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)

View File

@@ -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})

View File

@@ -21,7 +21,9 @@
#include <stdio.h>
#include <string.h>
#include <openssl/sha.h>
#ifdef __linux
#include <bits/fcntl-linux.h>
#endif
#include <stdint.h>
#include <stdlib.h>

View File

@@ -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 <errno.h>
#include <stdlib.h>
@@ -32,7 +36,9 @@
#include <stddef.h>
#include <pwd.h>
#include <inttypes.h>
#ifdef __linux
#include <bits/fcntl-linux.h>
#endif
#include <openssl/sha.h>
#include "hashtbl.h"

View File

@@ -29,7 +29,9 @@
#include <string.h>
#include <errno.h>
#include <sys/stat.h>
#ifdef __linux
#include <bits/fcntl-linux.h>
#endif
#include <pwd.h>
#include <wordexp.h>
#include <fcntl.h>
@@ -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);
}

View File

@@ -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 <string.h>
#include <errno.h>
#include <sys/stat.h>
#ifdef __linux
#include <bits/fcntl-linux.h>
#endif
#include <fuse/fuse_common.h>
#include <stdint.h>
#include <libgen.h>

View File

@@ -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 <stdio.h>
#include <stdlib.h>

View File

@@ -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"