2012-06-08 21:57:36 +00:00
|
|
|
/* $NetBSD: arch.c,v 1.62 2010/11/27 16:00:09 christos Exp $ */
|
|
|
|
|
1996-10-06 15:57:15 +00:00
|
|
|
/*
|
|
|
|
* Copyright (c) 1988, 1989, 1990, 1993
|
|
|
|
* The Regents of the University of California. All rights reserved.
|
2012-06-08 21:57:36 +00:00
|
|
|
*
|
|
|
|
* This code is derived from software contributed to Berkeley by
|
|
|
|
* Adam de Boor.
|
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
* 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.
|
|
|
|
* 3. Neither the name of the University nor the names of its contributors
|
|
|
|
* may be used to endorse or promote products derived from this software
|
|
|
|
* without specific prior written permission.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``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 REGENTS OR CONTRIBUTORS 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.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
1996-10-06 15:57:15 +00:00
|
|
|
* Copyright (c) 1989 by Berkeley Softworks
|
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* This code is derived from software contributed to Berkeley by
|
|
|
|
* Adam de Boor.
|
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
* 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.
|
|
|
|
* 3. All advertising materials mentioning features or use of this software
|
|
|
|
* must display the following acknowledgement:
|
|
|
|
* This product includes software developed by the University of
|
|
|
|
* California, Berkeley and its contributors.
|
|
|
|
* 4. Neither the name of the University nor the names of its contributors
|
|
|
|
* may be used to endorse or promote products derived from this software
|
|
|
|
* without specific prior written permission.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``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 REGENTS OR CONTRIBUTORS 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.
|
|
|
|
*/
|
|
|
|
|
2012-06-08 21:57:36 +00:00
|
|
|
#ifndef MAKE_NATIVE
|
|
|
|
static char rcsid[] = "$NetBSD: arch.c,v 1.62 2010/11/27 16:00:09 christos Exp $";
|
|
|
|
#else
|
|
|
|
#include <sys/cdefs.h>
|
1996-10-06 15:57:15 +00:00
|
|
|
#ifndef lint
|
2012-06-08 21:57:36 +00:00
|
|
|
#if 0
|
|
|
|
static char sccsid[] = "@(#)arch.c 8.2 (Berkeley) 1/2/94";
|
|
|
|
#else
|
|
|
|
__RCSID("$NetBSD: arch.c,v 1.62 2010/11/27 16:00:09 christos Exp $");
|
|
|
|
#endif
|
1996-10-06 15:57:15 +00:00
|
|
|
#endif /* not lint */
|
2012-06-08 21:57:36 +00:00
|
|
|
#endif
|
1996-10-06 15:57:15 +00:00
|
|
|
|
|
|
|
/*-
|
|
|
|
* arch.c --
|
|
|
|
* Functions to manipulate libraries, archives and their members.
|
|
|
|
*
|
|
|
|
* Once again, cacheing/hashing comes into play in the manipulation
|
|
|
|
* of archives. The first time an archive is referenced, all of its members'
|
|
|
|
* headers are read and hashed and the archive closed again. All hashed
|
|
|
|
* archives are kept on a list which is searched each time an archive member
|
|
|
|
* is referenced.
|
|
|
|
*
|
|
|
|
* The interface to this module is:
|
|
|
|
* Arch_ParseArchive Given an archive specification, return a list
|
|
|
|
* of GNode's, one for each member in the spec.
|
|
|
|
* FAILURE is returned if the specification is
|
|
|
|
* invalid for some reason.
|
|
|
|
*
|
|
|
|
* Arch_Touch Alter the modification time of the archive
|
|
|
|
* member described by the given node to be
|
|
|
|
* the current time.
|
|
|
|
*
|
|
|
|
* Arch_TouchLib Update the modification time of the library
|
|
|
|
* described by the given node. This is special
|
|
|
|
* because it also updates the modification time
|
|
|
|
* of the library's table of contents.
|
|
|
|
*
|
|
|
|
* Arch_MTime Find the modification time of a member of
|
|
|
|
* an archive *in the archive*. The time is also
|
|
|
|
* placed in the member's GNode. Returns the
|
|
|
|
* modification time.
|
|
|
|
*
|
|
|
|
* Arch_MemTime Find the modification time of a member of
|
|
|
|
* an archive. Called when the member doesn't
|
|
|
|
* already exist. Looks in the archive for the
|
|
|
|
* modification time. Returns the modification
|
|
|
|
* time.
|
|
|
|
*
|
|
|
|
* Arch_FindLib Search for a library along a path. The
|
|
|
|
* library name in the GNode should be in
|
|
|
|
* -l<name> format.
|
|
|
|
*
|
|
|
|
* Arch_LibOODate Special function to decide if a library node
|
|
|
|
* is out-of-date.
|
|
|
|
*
|
|
|
|
* Arch_Init Initialize this module.
|
|
|
|
*
|
|
|
|
* Arch_End Cleanup this module.
|
|
|
|
*/
|
|
|
|
|
2012-06-08 21:57:36 +00:00
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
# include "config.h"
|
|
|
|
#endif
|
1996-10-06 15:57:15 +00:00
|
|
|
#include <sys/types.h>
|
|
|
|
#include <sys/stat.h>
|
|
|
|
#include <sys/time.h>
|
|
|
|
#include <sys/param.h>
|
|
|
|
#include <ctype.h>
|
2012-06-08 21:57:36 +00:00
|
|
|
#ifdef HAVE_AR_H
|
1996-10-06 15:57:15 +00:00
|
|
|
#include <ar.h>
|
2012-06-08 21:57:36 +00:00
|
|
|
#else
|
|
|
|
struct ar_hdr {
|
|
|
|
char ar_name[16]; /* name */
|
|
|
|
char ar_date[12]; /* modification time */
|
|
|
|
char ar_uid[6]; /* user id */
|
|
|
|
char ar_gid[6]; /* group id */
|
|
|
|
char ar_mode[8]; /* octal file permissions */
|
|
|
|
char ar_size[10]; /* size in bytes */
|
|
|
|
#ifndef ARFMAG
|
|
|
|
#define ARFMAG "`\n"
|
|
|
|
#endif
|
|
|
|
char ar_fmag[2]; /* consistency check */
|
|
|
|
};
|
|
|
|
#endif
|
|
|
|
#if defined(HAVE_RANLIB_H) && !(defined(__ELF__) || defined(NO_RANLIB))
|
1997-07-06 06:54:14 +00:00
|
|
|
#include <ranlib.h>
|
2012-06-08 21:57:36 +00:00
|
|
|
#endif
|
|
|
|
#include <fcntl.h>
|
1996-10-06 15:57:15 +00:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
2012-06-08 21:57:36 +00:00
|
|
|
#ifdef HAVE_UTIME_H
|
|
|
|
#include <utime.h>
|
|
|
|
#endif
|
|
|
|
|
1996-10-06 15:57:15 +00:00
|
|
|
#include "make.h"
|
|
|
|
#include "hash.h"
|
|
|
|
#include "dir.h"
|
2012-06-08 21:57:36 +00:00
|
|
|
|
|
|
|
#ifdef TARGET_MACHINE
|
|
|
|
#undef MAKE_MACHINE
|
|
|
|
#define MAKE_MACHINE TARGET_MACHINE
|
|
|
|
#endif
|
|
|
|
#ifdef TARGET_MACHINE_ARCH
|
|
|
|
#undef MAKE_MACHINE_ARCH
|
|
|
|
#define MAKE_MACHINE_ARCH TARGET_MACHINE_ARCH
|
|
|
|
#endif
|
1996-10-06 15:57:15 +00:00
|
|
|
|
|
|
|
static Lst archives; /* Lst of archives we've already examined */
|
|
|
|
|
|
|
|
typedef struct Arch {
|
|
|
|
char *name; /* Name of archive */
|
|
|
|
Hash_Table members; /* All the members of the archive described
|
|
|
|
* by <name, struct ar_hdr *> key/value pairs */
|
2012-06-08 21:57:36 +00:00
|
|
|
char *fnametab; /* Extended name table strings */
|
|
|
|
size_t fnamesize; /* Size of the string table */
|
1996-10-06 15:57:15 +00:00
|
|
|
} Arch;
|
|
|
|
|
2012-06-08 21:57:36 +00:00
|
|
|
static int ArchFindArchive(const void *, const void *);
|
|
|
|
#ifdef CLEANUP
|
|
|
|
static void ArchFree(void *);
|
|
|
|
#endif
|
|
|
|
static struct ar_hdr *ArchStatMember(char *, char *, Boolean);
|
|
|
|
static FILE *ArchFindMember(char *, char *, struct ar_hdr *, const char *);
|
|
|
|
#if defined(__svr4__) || defined(__SVR4) || defined(__ELF__)
|
|
|
|
#define SVR4ARCHIVES
|
|
|
|
static int ArchSVR4Entry(Arch *, char *, size_t, FILE *);
|
|
|
|
#endif
|
|
|
|
|
1996-10-06 15:57:15 +00:00
|
|
|
|
2012-06-08 21:57:36 +00:00
|
|
|
#if defined(_AIX)
|
|
|
|
# define AR_NAME _ar_name.ar_name
|
|
|
|
# define AR_FMAG _ar_name.ar_fmag
|
|
|
|
# define SARMAG SAIAMAG
|
|
|
|
# define ARMAG AIAMAG
|
|
|
|
# define ARFMAG AIAFMAG
|
|
|
|
#endif
|
|
|
|
#ifndef AR_NAME
|
|
|
|
# define AR_NAME ar_name
|
|
|
|
#endif
|
|
|
|
#ifndef AR_DATE
|
|
|
|
# define AR_DATE ar_date
|
|
|
|
#endif
|
|
|
|
#ifndef AR_SIZE
|
|
|
|
# define AR_SIZE ar_size
|
|
|
|
#endif
|
|
|
|
#ifndef AR_FMAG
|
|
|
|
# define AR_FMAG ar_fmag
|
|
|
|
#endif
|
|
|
|
#ifndef ARMAG
|
|
|
|
# define ARMAG "!<arch>\n"
|
|
|
|
#endif
|
|
|
|
#ifndef SARMAG
|
|
|
|
# define SARMAG 8
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#define AR_MAX_NAME_LEN (sizeof(arh.AR_NAME)-1)
|
|
|
|
|
|
|
|
#ifdef CLEANUP
|
1996-10-06 15:57:15 +00:00
|
|
|
/*-
|
|
|
|
*-----------------------------------------------------------------------
|
|
|
|
* ArchFree --
|
|
|
|
* Free memory used by an archive
|
|
|
|
*
|
|
|
|
* Results:
|
|
|
|
* None.
|
|
|
|
*
|
|
|
|
* Side Effects:
|
|
|
|
* None.
|
|
|
|
*
|
|
|
|
*-----------------------------------------------------------------------
|
|
|
|
*/
|
|
|
|
static void
|
2012-06-08 21:57:36 +00:00
|
|
|
ArchFree(void *ap)
|
1996-10-06 15:57:15 +00:00
|
|
|
{
|
2012-06-08 21:57:36 +00:00
|
|
|
Arch *a = (Arch *)ap;
|
1996-10-06 15:57:15 +00:00
|
|
|
Hash_Search search;
|
|
|
|
Hash_Entry *entry;
|
2012-06-08 21:57:36 +00:00
|
|
|
|
|
|
|
/* Free memory from hash entries */
|
1996-10-06 15:57:15 +00:00
|
|
|
for (entry = Hash_EnumFirst(&a->members, &search);
|
2012-06-08 21:57:36 +00:00
|
|
|
entry != NULL;
|
1996-10-06 15:57:15 +00:00
|
|
|
entry = Hash_EnumNext(&search))
|
2012-06-08 21:57:36 +00:00
|
|
|
free(Hash_GetValue(entry));
|
1996-10-06 15:57:15 +00:00
|
|
|
|
|
|
|
free(a->name);
|
2012-06-08 21:57:36 +00:00
|
|
|
if (a->fnametab)
|
|
|
|
free(a->fnametab);
|
1996-10-06 15:57:15 +00:00
|
|
|
Hash_DeleteTable(&a->members);
|
2012-06-08 21:57:36 +00:00
|
|
|
free(a);
|
1996-10-06 15:57:15 +00:00
|
|
|
}
|
2012-06-08 21:57:36 +00:00
|
|
|
#endif
|
1996-10-06 15:57:15 +00:00
|
|
|
|
|
|
|
|
|
|
|
/*-
|
|
|
|
*-----------------------------------------------------------------------
|
|
|
|
* Arch_ParseArchive --
|
|
|
|
* Parse the archive specification in the given line and find/create
|
|
|
|
* the nodes for the specified archive members, placing their nodes
|
|
|
|
* on the given list.
|
|
|
|
*
|
2012-06-08 21:57:36 +00:00
|
|
|
* Input:
|
|
|
|
* linePtr Pointer to start of specification
|
|
|
|
* nodeLst Lst on which to place the nodes
|
|
|
|
* ctxt Context in which to expand variables
|
|
|
|
*
|
1996-10-06 15:57:15 +00:00
|
|
|
* Results:
|
|
|
|
* SUCCESS if it was a valid specification. The linePtr is updated
|
|
|
|
* to point to the first non-space after the archive spec. The
|
|
|
|
* nodes for the members are placed on the given list.
|
|
|
|
*
|
|
|
|
* Side Effects:
|
|
|
|
* Some nodes may be created. The given list is extended.
|
|
|
|
*
|
|
|
|
*-----------------------------------------------------------------------
|
|
|
|
*/
|
|
|
|
ReturnStatus
|
2012-06-08 21:57:36 +00:00
|
|
|
Arch_ParseArchive(char **linePtr, Lst nodeLst, GNode *ctxt)
|
1996-10-06 15:57:15 +00:00
|
|
|
{
|
2012-06-08 21:57:36 +00:00
|
|
|
char *cp; /* Pointer into line */
|
1996-10-06 15:57:15 +00:00
|
|
|
GNode *gn; /* New node */
|
|
|
|
char *libName; /* Library-part of specification */
|
|
|
|
char *memName; /* Member-part of specification */
|
2012-06-08 21:57:36 +00:00
|
|
|
char *nameBuf; /* temporary place for node name */
|
1996-10-06 15:57:15 +00:00
|
|
|
char saveChar; /* Ending delimiter of member-name */
|
|
|
|
Boolean subLibName; /* TRUE if libName should have/had
|
|
|
|
* variable substitution performed on it */
|
|
|
|
|
|
|
|
libName = *linePtr;
|
2012-06-08 21:57:36 +00:00
|
|
|
|
1996-10-06 15:57:15 +00:00
|
|
|
subLibName = FALSE;
|
|
|
|
|
|
|
|
for (cp = libName; *cp != '(' && *cp != '\0'; cp++) {
|
|
|
|
if (*cp == '$') {
|
|
|
|
/*
|
|
|
|
* Variable spec, so call the Var module to parse the puppy
|
|
|
|
* so we can safely advance beyond it...
|
|
|
|
*/
|
|
|
|
int length;
|
2012-06-08 21:57:36 +00:00
|
|
|
void *freeIt;
|
1996-10-06 15:57:15 +00:00
|
|
|
char *result;
|
2012-06-08 21:57:36 +00:00
|
|
|
|
|
|
|
result = Var_Parse(cp, ctxt, TRUE, &length, &freeIt);
|
|
|
|
if (freeIt)
|
|
|
|
free(freeIt);
|
1996-10-06 15:57:15 +00:00
|
|
|
if (result == var_Error) {
|
|
|
|
return(FAILURE);
|
|
|
|
} else {
|
|
|
|
subLibName = TRUE;
|
|
|
|
}
|
2012-06-08 21:57:36 +00:00
|
|
|
|
1996-10-06 15:57:15 +00:00
|
|
|
cp += length-1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
*cp++ = '\0';
|
|
|
|
if (subLibName) {
|
|
|
|
libName = Var_Subst(NULL, libName, ctxt, TRUE);
|
|
|
|
}
|
2012-06-08 21:57:36 +00:00
|
|
|
|
1996-10-06 15:57:15 +00:00
|
|
|
|
|
|
|
for (;;) {
|
|
|
|
/*
|
|
|
|
* First skip to the start of the member's name, mark that
|
|
|
|
* place and skip to the end of it (either white-space or
|
|
|
|
* a close paren).
|
|
|
|
*/
|
|
|
|
Boolean doSubst = FALSE; /* TRUE if need to substitute in memName */
|
|
|
|
|
2012-06-08 21:57:36 +00:00
|
|
|
while (*cp != '\0' && *cp != ')' && isspace ((unsigned char)*cp)) {
|
1996-10-06 15:57:15 +00:00
|
|
|
cp++;
|
|
|
|
}
|
|
|
|
memName = cp;
|
2012-06-08 21:57:36 +00:00
|
|
|
while (*cp != '\0' && *cp != ')' && !isspace ((unsigned char)*cp)) {
|
1996-10-06 15:57:15 +00:00
|
|
|
if (*cp == '$') {
|
|
|
|
/*
|
|
|
|
* Variable spec, so call the Var module to parse the puppy
|
|
|
|
* so we can safely advance beyond it...
|
|
|
|
*/
|
|
|
|
int length;
|
2012-06-08 21:57:36 +00:00
|
|
|
void *freeIt;
|
1996-10-06 15:57:15 +00:00
|
|
|
char *result;
|
|
|
|
|
2012-06-08 21:57:36 +00:00
|
|
|
result = Var_Parse(cp, ctxt, TRUE, &length, &freeIt);
|
|
|
|
if (freeIt)
|
|
|
|
free(freeIt);
|
1996-10-06 15:57:15 +00:00
|
|
|
if (result == var_Error) {
|
|
|
|
return(FAILURE);
|
|
|
|
} else {
|
|
|
|
doSubst = TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
cp += length;
|
|
|
|
} else {
|
|
|
|
cp++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* If the specification ends without a closing parenthesis,
|
|
|
|
* chances are there's something wrong (like a missing backslash),
|
|
|
|
* so it's better to return failure than allow such things to happen
|
|
|
|
*/
|
|
|
|
if (*cp == '\0') {
|
|
|
|
printf("No closing parenthesis in archive specification\n");
|
|
|
|
return (FAILURE);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* If we didn't move anywhere, we must be done
|
|
|
|
*/
|
|
|
|
if (cp == memName) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
saveChar = *cp;
|
|
|
|
*cp = '\0';
|
|
|
|
|
|
|
|
/*
|
|
|
|
* XXX: This should be taken care of intelligently by
|
|
|
|
* SuffExpandChildren, both for the archive and the member portions.
|
|
|
|
*/
|
|
|
|
/*
|
|
|
|
* If member contains variables, try and substitute for them.
|
|
|
|
* This will slow down archive specs with dynamic sources, of course,
|
|
|
|
* since we'll be (non-)substituting them three times, but them's
|
|
|
|
* the breaks -- we need to do this since SuffExpandChildren calls
|
|
|
|
* us, otherwise we could assume the thing would be taken care of
|
|
|
|
* later.
|
|
|
|
*/
|
|
|
|
if (doSubst) {
|
|
|
|
char *buf;
|
|
|
|
char *sacrifice;
|
|
|
|
char *oldMemName = memName;
|
2012-06-08 21:57:36 +00:00
|
|
|
size_t sz;
|
|
|
|
|
1996-10-06 15:57:15 +00:00
|
|
|
memName = Var_Subst(NULL, memName, ctxt, TRUE);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Now form an archive spec and recurse to deal with nested
|
|
|
|
* variables and multi-word variable values.... The results
|
|
|
|
* are just placed at the end of the nodeLst we're returning.
|
|
|
|
*/
|
2012-06-08 21:57:36 +00:00
|
|
|
sz = strlen(memName)+strlen(libName)+3;
|
|
|
|
buf = sacrifice = bmake_malloc(sz);
|
1996-10-06 15:57:15 +00:00
|
|
|
|
2012-06-08 21:57:36 +00:00
|
|
|
snprintf(buf, sz, "%s(%s)", libName, memName);
|
1996-10-06 15:57:15 +00:00
|
|
|
|
|
|
|
if (strchr(memName, '$') && strcmp(memName, oldMemName) == 0) {
|
|
|
|
/*
|
|
|
|
* Must contain dynamic sources, so we can't deal with it now.
|
|
|
|
* Just create an ARCHV node for the thing and let
|
|
|
|
* SuffExpandChildren handle it...
|
|
|
|
*/
|
|
|
|
gn = Targ_FindNode(buf, TARG_CREATE);
|
|
|
|
|
2012-06-08 21:57:36 +00:00
|
|
|
if (gn == NULL) {
|
1996-10-06 15:57:15 +00:00
|
|
|
free(buf);
|
|
|
|
return(FAILURE);
|
|
|
|
} else {
|
|
|
|
gn->type |= OP_ARCHV;
|
2012-06-08 21:57:36 +00:00
|
|
|
(void)Lst_AtEnd(nodeLst, gn);
|
1996-10-06 15:57:15 +00:00
|
|
|
}
|
|
|
|
} else if (Arch_ParseArchive(&sacrifice, nodeLst, ctxt)!=SUCCESS) {
|
|
|
|
/*
|
|
|
|
* Error in nested call -- free buffer and return FAILURE
|
|
|
|
* ourselves.
|
|
|
|
*/
|
|
|
|
free(buf);
|
|
|
|
return(FAILURE);
|
|
|
|
}
|
|
|
|
/*
|
|
|
|
* Free buffer and continue with our work.
|
|
|
|
*/
|
|
|
|
free(buf);
|
|
|
|
} else if (Dir_HasWildcards(memName)) {
|
|
|
|
Lst members = Lst_Init(FALSE);
|
|
|
|
char *member;
|
2012-06-08 21:57:36 +00:00
|
|
|
size_t sz = MAXPATHLEN, nsz;
|
|
|
|
nameBuf = bmake_malloc(sz);
|
1996-10-06 15:57:15 +00:00
|
|
|
|
|
|
|
Dir_Expand(memName, dirSearchPath, members);
|
|
|
|
while (!Lst_IsEmpty(members)) {
|
|
|
|
member = (char *)Lst_DeQueue(members);
|
2012-06-08 21:57:36 +00:00
|
|
|
nsz = strlen(libName) + strlen(member) + 3;
|
|
|
|
if (sz > nsz)
|
|
|
|
nameBuf = bmake_realloc(nameBuf, sz = nsz * 2);
|
|
|
|
|
|
|
|
snprintf(nameBuf, sz, "%s(%s)", libName, member);
|
1996-10-06 15:57:15 +00:00
|
|
|
free(member);
|
2012-06-08 21:57:36 +00:00
|
|
|
gn = Targ_FindNode(nameBuf, TARG_CREATE);
|
|
|
|
if (gn == NULL) {
|
|
|
|
free(nameBuf);
|
1996-10-06 15:57:15 +00:00
|
|
|
return (FAILURE);
|
|
|
|
} else {
|
|
|
|
/*
|
|
|
|
* We've found the node, but have to make sure the rest of
|
|
|
|
* the world knows it's an archive member, without having
|
|
|
|
* to constantly check for parentheses, so we type the
|
|
|
|
* thing with the OP_ARCHV bit before we place it on the
|
|
|
|
* end of the provided list.
|
|
|
|
*/
|
|
|
|
gn->type |= OP_ARCHV;
|
2012-06-08 21:57:36 +00:00
|
|
|
(void)Lst_AtEnd(nodeLst, gn);
|
1996-10-06 15:57:15 +00:00
|
|
|
}
|
|
|
|
}
|
2012-06-08 21:57:36 +00:00
|
|
|
Lst_Destroy(members, NULL);
|
|
|
|
free(nameBuf);
|
1996-10-06 15:57:15 +00:00
|
|
|
} else {
|
2012-06-08 21:57:36 +00:00
|
|
|
size_t sz = strlen(libName) + strlen(memName) + 3;
|
|
|
|
nameBuf = bmake_malloc(sz);
|
|
|
|
snprintf(nameBuf, sz, "%s(%s)", libName, memName);
|
|
|
|
gn = Targ_FindNode(nameBuf, TARG_CREATE);
|
|
|
|
free(nameBuf);
|
|
|
|
if (gn == NULL) {
|
1996-10-06 15:57:15 +00:00
|
|
|
return (FAILURE);
|
|
|
|
} else {
|
|
|
|
/*
|
|
|
|
* We've found the node, but have to make sure the rest of the
|
|
|
|
* world knows it's an archive member, without having to
|
|
|
|
* constantly check for parentheses, so we type the thing with
|
|
|
|
* the OP_ARCHV bit before we place it on the end of the
|
|
|
|
* provided list.
|
|
|
|
*/
|
|
|
|
gn->type |= OP_ARCHV;
|
2012-06-08 21:57:36 +00:00
|
|
|
(void)Lst_AtEnd(nodeLst, gn);
|
1996-10-06 15:57:15 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
if (doSubst) {
|
|
|
|
free(memName);
|
|
|
|
}
|
2012-06-08 21:57:36 +00:00
|
|
|
|
1996-10-06 15:57:15 +00:00
|
|
|
*cp = saveChar;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* If substituted libName, free it now, since we need it no longer.
|
|
|
|
*/
|
|
|
|
if (subLibName) {
|
|
|
|
free(libName);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* We promised the pointer would be set up at the next non-space, so
|
|
|
|
* we must advance cp there before setting *linePtr... (note that on
|
|
|
|
* entrance to the loop, cp is guaranteed to point at a ')')
|
|
|
|
*/
|
|
|
|
do {
|
|
|
|
cp++;
|
2012-06-08 21:57:36 +00:00
|
|
|
} while (*cp != '\0' && isspace ((unsigned char)*cp));
|
1996-10-06 15:57:15 +00:00
|
|
|
|
|
|
|
*linePtr = cp;
|
|
|
|
return (SUCCESS);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*-
|
|
|
|
*-----------------------------------------------------------------------
|
|
|
|
* ArchFindArchive --
|
|
|
|
* See if the given archive is the one we are looking for. Called
|
|
|
|
* From ArchStatMember and ArchFindMember via Lst_Find.
|
|
|
|
*
|
2012-06-08 21:57:36 +00:00
|
|
|
* Input:
|
|
|
|
* ar Current list element
|
|
|
|
* archName Name we want
|
|
|
|
*
|
1996-10-06 15:57:15 +00:00
|
|
|
* Results:
|
|
|
|
* 0 if it is, non-zero if it isn't.
|
|
|
|
*
|
|
|
|
* Side Effects:
|
|
|
|
* None.
|
|
|
|
*
|
|
|
|
*-----------------------------------------------------------------------
|
|
|
|
*/
|
|
|
|
static int
|
2012-06-08 21:57:36 +00:00
|
|
|
ArchFindArchive(const void *ar, const void *archName)
|
1996-10-06 15:57:15 +00:00
|
|
|
{
|
2012-06-08 21:57:36 +00:00
|
|
|
return (strcmp(archName, ((const Arch *)ar)->name));
|
1996-10-06 15:57:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*-
|
|
|
|
*-----------------------------------------------------------------------
|
|
|
|
* ArchStatMember --
|
|
|
|
* Locate a member of an archive, given the path of the archive and
|
|
|
|
* the path of the desired member.
|
|
|
|
*
|
2012-06-08 21:57:36 +00:00
|
|
|
* Input:
|
|
|
|
* archive Path to the archive
|
|
|
|
* member Name of member. If it is a path, only the last
|
|
|
|
* component is used.
|
|
|
|
* hash TRUE if archive should be hashed if not already so.
|
|
|
|
*
|
1996-10-06 15:57:15 +00:00
|
|
|
* Results:
|
|
|
|
* A pointer to the current struct ar_hdr structure for the member. Note
|
|
|
|
* That no position is returned, so this is not useful for touching
|
|
|
|
* archive members. This is mostly because we have no assurances that
|
|
|
|
* The archive will remain constant after we read all the headers, so
|
|
|
|
* there's not much point in remembering the position...
|
|
|
|
*
|
|
|
|
* Side Effects:
|
|
|
|
*
|
|
|
|
*-----------------------------------------------------------------------
|
|
|
|
*/
|
|
|
|
static struct ar_hdr *
|
2012-06-08 21:57:36 +00:00
|
|
|
ArchStatMember(char *archive, char *member, Boolean hash)
|
1996-10-06 15:57:15 +00:00
|
|
|
{
|
|
|
|
FILE * arch; /* Stream to archive */
|
|
|
|
int size; /* Size of archive member */
|
|
|
|
char *cp; /* Useful character pointer */
|
|
|
|
char magic[SARMAG];
|
|
|
|
LstNode ln; /* Lst member containing archive descriptor */
|
|
|
|
Arch *ar; /* Archive descriptor */
|
|
|
|
Hash_Entry *he; /* Entry containing member's description */
|
|
|
|
struct ar_hdr arh; /* archive-member header for reading archive */
|
|
|
|
char memName[MAXPATHLEN+1];
|
|
|
|
/* Current member name while hashing. */
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Because of space constraints and similar things, files are archived
|
|
|
|
* using their final path components, not the entire thing, so we need
|
|
|
|
* to point 'member' to the final component, if there is one, to make
|
|
|
|
* the comparisons easier...
|
|
|
|
*/
|
2012-06-08 21:57:36 +00:00
|
|
|
cp = strrchr(member, '/');
|
|
|
|
if (cp != NULL) {
|
1996-10-06 15:57:15 +00:00
|
|
|
member = cp + 1;
|
|
|
|
}
|
|
|
|
|
2012-06-08 21:57:36 +00:00
|
|
|
ln = Lst_Find(archives, archive, ArchFindArchive);
|
|
|
|
if (ln != NULL) {
|
|
|
|
ar = (Arch *)Lst_Datum(ln);
|
1996-10-06 15:57:15 +00:00
|
|
|
|
2012-06-08 21:57:36 +00:00
|
|
|
he = Hash_FindEntry(&ar->members, member);
|
1996-10-06 15:57:15 +00:00
|
|
|
|
2012-06-08 21:57:36 +00:00
|
|
|
if (he != NULL) {
|
|
|
|
return ((struct ar_hdr *)Hash_GetValue(he));
|
1996-10-06 15:57:15 +00:00
|
|
|
} else {
|
|
|
|
/* Try truncated name */
|
|
|
|
char copy[AR_MAX_NAME_LEN+1];
|
2012-06-08 21:57:36 +00:00
|
|
|
size_t len = strlen(member);
|
1996-10-06 15:57:15 +00:00
|
|
|
|
|
|
|
if (len > AR_MAX_NAME_LEN) {
|
|
|
|
len = AR_MAX_NAME_LEN;
|
|
|
|
strncpy(copy, member, AR_MAX_NAME_LEN);
|
|
|
|
copy[AR_MAX_NAME_LEN] = '\0';
|
|
|
|
}
|
2012-06-08 21:57:36 +00:00
|
|
|
if ((he = Hash_FindEntry(&ar->members, copy)) != NULL)
|
|
|
|
return ((struct ar_hdr *)Hash_GetValue(he));
|
|
|
|
return NULL;
|
1996-10-06 15:57:15 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!hash) {
|
|
|
|
/*
|
|
|
|
* Caller doesn't want the thing hashed, just use ArchFindMember
|
|
|
|
* to read the header for the member out and close down the stream
|
|
|
|
* again. Since the archive is not to be hashed, we assume there's
|
|
|
|
* no need to allocate extra room for the header we're returning,
|
|
|
|
* so just declare it static.
|
|
|
|
*/
|
|
|
|
static struct ar_hdr sarh;
|
|
|
|
|
|
|
|
arch = ArchFindMember(archive, member, &sarh, "r");
|
|
|
|
|
2012-06-08 21:57:36 +00:00
|
|
|
if (arch == NULL) {
|
|
|
|
return NULL;
|
1996-10-06 15:57:15 +00:00
|
|
|
} else {
|
|
|
|
fclose(arch);
|
|
|
|
return (&sarh);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* We don't have this archive on the list yet, so we want to find out
|
|
|
|
* everything that's in it and cache it so we can get at it quickly.
|
|
|
|
*/
|
2012-06-08 21:57:36 +00:00
|
|
|
arch = fopen(archive, "r");
|
|
|
|
if (arch == NULL) {
|
|
|
|
return NULL;
|
1996-10-06 15:57:15 +00:00
|
|
|
}
|
2012-06-08 21:57:36 +00:00
|
|
|
|
1996-10-06 15:57:15 +00:00
|
|
|
/*
|
|
|
|
* We use the ARMAG string to make sure this is an archive we
|
|
|
|
* can handle...
|
|
|
|
*/
|
2012-06-08 21:57:36 +00:00
|
|
|
if ((fread(magic, SARMAG, 1, arch) != 1) ||
|
|
|
|
(strncmp(magic, ARMAG, SARMAG) != 0)) {
|
|
|
|
fclose(arch);
|
|
|
|
return NULL;
|
1996-10-06 15:57:15 +00:00
|
|
|
}
|
|
|
|
|
2012-06-08 21:57:36 +00:00
|
|
|
ar = bmake_malloc(sizeof(Arch));
|
|
|
|
ar->name = bmake_strdup(archive);
|
|
|
|
ar->fnametab = NULL;
|
|
|
|
ar->fnamesize = 0;
|
|
|
|
Hash_InitTable(&ar->members, -1);
|
1996-10-06 15:57:15 +00:00
|
|
|
memName[AR_MAX_NAME_LEN] = '\0';
|
2012-06-08 21:57:36 +00:00
|
|
|
|
|
|
|
while (fread((char *)&arh, sizeof(struct ar_hdr), 1, arch) == 1) {
|
|
|
|
if (strncmp( arh.AR_FMAG, ARFMAG, sizeof(arh.AR_FMAG)) != 0) {
|
|
|
|
/*
|
|
|
|
* The header is bogus, so the archive is bad
|
|
|
|
* and there's no way we can recover...
|
|
|
|
*/
|
|
|
|
goto badarch;
|
1996-10-06 15:57:15 +00:00
|
|
|
} else {
|
2012-06-08 21:57:36 +00:00
|
|
|
/*
|
|
|
|
* We need to advance the stream's pointer to the start of the
|
|
|
|
* next header. Files are padded with newlines to an even-byte
|
|
|
|
* boundary, so we need to extract the size of the file from the
|
|
|
|
* 'size' field of the header and round it up during the seek.
|
|
|
|
*/
|
|
|
|
arh.AR_SIZE[sizeof(arh.AR_SIZE)-1] = '\0';
|
|
|
|
size = (int)strtol(arh.AR_SIZE, NULL, 10);
|
|
|
|
|
|
|
|
(void)strncpy(memName, arh.AR_NAME, sizeof(arh.AR_NAME));
|
1996-10-06 15:57:15 +00:00
|
|
|
for (cp = &memName[AR_MAX_NAME_LEN]; *cp == ' '; cp--) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
cp[1] = '\0';
|
|
|
|
|
2012-06-08 21:57:36 +00:00
|
|
|
#ifdef SVR4ARCHIVES
|
|
|
|
/*
|
|
|
|
* svr4 names are slash terminated. Also svr4 extended AR format.
|
|
|
|
*/
|
|
|
|
if (memName[0] == '/') {
|
|
|
|
/*
|
|
|
|
* svr4 magic mode; handle it
|
|
|
|
*/
|
|
|
|
switch (ArchSVR4Entry(ar, memName, size, arch)) {
|
|
|
|
case -1: /* Invalid data */
|
|
|
|
goto badarch;
|
|
|
|
case 0: /* List of files entry */
|
|
|
|
continue;
|
|
|
|
default: /* Got the entry */
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
if (cp[0] == '/')
|
|
|
|
cp[0] = '\0';
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
1996-10-06 15:57:15 +00:00
|
|
|
#ifdef AR_EFMT1
|
|
|
|
/*
|
|
|
|
* BSD 4.4 extended AR format: #1/<namelen>, with name as the
|
|
|
|
* first <namelen> bytes of the file
|
|
|
|
*/
|
|
|
|
if (strncmp(memName, AR_EFMT1, sizeof(AR_EFMT1) - 1) == 0 &&
|
2012-06-08 21:57:36 +00:00
|
|
|
isdigit((unsigned char)memName[sizeof(AR_EFMT1) - 1])) {
|
1996-10-06 15:57:15 +00:00
|
|
|
|
|
|
|
unsigned int elen = atoi(&memName[sizeof(AR_EFMT1)-1]);
|
|
|
|
|
2012-06-08 21:57:36 +00:00
|
|
|
if (elen > MAXPATHLEN)
|
|
|
|
goto badarch;
|
|
|
|
if (fread(memName, elen, 1, arch) != 1)
|
|
|
|
goto badarch;
|
1996-10-06 15:57:15 +00:00
|
|
|
memName[elen] = '\0';
|
2012-06-08 21:57:36 +00:00
|
|
|
fseek(arch, -elen, SEEK_CUR);
|
1996-10-06 15:57:15 +00:00
|
|
|
if (DEBUG(ARCH) || DEBUG(MAKE)) {
|
2012-06-08 21:57:36 +00:00
|
|
|
fprintf(debug_file, "ArchStat: Extended format entry for %s\n", memName);
|
1996-10-06 15:57:15 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2012-06-08 21:57:36 +00:00
|
|
|
he = Hash_CreateEntry(&ar->members, memName, NULL);
|
|
|
|
Hash_SetValue(he, bmake_malloc(sizeof(struct ar_hdr)));
|
|
|
|
memcpy(Hash_GetValue(he), &arh, sizeof(struct ar_hdr));
|
1996-10-06 15:57:15 +00:00
|
|
|
}
|
2012-06-08 21:57:36 +00:00
|
|
|
fseek(arch, (size + 1) & ~1, SEEK_CUR);
|
1996-10-06 15:57:15 +00:00
|
|
|
}
|
|
|
|
|
2012-06-08 21:57:36 +00:00
|
|
|
fclose(arch);
|
1996-10-06 15:57:15 +00:00
|
|
|
|
2012-06-08 21:57:36 +00:00
|
|
|
(void)Lst_AtEnd(archives, ar);
|
1996-10-06 15:57:15 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Now that the archive has been read and cached, we can look into
|
|
|
|
* the hash table to find the desired member's header.
|
|
|
|
*/
|
2012-06-08 21:57:36 +00:00
|
|
|
he = Hash_FindEntry(&ar->members, member);
|
1996-10-06 15:57:15 +00:00
|
|
|
|
2012-06-08 21:57:36 +00:00
|
|
|
if (he != NULL) {
|
|
|
|
return ((struct ar_hdr *)Hash_GetValue(he));
|
1996-10-06 15:57:15 +00:00
|
|
|
} else {
|
2012-06-08 21:57:36 +00:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
badarch:
|
|
|
|
fclose(arch);
|
|
|
|
Hash_DeleteTable(&ar->members);
|
|
|
|
if (ar->fnametab)
|
|
|
|
free(ar->fnametab);
|
|
|
|
free(ar);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef SVR4ARCHIVES
|
|
|
|
/*-
|
|
|
|
*-----------------------------------------------------------------------
|
|
|
|
* ArchSVR4Entry --
|
|
|
|
* Parse an SVR4 style entry that begins with a slash.
|
|
|
|
* If it is "//", then load the table of filenames
|
|
|
|
* If it is "/<offset>", then try to substitute the long file name
|
|
|
|
* from offset of a table previously read.
|
|
|
|
*
|
|
|
|
* Results:
|
|
|
|
* -1: Bad data in archive
|
|
|
|
* 0: A table was loaded from the file
|
|
|
|
* 1: Name was successfully substituted from table
|
|
|
|
* 2: Name was not successfully substituted from table
|
|
|
|
*
|
|
|
|
* Side Effects:
|
|
|
|
* If a table is read, the file pointer is moved to the next archive
|
|
|
|
* member
|
|
|
|
*
|
|
|
|
*-----------------------------------------------------------------------
|
|
|
|
*/
|
|
|
|
static int
|
|
|
|
ArchSVR4Entry(Arch *ar, char *name, size_t size, FILE *arch)
|
|
|
|
{
|
|
|
|
#define ARLONGNAMES1 "//"
|
|
|
|
#define ARLONGNAMES2 "/ARFILENAMES"
|
|
|
|
size_t entry;
|
|
|
|
char *ptr, *eptr;
|
|
|
|
|
|
|
|
if (strncmp(name, ARLONGNAMES1, sizeof(ARLONGNAMES1) - 1) == 0 ||
|
|
|
|
strncmp(name, ARLONGNAMES2, sizeof(ARLONGNAMES2) - 1) == 0) {
|
|
|
|
|
|
|
|
if (ar->fnametab != NULL) {
|
|
|
|
if (DEBUG(ARCH)) {
|
|
|
|
fprintf(debug_file, "Attempted to redefine an SVR4 name table\n");
|
|
|
|
}
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* This is a table of archive names, so we build one for
|
|
|
|
* ourselves
|
|
|
|
*/
|
|
|
|
ar->fnametab = bmake_malloc(size);
|
|
|
|
ar->fnamesize = size;
|
|
|
|
|
|
|
|
if (fread(ar->fnametab, size, 1, arch) != 1) {
|
|
|
|
if (DEBUG(ARCH)) {
|
|
|
|
fprintf(debug_file, "Reading an SVR4 name table failed\n");
|
|
|
|
}
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
eptr = ar->fnametab + size;
|
|
|
|
for (entry = 0, ptr = ar->fnametab; ptr < eptr; ptr++)
|
|
|
|
switch (*ptr) {
|
|
|
|
case '/':
|
|
|
|
entry++;
|
|
|
|
*ptr = '\0';
|
|
|
|
break;
|
|
|
|
|
|
|
|
case '\n':
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (DEBUG(ARCH)) {
|
|
|
|
fprintf(debug_file, "Found svr4 archive name table with %lu entries\n",
|
|
|
|
(u_long)entry);
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (name[1] == ' ' || name[1] == '\0')
|
|
|
|
return 2;
|
|
|
|
|
|
|
|
entry = (size_t)strtol(&name[1], &eptr, 0);
|
|
|
|
if ((*eptr != ' ' && *eptr != '\0') || eptr == &name[1]) {
|
|
|
|
if (DEBUG(ARCH)) {
|
|
|
|
fprintf(debug_file, "Could not parse SVR4 name %s\n", name);
|
|
|
|
}
|
|
|
|
return 2;
|
|
|
|
}
|
|
|
|
if (entry >= ar->fnamesize) {
|
|
|
|
if (DEBUG(ARCH)) {
|
|
|
|
fprintf(debug_file, "SVR4 entry offset %s is greater than %lu\n",
|
|
|
|
name, (u_long)ar->fnamesize);
|
|
|
|
}
|
|
|
|
return 2;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (DEBUG(ARCH)) {
|
|
|
|
fprintf(debug_file, "Replaced %s with %s\n", name, &ar->fnametab[entry]);
|
1996-10-06 15:57:15 +00:00
|
|
|
}
|
2012-06-08 21:57:36 +00:00
|
|
|
|
|
|
|
(void)strncpy(name, &ar->fnametab[entry], MAXPATHLEN);
|
|
|
|
name[MAXPATHLEN] = '\0';
|
|
|
|
return 1;
|
1996-10-06 15:57:15 +00:00
|
|
|
}
|
2012-06-08 21:57:36 +00:00
|
|
|
#endif
|
|
|
|
|
1996-10-06 15:57:15 +00:00
|
|
|
|
|
|
|
/*-
|
|
|
|
*-----------------------------------------------------------------------
|
|
|
|
* ArchFindMember --
|
|
|
|
* Locate a member of an archive, given the path of the archive and
|
|
|
|
* the path of the desired member. If the archive is to be modified,
|
|
|
|
* the mode should be "r+", if not, it should be "r".
|
|
|
|
*
|
2012-06-08 21:57:36 +00:00
|
|
|
* Input:
|
|
|
|
* archive Path to the archive
|
|
|
|
* member Name of member. If it is a path, only the last
|
|
|
|
* component is used.
|
|
|
|
* arhPtr Pointer to header structure to be filled in
|
|
|
|
* mode The mode for opening the stream
|
|
|
|
*
|
1996-10-06 15:57:15 +00:00
|
|
|
* Results:
|
|
|
|
* An FILE *, opened for reading and writing, positioned at the
|
|
|
|
* start of the member's struct ar_hdr, or NULL if the member was
|
|
|
|
* nonexistent. The current struct ar_hdr for member.
|
|
|
|
*
|
|
|
|
* Side Effects:
|
|
|
|
* The passed struct ar_hdr structure is filled in.
|
|
|
|
*
|
|
|
|
*-----------------------------------------------------------------------
|
|
|
|
*/
|
|
|
|
static FILE *
|
2012-06-08 21:57:36 +00:00
|
|
|
ArchFindMember(char *archive, char *member, struct ar_hdr *arhPtr,
|
|
|
|
const char *mode)
|
1996-10-06 15:57:15 +00:00
|
|
|
{
|
|
|
|
FILE * arch; /* Stream to archive */
|
|
|
|
int size; /* Size of archive member */
|
|
|
|
char *cp; /* Useful character pointer */
|
|
|
|
char magic[SARMAG];
|
2012-06-08 21:57:36 +00:00
|
|
|
size_t len, tlen;
|
1996-10-06 15:57:15 +00:00
|
|
|
|
2012-06-08 21:57:36 +00:00
|
|
|
arch = fopen(archive, mode);
|
|
|
|
if (arch == NULL) {
|
|
|
|
return NULL;
|
1996-10-06 15:57:15 +00:00
|
|
|
}
|
2012-06-08 21:57:36 +00:00
|
|
|
|
1996-10-06 15:57:15 +00:00
|
|
|
/*
|
|
|
|
* We use the ARMAG string to make sure this is an archive we
|
|
|
|
* can handle...
|
|
|
|
*/
|
2012-06-08 21:57:36 +00:00
|
|
|
if ((fread(magic, SARMAG, 1, arch) != 1) ||
|
|
|
|
(strncmp(magic, ARMAG, SARMAG) != 0)) {
|
|
|
|
fclose(arch);
|
|
|
|
return NULL;
|
1996-10-06 15:57:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Because of space constraints and similar things, files are archived
|
|
|
|
* using their final path components, not the entire thing, so we need
|
|
|
|
* to point 'member' to the final component, if there is one, to make
|
|
|
|
* the comparisons easier...
|
|
|
|
*/
|
2012-06-08 21:57:36 +00:00
|
|
|
cp = strrchr(member, '/');
|
|
|
|
if (cp != NULL) {
|
1996-10-06 15:57:15 +00:00
|
|
|
member = cp + 1;
|
|
|
|
}
|
2012-06-08 21:57:36 +00:00
|
|
|
len = tlen = strlen(member);
|
|
|
|
if (len > sizeof(arhPtr->AR_NAME)) {
|
|
|
|
tlen = sizeof(arhPtr->AR_NAME);
|
1996-10-06 15:57:15 +00:00
|
|
|
}
|
2012-06-08 21:57:36 +00:00
|
|
|
|
|
|
|
while (fread((char *)arhPtr, sizeof(struct ar_hdr), 1, arch) == 1) {
|
|
|
|
if (strncmp(arhPtr->AR_FMAG, ARFMAG, sizeof(arhPtr->AR_FMAG) ) != 0) {
|
1996-10-06 15:57:15 +00:00
|
|
|
/*
|
|
|
|
* The header is bogus, so the archive is bad
|
|
|
|
* and there's no way we can recover...
|
|
|
|
*/
|
2012-06-08 21:57:36 +00:00
|
|
|
fclose(arch);
|
|
|
|
return NULL;
|
|
|
|
} else if (strncmp(member, arhPtr->AR_NAME, tlen) == 0) {
|
1996-10-06 15:57:15 +00:00
|
|
|
/*
|
|
|
|
* If the member's name doesn't take up the entire 'name' field,
|
|
|
|
* we have to be careful of matching prefixes. Names are space-
|
|
|
|
* padded to the right, so if the character in 'name' at the end
|
|
|
|
* of the matched string is anything but a space, this isn't the
|
|
|
|
* member we sought.
|
|
|
|
*/
|
2012-06-08 21:57:36 +00:00
|
|
|
if (tlen != sizeof(arhPtr->AR_NAME) && arhPtr->AR_NAME[tlen] != ' '){
|
1996-10-06 15:57:15 +00:00
|
|
|
goto skip;
|
|
|
|
} else {
|
|
|
|
/*
|
|
|
|
* To make life easier, we reposition the file at the start
|
|
|
|
* of the header we just read before we return the stream.
|
|
|
|
* In a more general situation, it might be better to leave
|
|
|
|
* the file at the actual member, rather than its header, but
|
|
|
|
* not here...
|
|
|
|
*/
|
2012-06-08 21:57:36 +00:00
|
|
|
fseek(arch, -sizeof(struct ar_hdr), SEEK_CUR);
|
1996-10-06 15:57:15 +00:00
|
|
|
return (arch);
|
|
|
|
}
|
|
|
|
} else
|
|
|
|
#ifdef AR_EFMT1
|
|
|
|
/*
|
|
|
|
* BSD 4.4 extended AR format: #1/<namelen>, with name as the
|
|
|
|
* first <namelen> bytes of the file
|
|
|
|
*/
|
2012-06-08 21:57:36 +00:00
|
|
|
if (strncmp(arhPtr->AR_NAME, AR_EFMT1,
|
1996-10-06 15:57:15 +00:00
|
|
|
sizeof(AR_EFMT1) - 1) == 0 &&
|
2012-06-08 21:57:36 +00:00
|
|
|
isdigit((unsigned char)arhPtr->AR_NAME[sizeof(AR_EFMT1) - 1])) {
|
1996-10-06 15:57:15 +00:00
|
|
|
|
2012-06-08 21:57:36 +00:00
|
|
|
unsigned int elen = atoi(&arhPtr->AR_NAME[sizeof(AR_EFMT1)-1]);
|
|
|
|
char ename[MAXPATHLEN + 1];
|
1996-10-06 15:57:15 +00:00
|
|
|
|
|
|
|
if (elen > MAXPATHLEN) {
|
2012-06-08 21:57:36 +00:00
|
|
|
fclose(arch);
|
1996-10-06 15:57:15 +00:00
|
|
|
return NULL;
|
|
|
|
}
|
2012-06-08 21:57:36 +00:00
|
|
|
if (fread(ename, elen, 1, arch) != 1) {
|
|
|
|
fclose(arch);
|
1996-10-06 15:57:15 +00:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
ename[elen] = '\0';
|
|
|
|
if (DEBUG(ARCH) || DEBUG(MAKE)) {
|
2012-06-08 21:57:36 +00:00
|
|
|
fprintf(debug_file, "ArchFind: Extended format entry for %s\n", ename);
|
1996-10-06 15:57:15 +00:00
|
|
|
}
|
|
|
|
if (strncmp(ename, member, len) == 0) {
|
|
|
|
/* Found as extended name */
|
2012-06-08 21:57:36 +00:00
|
|
|
fseek(arch, -sizeof(struct ar_hdr) - elen, SEEK_CUR);
|
1996-10-06 15:57:15 +00:00
|
|
|
return (arch);
|
|
|
|
}
|
2012-06-08 21:57:36 +00:00
|
|
|
fseek(arch, -elen, SEEK_CUR);
|
1996-10-06 15:57:15 +00:00
|
|
|
goto skip;
|
|
|
|
} else
|
|
|
|
#endif
|
|
|
|
{
|
|
|
|
skip:
|
|
|
|
/*
|
|
|
|
* This isn't the member we're after, so we need to advance the
|
|
|
|
* stream's pointer to the start of the next header. Files are
|
|
|
|
* padded with newlines to an even-byte boundary, so we need to
|
|
|
|
* extract the size of the file from the 'size' field of the
|
|
|
|
* header and round it up during the seek.
|
|
|
|
*/
|
2012-06-08 21:57:36 +00:00
|
|
|
arhPtr->ar_size[sizeof(arhPtr->AR_SIZE)-1] = '\0';
|
|
|
|
size = (int)strtol(arhPtr->AR_SIZE, NULL, 10);
|
|
|
|
fseek(arch, (size + 1) & ~1, SEEK_CUR);
|
1996-10-06 15:57:15 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* We've looked everywhere, but the member is not to be found. Close the
|
|
|
|
* archive and return NULL -- an error.
|
|
|
|
*/
|
2012-06-08 21:57:36 +00:00
|
|
|
fclose(arch);
|
|
|
|
return NULL;
|
1996-10-06 15:57:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*-
|
|
|
|
*-----------------------------------------------------------------------
|
|
|
|
* Arch_Touch --
|
|
|
|
* Touch a member of an archive.
|
|
|
|
*
|
2012-06-08 21:57:36 +00:00
|
|
|
* Input:
|
|
|
|
* gn Node of member to touch
|
|
|
|
*
|
1996-10-06 15:57:15 +00:00
|
|
|
* Results:
|
|
|
|
* The 'time' field of the member's header is updated.
|
|
|
|
*
|
|
|
|
* Side Effects:
|
|
|
|
* The modification time of the entire archive is also changed.
|
|
|
|
* For a library, this could necessitate the re-ranlib'ing of the
|
|
|
|
* whole thing.
|
|
|
|
*
|
|
|
|
*-----------------------------------------------------------------------
|
|
|
|
*/
|
|
|
|
void
|
2012-06-08 21:57:36 +00:00
|
|
|
Arch_Touch(GNode *gn)
|
1996-10-06 15:57:15 +00:00
|
|
|
{
|
|
|
|
FILE * arch; /* Stream open to archive, positioned properly */
|
|
|
|
struct ar_hdr arh; /* Current header describing member */
|
|
|
|
char *p1, *p2;
|
|
|
|
|
2012-06-08 21:57:36 +00:00
|
|
|
arch = ArchFindMember(Var_Value(ARCHIVE, gn, &p1),
|
|
|
|
Var_Value(MEMBER, gn, &p2),
|
1996-10-06 15:57:15 +00:00
|
|
|
&arh, "r+");
|
|
|
|
if (p1)
|
|
|
|
free(p1);
|
|
|
|
if (p2)
|
|
|
|
free(p2);
|
2012-06-08 21:57:36 +00:00
|
|
|
snprintf(arh.AR_DATE, sizeof(arh.AR_DATE), "%-12ld", (long) now);
|
1996-10-06 15:57:15 +00:00
|
|
|
|
2012-06-08 21:57:36 +00:00
|
|
|
if (arch != NULL) {
|
|
|
|
(void)fwrite((char *)&arh, sizeof(struct ar_hdr), 1, arch);
|
|
|
|
fclose(arch);
|
1996-10-06 15:57:15 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*-
|
|
|
|
*-----------------------------------------------------------------------
|
|
|
|
* Arch_TouchLib --
|
|
|
|
* Given a node which represents a library, touch the thing, making
|
|
|
|
* sure that the table of contents also is touched.
|
|
|
|
*
|
2012-06-08 21:57:36 +00:00
|
|
|
* Input:
|
|
|
|
* gn The node of the library to touch
|
|
|
|
*
|
1996-10-06 15:57:15 +00:00
|
|
|
* Results:
|
|
|
|
* None.
|
|
|
|
*
|
|
|
|
* Side Effects:
|
|
|
|
* Both the modification time of the library and of the RANLIBMAG
|
|
|
|
* member are set to 'now'.
|
|
|
|
*
|
|
|
|
*-----------------------------------------------------------------------
|
|
|
|
*/
|
|
|
|
void
|
2012-06-08 21:57:36 +00:00
|
|
|
#if !defined(RANLIBMAG)
|
|
|
|
Arch_TouchLib(GNode *gn __unused)
|
|
|
|
#else
|
|
|
|
Arch_TouchLib(GNode *gn)
|
|
|
|
#endif
|
1996-10-06 15:57:15 +00:00
|
|
|
{
|
2012-06-08 21:57:36 +00:00
|
|
|
#ifdef RANLIBMAG
|
1996-10-06 15:57:15 +00:00
|
|
|
FILE * arch; /* Stream open to archive */
|
|
|
|
struct ar_hdr arh; /* Header describing table of contents */
|
2012-06-08 21:57:36 +00:00
|
|
|
struct utimbuf times; /* Times for utime() call */
|
1996-10-06 15:57:15 +00:00
|
|
|
|
2012-06-08 21:57:36 +00:00
|
|
|
arch = ArchFindMember(gn->path, UNCONST(RANLIBMAG), &arh, "r+");
|
|
|
|
snprintf(arh.AR_DATE, sizeof(arh.AR_DATE), "%-12ld", (long) now);
|
1996-10-06 15:57:15 +00:00
|
|
|
|
2012-06-08 21:57:36 +00:00
|
|
|
if (arch != NULL) {
|
|
|
|
(void)fwrite((char *)&arh, sizeof(struct ar_hdr), 1, arch);
|
|
|
|
fclose(arch);
|
1996-10-06 15:57:15 +00:00
|
|
|
|
2012-06-08 21:57:36 +00:00
|
|
|
times.actime = times.modtime = now;
|
|
|
|
utime(gn->path, ×);
|
1996-10-06 15:57:15 +00:00
|
|
|
}
|
2012-06-08 21:57:36 +00:00
|
|
|
#endif
|
1996-10-06 15:57:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*-
|
|
|
|
*-----------------------------------------------------------------------
|
|
|
|
* Arch_MTime --
|
|
|
|
* Return the modification time of a member of an archive.
|
|
|
|
*
|
2012-06-08 21:57:36 +00:00
|
|
|
* Input:
|
|
|
|
* gn Node describing archive member
|
|
|
|
*
|
1996-10-06 15:57:15 +00:00
|
|
|
* Results:
|
2012-06-08 21:57:36 +00:00
|
|
|
* The modification time(seconds).
|
1996-10-06 15:57:15 +00:00
|
|
|
*
|
|
|
|
* Side Effects:
|
|
|
|
* The mtime field of the given node is filled in with the value
|
|
|
|
* returned by the function.
|
|
|
|
*
|
|
|
|
*-----------------------------------------------------------------------
|
|
|
|
*/
|
2012-06-08 21:57:36 +00:00
|
|
|
time_t
|
|
|
|
Arch_MTime(GNode *gn)
|
1996-10-06 15:57:15 +00:00
|
|
|
{
|
|
|
|
struct ar_hdr *arhPtr; /* Header of desired member */
|
2012-06-08 21:57:36 +00:00
|
|
|
time_t modTime; /* Modification time as an integer */
|
1996-10-06 15:57:15 +00:00
|
|
|
char *p1, *p2;
|
|
|
|
|
2012-06-08 21:57:36 +00:00
|
|
|
arhPtr = ArchStatMember(Var_Value(ARCHIVE, gn, &p1),
|
|
|
|
Var_Value(MEMBER, gn, &p2),
|
1996-10-06 15:57:15 +00:00
|
|
|
TRUE);
|
|
|
|
if (p1)
|
|
|
|
free(p1);
|
|
|
|
if (p2)
|
|
|
|
free(p2);
|
|
|
|
|
2012-06-08 21:57:36 +00:00
|
|
|
if (arhPtr != NULL) {
|
|
|
|
modTime = (time_t)strtol(arhPtr->AR_DATE, NULL, 10);
|
1996-10-06 15:57:15 +00:00
|
|
|
} else {
|
|
|
|
modTime = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
gn->mtime = modTime;
|
|
|
|
return (modTime);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*-
|
|
|
|
*-----------------------------------------------------------------------
|
|
|
|
* Arch_MemMTime --
|
|
|
|
* Given a non-existent archive member's node, get its modification
|
|
|
|
* time from its archived form, if it exists.
|
|
|
|
*
|
|
|
|
* Results:
|
|
|
|
* The modification time.
|
|
|
|
*
|
|
|
|
* Side Effects:
|
|
|
|
* The mtime field is filled in.
|
|
|
|
*
|
|
|
|
*-----------------------------------------------------------------------
|
|
|
|
*/
|
2012-06-08 21:57:36 +00:00
|
|
|
time_t
|
|
|
|
Arch_MemMTime(GNode *gn)
|
1996-10-06 15:57:15 +00:00
|
|
|
{
|
|
|
|
LstNode ln;
|
|
|
|
GNode *pgn;
|
|
|
|
char *nameStart,
|
|
|
|
*nameEnd;
|
|
|
|
|
2012-06-08 21:57:36 +00:00
|
|
|
if (Lst_Open(gn->parents) != SUCCESS) {
|
1996-10-06 15:57:15 +00:00
|
|
|
gn->mtime = 0;
|
|
|
|
return (0);
|
|
|
|
}
|
2012-06-08 21:57:36 +00:00
|
|
|
while ((ln = Lst_Next(gn->parents)) != NULL) {
|
|
|
|
pgn = (GNode *)Lst_Datum(ln);
|
1996-10-06 15:57:15 +00:00
|
|
|
|
|
|
|
if (pgn->type & OP_ARCHV) {
|
|
|
|
/*
|
|
|
|
* If the parent is an archive specification and is being made
|
|
|
|
* and its member's name matches the name of the node we were
|
|
|
|
* given, record the modification time of the parent in the
|
|
|
|
* child. We keep searching its parents in case some other
|
|
|
|
* parent requires this child to exist...
|
|
|
|
*/
|
2012-06-08 21:57:36 +00:00
|
|
|
nameStart = strchr(pgn->name, '(') + 1;
|
|
|
|
nameEnd = strchr(nameStart, ')');
|
1996-10-06 15:57:15 +00:00
|
|
|
|
2012-06-08 21:57:36 +00:00
|
|
|
if ((pgn->flags & REMAKE) &&
|
1996-10-06 15:57:15 +00:00
|
|
|
strncmp(nameStart, gn->name, nameEnd - nameStart) == 0) {
|
|
|
|
gn->mtime = Arch_MTime(pgn);
|
|
|
|
}
|
2012-06-08 21:57:36 +00:00
|
|
|
} else if (pgn->flags & REMAKE) {
|
1996-10-06 15:57:15 +00:00
|
|
|
/*
|
|
|
|
* Something which isn't a library depends on the existence of
|
|
|
|
* this target, so it needs to exist.
|
|
|
|
*/
|
|
|
|
gn->mtime = 0;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-06-08 21:57:36 +00:00
|
|
|
Lst_Close(gn->parents);
|
1996-10-06 15:57:15 +00:00
|
|
|
|
|
|
|
return (gn->mtime);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*-
|
|
|
|
*-----------------------------------------------------------------------
|
|
|
|
* Arch_FindLib --
|
2012-06-08 21:57:36 +00:00
|
|
|
* Search for a library along the given search path.
|
|
|
|
*
|
|
|
|
* Input:
|
|
|
|
* gn Node of library to find
|
|
|
|
* path Search path
|
1996-10-06 15:57:15 +00:00
|
|
|
*
|
|
|
|
* Results:
|
|
|
|
* None.
|
|
|
|
*
|
|
|
|
* Side Effects:
|
|
|
|
* The node's 'path' field is set to the found path (including the
|
|
|
|
* actual file name, not -l...). If the system can handle the -L
|
|
|
|
* flag when linking (or we cannot find the library), we assume that
|
|
|
|
* the user has placed the .LIBRARIES variable in the final linking
|
|
|
|
* command (or the linker will know where to find it) and set the
|
|
|
|
* TARGET variable for this node to be the node's name. Otherwise,
|
|
|
|
* we set the TARGET variable to be the full path of the library,
|
|
|
|
* as returned by Dir_FindFile.
|
|
|
|
*
|
|
|
|
*-----------------------------------------------------------------------
|
|
|
|
*/
|
|
|
|
void
|
2012-06-08 21:57:36 +00:00
|
|
|
Arch_FindLib(GNode *gn, Lst path)
|
1996-10-06 15:57:15 +00:00
|
|
|
{
|
|
|
|
char *libName; /* file name for archive */
|
2012-06-08 21:57:36 +00:00
|
|
|
size_t sz = strlen(gn->name) + 6 - 2;
|
1996-10-06 15:57:15 +00:00
|
|
|
|
2012-06-08 21:57:36 +00:00
|
|
|
libName = bmake_malloc(sz);
|
|
|
|
snprintf(libName, sz, "lib%s.a", &gn->name[2]);
|
1996-10-06 15:57:15 +00:00
|
|
|
|
2012-06-08 21:57:36 +00:00
|
|
|
gn->path = Dir_FindFile(libName, path);
|
1996-10-06 15:57:15 +00:00
|
|
|
|
2012-06-08 21:57:36 +00:00
|
|
|
free(libName);
|
1996-10-06 15:57:15 +00:00
|
|
|
|
|
|
|
#ifdef LIBRARIES
|
2012-06-08 21:57:36 +00:00
|
|
|
Var_Set(TARGET, gn->name, gn, 0);
|
1996-10-06 15:57:15 +00:00
|
|
|
#else
|
2012-06-08 21:57:36 +00:00
|
|
|
Var_Set(TARGET, gn->path == NULL ? gn->name : gn->path, gn, 0);
|
|
|
|
#endif /* LIBRARIES */
|
1996-10-06 15:57:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*-
|
|
|
|
*-----------------------------------------------------------------------
|
|
|
|
* Arch_LibOODate --
|
|
|
|
* Decide if a node with the OP_LIB attribute is out-of-date. Called
|
|
|
|
* from Make_OODate to make its life easier.
|
|
|
|
*
|
|
|
|
* There are several ways for a library to be out-of-date that are
|
|
|
|
* not available to ordinary files. In addition, there are ways
|
|
|
|
* that are open to regular files that are not available to
|
|
|
|
* libraries. A library that is only used as a source is never
|
|
|
|
* considered out-of-date by itself. This does not preclude the
|
|
|
|
* library's modification time from making its parent be out-of-date.
|
|
|
|
* A library will be considered out-of-date for any of these reasons,
|
|
|
|
* given that it is a target on a dependency line somewhere:
|
|
|
|
* Its modification time is less than that of one of its
|
2012-06-08 21:57:36 +00:00
|
|
|
* sources (gn->mtime < gn->cmgn->mtime).
|
1996-10-06 15:57:15 +00:00
|
|
|
* Its modification time is greater than the time at which the
|
|
|
|
* make began (i.e. it's been modified in the course
|
|
|
|
* of the make, probably by archiving).
|
|
|
|
* The modification time of one of its sources is greater than
|
|
|
|
* the one of its RANLIBMAG member (i.e. its table of contents
|
|
|
|
* is out-of-date). We don't compare of the archive time
|
|
|
|
* vs. TOC time because they can be too close. In my
|
|
|
|
* opinion we should not bother with the TOC at all since
|
|
|
|
* this is used by 'ar' rules that affect the data contents
|
|
|
|
* of the archive, not by ranlib rules, which affect the
|
2012-06-08 21:57:36 +00:00
|
|
|
* TOC.
|
|
|
|
*
|
|
|
|
* Input:
|
|
|
|
* gn The library's graph node
|
1996-10-06 15:57:15 +00:00
|
|
|
*
|
|
|
|
* Results:
|
|
|
|
* TRUE if the library is out-of-date. FALSE otherwise.
|
|
|
|
*
|
|
|
|
* Side Effects:
|
|
|
|
* The library will be hashed if it hasn't been already.
|
|
|
|
*
|
|
|
|
*-----------------------------------------------------------------------
|
|
|
|
*/
|
|
|
|
Boolean
|
2012-06-08 21:57:36 +00:00
|
|
|
Arch_LibOODate(GNode *gn)
|
1996-10-06 15:57:15 +00:00
|
|
|
{
|
|
|
|
Boolean oodate;
|
2012-06-08 21:57:36 +00:00
|
|
|
|
|
|
|
if (gn->type & OP_PHONY) {
|
|
|
|
oodate = TRUE;
|
|
|
|
} else if (OP_NOP(gn->type) && Lst_IsEmpty(gn->children)) {
|
1996-10-06 15:57:15 +00:00
|
|
|
oodate = FALSE;
|
2012-06-08 21:57:36 +00:00
|
|
|
} else if ((!Lst_IsEmpty(gn->children) && gn->cmgn == NULL) ||
|
|
|
|
(gn->mtime > now) ||
|
|
|
|
(gn->cmgn != NULL && gn->mtime < gn->cmgn->mtime)) {
|
1996-10-06 15:57:15 +00:00
|
|
|
oodate = TRUE;
|
|
|
|
} else {
|
2012-06-08 21:57:36 +00:00
|
|
|
#ifdef RANLIBMAG
|
1996-10-06 15:57:15 +00:00
|
|
|
struct ar_hdr *arhPtr; /* Header for __.SYMDEF */
|
|
|
|
int modTimeTOC; /* The table-of-contents's mod time */
|
|
|
|
|
2012-06-08 21:57:36 +00:00
|
|
|
arhPtr = ArchStatMember(gn->path, UNCONST(RANLIBMAG), FALSE);
|
1996-10-06 15:57:15 +00:00
|
|
|
|
2012-06-08 21:57:36 +00:00
|
|
|
if (arhPtr != NULL) {
|
|
|
|
modTimeTOC = (int)strtol(arhPtr->AR_DATE, NULL, 10);
|
1996-10-06 15:57:15 +00:00
|
|
|
|
|
|
|
if (DEBUG(ARCH) || DEBUG(MAKE)) {
|
2012-06-08 21:57:36 +00:00
|
|
|
fprintf(debug_file, "%s modified %s...", RANLIBMAG, Targ_FmtTime(modTimeTOC));
|
1996-10-06 15:57:15 +00:00
|
|
|
}
|
2012-06-08 21:57:36 +00:00
|
|
|
oodate = (gn->cmgn == NULL || gn->cmgn->mtime > modTimeTOC);
|
1996-10-06 15:57:15 +00:00
|
|
|
} else {
|
|
|
|
/*
|
|
|
|
* A library w/o a table of contents is out-of-date
|
|
|
|
*/
|
|
|
|
if (DEBUG(ARCH) || DEBUG(MAKE)) {
|
2012-06-08 21:57:36 +00:00
|
|
|
fprintf(debug_file, "No t.o.c....");
|
1996-10-06 15:57:15 +00:00
|
|
|
}
|
|
|
|
oodate = TRUE;
|
|
|
|
}
|
2012-06-08 21:57:36 +00:00
|
|
|
#else
|
|
|
|
oodate = FALSE;
|
|
|
|
#endif
|
1996-10-06 15:57:15 +00:00
|
|
|
}
|
|
|
|
return (oodate);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*-
|
|
|
|
*-----------------------------------------------------------------------
|
|
|
|
* Arch_Init --
|
|
|
|
* Initialize things for this module.
|
|
|
|
*
|
|
|
|
* Results:
|
|
|
|
* None.
|
|
|
|
*
|
|
|
|
* Side Effects:
|
|
|
|
* The 'archives' list is initialized.
|
|
|
|
*
|
|
|
|
*-----------------------------------------------------------------------
|
|
|
|
*/
|
|
|
|
void
|
2012-06-08 21:57:36 +00:00
|
|
|
Arch_Init(void)
|
1996-10-06 15:57:15 +00:00
|
|
|
{
|
2012-06-08 21:57:36 +00:00
|
|
|
archives = Lst_Init(FALSE);
|
1996-10-06 15:57:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*-
|
|
|
|
*-----------------------------------------------------------------------
|
|
|
|
* Arch_End --
|
|
|
|
* Cleanup things for this module.
|
|
|
|
*
|
|
|
|
* Results:
|
|
|
|
* None.
|
|
|
|
*
|
|
|
|
* Side Effects:
|
|
|
|
* The 'archives' list is freed
|
|
|
|
*
|
|
|
|
*-----------------------------------------------------------------------
|
|
|
|
*/
|
|
|
|
void
|
2012-06-08 21:57:36 +00:00
|
|
|
Arch_End(void)
|
1996-10-06 15:57:15 +00:00
|
|
|
{
|
2012-06-08 21:57:36 +00:00
|
|
|
#ifdef CLEANUP
|
1996-10-06 15:57:15 +00:00
|
|
|
Lst_Destroy(archives, ArchFree);
|
2012-06-08 21:57:36 +00:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
/*-
|
|
|
|
*-----------------------------------------------------------------------
|
|
|
|
* Arch_IsLib --
|
|
|
|
* Check if the node is a library
|
|
|
|
*
|
|
|
|
* Results:
|
|
|
|
* True or False.
|
|
|
|
*
|
|
|
|
* Side Effects:
|
|
|
|
* None.
|
|
|
|
*
|
|
|
|
*-----------------------------------------------------------------------
|
|
|
|
*/
|
|
|
|
int
|
|
|
|
Arch_IsLib(GNode *gn)
|
|
|
|
{
|
|
|
|
static const char armag[] = "!<arch>\n";
|
|
|
|
char buf[sizeof(armag)-1];
|
|
|
|
int fd;
|
|
|
|
|
|
|
|
if ((fd = open(gn->path, O_RDONLY)) == -1)
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
if (read(fd, buf, sizeof(buf)) != sizeof(buf)) {
|
|
|
|
(void)close(fd);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
(void)close(fd);
|
|
|
|
|
|
|
|
return memcmp(buf, armag, sizeof(buf)) == 0;
|
1996-10-06 15:57:15 +00:00
|
|
|
}
|