summaryrefslogtreecommitdiffstats
path: root/usr.bin/c99
diff options
context:
space:
mode:
authortjr <tjr@FreeBSD.org>2002-10-08 02:19:54 +0000
committertjr <tjr@FreeBSD.org>2002-10-08 02:19:54 +0000
commit50bdbd28dada2ce646318a849c7ec5a31ee91275 (patch)
treed6b607de325c4b6933a593a8010d23e3da94d5bf /usr.bin/c99
parent56fe29cbbf9c201582b6c8059459ca22a08ecb2e (diff)
downloadFreeBSD-src-50bdbd28dada2ce646318a849c7ec5a31ee91275.zip
FreeBSD-src-50bdbd28dada2ce646318a849c7ec5a31ee91275.tar.gz
Re-add the code which maps POSIX standard library names into the ones
FreeBSD uses; f.e. -lpthread -> -pthread, -lxnet -> nothing.
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 69bf922..db74cd7 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,
OpenPOWER on IntegriCloud