aboutsummaryrefslogtreecommitdiff
path: root/usr.bin/c99
diff options
context:
space:
mode:
authorTim J. Robbins <tjr@FreeBSD.org>2002-10-08 02:19:54 +0000
committerTim J. Robbins <tjr@FreeBSD.org>2002-10-08 02:19:54 +0000
commit363a99169a07f8a219b0281b2726fdc5fe719a65 (patch)
treed6b607de325c4b6933a593a8010d23e3da94d5bf /usr.bin/c99
parent0b294f891d75eaf5f346698c6ed4aba71e1c5fee (diff)
downloadsrc-363a99169a07f8a219b0281b2726fdc5fe719a65.tar.gz
src-363a99169a07f8a219b0281b2726fdc5fe719a65.zip
Re-add the code which maps POSIX standard library names into the ones
FreeBSD uses; f.e. -lpthread -> -pthread, -lxnet -> nothing.
Notes
Notes: svn path=/head/; revision=104647
Diffstat (limited to 'usr.bin/c99')
-rw-r--r--usr.bin/c99/c99.c53
1 files changed, 49 insertions, 4 deletions
diff --git a/usr.bin/c99/c99.c b/usr.bin/c99/c99.c
index 69bf922a762d..db74cd73f09f 100644
--- a/usr.bin/c99/c99.c
+++ b/usr.bin/c99/c99.c
@@ -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");
}
@@ -79,6 +105,25 @@ addarg(const char *item)
}
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)
{
fprintf(stderr,