[Cmake-commits] [cmake-commits] hoffman committed README NONE 1.1 libarchive.1aix53.spec NONE 1.1 libarchive.spec NONE 1.1 libarchive_autodetect-st_lib_archive.m4 NONE 1.1 untar.c NONE 1.1

cmake-commits at cmake.org cmake-commits at cmake.org
Fri Oct 30 13:09:33 EDT 2009


Update of /cvsroot/CMake/CMake/Utilities/cmlibarchive/contrib
In directory public:/mounts/ram/cvs-serv26614/Utilities/cmlibarchive/contrib

Added Files:
	README libarchive.1aix53.spec libarchive.spec 
	libarchive_autodetect-st_lib_archive.m4 untar.c 
Log Message:
Switch to using libarchive from libtar for cpack and cmake -E tar

This allows for a built in bzip and zip capability, so external tools 
will not be needed for these packagers.  The cmake -E tar xf should be
able to handle all compression types now as well.



--- NEW FILE: untar.c ---
/*
 * "untar" is an extremely simple tar extractor:
 *  * A single C source file, so it should be easy to compile
 *    and run on any system with a C compiler.
 *  * Extremely portable standard C.  The only non-ANSI function
 *    used is mkdir().
 *  * Reads basic ustar tar archives.
 *  * Does not require libarchive or any other special library.
 *
 * To compile: cc -o untar untar.c
 *
 * Usage:  untar <archive>
 *
 * In particular, this program should be sufficient to extract the
 * distribution for libarchive, allowing people to bootstrap
 * libarchive on systems that do not already have a tar program.
 *
 * To unpack libarchive-x.y.z.tar.gz:
 *    * gunzip libarchive-x.y.z.tar.gz
 *    * untar libarchive-x.y.z.tar
 *
 * Written by Tim Kientzle, March 2009.
 *
 * Released into the public domain.
 */

/* These are all highly standard and portable headers. */
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

/* This is for mkdir(); this may need to be changed for some platforms. */
#include <sys/stat.h>  /* For mkdir() */

/* Parse an octal number, ignoring leading and trailing nonsense. */
static int
parseoct(const char *p, size_t n)
{
    int i = 0;

    while (*p < '0' || *p > '7') {
        ++p;
        --n;
    }
    while (*p >= '0' && *p <= '7' && n > 0) {
        i *= 8;
        i += *p - '0';
        ++p;
        --n;
    }
    return (i);
}

/* Returns true if this is 512 zero bytes. */
static int
is_end_of_archive(const char *p)
{
    int n;
    for (n = 511; n >= 0; --n)
        if (p[n] != '\0')
            return (0);
    return (1);
}

/* Create a directory, including parent directories as necessary. */
static void
create_dir(char *pathname, int mode)
{
    char *p;
    int r;

    /* Strip trailing '/' */
    if (pathname[strlen(pathname) - 1] == '/')
        pathname[strlen(pathname) - 1] = '\0';

    /* Try creating the directory. */
    r = mkdir(pathname, mode);

    if (r != 0) {
        /* On failure, try creating parent directory. */
        p = strrchr(pathname, '/');
        if (p != NULL) {
            *p = '\0';
            create_dir(pathname, 0755);
            *p = '/';
            r = mkdir(pathname, mode);
        }
    }
    if (r != 0)
        fprintf(stderr, "Could not create directory %s\n", pathname);
}

/* Create a file, including parent directory as necessary. */
static FILE *
create_file(char *pathname, int mode)
{
    FILE *f;
    f = fopen(pathname, "w+");
    if (f == NULL) {
        /* Try creating parent dir and then creating file. */
        char *p = strrchr(pathname, '/');
        if (p != NULL) {
            *p = '\0';
            create_dir(pathname, 0755);
            *p = '/';
            f = fopen(pathname, "w+");
        }
    }
    return (f);
}

/* Verify the tar checksum. */
static int
verify_checksum(const char *p)
{
    int n, u = 0;
    for (n = 0; n < 512; ++n) {
        if (n < 148 || n > 155)
            /* Standard tar checksum adds unsigned bytes. */
            u += ((unsigned char *)p)[n];
        else
            u += 0x20;

    }
    return (u == parseoct(p + 148, 8));
}

