diff --git a/build.sh b/build.sh index 77de8ecdd..54d7b3be2 100755 --- a/build.sh +++ b/build.sh @@ -38,6 +38,11 @@ case "$os" in plat_cflags="$plat_cflags -DAT_REMOVEDIR=0x200" CC=clang ;; + FreeBSD) + plat_files="$plat_files ../src/compat/clearenv.c " + plat_files="$plat_files ../src/compat/dir_mutex.c " + plat_files="$plat_files ../src/compat/utimensat.c" + ;; esac rm -rf build diff --git a/src/tup/option.c b/src/tup/option.c index 96b006a8a..d23bceab5 100644 --- a/src/tup/option.c +++ b/src/tup/option.c @@ -18,7 +18,7 @@ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. */ -#if defined(__APPLE__) || defined(__FreeBSD__) +#if defined(__APPLE__) #include #elif defined(_WIN32) /* Don't let Windows define SLIST_ENTRY and conflict with bsd/queue.h */ @@ -290,9 +290,9 @@ static const char *cpu_number(void) static char buf[10]; int count = 1; -#if defined(__linux__) || defined(__sun__) +#if defined(__linux__) || defined(__sun__) || defined(__FreeBSD__) count = sysconf(_SC_NPROCESSORS_ONLN); -#elif defined(__APPLE__) || defined(__FreeBSD__) +#elif defined(__APPLE__) int nm[2]; size_t len = 4; diff --git a/src/tup/platform.c b/src/tup/platform.c index eb176af2f..d5a71ef9d 100644 --- a/src/tup/platform.c +++ b/src/tup/platform.c @@ -23,6 +23,8 @@ /* NOTE: Please keep the list in tup.1 in sync */ #ifdef __linux__ const char *tup_platform = "linux"; +#elif __FreeBSD__ +const char *tup_platform = "freebsd"; #elif __sun__ const char *tup_platform = "solaris"; #elif __APPLE__ diff --git a/src/tup/server/fuse_fs.c b/src/tup/server/fuse_fs.c index 51366a0c8..59a372418 100644 --- a/src/tup/server/fuse_fs.c +++ b/src/tup/server/fuse_fs.c @@ -25,6 +25,12 @@ /* For pread()/pwrite() */ #define _XOPEN_SOURCE 500 #endif +#ifdef __FreeBSD__ +/* For S_IFDIR */ +# define __XSI_VISIBLE 1 +/* For AT_SYMLINK_NOFOLLOW */ +# define __BSD_VISIBLE 1 +#endif #include "compat/utimensat.h" #include "tup_fuse_fs.h" @@ -38,6 +44,10 @@ #include #include #include +#ifdef __FreeBSD__ +# include +# include +#endif static struct thread_root troot = THREAD_ROOT_INITIALIZER; static int server_mode = 0; diff --git a/src/tup/server/fuse_server.c b/src/tup/server/fuse_server.c index ed939a472..5dbb885cd 100644 --- a/src/tup/server/fuse_server.c +++ b/src/tup/server/fuse_server.c @@ -91,7 +91,7 @@ static int os_unmount(void) } return rc; } -#elif defined(__APPLE__) +#elif defined(__APPLE__) || defined(__FreeBSD__) static int os_unmount(void) { if(unmount(TUP_MNT, MNT_FORCE) < 0) { diff --git a/src/tup/server/master_fork.c b/src/tup/server/master_fork.c index 2fdab2106..28c4e657e 100644 --- a/src/tup/server/master_fork.c +++ b/src/tup/server/master_fork.c @@ -33,6 +33,9 @@ #include #include #include +#ifdef __FreeBSD__ +# include +#endif #include #include @@ -279,12 +282,18 @@ static int setup_subprocess(tupid_t sid, const char *job, const char *dir, fprintf(stderr, "tup internal error: Trying to run sub-process in a chroot, but tup is not privileged.\n"); return -1; } -#ifdef __APPLE__ +#if defined(__APPLE__) if(mount("devfs", dev, MNT_DONTBROWSE, NULL) < 0) { perror("mount"); fprintf(stderr, "tup error: Unable to mount /dev into fuse file-system.\n"); return -1; } +#elif defined(__FreeBSD__) + if(mount("devfs", dev, 0, NULL) < 0) { + perror("mount"); + fprintf(stderr, "tup error: Unable to mount /dev into fuse file-system.\n"); + return -1; + } #else /* The "tmpfs" argument is ignored since we use MS_BIND, but * valgrind complains about it if we use NULL. @@ -548,7 +557,7 @@ static void *child_waiter(void *arg) } if(waiter->do_chroot && tup_privileged()) { int rc; -#ifdef __APPLE__ +#if defined(__APPLE__) || defined(__FreeBSD__) rc = unmount(waiter->dev, MNT_FORCE); #else rc = umount2(waiter->dev, MNT_FORCE); diff --git a/tup.1 b/tup.1 index ea46faf2e..8c59be87e 100644 --- a/tup.1 +++ b/tup.1 @@ -528,7 +528,7 @@ In tup.config, comments are determined by a '#' character in the first column. T In this case, the @-variable "FOO" is explicitly set to "n". .TP .B @(TUP_PLATFORM) -TUP_PLATFORM is a special @-variable. If CONFIG_TUP_PLATFORM is not set in the tup.config file, it has a default value according to the platform that tup itself was compiled in. Currently the default value is one of "linux", "solaris", "macosx", or "win32". +TUP_PLATFORM is a special @-variable. If CONFIG_TUP_PLATFORM is not set in the tup.config file, it has a default value according to the platform that tup itself was compiled in. Currently the default value is one of "linux", "freebsd", "solaris", "macosx", or "win32". .TP .B @(TUP_ARCH) TUP_ARCH is another special @-variable. If CONFIG_TUP_ARCH is not set in the tup.config file, it has a default value according to the processor architecture that tup itself was compiled in. Currently the default value is one of "i386", "x86_64", "powerpc", "powerpc64", "ia64", "alpha", "sparc" or "arm".