summaryrefslogtreecommitdiffstats
path: root/usr.bin/tar
diff options
context:
space:
mode:
authorkientzle <kientzle@FreeBSD.org>2004-08-07 03:24:49 +0000
committerkientzle <kientzle@FreeBSD.org>2004-08-07 03:24:49 +0000
commita34feb1b97eeddad92bc8a7aab3be391247ff685 (patch)
tree8cd1365aae2daecf40fb6ba0c152ff1f524aa6c6 /usr.bin/tar
parent237a0ce1f8117c40c606f8734ead347261516646 (diff)
downloadFreeBSD-src-a34feb1b97eeddad92bc8a7aab3be391247ff685.zip
FreeBSD-src-a34feb1b97eeddad92bc8a7aab3be391247ff685.tar.gz
Add "make distfile" capabilities to bsdtar, including informational
COPYING file and some conditional compilation cleanups.
Diffstat (limited to 'usr.bin/tar')
-rw-r--r--usr.bin/tar/COPYING28
-rw-r--r--usr.bin/tar/Makefile34
-rw-r--r--usr.bin/tar/Makefile.am18
-rw-r--r--usr.bin/tar/bsdtar.c35
-rw-r--r--usr.bin/tar/bsdtar_platform.h129
-rw-r--r--usr.bin/tar/configure.ac.in53
-rw-r--r--usr.bin/tar/write.c4
7 files changed, 251 insertions, 50 deletions
diff --git a/usr.bin/tar/COPYING b/usr.bin/tar/COPYING
new file mode 100644
index 0000000..c702482
--- /dev/null
+++ b/usr.bin/tar/COPYING
@@ -0,0 +1,28 @@
+All of the C source code and documentation in this package is subject
+to the following:
+
+Copyright (c) 2003-2004 Tim Kientzle
+All rights reserved.
+
+Redistribution and use in source and binary forms, with or without
+modification, are permitted provided that the following conditions
+are met:
+1. Redistributions of source code must retain the above copyright
+ notice, this list of conditions and the following disclaimer
+ in this position and unchanged.
+2. Redistributions in binary form must reproduce the above copyright
+ notice, this list of conditions and the following disclaimer in the
+ documentation and/or other materials provided with the distribution.
+
+THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR
+IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT,
+INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+$FreeBSD$
diff --git a/usr.bin/tar/Makefile b/usr.bin/tar/Makefile
index c4917be..c7409b1 100644
--- a/usr.bin/tar/Makefile
+++ b/usr.bin/tar/Makefile
@@ -1,5 +1,10 @@
# $FreeBSD$
+#
+# Use "make distfile" to build a tar.gz file suitable for distribution,
+# including an autoconf/automake-generated build system.
+#
+
PROG= bsdtar
VERSION= 1.00
SRCS= bsdtar.c matching.c read.c util.c write.c
@@ -13,5 +18,32 @@ SYMLINKS= ${BINDIR}/bsdtar ${BINDIR}/tar
MLINKS= bsdtar.1 tar.1
.endif
-.include <bsd.prog.mk>
+DIST_BUILD_DIR= ${.OBJDIR}/${PROG}-${VERSION}
+CLEANDIRS+= ${DIST_BUILD_DIR}
+DISTFILE= ${PROG}-${VERSION}.tar.gz
+# Files that just get copied to the distfile build directory
+DIST_FILES= ${SRCS}
+DIST_FILES+= ${MAN}
+DIST_FILES+= bsdtar.h bsdtar_platform.h
+DIST_FILES+= Makefile.am
+DIST_FILES+= fts.c fts.h
+distfile:
+ rm -rf ${DIST_BUILD_DIR}
+ mkdir ${DIST_BUILD_DIR}
+ for f in ${DIST_FILES}; \
+ do \
+ cat ${.CURDIR}/$$f >${DIST_BUILD_DIR}/$$f; \
+ done
+ cat ${.CURDIR}/configure.ac.in | \
+ sed 's/@VERSION@/${VERSION}/' | \
+ cat > ${DIST_BUILD_DIR}/configure.ac
+ (cd ${DIST_BUILD_DIR} && aclocal && autoheader && autoconf )
+ (cd ${DIST_BUILD_DIR} && automake -a --foreign)
+ (cd ${DIST_BUILD_DIR} && ./configure && make distcheck && make dist)
+ mv ${DIST_BUILD_DIR}/${DISTFILE} ${.OBJDIR}
+ @echo ==================================================
+ @echo Created ${.OBJDIR}/${DISTFILE}
+ @echo ==================================================
+
+.include <bsd.prog.mk>
diff --git a/usr.bin/tar/Makefile.am b/usr.bin/tar/Makefile.am
new file mode 100644
index 0000000..e9dc2f9
--- /dev/null
+++ b/usr.bin/tar/Makefile.am
@@ -0,0 +1,18 @@
+# $FreeBSD$
+
+# Process this file with automake to create Makefile.in
+
+bin_PROGRAMS= bsdtar
+bsdtar_SOURCES= \
+ bsdtar.c \
+ bsdtar.h \
+ bsdtar_platform.h \
+ fts.c \
+ fts.h \
+ matching.c \
+ read.c \
+ util.c \
+ write.c
+bsdtar_LDADD= -larchive -lbz2 -lz
+
+dist_man_MANS= bsdtar.1
diff --git a/usr.bin/tar/bsdtar.c b/usr.bin/tar/bsdtar.c
index c4f00a7..aa9fc95 100644
--- a/usr.bin/tar/bsdtar.c
+++ b/usr.bin/tar/bsdtar.c
@@ -47,18 +47,29 @@ struct option {
#define no_argument 0
#define required_argument 1
#endif
-#ifdef HAVE_NL_LANGINFO_D_MD_ORDER
+#ifdef HAVE_LANGINFO_H
#include <langinfo.h>
#endif
#include <locale.h>
+#ifdef HAVE_PATHS_H
+#include <paths.h>
+#endif
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include <unistd.h>
+#if HAVE_ZLIB_H
+#include <zlib.h>
+#endif
#include "bsdtar.h"
+#ifndef _PATH_DEFTAPE
+#define _PATH_DEFTAPE "/dev/tape"
+#endif
+
+
static int bsdtar_getopt(struct bsdtar *, const char *optstring,
const struct option **poption);
static void long_help(struct bsdtar *);
@@ -171,7 +182,7 @@ main(int argc, char **argv)
if (setlocale(LC_ALL, "") == NULL)
bsdtar_warnc(bsdtar, 0, "Failed to set default locale");
-#ifdef HAVE_NL_LANGINFO_D_MD_ORDER
+#if defined(HAVE_NL_LANGINFO) && defined(HAVE_D_MD_ORDER)
bsdtar->day_first = (*nl_langinfo(D_MD_ORDER) == 'd');
#endif
mode = '\0';
@@ -269,11 +280,16 @@ main(int argc, char **argv)
optarg);
break;
case 'j': /* GNU tar */
+#if HAVE_LIBBZ2
if (bsdtar->create_compression != '\0')
bsdtar_errc(bsdtar, 1, 0,
"Can't specify both -%c and -%c", opt,
bsdtar->create_compression);
bsdtar->create_compression = opt;
+#else
+ bsdtar_warnc(bsdtar, 0, "-j compression not supported by this version of bsdtar");
+ usage(bsdtar);
+#endif
break;
case 'k': /* GNU tar */
bsdtar->extract_flags |= ARCHIVE_EXTRACT_NO_OVERWRITE;
@@ -395,11 +411,16 @@ main(int argc, char **argv)
mode = opt;
break;
case 'y': /* FreeBSD version of GNU tar */
+#if HAVE_LIBBZ2
if (bsdtar->create_compression != '\0')
bsdtar_errc(bsdtar, 1, 0,
"Can't specify both -%c and -%c", opt,
bsdtar->create_compression);
bsdtar->create_compression = opt;
+#else
+ bsdtar_warnc(bsdtar, 0, "-y compression not supported by this version of bsdtar");
+ usage(bsdtar);
+#endif
break;
case 'Z': /* GNU tar */
if (bsdtar->create_compression != '\0')
@@ -409,13 +430,19 @@ main(int argc, char **argv)
bsdtar->create_compression = opt;
break;
case 'z': /* GNU tar, star, many others */
+#if HAVE_LIBZ
if (bsdtar->create_compression != '\0')
bsdtar_errc(bsdtar, 1, 0,
"Can't specify both -%c and -%c", opt,
bsdtar->create_compression);
bsdtar->create_compression = opt;
+#else
+ bsdtar_warnc(bsdtar, 0, "-z compression not supported by this version of bsdtar");
+ usage(bsdtar);
+#endif
break;
default:
+ bsdtar_warnc(bsdtar, 0, "Unrecognized option -c", optopt);
usage(bsdtar);
}
}
@@ -682,8 +709,8 @@ long_help(struct bsdtar *bsdtar)
} else
putchar(*p);
}
- printf("\n");
- version();
+ fprintf(stdout, "\n%s %s\n", PACKAGE_NAME, PACKAGE_VERSION);
+ fprintf(stdout, "%s\n", archive_version());
}
static int
diff --git a/usr.bin/tar/bsdtar_platform.h b/usr.bin/tar/bsdtar_platform.h
index f49a0e7..a6919a9 100644
--- a/usr.bin/tar/bsdtar_platform.h
+++ b/usr.bin/tar/bsdtar_platform.h
@@ -35,22 +35,84 @@
#ifndef BSDTAR_PLATFORM_H_INCLUDED
#define BSDTAR_PLATFORM_H_INCLUDED
-/* FreeBSD-specific definitions. */
-#ifdef __FreeBSD__
-#include <sys/cdefs.h> /* For __FBSDID */
-#include <paths.h> /* For _PATH_DEFTAPE */
+#if HAVE_CONFIG_H
+#include "config.h"
+#else
-#define HAVE_CHFLAGS 1
-#define ARCHIVE_STAT_MTIME_NANOS(st) (st)->st_mtimespec.tv_nsec
+#ifdef __FreeBSD__
+/* A default configuration for FreeBSD, used if there is no config.h. */
+#define PACKAGE_NAME "bsdtar"
+#define PACKAGE_VERSION "1.00"
+#define HAVE_BZLIB_H 1
+#define HAVE_CHFLAGS 1
+#define HAVE_DIRENT_H 1
+#define HAVE_D_MD_ORDER 1
+#define HAVE_FCHDIR 1
+#define HAVE_FCNTL_H 1
+#define HAVE_FNMATCH 1
+#define HAVE_FTRUNCATE 1
+#define HAVE_GETOPT_LONG 1
+#define HAVE_INTTYPES_H 1
+#define HAVE_LANGINFO_H 1
+#define HAVE_LIBARCHIVE 1
+#define HAVE_LIBBZ2 1
+#define HAVE_LIBZ 1
+#define HAVE_LIMITS_H 1
+#define HAVE_LOCALE_H 1
+#define HAVE_MALLOC 1
+#define HAVE_MEMMOVE 1
+#define HAVE_MEMORY_H 1
+#define HAVE_MEMSET 1
#if __FreeBSD_version >= 450002 /* nl_langinfo introduced */
-/* nl_langinfo supports D_MD_ORDER (FreeBSD extension) */
-#define HAVE_NL_LANGINFO_D_MD_ORDER 1
+#define HAVE_NL_LANGINFO 1
#endif
-
+#define HAVE_PATHS_H 1
+#define HAVE_SETLOCALE 1
+#define HAVE_STDINT_H 1
+#define HAVE_STDLIB_H 1
+#define HAVE_STRCHR 1
+#define HAVE_STRDUP 1
+#define HAVE_STRERROR 1
+#define HAVE_STRFTIME 1
+#define HAVE_STRINGS_H 1
+#define HAVE_STRING_H 1
+#define HAVE_STRRCHR 1
+#define HAVE_STRUCT_STAT_ST_MTIMESPEC_TV_NSEC 1
+#define HAVE_STRUCT_STAT_ST_RDEV 1
#if __FreeBSD__ > 4
-#define HAVE_GETOPT_LONG 1
-#define HAVE_POSIX_ACL 1
+#define HAVE_SYS_ACL_H 1
+#endif
+#define HAVE_SYS_IOCTL_H 1
+#define HAVE_SYS_PARAM_H 1
+#define HAVE_SYS_STAT_H 1
+#define HAVE_SYS_TYPES_H 1
+#define HAVE_UNISTD_H 1
+#define HAVE_VPRINTF 1
+#define HAVE_ZLIB_H 1
+#define STDC_HEADERS 1
+
+#else /* !__FreeBSD__ */
+/* Warn if the library hasn't been (automatically or manually) configured. */
+#error Oops: No config.h and no built-in configuration in archive_platform.h.
+#endif /* !__FreeBSD__ */
+
+#endif /* !HAVE_CONFIG_H */
+
+/* No non-FreeBSD platform will have __FBSDID, so just define it here. */
+#ifdef __FreeBSD__
+#include <sys/cdefs.h> /* For __FBSDID */
+#else
+#define __FBSDID(a) /* null */
+#endif
+
+#ifndef HAVE_LIBARCHIVE
+#error Configuration error: did not find libarchive.
+#endif
+
+/* TODO: Test for the functions we use as well... */
+#if HAVE_SYS_ACL_H
+#define HAVE_POSIX_ACLS 1
#endif
/*
@@ -58,54 +120,31 @@
* and format string here must be compatible with one another and
* large enough for any file.
*/
-#include <inttypes.h> /* for uintmax_t, if it exists */
-#ifdef UINTMAX_MAX
+#if HAVE_UINTMAX_T
#define BSDTAR_FILESIZE_TYPE uintmax_t
#define BSDTAR_FILESIZE_PRINTF "%ju"
#else
+#if HAVE_UNSIGNED_LONG_LONG
#define BSDTAR_FILESIZE_TYPE unsigned long long
#define BSDTAR_FILESIZE_PRINTF "%llu"
+#else
+#define BSDTAR_FILESIZE_TYPE unsigned long
+#define BSDTAR_FILESIZE_PRINTF "%lu"
#endif
-
-#if __FreeBSD__ < 5
-typedef int64_t id_t;
-#endif
-
-#endif /* __FreeBSD__ */
-
-/* No non-FreeBSD platform will have __FBSDID, so just define it here. */
-#ifndef __FreeBSD__
-#define __FBSDID(a) /* null */
#endif
-/* Linux */
-#ifdef linux
-#define _FILE_OFFSET_BITS 64 /* For a 64-bit off_t */
-#include <stdint.h> /* for uintmax_t */
-#define BSDTAR_FILESIZE_TYPE uintmax_t
-#define BSDTAR_FILESIZE_PRINTF "%ju"
/* XXX get fnmatch GNU extensions (FNM_LEADING_DIR)
* (should probably use AC_FUNC_FNMATCH_GNU once using autoconf...) */
-#define _GNU_SOURCE
-#define _PATH_DEFTAPE "/dev/st0"
-#define HAVE_GETOPT_LONG 1
-#ifdef HAVE_STRUCT_STAT_TIMESPEC
-/* Fetch the nanosecond portion of the timestamp from a struct stat pointer. */
-#define ARCHIVE_STAT_MTIME_NANOS(pstat) (pstat)->st_mtim.tv_nsec
+#if HAVE_STRUCT_STAT_ST_MTIMESPEC_TV_NSEC
+#define ARCHIVE_STAT_MTIME_NANOS(st) (st)->st_mtimespec.tv_nsec
+#else
+#if HAVE_STRUCT_STAT_ST_MTIM_TV_NSEC
+#define ARCHIVE_STAT_MTIME_NANOS(st) (st)->st_mtim.tv_nsec
#else
-/* High-res timestamps aren't available, so just use stubs here. */
-#define ARCHIVE_STAT_MTIME_NANOS(pstat) 0
+#define ARCHIVE_STAT_MTIME_NANOS(st) (0)
#endif
-
#endif
-/*
- * XXX TODO: Use autoconf to handle non-FreeBSD platforms.
- *
- * #if !defined(__FreeBSD__)
- * #include "config.h"
- * #endif
- */
#endif /* !BSDTAR_PLATFORM_H_INCLUDED */
diff --git a/usr.bin/tar/configure.ac.in b/usr.bin/tar/configure.ac.in
new file mode 100644
index 0000000..7d21439
--- /dev/null
+++ b/usr.bin/tar/configure.ac.in
@@ -0,0 +1,53 @@
+# $FreeBSD$
+
+# Process this file with autoconf to produce a configure script.
+AC_INIT(bsdtar, 1.00, kientzle@freebsd.org)
+AM_INIT_AUTOMAKE(bsdtar, 1.00)
+AC_CONFIG_SRCDIR([bsdtar.c])
+AM_CONFIG_HEADER([config.h])
+
+# Checks for programs.
+AC_PROG_CC
+
+# Checks for header files.
+AC_HEADER_DIRENT
+AC_HEADER_STDC
+AC_CHECK_HEADERS([bzlib.h fcntl.h inttypes.h langinfo.h limits.h locale.h paths.h stdint.h stdlib.h string.h sys/acl.h sys/ioctl.h sys/param.h unistd.h zlib.h])
+
+# Checks for libraries.
+AC_CHECK_LIB([z], [inflate])
+AC_CHECK_LIB([bz2], [BZ2_bzDecompressInit])
+AC_CHECK_LIB([archive], [archive_version])
+
+# Checks for typedefs, structures, and compiler characteristics.
+AC_C_CONST
+AC_TYPE_UID_T
+AC_TYPE_MODE_T
+AC_TYPE_OFF_T
+AC_TYPE_SIZE_T
+AC_CHECK_MEMBERS([struct stat.st_rdev, struct stat.st_mtimespec.tv_nsec, struct stat.st_mtim.tv_nsec])
+AC_CHECK_DECL([D_MD_ORDER],
+ [AC_DEFINE(HAVE_D_MD_ORDER, 1, [D_MD_ORDER is a valid argument to nl_langinfo])],
+ [],
+ [#include <langinfo.h>])
+
+# Checks for library functions.
+AC_FUNC_FNMATCH
+AC_PROG_GCC_TRADITIONAL
+AC_FUNC_LSTAT
+AC_HEADER_MAJOR
+AC_FUNC_MALLOC
+AC_FUNC_STAT
+AC_FUNC_STRFTIME
+AC_FUNC_VPRINTF
+AC_CHECK_TYPE([uintmax_t])
+AC_CHECK_TYPE([unsigned long long])
+AC_CHECK_FUNCS([chflags fchdir ftruncate getopt_long memmove memset nl_langinfo setlocale strchr strdup strerror strrchr sys/acl.h])
+
+#define HAVE_CHFLAGS 1
+
+# Additional requirements
+AC_SYS_LARGEFILE
+
+AC_CONFIG_FILES([Makefile])
+AC_OUTPUT
diff --git a/usr.bin/tar/write.c b/usr.bin/tar/write.c
index 6495e3d..0129762 100644
--- a/usr.bin/tar/write.c
+++ b/usr.bin/tar/write.c
@@ -170,12 +170,16 @@ tar_mode_c(struct bsdtar *bsdtar)
switch (bsdtar->create_compression) {
case 0:
break;
+#ifdef HAVE_LIBBZ2
case 'j': case 'y':
archive_write_set_compression_bzip2(a);
break;
+#endif
+#ifdef HAVE_LIBZ
case 'z':
archive_write_set_compression_gzip(a);
break;
+#endif
default:
bsdtar_errc(bsdtar, 1, 0,
"Unrecognized compression option -%c",
OpenPOWER on IntegriCloud