/* Extract a tar archive. */
static void
untar(FILE *a, const char *path)
{
    char buff[512];
    FILE *f = NULL;
    size_t bytes_read;
    int filesize;

    printf("Extracting from %s\n", path);
    for (;;) {
        bytes_read = fread(buff, 1, 512, a);
        if (bytes_read < 512) {
            fprintf(stderr,
                "Short read on %s: expected 512, got %d\n",
                path, bytes_read);
            return;
        }
        if (is_end_of_archive(buff)) {
            printf("End of %s\n", path);
            return;
        }
        if (!verify_checksum(buff)) {
            fprintf(stderr, "Checksum failure\n");
            return;
        }
        filesize = parseoct(buff + 124, 12);
        switch (buff[156]) {
        case '1':
            printf(" Ignoring hardlink %s\n", buff);
            break;
        case '2':
            printf(" Ignoring symlink %s\n", buff);
            break;
        case '3':
            printf(" Ignoring character device %s\n", buff);
                break;
        case '4':
            printf(" Ignoring block device %s\n", buff);
            break;
        case '5':
            printf(" Extracting dir %s\n", buff);
            create_dir(buff, parseoct(buff + 100, 8));
            filesize = 0;
            break;
        case '6':
            printf(" Ignoring FIFO %s\n", buff);
            break;
        default:
            printf(" Extracting file %s\n", buff);
            f = create_file(buff, parseoct(buff + 100, 8));
            break;
        }
        while (filesize > 0) {
            bytes_read = fread(buff, 1, 512, a);
            if (bytes_read < 512) {
                fprintf(stderr,
                    "Short read on %s: Expected 512, got %d\n",
                    path, bytes_read);
                return;
            }
            if (filesize < 512)
                bytes_read = filesize;
            if (f != NULL) {
                if (fwrite(buff, 1, bytes_read, f)
                    != bytes_read)
                {
                    fprintf(stderr, "Failed write\n");
                    fclose(f);
                    f = NULL;
                }
            }
            filesize -= bytes_read;
        }
        if (f != NULL) {
            fclose(f);
            f = NULL;
        }
    }
}

int
main(int argc, char **argv)
{
    FILE *a;

    ++argv; /* Skip program name */
    for ( ;*argv != NULL; ++argv) {
        a = fopen(*argv, "r");
        if (a == NULL)
            fprintf(stderr, "Unable to open %s\n", *argv);
        else {
            untar(a, *argv);
            fclose(a);
        }
    }
    return (0);
}

--- NEW FILE: libarchive.1aix53.spec ---
(This appears to be a binary file; contents omitted.)

--- NEW FILE: libarchive_autodetect-st_lib_archive.m4 ---
dnl
dnl @synopsis ST_LIB_ARCHIVE([ENABLED-DEFAULT])
dnl
dnl This macro figures out what's necessary to link a program against an
dnl instance of the BSD libarchive package by Tim Kientzle.
dnl 
dnl See http://people.freebsd.org/~kientzle/libarchive/ for more info.
dnl
dnl It exports and substitutes the variables LIBARCHIVE_LIBS, LIBARCHIVE_LDFLAGS,
dnl and LIBARCHIVE_CPPFLAGS to appropriate values for the identified instance of
dnl libarchive.  The values are AC_SUBST'd, so a user could, for example, simply
dnl include @LIBARCHIVE_CPPFLAGS@ in the definition of AM_CPPFLAGS in a Makefile.am.
dnl
dnl ENABLED-DEFAULT is either "yes" or "no" and determines whether the default value
dnl is --with-libarchive or --without-libarchive.  It is not possible to specify a
dnl default directory.  More simply, any reasonable choice for a default should just
dnl go into the auto-detect list.
dnl
dnl The macro defines the symbol HAVE_LIBARCHIVE if the library is found. You
dnl should use autoheader to include a definition for this symbol in a config.h
dnl file. Sample usage in a C/C++ source is as follows:
dnl
dnl   #ifdef HAVE_LIBARCHIVE
dnl   #include <archive.h>
dnl   #endif /* HAVE_LIBARCHIVE */
dnl
dnl @category InstalledPackages
dnl @author Andre Stechert <andre at splunk.com>
dnl @version 2006-04-20
dnl @license GPLWithACException

