4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License (the "License").
6 * You may not use this file except in compliance with the License.
8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 * or http://www.opensolaris.org/os/licensing.
10 * See the License for the specific language governing permissions
11 * and limitations under the License.
13 * When distributing Covered Code, include this CDDL HEADER in each
14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 * If applicable, add the following below this CDDL HEADER, with the
16 * fields enclosed by brackets "[]" replaced with your own identifying
17 * information: Portions Copyright [yyyy] [name of copyright owner]
22 * Copyright 1998 Sun Microsystems, Inc. All rights reserved.
23 * Use is subject to license terms.
26 #pragma init(ld_support_init)
33 #include <sys/param.h>
36 #define SUNPRO_DEPENDENCIES "SUNPRO_DEPENDENCIES"
39 * Linked list of strings - used to keep lists of names
40 * of directories or files.
48 typedef struct Stritem Stritem
;
50 static char * depend_file
= NULL
;
51 static Stritem
* list
= NULL
;
56 depend_file
= getenv(SUNPRO_DEPENDENCIES
);
57 } /* mk_state_init() */
62 prepend_str(Stritem
**list
, const char * str
)
67 if (!(new = calloc(1, sizeof (Stritem
)))) {
68 perror("libmakestate.so");
72 if (!(newstr
= malloc(strlen(str
) + 1))) {
73 perror("libmakestate.so");
77 new->str
= strcpy(newstr
, str
);
85 mk_state_collect_dep(const char * file
)
88 * SUNPRO_DEPENDENCIES wasn't set, we don't collect .make.state
94 prepend_str(&list
, file
);
96 } /* mk_state_collect_dep() */
100 mk_state_update_exit()
103 char lockfile
[MAXPATHLEN
], * err
, * space
, * target
;
105 extern char * file_lock(char *, char *, int);
110 if ((space
= strchr(depend_file
, ' ')) == NULL
)
115 (void) sprintf(lockfile
, "%s.lock", depend_file
);
116 if ((err
= file_lock(depend_file
, lockfile
, 0))) {
117 (void) fprintf(stderr
, "%s\n", err
);
121 if (!(ofp
= fopen(depend_file
, "a")))
125 (void) fprintf(ofp
, "%s: ", target
);
127 for (cur
= list
; cur
; cur
= cur
->next
)
128 (void) fprintf(ofp
, " %s", cur
->str
);
130 (void) fputc('\n', ofp
);
133 (void) unlink(lockfile
);
136 } /* mk_state_update_exit() */
139 /* LINTED static unused */
144 } /* ld_support_init() */
148 ld_file(const char * file
, const Elf_Kind ekind
, int flags
, Elf
*elf
)
150 if(! ((flags
& LD_SUP_DERIVED
) && !(flags
& LD_SUP_EXTRACTED
)))
153 mk_state_collect_dep(file
);
158 ld_atexit(int exit_code
)
163 mk_state_update_exit();
168 * Supporting 64-bit objects
171 ld_file64(const char * file
, const Elf_Kind ekind
, int flags
, Elf
*elf
)
173 if(! ((flags
& LD_SUP_DERIVED
) && !(flags
& LD_SUP_EXTRACTED
)))
176 mk_state_collect_dep(file
);
181 ld_atexit64(int exit_code
)
186 mk_state_update_exit();
188 } /* ld_atexit64() */