Like on Mac OS X, the linker doesn't automatically resolve dependencies. Signed-off-by: Tomas Carnecky <tom at dbservice.com> --- Makefile.local | 2 +- configure | 28 ++++++++++++++------ lib/Makefile.local | 2 +- notmuch-new.c | 70 ++++++++++++++++++++++++++++++++++++++++++++++------ 4 files changed, 83 insertions(+), 19 deletions(-)
diff --git a/Makefile.local b/Makefile.local index 5bb570b..5bc872b 100644 --- a/Makefile.local +++ b/Makefile.local @@ -255,7 +255,7 @@ notmuch_client_srcs = \ notmuch_client_modules = $(notmuch_client_srcs:.c=.o) notmuch: $(notmuch_client_modules) lib/libnotmuch.a - $(call quiet,CXX $(CFLAGS)) $^ $(FINAL_LIBNOTMUCH_LDFLAGS) -o $@ + $(call quiet,CXX $(CFLAGS)) $^ $(FINAL_NOTMUCH_LDFLAGS) -o $@ notmuch-shared: $(notmuch_client_modules) lib/$(LINKER_NAME) $(call quiet,$(FINAL_NOTMUCH_LINKER) $(CFLAGS)) $(notmuch_client_modules) $(FINAL_NOTMUCH_LDFLAGS) -o $@ diff --git a/configure b/configure index c522ad8..91e08dd 100755 --- a/configure +++ b/configure @@ -257,15 +257,26 @@ else have_emacs=0 fi -printf "Checking for Mac OS X (for shared library)... " +printf "Checking which platform we are on... " if [ `uname` = "Darwin" ] ; then - printf "Yes.\n" - mac_os_x=1 + printf "Mac OS X.\n" + platform=MACOSX linker_resolves_library_dependencies=0 -else - printf "No.\n" - mac_os_x=0 +elif [ `uname` = "SunOS" ] ; then + printf "Solaris.\n" + platform=SOLARIS + linker_resolves_library_dependencies=0 +elif [ `uname` = "Linux" ] ; then + printf "Linux\n" + platform=LINUX linker_resolves_library_dependencies=1 +else + printf "Unknown.\n" + cat <<EOF + +*** Warning: Unknown platform. Notmuch might or might not build correctly. + +EOF fi if [ $errors -gt 0 ]; then @@ -433,9 +444,8 @@ HAVE_GETLINE = ${have_getline} # build its own version) HAVE_STRCASESTR = ${have_strcasestr} -# Whether we are building on OS X. This will affect how we build the -# shared library. -MAC_OS_X = ${mac_os_x} +# Supported platforms (so far) are: LINUX, MACOSX, SOLARIS +PLATFORM = ${platform} # Whether the linker will automatically resolve the dependency of one # library on another (if not, then linking a binary requires linking diff --git a/lib/Makefile.local b/lib/Makefile.local index 0cc1d39..62f2316 100644 --- a/lib/Makefile.local +++ b/lib/Makefile.local @@ -22,7 +22,7 @@ LIBNOTMUCH_VERSION_MINOR = 1 # simply compatible changes to the implementation). LIBNOTMUCH_VERSION_RELEASE = 0 -ifeq ($(MAC_OS_X),1) +ifeq ($(PLATFORM),MACOSX) LIBRARY_SUFFIX = dylib # On OS X, library version numbers go before suffix. LINKER_NAME = libnotmuch.$(LIBRARY_SUFFIX) diff --git a/notmuch-new.c b/notmuch-new.c index 8818728..aacb5a6 100644 --- a/notmuch-new.c +++ b/notmuch-new.c @@ -135,6 +135,62 @@ dirent_sort_strcmp_name (const struct dirent **a, const struct dirent **b) return strcmp ((*a)->d_name, (*b)->d_name); } +/* Helper functions to test if a given dirent is of a certain type + */ +static int +_is_reg(const char *path, struct dirent *entry) +{ +#ifdef DT_REG + if (entry->d_type == DT_REG) + return 1; +#endif + + char buffer[PATH_MAX]; + snprintf(buffer, PATH_MAX, "%s/%s", path, entry->d_name); + + struct stat sbuf; + if (!stat(buffer, &sbuf)) + return S_ISREG(sbuf.st_mode); + + return 0; +} + +static int +_is_dir(const char *path, struct dirent *entry) +{ +#ifdef DT_DIR + if (entry->d_type == DT_DIR) + return 1; +#endif + + char buffer[PATH_MAX]; + snprintf(buffer, PATH_MAX, "%s/%s", path, entry->d_name); + + struct stat sbuf; + if (!stat(buffer, &sbuf)) + return S_ISDIR(sbuf.st_mode); + + return 0; +} + +static int +_is_lnk(const char *path, struct dirent *entry) +{ +#ifdef DT_LNK + if (entry->d_type == DT_LNK) + return 1; +#endif + + char buffer[PATH_MAX]; + snprintf(buffer, PATH_MAX, "%s/%s", path, entry->d_name); + + struct stat sbuf; + if (!stat(buffer, &sbuf)) + return S_ISLNK(sbuf.st_mode); + + return 0; +} + /* Test if the directory looks like a Maildir directory. * * Search through the array of directory entries to see if we can find all @@ -143,12 +199,12 @@ dirent_sort_strcmp_name (const struct dirent **a, const struct dirent **b) * Return 1 if the directory looks like a Maildir and 0 otherwise. */ static int -_entries_resemble_maildir (struct dirent **entries, int count) +_entries_resemble_maildir (const char *path, struct dirent **entries, int count) { int i, found = 0; for (i = 0; i < count; i++) { - if (entries[i]->d_type != DT_DIR && entries[i]->d_type != DT_UNKNOWN) + if (!_is_dir(path, entries[i])) continue; if (strcmp(entries[i]->d_name, "new") == 0 || @@ -261,7 +317,7 @@ add_files_recursive (notmuch_database_t *notmuch, } /* Pass 1: Recurse into all sub-directories. */ - is_maildir = _entries_resemble_maildir (fs_entries, num_fs_entries); + is_maildir = _entries_resemble_maildir (path, fs_entries, num_fs_entries); for (i = 0; i < num_fs_entries; i++) { if (interrupted) @@ -276,9 +332,7 @@ add_files_recursive (notmuch_database_t *notmuch, * scandir results, then it might be a directory (and if not, * then we'll stat and return immediately in the next level of * recursion). */ - if (entry->d_type != DT_DIR && - entry->d_type != DT_LNK && - entry->d_type != DT_UNKNOWN) + if (!_is_dir(path, entry) && !_is_lnk(path, entry)) { continue; } @@ -356,7 +410,7 @@ add_files_recursive (notmuch_database_t *notmuch, * * In either case, a stat does the trick. */ - if (entry->d_type == DT_LNK || entry->d_type == DT_UNKNOWN) { + if (_is_lnk(path, entry)) { int err; next = talloc_asprintf (notmuch, "%s/%s", path, entry->d_name); @@ -372,7 +426,7 @@ add_files_recursive (notmuch_database_t *notmuch, if (! S_ISREG (st.st_mode)) continue; - } else if (entry->d_type != DT_REG) { + } else if (!_is_reg(path, entry)) { continue; } -- 1.7.1