]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
hardlink: enable build with and without pcre2
authorRuediger Meier <ruediger.meier@ga-group.nl>
Tue, 12 Jun 2018 12:04:06 +0000 (14:04 +0200)
committerRuediger Meier <ruediger.meier@ga-group.nl>
Mon, 12 Nov 2018 18:40:33 +0000 (19:40 +0100)
Signed-off-by: Ruediger Meier <ruediger.meier@ga-group.nl>
.gitignore
configure.ac
misc-utils/Makemodule.am
misc-utils/hardlink.c

index 9f2fb17db52d09ddc967e20087628bf57e643f38..b582a8627fdba3ee2be33a3909d061990cf45d7e 100644 (file)
@@ -96,6 +96,7 @@ ylwrap
 /fsfreeze
 /fstrim
 /getopt
+/hardlink
 /hexdump
 /hwclock
 /ionice
index b3430dac43d12b5b7ffbc8ffde9c1e854ac270dd..260283cf27d71bef7bb7a96151bd8bc43212de21 100644 (file)
@@ -1372,6 +1372,18 @@ UL_REQUIRES_HAVE([setpriv], [linux_securebits_h], [securebits.h header file])
 UL_REQUIRES_HAVE([setpriv], [cap_ng], [libcap-ng library])
 AM_CONDITIONAL([BUILD_SETPRIV], [test "x$build_setpriv" = xyes])
 
+PKG_CHECK_MODULES([PCRE], [libpcre2-8], [have_pcre=yes], [have_pcre=no])
+AS_IF([test "x$have_pcre" = xyes ], [
+    AC_DEFINE([HAVE_PCRE], [1], [Define if libpcre2 is available])
+])
+AM_CONDITIONAL([HAVE_PCRE], [test "x$have_pcre" = xyes])
+
+AC_ARG_ENABLE([hardlink],
+  AS_HELP_STRING([--disable-hardlink], [do not build hardlink]),
+  [], [UL_DEFAULT_ENABLE([hardlink], [check])]
+)
+UL_BUILD_INIT([hardlink])
+AM_CONDITIONAL([BUILD_HARDLINK], [test "x$build_hardlink" = xyes])
 
 AC_ARG_ENABLE([eject],
   AS_HELP_STRING([--disable-eject], [do not build eject]),
index 36195b7a309f1c886117c7d5b7b115bdf44a1ab3..30b7c2f0f6326e0496808bd97f626e81afacf0bc 100644 (file)
@@ -211,3 +211,15 @@ fincore_SOURCES = misc-utils/fincore.c
 fincore_LDADD = $(LDADD) libsmartcols.la libcommon.la
 fincore_CFLAGS = $(AM_CFLAGS) -I$(ul_libsmartcols_incdir)
 endif
+
+if BUILD_HARDLINK
+usrbin_exec_PROGRAMS += hardlink
+hardlink_SOURCES = misc-utils/hardlink.c
+hardlink_LDADD = $(LDADD) libcommon.la
+hardlink_CFLAGS = $(AM_CFLAGS)
+if HAVE_PCRE
+hardlink_LDADD += $(PCRE_LIBS)
+hardlink_CFLAGS += $(PCRE_CFLAGS)
+endif
+dist_man_MANS += misc-utils/hardlink.1
+endif
index 8e74ca02105eebbf07ffc335346bfe257fdfe6f4..ba519993a385bb0c3e175c2124cb824c1311e055 100644 (file)
@@ -22,7 +22,6 @@
 /*  Changes by Todd Lewis that adds option -x to exclude files with pcre lib */
 
 #define _GNU_SOURCE
-#define PCRE2_CODE_UNIT_WIDTH 8
 #include <sys/types.h>
 #include <stdlib.h>
 #include <stdio.h>
 #include <dirent.h>
 #include <fcntl.h>
 #include <errno.h>
-#include <pcre2.h>
+#ifdef HAVE_PCRE
+# define PCRE2_CODE_UNIT_WIDTH 8
+# include <pcre2.h>
+#endif
 
 #define NHASH  (1<<17) /* Must be a power of 2! */
 #define NIOBUF (1<<12)
 #define NAMELEN        4096
 #define NBUF   64
 
+#ifdef HAVE_PCRE
 pcre2_code *re;
 PCRE2_SPTR exclude_pattern;
 pcre2_match_data *match_data;
+#endif
 
 struct _f;
 typedef struct _h {
@@ -336,8 +340,10 @@ int main(int argc, char **argv)
 {
   int ch;
   int i;
+#ifdef HAVE_PCRE
   int errornumber;
   PCRE2_SIZE erroroffset;
+#endif
   dynstr nam1 = {NULL, 0};
   while ((ch = getopt (argc, argv, "cnvhfx:")) != -1) {
     switch (ch) {
@@ -354,7 +360,12 @@ int main(int argc, char **argv)
       force=1;
       break;
     case 'x':
+#ifdef HAVE_PCRE
        exclude_pattern = (PCRE2_SPTR)optarg;
+#else
+               fprintf(stderr, "option x not supported (built without pcre2)\n");
+               exit(1);
+#endif
        break;
     case 'h':
     default:
@@ -363,6 +374,7 @@ int main(int argc, char **argv)
   }
   if (optind >= argc)
     usage(argv[0]);
+#ifdef HAVE_PCRE
   if (exclude_pattern) {
     re = pcre2_compile(
           exclude_pattern,       /* the pattern */
@@ -379,6 +391,7 @@ int main(int argc, char **argv)
     }
     match_data = pcre2_match_data_create_from_pattern(re, NULL);
   }
+#endif
   for (i = optind; i < argc; i++)
     rf(argv[i]);
   while (dirs) {
@@ -403,6 +416,7 @@ int main(int argc, char **argv)
         if (!di->d_name[1] || !strcmp(di->d_name, ".."))
           continue;
       }
+#ifdef HAVE_PCRE
       if (re && pcre2_match(
                   re,                 /* compiled regex */
                   (PCRE2_SPTR)di->d_name,
@@ -418,6 +432,7 @@ int main(int argc, char **argv)
         }
         continue; 
       }
+#endif
       {
         size_t subdirlen;
         growstr(&nam1, add2(nam1baselen, subdirlen = strlen(di->d_name)));