Re-add the code which maps POSIX standard library names into the ones

FreeBSD uses; f.e. -lpthread -> -pthread, -lxnet -> nothing.
This commit is contained in:
Tim J. Robbins 2002-10-08 02:19:54 +00:00
parent 0b294f891d
commit 363a99169a
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=104647

View File

@ -28,7 +28,8 @@
* c99 -- compile standard C programs
*
* This is essentially a wrapper around the system C compiler that forces
* the compiler into C99 mode.
* the compiler into C99 mode and handles some of the standard libraries
* specially.
*/
#include <sys/cdefs.h>
@ -45,22 +46,47 @@ __FBSDID("$FreeBSD$");
char **args;
u_int cargs, nargs;
void addarg(const char *item);
void addarg(const char *);
void addlib(const char *);
void usage(void);
int
main(int argc, char *argv[])
{
int i;
int ch, i;
args = NULL;
cargs = nargs = 0;
while ((ch = getopt(argc, argv, "cD:EgI:L:o:O:sU:l:")) != -1) {
if (ch == 'l') {
/* Gone too far. Back up and get out. */
if (argv[optind - 1][0] == '-')
optind -= 1;
else
optind -= 2;
break;
} else if (ch == '?')
usage();
}
addarg("cc");
addarg("-std=iso9899:1999");
addarg("-pedantic");
for (i = 1; i < argc; i++)
for (i = 1; i < optind; i++)
addarg(argv[i]);
while (i < argc) {
if (strncmp(argv[i], "-l", 2) == 0) {
if (argv[i][2] != '\0')
addlib(argv[i++] + 2);
else {
if (argv[++i] == NULL)
usage();
addlib(argv[i++]);
}
} else
addarg(argv[i++]);
}
execv("/usr/bin/cc", args);
err(1, "/usr/bin/cc");
}
@ -78,6 +104,25 @@ addarg(const char *item)
args[nargs] = NULL;
}
void
addlib(const char *lib)
{
if (strcmp(lib, "pthread") == 0)
/* FreeBSD's gcc uses -pthread instead of -lpthread. */
addarg("-pthread");
else if (strcmp(lib, "rt") == 0)
/* librt functionality is in libc or unimplemented. */
;
else if (strcmp(lib, "xnet") == 0)
/* xnet functionality is in libc. */
;
else {
addarg("-l");
addarg(lib);
}
}
void
usage(void)
{