Add "make distfile" capabilities to bsdtar, including informational

COPYING file and some conditional compilation cleanups.
This commit is contained in:
Tim Kientzle 2004-08-07 03:24:49 +00:00
parent bfe891b141
commit 5232906014
7 changed files with 254 additions and 53 deletions

28
usr.bin/tar/COPYING Normal file
View File

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

View File

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

18
usr.bin/tar/Makefile.am Normal file
View File

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

View File

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

View File

@ -35,22 +35,84 @@
#ifndef BSDTAR_PLATFORM_H_INCLUDED
#define BSDTAR_PLATFORM_H_INCLUDED
/* FreeBSD-specific definitions. */
#if HAVE_CONFIG_H
#include "config.h"
#else
#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 */
#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_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 */
#include <paths.h> /* For _PATH_DEFTAPE */
#define HAVE_CHFLAGS 1
#define ARCHIVE_STAT_MTIME_NANOS(st) (st)->st_mtimespec.tv_nsec
#if __FreeBSD_version >= 450002 /* nl_langinfo introduced */
/* nl_langinfo supports D_MD_ORDER (FreeBSD extension) */
#define HAVE_NL_LANGINFO_D_MD_ORDER 1
#else
#define __FBSDID(a) /* null */
#endif
#if __FreeBSD__ > 4
#define HAVE_GETOPT_LONG 1
#define HAVE_POSIX_ACL 1
#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
#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
/* High-res timestamps aren't available, so just use stubs here. */
#define ARCHIVE_STAT_MTIME_NANOS(pstat) 0
#if HAVE_STRUCT_STAT_ST_MTIM_TV_NSEC
#define ARCHIVE_STAT_MTIME_NANOS(st) (st)->st_mtim.tv_nsec
#else
#define ARCHIVE_STAT_MTIME_NANOS(st) (0)
#endif
#endif
#endif
/*
* XXX TODO: Use autoconf to handle non-FreeBSD platforms.
*
* #if !defined(__FreeBSD__)
* #include "config.h"
* #endif
*/
#endif /* !BSDTAR_PLATFORM_H_INCLUDED */

View File

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

View File

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