2 * Copyright (c) 1988, 1989, 1990, 1993
3 * The Regents of the University of California. All rights reserved.
4 * Copyright (c) 1989 by Berkeley Softworks
7 * This code is derived from software contributed to Berkeley by
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer.
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in the
17 * documentation and/or other materials provided with the distribution.
18 * 3. All advertising materials mentioning features or use of this software
19 * must display the following acknowledgement:
20 * This product includes software developed by the University of
21 * California, Berkeley and its contributors.
22 * 4. Neither the name of the University nor the names of its contributors
23 * may be used to endorse or promote products derived from this software
24 * without specific prior written permission.
26 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
27 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
28 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
29 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
30 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
31 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
32 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
33 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
34 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
35 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
38 * @(#)arch.c 8.2 (Berkeley) 1/2/94
39 * $FreeBSD: src/usr.bin/make/arch.c,v 1.48 2005/02/10 14:39:05 harti Exp $
40 * $DragonFly: src/usr.bin/make/arch.c,v 1.39 2005/03/03 18:22:58 okumoto Exp $
45 * Functions to manipulate libraries, archives and their members.
47 * Once again, cacheing/hashing comes into play in the manipulation
48 * of archives. The first time an archive is referenced, all of its members'
49 * headers are read and hashed and the archive closed again. All hashed
50 * archives are kept on a list which is searched each time an archive member
53 * The interface to this module is:
54 * Arch_ParseArchive Given an archive specification, return a list
55 * of GNode's, one for each member in the spec.
56 * FAILURE is returned if the specification is
57 * invalid for some reason.
59 * Arch_Touch Alter the modification time of the archive
60 * member described by the given node to be
63 * Arch_TouchLib Update the modification time of the library
64 * described by the given node. This is special
65 * because it also updates the modification time
66 * of the library's table of contents.
68 * Arch_MTime Find the modification time of a member of
69 * an archive *in the archive*. The time is also
70 * placed in the member's GNode. Returns the
73 * Arch_MemTime Find the modification time of a member of
74 * an archive. Called when the member doesn't
75 * already exist. Looks in the archive for the
76 * modification time. Returns the modification
79 * Arch_FindLib Search for a library along a path. The
80 * library name in the GNode should be in
83 * Arch_LibOODate Special function to decide if a library node
86 * Arch_Init Initialize this module.
89 #include <sys/param.h>
90 #include <sys/types.h>
111 /* Lst of archives we've already examined */
112 static Lst archives = Lst_Initializer(archives);
114 typedef struct Arch {
115 char *name; /* Name of archive */
118 * All the members of the archive described
119 * by <name, struct ar_hdr *> key/value pairs
123 char *fnametab; /* Extended name table strings */
124 size_t fnamesize; /* Size of the string table */
127 #if defined(__svr4__) || defined(__SVR4) || defined(__ELF__)
132 *-----------------------------------------------------------------------
133 * Arch_ParseArchive --
134 * Parse the archive specification in the given line and find/create
135 * the nodes for the specified archive members, placing their nodes
136 * on the given list, given the pointer to the start of the
137 * specification, a Lst on which to place the nodes, and a context
138 * in which to expand variables.
141 * SUCCESS if it was a valid specification. The linePtr is updated
142 * to point to the first non-space after the archive spec. The
143 * nodes for the members are placed on the given list.
146 * Some nodes may be created. The given list is extended.
148 *-----------------------------------------------------------------------
151 Arch_ParseArchive(char **linePtr, Lst *nodeLst, GNode *ctxt)
153 char *cp; /* Pointer into line */
154 GNode *gn; /* New node */
155 char *libName; /* Library-part of specification */
156 char *memName; /* Member-part of specification */
157 char *nameBuf; /* temporary place for node name */
158 char saveChar; /* Ending delimiter of member-name */
159 Boolean subLibName; /* TRUE if libName should have/had
160 * variable substitution performed on it */
166 for (cp = libName; *cp != '(' && *cp != '\0'; cp++) {
169 * Variable spec, so call the Var module to parse the
170 * puppy so we can safely advance beyond it...
176 result = Var_Parse(cp, ctxt, TRUE, &length, &freeIt);
177 if (result == var_Error) {
193 buf = Var_Subst(NULL, libName, ctxt, TRUE);
194 libName = Buf_GetAll(buf, NULL);
195 Buf_Destroy(buf, FALSE);
200 * First skip to the start of the member's name, mark that
201 * place and skip to the end of it (either white-space or
206 * TRUE if need to substitute in memName
208 Boolean doSubst = FALSE;
210 while (*cp != '\0' && *cp != ')' &&
211 isspace((unsigned char)*cp)) {
216 while (*cp != '\0' && *cp != ')' &&
217 !isspace((unsigned char)*cp)) {
220 * Variable spec, so call the Var module to
221 * parse the puppy so we can safely advance
228 result = Var_Parse(cp, ctxt, TRUE,
230 if (result == var_Error) {
245 * If the specification ends without a closing parenthesis,
246 * chances are there's something wrong (like a missing
247 * backslash), so it's better to return failure than allow
248 * such things to happen
251 printf("No closing parenthesis in archive "
257 * If we didn't move anywhere, we must be done
267 * XXX: This should be taken care of intelligently by
268 * SuffExpandChildren, both for the archive and the member
272 * If member contains variables, try and substitute for them.
273 * This will slow down archive specs with dynamic sources, of
274 * course, since we'll be (non-)substituting them three times,
275 * but them's the breaks -- we need to do this since
276 * SuffExpandChildren calls us, otherwise we could assume the
277 * thing would be taken care of later.
282 char *oldMemName = memName;
287 * Now form an archive spec and recurse to deal with
288 * nested variables and multi-word variable values....
289 * The results are just placed at the end of the
290 * nodeLst we're returning.
292 buf1 = Var_Subst(NULL, memName, ctxt, TRUE);
293 memName = Buf_GetAll(buf1, NULL);
295 sz = strlen(memName) + strlen(libName) + 3;
298 snprintf(buf, sz, "%s(%s)", libName, memName);
302 if (strchr(memName, '$') &&
303 strcmp(memName, oldMemName) == 0) {
305 * Must contain dynamic sources, so we can't
307 * Just create an ARCHV node for the thing and
308 * let SuffExpandChildren handle it...
310 gn = Targ_FindNode(buf, TARG_CREATE);
314 Buf_Destroy(buf1, FALSE);
317 gn->type |= OP_ARCHV;
318 Lst_AtEnd(nodeLst, (void *)gn);
319 } else if (Arch_ParseArchive(&sacrifice, nodeLst,
322 * Error in nested call -- free buffer and
323 * return FAILURE ourselves.
326 Buf_Destroy(buf1, FALSE);
330 /* Free buffer and continue with our work. */
332 Buf_Destroy(buf1, FALSE);
334 } else if (Dir_HasWildcards(memName)) {
335 Lst members = Lst_Initializer(members);
337 size_t sz = MAXPATHLEN;
340 nameBuf = emalloc(sz);
342 Dir_Expand(memName, &dirSearchPath, &members);
343 while (!Lst_IsEmpty(&members)) {
344 member = Lst_DeQueue(&members);
345 nsz = strlen(libName) + strlen(member) + 3;
348 nameBuf = erealloc(nameBuf, sz);
351 snprintf(nameBuf, sz, "%s(%s)",
354 gn = Targ_FindNode(nameBuf, TARG_CREATE);
357 /* XXXHB Lst_Destroy(&members) */
361 * We've found the node, but have to make sure
362 * the rest of the world knows it's an archive
363 * member, without having to constantly check
364 * for parentheses, so we type the thing with
365 * the OP_ARCHV bit before we place it on the
366 * end of the provided list.
368 gn->type |= OP_ARCHV;
369 Lst_AtEnd(nodeLst, gn);
373 size_t sz = strlen(libName) + strlen(memName) + 3;
375 nameBuf = emalloc(sz);
376 snprintf(nameBuf, sz, "%s(%s)", libName, memName);
377 gn = Targ_FindNode(nameBuf, TARG_CREATE);
383 * We've found the node, but have to make sure the
384 * rest of the world knows it's an archive member,
385 * without having to constantly check for parentheses,
386 * so we type the thing with the OP_ARCHV bit before
387 * we place it on the end of the provided list.
389 gn->type |= OP_ARCHV;
390 Lst_AtEnd(nodeLst, gn);
400 * If substituted libName, free it now, since we need it no longer.
407 * We promised the pointer would be set up at the next non-space, so
408 * we must advance cp there before setting *linePtr... (note that on
409 * entrance to the loop, cp is guaranteed to point at a ')')
413 } while (*cp != '\0' && isspace((unsigned char)*cp));
420 *-----------------------------------------------------------------------
422 * See if the given archive is the one we are looking for. Called
423 * From ArchStatMember and ArchFindMember via Lst_Find with the
424 * current list element and the name we want.
427 * 0 if it is, non-zero if it isn't.
432 *-----------------------------------------------------------------------
435 ArchFindArchive(const void *ar, const void *archName)
438 return (strcmp(archName, ((const Arch *)ar)->name));
442 *-----------------------------------------------------------------------
444 * Locate a member of an archive, given the path of the archive and
445 * the path of the desired member. If the archive is to be modified,
446 * the mode should be "r+", if not, it should be "r". arhPtr is a
447 * poitner to the header structure to fill in.
450 * An FILE *, opened for reading and writing, positioned at the
451 * start of the member's struct ar_hdr, or NULL if the member was
452 * nonexistent. The current struct ar_hdr for member.
455 * The passed struct ar_hdr structure is filled in.
457 *-----------------------------------------------------------------------
460 ArchFindMember(const char *archive, const char *member, struct ar_hdr *arhPtr,
463 FILE *arch; /* Stream to archive */
464 int size; /* Size of archive member */
465 const char *cp; /* Useful character pointer */
470 arch = fopen(archive, mode);
476 * We use the ARMAG string to make sure this is an archive we
479 if (fread(magic, SARMAG, 1, arch) != 1 ||
480 strncmp(magic, ARMAG, SARMAG) != 0) {
486 * Because of space constraints and similar things, files are archived
487 * using their final path components, not the entire thing, so we need
488 * to point 'member' to the final component, if there is one, to make
489 * the comparisons easier...
491 cp = strrchr(member, '/');
492 if (cp != NULL && strcmp(member, RANLIBMAG) != 0) {
495 len = tlen = strlen(member);
496 if (len > sizeof(arhPtr->ar_name)) {
497 tlen = sizeof(arhPtr->ar_name);
500 while (fread(arhPtr, sizeof(struct ar_hdr), 1, arch) == 1) {
501 if (strncmp(arhPtr->ar_fmag, ARFMAG,
502 sizeof(arhPtr->ar_fmag)) != 0) {
504 * The header is bogus, so the archive is bad
505 * and there's no way we can recover...
511 if (strncmp(member, arhPtr->ar_name, tlen) == 0) {
513 * If the member's name doesn't take up the entire
514 * 'name' field, we have to be careful of matching
515 * prefixes. Names are space-padded to the right, so if
516 * the character in 'name' at the end of the matched
517 * string is anything but a space, this isn't the
518 * member we sought. Additionally there may be a
519 * slash at the end of the name (System 5 style).
521 if (tlen != sizeof(arhPtr->ar_name) &&
522 arhPtr->ar_name[tlen] != ' ' &&
523 arhPtr->ar_name[tlen] != '/') {
527 * To make life easier, we reposition the file at the
528 * start of the header we just read before we return the
529 * stream. In a more general situation, it might be
530 * better to leave the file at the actual member, rather
531 * than its header, but not here...
533 fseek(arch, -sizeof(struct ar_hdr), SEEK_CUR);
538 * BSD 4.4 extended AR format: #1/<namelen>, with name as the
539 * first <namelen> bytes of the file
541 if (strncmp(arhPtr->ar_name, AR_EFMT1,
542 sizeof(AR_EFMT1) - 1) == 0 &&
543 isdigit(arhPtr->ar_name[sizeof(AR_EFMT1) - 1])) {
545 char ename[MAXPATHLEN];
547 elen = atoi(&arhPtr->ar_name[sizeof(AR_EFMT1) - 1]);
548 if (elen > MAXPATHLEN) {
552 if (fread(ename, elen, 1, arch) != 1) {
560 if (DEBUG(ARCH) || DEBUG(MAKE)) {
561 printf("ArchFind: Extended format entry for "
564 if (strncmp(ename, member, len) == 0) {
565 /* Found as extended name */
566 fseek(arch, -sizeof(struct ar_hdr) - elen,
570 fseek(arch, -elen, SEEK_CUR);
576 * This isn't the member we're after, so we need to advance the
577 * stream's pointer to the start of the next header. Files are
578 * padded with newlines to an even-byte boundary, so we need to
579 * extract the size of the file from the 'size' field of the
580 * header and round it up during the seek.
582 arhPtr->ar_size[sizeof(arhPtr->ar_size) - 1] = '\0';
583 size = (int)strtol(arhPtr->ar_size, NULL, 10);
584 fseek(arch, (size + 1) & ~1, SEEK_CUR);
588 * We've looked everywhere, but the member is not to be found. Close the
589 * archive and return NULL -- an error.
597 *-----------------------------------------------------------------------
599 * Parse an SVR4 style entry that begins with a slash.
600 * If it is "//", then load the table of filenames
601 * If it is "/<offset>", then try to substitute the long file name
602 * from offset of a table previously read.
605 * -1: Bad data in archive
606 * 0: A table was loaded from the file
607 * 1: Name was successfully substituted from table
608 * 2: Name was not successfully substituted from table
611 * If a table is read, the file pointer is moved to the next archive
614 *-----------------------------------------------------------------------
617 ArchSVR4Entry(Arch *ar, char *name, size_t size, FILE *arch)
619 #define ARLONGNAMES1 "//"
620 #define ARLONGNAMES2 "/ARFILENAMES"
625 if (strncmp(name, ARLONGNAMES1, sizeof(ARLONGNAMES1) - 1) == 0 ||
626 strncmp(name, ARLONGNAMES2, sizeof(ARLONGNAMES2) - 1) == 0) {
628 if (ar->fnametab != NULL) {
629 DEBUGF(ARCH, ("Attempted to redefine an SVR4 name "
635 * This is a table of archive names, so we build one for
638 ar->fnametab = emalloc(size);
639 ar->fnamesize = size;
641 if (fread(ar->fnametab, size, 1, arch) != 1) {
642 DEBUGF(ARCH, ("Reading an SVR4 name table failed\n"));
645 eptr = ar->fnametab + size;
646 for (entry = 0, ptr = ar->fnametab; ptr < eptr; ptr++) {
660 DEBUGF(ARCH, ("Found svr4 archive name table with %zu "
661 "entries\n", entry));
665 if (name[1] == ' ' || name[1] == '\0')
668 entry = (size_t)strtol(&name[1], &eptr, 0);
669 if ((*eptr != ' ' && *eptr != '\0') || eptr == &name[1]) {
670 DEBUGF(ARCH, ("Could not parse SVR4 name %s\n", name));
673 if (entry >= ar->fnamesize) {
674 DEBUGF(ARCH, ("SVR4 entry offset %s is greater than %zu\n",
675 name, ar->fnamesize));
679 DEBUGF(ARCH, ("Replaced %s with %s\n", name, &ar->fnametab[entry]));
681 strncpy(name, &ar->fnametab[entry], MAXPATHLEN);
682 name[MAXPATHLEN - 1] = '\0';
688 *-----------------------------------------------------------------------
690 * Locate a member of an archive, given the path of the archive and
691 * the path of the desired member, and a boolean representing whether
692 * or not the archive should be hashed (if not already hashed).
695 * A pointer to the current struct ar_hdr structure for the member. Note
696 * That no position is returned, so this is not useful for touching
697 * archive members. This is mostly because we have no assurances that
698 * The archive will remain constant after we read all the headers, so
699 * there's not much point in remembering the position...
703 *-----------------------------------------------------------------------
705 static struct ar_hdr *
706 ArchStatMember(const char *archive, const char *member, Boolean hash)
708 #define AR_MAX_NAME_LEN (sizeof(arh.ar_name) - 1)
709 FILE *arch; /* Stream to archive */
710 int size; /* Size of archive member */
711 char *cp; /* Useful character pointer */
713 LstNode *ln; /* Lst member containing archive descriptor */
714 Arch *ar; /* Archive descriptor */
715 Hash_Entry *he; /* Entry containing member's description */
716 struct ar_hdr arh; /* archive-member header for reading archive */
717 char memName[MAXPATHLEN]; /* Current member name while hashing */
720 * Because of space constraints and similar things, files are archived
721 * using their final path components, not the entire thing, so we need
722 * to point 'member' to the final component, if there is one, to make
723 * the comparisons easier...
725 cp = strrchr(member, '/');
726 if (cp != NULL && strcmp(member, RANLIBMAG) != 0)
729 ln = Lst_Find(&archives, archive, ArchFindArchive);
731 char copy[AR_MAX_NAME_LEN + 1];
735 he = Hash_FindEntry(&ar->members, member);
737 return (Hash_GetValue(he));
740 /* Try truncated name */
741 strncpy(copy, member, AR_MAX_NAME_LEN);
742 copy[AR_MAX_NAME_LEN] = '\0';
744 if ((he = Hash_FindEntry(&ar->members, copy)) != NULL)
745 return (Hash_GetValue(he));
751 * Caller doesn't want the thing hashed, just use ArchFindMember
752 * to read the header for the member out and close down the
753 * stream again. Since the archive is not to be hashed, we
754 * assume there's no need to allocate extra room for the header
755 * we're returning, so just declare it static.
757 static struct ar_hdr sarh;
759 arch = ArchFindMember(archive, member, &sarh, "r");
768 * We don't have this archive on the list yet, so we want to find out
769 * everything that's in it and cache it so we can get at it quickly.
771 arch = fopen(archive, "r");
777 * We use the ARMAG string to make sure this is an archive we
780 if (fread(magic, SARMAG, 1, arch) != 1 ||
781 strncmp(magic, ARMAG, SARMAG) != 0) {
786 ar = emalloc(sizeof(Arch));
787 ar->name = estrdup(archive);
790 Hash_InitTable(&ar->members, -1);
791 memName[AR_MAX_NAME_LEN] = '\0';
793 while (fread(&arh, sizeof(struct ar_hdr), 1, arch) == 1) {
794 if (strncmp(arh.ar_fmag, ARFMAG, sizeof(arh.ar_fmag)) != 0) {
796 * The header is bogus, so the archive is bad
797 * and there's no way we can recover...
802 * We need to advance the stream's pointer to the start of the
803 * next header. Files are padded with newlines to an even-byte
804 * boundary, so we need to extract the size of the file from the
805 * 'size' field of the header and round it up during the seek.
807 arh.ar_size[sizeof(arh.ar_size) - 1] = '\0';
808 size = (int)strtol(arh.ar_size, NULL, 10);
810 strncpy(memName, arh.ar_name, sizeof(arh.ar_name));
811 for (cp = &memName[AR_MAX_NAME_LEN]; *cp == ' '; cp--) {
818 * svr4 names are slash terminated. Also svr4 extended AR
821 if (memName[0] == '/') {
823 * svr4 magic mode; handle it
825 switch (ArchSVR4Entry(ar, memName, size, arch)) {
827 case -1: /* Invalid data */
830 case 0: /* List of files entry */
832 default: /* Got the entry */
843 * BSD 4.4 extended AR format: #1/<namelen>, with name as the
844 * first <namelen> bytes of the file
846 if (strncmp(memName, AR_EFMT1, sizeof(AR_EFMT1) - 1) == 0 &&
847 isdigit(memName[sizeof(AR_EFMT1) - 1])) {
848 unsigned elen = atoi(&memName[sizeof(AR_EFMT1) - 1]);
850 if (elen > MAXPATHLEN)
852 if (fread(memName, elen, 1, arch) != 1)
854 memName[elen] = '\0';
855 fseek(arch, -elen, SEEK_CUR);
857 * XXX Multiple levels may be asked for, make this
858 * conditional on one, and use DEBUGF.
860 if (DEBUG(ARCH) || DEBUG(MAKE)) {
861 fprintf(stderr, "ArchStat: Extended format "
862 "entry for %s\n", memName);
867 he = Hash_CreateEntry(&ar->members, memName, NULL);
868 Hash_SetValue(he, emalloc(sizeof(struct ar_hdr)));
869 memcpy(Hash_GetValue(he), &arh, sizeof(struct ar_hdr));
870 fseek(arch, (size + 1) & ~1, SEEK_CUR);
875 Lst_AtEnd(&archives, ar);
878 * Now that the archive has been read and cached, we can look into
879 * the hash table to find the desired member's header.
881 he = Hash_FindEntry(&ar->members, member);
884 return (Hash_GetValue (he));
891 Hash_DeleteTable(&ar->members);
898 *-----------------------------------------------------------------------
900 * Touch a member of an archive.
903 * The 'time' field of the member's header is updated.
906 * The modification time of the entire archive is also changed.
907 * For a library, this could necessitate the re-ranlib'ing of the
910 *-----------------------------------------------------------------------
913 Arch_Touch(GNode *gn)
915 FILE *arch; /* Archive stream, positioned properly */
916 struct ar_hdr arh; /* Current header describing member */
919 arch = ArchFindMember(Var_Value(ARCHIVE, gn, &p1),
920 Var_Value(TARGET, gn, &p2), &arh, "r+");
925 snprintf(arh.ar_date, sizeof(arh.ar_date), "%-12ld", (long)now);
926 fwrite(&arh, sizeof(struct ar_hdr), 1, arch);
932 *-----------------------------------------------------------------------
934 * Given a node which represents a library, touch the thing, making
935 * sure that the table of contents also is touched.
941 * Both the modification time of the library and of the RANLIBMAG
942 * member are set to 'now'.
944 *-----------------------------------------------------------------------
947 Arch_TouchLib(GNode *gn)
950 FILE *arch; /* Stream open to archive */
951 struct ar_hdr arh; /* Header describing table of contents */
952 struct utimbuf times; /* Times for utime() call */
954 arch = ArchFindMember(gn->path, RANLIBMAG, &arh, "r+");
956 snprintf(arh.ar_date, sizeof(arh.ar_date),
957 "%-12ld", (long) now);
958 fwrite(&arh, sizeof(struct ar_hdr), 1, arch);
961 times.actime = times.modtime = now;
962 utime(gn->path, ×);
968 *-----------------------------------------------------------------------
970 * Return the modification time of a member of an archive, given its
974 * The modification time(seconds).
975 * XXXHB this should be a long.
978 * The mtime field of the given node is filled in with the value
979 * returned by the function.
981 *-----------------------------------------------------------------------
984 Arch_MTime(GNode *gn)
986 struct ar_hdr *arhPtr; /* Header of desired member */
987 int modTime; /* Modification time as an integer */
990 arhPtr = ArchStatMember(Var_Value(ARCHIVE, gn, &p1),
991 Var_Value(TARGET, gn, &p2), TRUE);
995 if (arhPtr != NULL) {
996 modTime = (int)strtol(arhPtr->ar_date, NULL, 10);
1001 gn->mtime = modTime;
1006 *-----------------------------------------------------------------------
1008 * Given a non-existent archive member's node, get its modification
1009 * time from its archived form, if it exists.
1012 * The modification time.
1015 * The mtime field is filled in.
1017 *-----------------------------------------------------------------------
1020 Arch_MemMTime(GNode *gn)
1027 for (ln = Lst_First(&gn->parents); ln != NULL; ln = Lst_Succ(ln)) {
1028 pgn = Lst_Datum(ln);
1030 if (pgn->type & OP_ARCHV) {
1032 * If the parent is an archive specification and is
1033 * being made and its member's name matches the name of
1034 * the node we were given, record the modification time
1035 * of the parent in the child. We keep searching its
1036 * parents in case some other parent requires this
1039 nameStart = strchr(pgn->name, '(') + 1;
1040 nameEnd = strchr(nameStart, ')');
1042 if (pgn->make && strncmp(nameStart, gn->name,
1043 nameEnd - nameStart) == 0) {
1044 gn->mtime = Arch_MTime(pgn);
1046 } else if (pgn->make) {
1048 * Something which isn't a library depends on the
1049 * existence of this target, so it needs to exist.
1059 *-----------------------------------------------------------------------
1061 * Search for a named library along the given search path.
1067 * The node's 'path' field is set to the found path (including the
1068 * actual file name, not -l...). If the system can handle the -L
1069 * flag when linking (or we cannot find the library), we assume that
1070 * the user has placed the .LIBRARIES variable in the final linking
1071 * command (or the linker will know where to find it) and set the
1072 * TARGET variable for this node to be the node's name. Otherwise,
1073 * we set the TARGET variable to be the full path of the library,
1074 * as returned by Dir_FindFile.
1076 *-----------------------------------------------------------------------
1079 Arch_FindLib(GNode *gn, Lst *path)
1081 char *libName; /* file name for archive */
1084 sz = strlen(gn->name) + 4;
1085 libName = emalloc(sz);
1086 snprintf(libName, sz, "lib%s.a", &gn->name[2]);
1088 gn->path = Dir_FindFile(libName, path);
1093 Var_Set(TARGET, gn->name, gn);
1095 Var_Set(TARGET, gn->path == NULL ? gn->name : gn->path, gn);
1096 #endif /* LIBRARIES */
1100 *-----------------------------------------------------------------------
1102 * Decide if a node with the OP_LIB attribute is out-of-date. Called
1103 * from Make_OODate to make its life easier, with the library's
1106 * There are several ways for a library to be out-of-date that are
1107 * not available to ordinary files. In addition, there are ways
1108 * that are open to regular files that are not available to
1109 * libraries. A library that is only used as a source is never
1110 * considered out-of-date by itself. This does not preclude the
1111 * library's modification time from making its parent be out-of-date.
1112 * A library will be considered out-of-date for any of these reasons,
1113 * given that it is a target on a dependency line somewhere:
1114 * Its modification time is less than that of one of its
1115 * sources (gn->mtime < gn->cmtime).
1116 * Its modification time is greater than the time at which the
1117 * make began (i.e. it's been modified in the course
1118 * of the make, probably by archiving).
1119 * The modification time of one of its sources is greater than
1120 * the one of its RANLIBMAG member (i.e. its table of contents
1121 * is out-of-date). We don't compare of the archive time
1122 * vs. TOC time because they can be too close. In my
1123 * opinion we should not bother with the TOC at all since
1124 * this is used by 'ar' rules that affect the data contents
1125 * of the archive, not by ranlib rules, which affect the
1129 * TRUE if the library is out-of-date. FALSE otherwise.
1132 * The library will be hashed if it hasn't been already.
1134 *-----------------------------------------------------------------------
1137 Arch_LibOODate(GNode *gn)
1140 struct ar_hdr *arhPtr; /* Header for __.SYMDEF */
1141 int modTimeTOC; /* The table-of-contents's mod time */
1144 if (OP_NOP(gn->type) && Lst_IsEmpty(&gn->children)) {
1147 if (gn->mtime > now || gn->mtime < gn->cmtime) {
1152 arhPtr = ArchStatMember(gn->path, RANLIBMAG, FALSE);
1154 if (arhPtr != NULL) {
1155 modTimeTOC = (int)strtol(arhPtr->ar_date, NULL, 10);
1157 /* XXX choose one. */
1158 if (DEBUG(ARCH) || DEBUG(MAKE)) {
1159 printf("%s modified %s...", RANLIBMAG,
1160 Targ_FmtTime(modTimeTOC));
1162 return (gn->cmtime > modTimeTOC);
1165 * A library w/o a table of contents is out-of-date
1167 if (DEBUG(ARCH) || DEBUG(MAKE)) {
1168 printf("No t.o.c....");
1173 return (gn->mtime == 0); /* out-of-date if not present */
1178 *-----------------------------------------------------------------------
1180 * Initialize things for this module.
1185 *-----------------------------------------------------------------------