AC_DEFUN([ST_LIB_ARCHIVE],
[
#
# Handle input from the configurer and blend with the requirements from the maintainer.
# We go through the trouble of creating a second set of variables other than the with_foo
# variables in order to be sure that error/corner cases have been cleaned up.
#
# After this statement, three trusted variable are defined.
#
# st_lib_archive_ENABLED will be either "yes" or "no".  its value determines whether
# or not we bother with the rest of the checks and whether or not we export a
# bunch of variables.
#
# st_lib_archive_LOCATION will be either "auto" or "defined".  if it is "auto", then
# we try a bunch of standard locations.  if it is "defined", then we just try the value
# provided in st_lib_archive_DIR.
#
# st_lib_archive_DIR will contain the string provided by the user, provided that it's
# actually a directory.
#
AC_MSG_CHECKING([if libarchive is wanted])
AC_ARG_WITH([libarchive],
    AS_HELP_STRING([--with-libarchive=DIR], [libarchive installation directory]),
    [if test "x$with_libarchive" = "xno" ; then
        st_lib_archive_ENABLED=no
    elif test "x$with_libarchive" = "xyes" ; then
        st_lib_archive_ENABLED=yes
        st_lib_archive_LOCATION=auto
    else
        st_lib_archive_ENABLED=yes
        st_lib_archive_LOCATION=defined
        if test -d "$with_libarchive" ; then
            st_lib_archive_DIR="$with_libarchive"
        else
            AC_MSG_ERROR([$with_libarchive is not a directory])
        fi
    fi],
    [if test "x$1" = "xno" ; then
        st_lib_archive_ENABLED=no
    elif test "x$1" = "xyes" ; then
        st_lib_archive_ENABLED=yes
    else
        st_lib_archive_ENABLED=yes
    fi])

if test "$st_lib_archive_ENABLED" = "yes" ; then
    AC_MSG_RESULT([yes])
#
# After this statement, one trusted variable is defined.
#
# st_lib_archive_LIB will be either "lib" or "lib64", depending on whether the configurer
# specified 32, 64.  The default is "lib".
#
    AC_MSG_CHECKING([whether to use lib or lib64])
    AC_ARG_WITH([libarchive-bits],
        AS_HELP_STRING([--with-libarchive-bits=32/64], [if 64, look in /lib64 on hybrid systems]),
        [if test "x$with_libarchive_bits" = "x32" ; then
            st_lib_archive_LIB=lib
        elif test "x$with_libarchive_bits" = "x64" ; then
            st_lib_archive_LIB=lib64
        else
            AC_MSG_ERROR([the argument must be either 32 or 64])
        fi],
        [st_lib_archive_LIB=lib])
    AC_MSG_RESULT($st_lib_archive_LIB)
#
# Save the environment before verifying libarchive availability
#
    st_lib_archive_SAVECPPFLAGS="$CPPFLAGS"
    st_lib_archive_SAVELDFLAGS="$LDFLAGS"
    AC_LANG_SAVE
    AC_LANG_C

    if test "x$st_lib_archive_LOCATION" = "xdefined" ; then
        CPPFLAGS="-I$st_lib_archive_DIR/include $st_lib_archive_SAVECPPFLAGS"
        LDFLAGS="-L$st_lib_archive_DIR/$st_lib_archive_LIB $st_lib_archive_SAVELDFLAGS"
        AC_CHECK_LIB(archive, archive_read_new, [st_lib_archive_found_lib=yes], [st_lib_archive_found_lib=no])
        AC_CHECK_HEADER(archive.h, [st_lib_archive_found_hdr=yes], [st_lib_archive_found_hdr=no])
        if test "x$st_lib_archive_found_lib" = "xyes" && test "x$st_lib_archive_found_hdr" = "xyes"; then
            LIBARCHIVE_CPPFLAGS="-I$dir/include"
            LIBARCHIVE_LDFLAGS="-L$dir/$st_lib_archive_LIB"
        else
            AC_MSG_ERROR([could not find libarchive in the requested location])
        fi
    else
        #
        # These are the common install directories for Linux, FreeBSD, Solaris, and Mac.
        #
        for dir in /usr /usr/local /usr/sfw /opt/csw /opt/local /sw
        do
            if test -d "$dir" ; then
                CPPFLAGS="-I$dir/include $st_lib_archive_SAVECPPFLAGS"
                LDFLAGS="-L$dir/$st_lib_archive_LIB $st_lib_archive_SAVELDFLAGS"
                AC_CHECK_LIB(archive, archive_read_new, [st_lib_archive_found_lib=yes], [st_lib_archive_found_lib=no])
                AC_CHECK_HEADER(archive.h, [st_lib_archive_found_hdr=yes], [st_lib_archive_found_hdr=no])
                if test "x$st_lib_archive_found_lib" = "xyes" && test "x$st_lib_archive_found_hdr" = "xyes"; then
                    LIBARCHIVE_CPPFLAGS="-I$dir/include"
                    LIBARCHIVE_LDFLAGS="-L$dir/$st_lib_archive_LIB"
                    break
                fi
            fi
        done
    fi

    if test "x$st_lib_archive_found_hdr" = "xyes" && test "x$st_lib_archive_found_lib" = "xyes" ; then
        LIBARCHIVE_LIBS="-larchive"
        AC_DEFINE([HAVE_LIBARCHIVE], [1], [Defined to 1 if libarchive is available for use.])
        AC_SUBST(LIBARCHIVE_LIBS)
        AC_SUBST(LIBARCHIVE_CPPFLAGS)
        AC_SUBST(LIBARCHIVE_LDFLAGS)
    fi

#
# Restore the environment now that we're done.
#
    AC_LANG_RESTORE
    CPPFLAGS="$st_lib_archive_SAVECPPFLAGS"
    LDFLAGS="$st_lib_archive_SAVELDFLAGS"
else
    AC_MSG_RESULT([no])
fi
AM_CONDITIONAL(LIBARCHIVE, test "x$st_lib_archive_found_lib" = "xyes" && test "x$st_lib_archive_found_hdr" = "xyes")
])

--- NEW FILE: libarchive.spec ---
(This appears to be a binary file; contents omitted.)

--- NEW FILE: README ---
Many people have graciously sent me configuration
files and other useful tidbits for use with libarchive.

I do not support or use any of these; but if you can use them, enjoy!

======================================================================

From: Andre Stechert <andre at splunk.com>

libarchive_autodetect-st_lib_archive.m4

M4 macros for use with autoconf to detect whether a suitable
version of libarchive is installed on this system.


======================================================================

libarchive.spec

An RPM ".spec" file for building libarchive on most systems.
This apparently was originally developed by a group at pld-linux.org.
Several people have sent me different versions of this file.

======================================================================

From: Robert Meier <rm1023 at dcx.com>

libarchive.1aix53.spec

As above, for use on AIX5.3.

======================================================================



More information about the Cmake-commits mailing list