annotate lwcc/driver-main.c @ 508:10f62dc61a75

Fix bad usage of sprintf() Usage of sprintf() to append to a string in the form of sprintf(buf, "%s...", buf...) is undefined, regardless whether it worked on a lot of older systems. It was always a bad idea and it now breaks on current glibc and gcc development environments. The moral: if any of your code uses sprintf() in a way similar to the above, fix it. It may not fail in a benign way.
author William Astle <lost@l-w.ca>
date Sun, 10 May 2020 22:38:24 -0600
parents 16bd8effb2f6
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
288
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
1 /*
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
2 lwcc/driver/main.c
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
3
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
4 Copyright © 2013 William Astle
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
5
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
6 This file is part of LWTOOLS.
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
7
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
8 LWTOOLS is free software: you can redistribute it and/or modify it under the
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
9 terms of the GNU General Public License as published by the Free Software
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
10 Foundation, either version 3 of the License, or (at your option) any later
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
11 version.
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
12
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
13 This program is distributed in the hope that it will be useful, but WITHOUT
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
14 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
15 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
16 more details.
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
17
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
18 You should have received a copy of the GNU General Public License along with
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
19 this program. If not, see <http://www.gnu.org/licenses/>.
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
20 */
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
21
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
22 #include <errno.h>
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
23 #include <signal.h>
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
24 #include <stdarg.h>
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
25 #include <stdio.h>
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
26 #include <stdlib.h>
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
27 #include <string.h>
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
28 #include <sys/types.h>
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
29 #include <sys/wait.h>
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
30 #include <unistd.h>
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
31
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
32 #include <lw_alloc.h>
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
33 #include <lw_string.h>
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
34 #include <lw_stringlist.h>
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
35
496
a38542cf4cc6 Make lwcc stuff compile (on Linux anyway)
William Astle <lost@l-w.ca>
parents: 295
diff changeset
36 #include <version.h>
a38542cf4cc6 Make lwcc stuff compile (on Linux anyway)
William Astle <lost@l-w.ca>
parents: 295
diff changeset
37
288
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
38 #define VERSTRING "lwcc from " PACKAGE_STRING
291
83f682ed4d65 Make lwcc driver understand -B
William Astle <lost@l-w.ca>
parents: 288
diff changeset
39 #define S(x) S2(x)
83f682ed4d65 Make lwcc driver understand -B
William Astle <lost@l-w.ca>
parents: 288
diff changeset
40 #define S2(x) #x
83f682ed4d65 Make lwcc driver understand -B
William Astle <lost@l-w.ca>
parents: 288
diff changeset
41
83f682ed4d65 Make lwcc driver understand -B
William Astle <lost@l-w.ca>
parents: 288
diff changeset
42 #define BASEDIR S(LWCC_LIBDIR)
288
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
43
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
44 /* list of compilation phases */
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
45 enum phase_t {
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
46 PHASE_DEFAULT = 0,
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
47 PHASE_PREPROCESS,
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
48 PHASE_COMPILE,
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
49 PHASE_ASSEMBLE,
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
50 PHASE_LINK
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
51 };
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
52
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
53 /* these are the names of various programs the compiler calls */
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
54 const char *linker_program_name = "lwlink";
504
16bd8effb2f6 Update lwcc driver to actually do something useful sometimes
William Astle <lost@l-w.ca>
parents: 496
diff changeset
55 const char *compiler_program_name = "lwcc-cc";
288
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
56 const char *assembler_program_name = "lwasm";
504
16bd8effb2f6 Update lwcc driver to actually do something useful sometimes
William Astle <lost@l-w.ca>
parents: 496
diff changeset
57 const char *preprocessor_program_name = "lwcc-cpp";
288
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
58
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
59 /* this will be set to the directory where temporary files get created */
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
60 const char *temp_directory = NULL;
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
61
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
62 /* these are for book keeping if we get interrupted - the volatile and atomic
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
63 types are needed because they are accessed in a signal handler */
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
64 static volatile sig_atomic_t sigterm_received = 0;
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
65 static volatile sig_atomic_t child_pid = 0;
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
66
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
67 /* path specified with --sysroot */
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
68 const char *sysroot = "";
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
69 /* path specified with -isysroot */
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
70 const char *isysroot = NULL;
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
71
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
72 /* record which phase to stop after for -c, -E, and -S */
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
73 /* default is to stop after PHASE_LINK */
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
74 static int stop_after = PHASE_DEFAULT;
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
75
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
76 int nostdinc = 0; // set if -nostdinc is specified
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
77 int nostartfiles = 0; // set if -nostartfiles is specified
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
78 int nostdlib = 0; // set if -nostdlib is specified
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
79 int verbose_mode = 0; // set to number of --verbose arguments
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
80 int save_temps = 0; // set if -save-temps is specified
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
81 int debug_mode = 0; // set if -g specified
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
82 int pic_mode = 0; // set to 1 if -fpic, 2 if -fPIC; last one specified wins
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
83 const char *output_file; // set to the value of the -o option (output file)
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
84
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
85 /* compiler base directory - from -B */
291
83f682ed4d65 Make lwcc driver understand -B
William Astle <lost@l-w.ca>
parents: 288
diff changeset
86 const char *basedir = BASEDIR;
288
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
87
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
88 /* used to ensure a unique temporary file at every stage */
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
89 static int file_counter = 0;
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
90
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
91 /* these are various string lists used to keep track of things, mostly
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
92 command line arguments. */
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
93
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
94 lw_stringlist_t input_files; // input files from command line
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
95 lw_stringlist_t runtime_dirs; // directories to search for runtime files
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
96 lw_stringlist_t lib_dirs; // directories to search for library files
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
97 lw_stringlist_t program_dirs; // directories to search for compiler program components
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
98 lw_stringlist_t preproc_args; // recorded arguments to pass through to the preprocessor
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
99 lw_stringlist_t include_dirs; // include paths specified with -I
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
100 lw_stringlist_t includes; // include paths specified with -include
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
101 lw_stringlist_t user_sysincdirs; // include paths specified with -isystem
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
102 lw_stringlist_t asm_args; // recorded arguments to pass through to the assembler
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
103 lw_stringlist_t linker_args; // recorded arguments to pass through to the linker
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
104 lw_stringlist_t sysincdirs; // the standard system include directories
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
105 lw_stringlist_t tempfiles; // a list of temporary files created which need to be cleaned up
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
106 lw_stringlist_t compiler_args; // recorded arguments to pass through to the compiler
291
83f682ed4d65 Make lwcc driver understand -B
William Astle <lost@l-w.ca>
parents: 288
diff changeset
107 lw_stringlist_t priv_sysincdirs; // system include directories for lwcc itself
288
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
108
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
109 /* forward delcarations */
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
110 static void parse_command_line(int, char **);
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
111
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
112 /* signal handler for SIGTERM - all it does is record the fact that
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
113 SIGTERM happened and propagate the signal to whatever child process
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
114 might currently be running */
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
115 static void exit_on_signal(int sig)
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
116 {
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
117 sigterm_received = 1;
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
118 if (child_pid)
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
119 kill(child_pid, SIGTERM);
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
120 }
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
121
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
122 /* utility function to carp about an error condition and bail */
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
123 void do_error(const char *f, ...)
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
124 {
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
125 va_list arg;
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
126 va_start(arg, f);
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
127 fprintf(stderr, "ERROR: ");
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
128 vfprintf(stderr, f, arg);
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
129 putc('\n', stderr);
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
130 va_end(arg);
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
131 exit(1);
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
132 }
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
133
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
134 /* utility function to carp about some condition; do not bail */
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
135 void do_warning(const char *f, ...)
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
136 {
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
137 va_list arg;
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
138 va_start(arg, f);
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
139 fprintf(stderr, "WARNING: ");
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
140 vfprintf(stderr, f, arg);
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
141 putc('\n', stderr);
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
142 va_end(arg);
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
143 }
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
144
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
145 /* utility function to print out an array of strings - stops at the first
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
146 NULL string pointer. */
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
147 static void print_array(char **arr)
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
148 {
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
149 int c = 0;
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
150 while (*arr)
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
151 {
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
152 if (c)
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
153 printf(" ");
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
154 printf("%s", *arr);
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
155 arr++;
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
156 c = 1;
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
157 }
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
158 }
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
159
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
160 /* expand any search path entries to reflect the sysroot and
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
161 isysroot settings. Note that it does NOT apply to the compiler
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
162 program search path */
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
163 static void expand_sysroot(void)
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
164 {
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
165 /* list of path lists to process for replacements of = */
291
83f682ed4d65 Make lwcc driver understand -B
William Astle <lost@l-w.ca>
parents: 288
diff changeset
166 lw_stringlist_t *lists[] = { &sysincdirs, &include_dirs, &user_sysincdirs, &lib_dirs, NULL };
288
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
167 /* list of replacement strings for = in the same order */
291
83f682ed4d65 Make lwcc driver understand -B
William Astle <lost@l-w.ca>
parents: 288
diff changeset
168 const char *sysroots[] = { isysroot, isysroot, isysroot, sysroot, NULL };
288
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
169 size_t i, sysroot_len, value_len;
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
170 char *path;
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
171 lw_stringlist_t newlist;
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
172 lw_stringlist_t working;
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
173 char *s;
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
174
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
175 /* for each list, run through entry by entry, do any needed replacement
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
176 and add the entry to a new list. Then replace the old list with the
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
177 new one. */
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
178 for (i = 0; lists[i] != NULL; i++)
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
179 {
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
180 working = *lists[i];
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
181 newlist = lw_stringlist_create();
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
182
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
183 lw_stringlist_reset(working);
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
184 for (s = lw_stringlist_current(working); s; s = lw_stringlist_next(working))
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
185 {
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
186 if (s[0] == '=')
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
187 {
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
188 sysroot_len = strlen(sysroots[i]);
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
189 value_len = strlen(s);
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
190 /* note that the skipped = will make up for the trailing NUL */
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
191 path = lw_alloc(sysroot_len + value_len);
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
192 memcpy(path, sysroots[i], sysroot_len);
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
193 /* the +1 here will copy the trailing NUL */
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
194 memcpy(path + sysroot_len, s + 1, value_len);
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
195 lw_stringlist_addstring(newlist, path);
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
196 lw_free(path);
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
197 }
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
198 else
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
199 {
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
200 lw_stringlist_addstring(newlist, s);
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
201 }
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
202 }
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
203 lw_stringlist_destroy(working);
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
204 *lists[i] = newlist;
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
205 }
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
206 }
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
207
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
208 /* look for file fn in path list p which is okay for access mode mode.
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
209 Return a string allocated by lw_alloc. */
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
210 static char *find_file(const char *fn, lw_stringlist_t p, int mode)
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
211 {
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
212 char *s;
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
213 char *f;
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
214 size_t lf, lp;
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
215 int need_slash;
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
216
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
217 lf = strlen(fn);
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
218 lw_stringlist_reset(p);
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
219 for (s = lw_stringlist_current(p); s; s = lw_stringlist_next(p))
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
220 {
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
221 lp = strlen(s);
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
222 need_slash = 0;
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
223 if (lp && s[lp - 1] == '/')
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
224 need_slash = 1;
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
225 f = lw_alloc(lp + lf + need_slash + 1);
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
226 memcpy(f, s, lp);
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
227 if (need_slash)
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
228 f[lp] = '/';
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
229 /* +1 gets the NUL */
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
230 memcpy(f + lp + need_slash, fn, lf + 1);
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
231 if (access(f, mode) == 0)
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
232 return f;
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
233 lw_free(f);
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
234 }
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
235 /* if not found anywhere, try the bare filename - it might work */
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
236 return lw_strdup(fn);
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
237 }
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
238
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
239 /* take a string list which contains an argv and execute the specified
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
240 program */
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
241 static int execute_program(lw_stringlist_t args)
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
242 {
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
243 int argc;
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
244 char **argv;
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
245 int result;
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
246 char *s;
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
247
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
248 argc = lw_stringlist_nstrings(args);
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
249 argv = lw_alloc(sizeof(char *) * (argc + 1));
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
250 lw_stringlist_reset(args);
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
251 for (result = 0, s = lw_stringlist_current(args); s; s = lw_stringlist_next(args))
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
252 {
504
16bd8effb2f6 Update lwcc driver to actually do something useful sometimes
William Astle <lost@l-w.ca>
parents: 496
diff changeset
253 argv[result++] = s;
288
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
254 }
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
255 argv[result] = NULL;
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
256
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
257 if (verbose_mode)
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
258 {
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
259 printf("Executing ");
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
260 print_array(argv);
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
261 printf("\n");
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
262 }
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
263
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
264 /* bail now if a signal happened */
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
265 if (sigterm_received)
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
266 {
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
267 lw_free(argv);
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
268 return 1;
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
269 }
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
270
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
271 /* make sure stdio has flushed everything so that output from the
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
272 child process doesn't get intermingled */
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
273 fflush(NULL);
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
274
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
275 /* now make the child process */
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
276 child_pid = fork();
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
277 if (child_pid == 0)
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
278 {
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
279 /* child process */
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
280 /* try executing program */
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
281 execvp(argv[0], argv);
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
282 /* only way to get here is if execvp() failed so carp about it and exit */
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
283 fprintf(stderr, "Exec of %s failed: %s", argv[0], strerror(errno));
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
284 /* exit with failure but don't call any atexit(), etc., functions */
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
285 _exit(127);
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
286 }
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
287 else if (child_pid == -1)
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
288 {
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
289 /* failure to make child process */
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
290 do_error("Failed to execute program %s: %s", argv[0], strerror(errno));
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
291 }
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
292 /* clean up argv */
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
293 lw_free(argv);
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
294
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
295 /* parent process - wait for child to exit */
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
296 while (waitpid(child_pid, &result, 0) == -1 && errno == EINTR)
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
297 /* do nothing */;
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
298 /* fetch actual return status */
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
299 result = WEXITSTATUS(result);
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
300 if (result)
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
301 {
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
302 /* carp about non-zero return status */
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
303 do_error("%s terminated with status %d", argv[0], result);
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
304 }
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
305 /* return nonzero if signalled to exit */
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
306 return sigterm_received;
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
307 }
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
308
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
309 /*
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
310 construct an output file name as follows:
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
311
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
312 1. if it is the last phase of compilation and an output file name is
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
313 specified, use that if not specified
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
314 2. if it is the last phase or we are saving temporary files, any suffix
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
315 on f is removed and replaced with nsuffix
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
316 3. otherwise, a temporary file is created. If necessary, a temporary
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
317 directory is created to hold the temporary file. The name of the temporary
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
318 file is recorded in the tempfiles string list for later cleanup. The name
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
319 of the temporary directory is recorded in temp_directory for later cleanup.
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
320 */
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
321 static char *output_name(const char *f, const char *nsuffix, int last)
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
322 {
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
323 const char *osuffix;
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
324 char *name;
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
325 size_t lf, ls, len;
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
326 int counter_len;
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
327
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
328 /* get a new file counter */
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
329 file_counter++;
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
330
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
331 /* if the output was specified, use it */
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
332 if (last && output_file)
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
333 {
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
334 return lw_strdup(output_file);
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
335 }
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
336
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
337 /* find the start of the old suffix */
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
338 osuffix = strrchr(f, '.');
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
339 if (osuffix != NULL && strchr(osuffix, '/') != NULL)
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
340 osuffix = NULL;
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
341 if (osuffix == NULL)
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
342 osuffix = f + strlen(f);
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
343
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
344 ls = strlen(nsuffix);
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
345
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
346 /* if this is the last stage or we're saving temps, use a name derived
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
347 from the original file name by replacing the suffix with nsuffix */
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
348 if (save_temps || last)
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
349 {
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
350 lf = osuffix - f;
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
351 name = lw_alloc(lf + ls + 1);
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
352 memcpy(name, f, lf);
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
353 /* note that the +1 will copy the trailing NUL */
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
354 memcpy(name + lf, nsuffix, ls + 1);
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
355 return name;
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
356 }
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
357
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
358 /* finally, use a temporary file */
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
359 if (temp_directory == NULL)
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
360 {
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
361 /* if we haven't already made a temporary directory, do so */
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
362 const char *dirtempl;
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
363 char *path;
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
364 size_t dirtempl_len;
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
365 int need_slash;
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
366
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
367 /* look for a TMPFIR environment variable and use that if present
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
368 but use /tmp as a fallback */
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
369 dirtempl = getenv("TMPDIR");
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
370 if (dirtempl == NULL)
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
371 dirtempl = "/tmp";
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
372 dirtempl_len = strlen(dirtempl);
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
373 /* work out if we need to add a slash on the end of the directory */
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
374 if (dirtempl_len && dirtempl[dirtempl_len - 1] == '/')
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
375 need_slash = 0;
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
376 else
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
377 need_slash = 1;
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
378 /* make a string of the form <tempdir>/lwcc-XXXXXX */
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
379 path = lw_alloc(dirtempl_len + need_slash + 11 + 1);
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
380 memcpy(path, dirtempl, dirtempl_len);
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
381 if (need_slash)
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
382 path[dirtempl_len] = '/';
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
383 memcpy(path + dirtempl_len + need_slash, "lwcc-XXXXXX", 12);
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
384 /* now make a temporary directory */
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
385 if (mkdtemp(path) == NULL)
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
386 do_error("mkdtemp failed: %s", strerror(errno));
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
387 /* record the temporary directory name */
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
388 temp_directory = path;
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
389 }
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
390 /* now create a file name in the temporary directory. The strategy here
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
391 uses a counter that is passed along and is guaranteed to be unique for
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
392 every file requested. */
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
393 lf = strlen(temp_directory);
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
394 /* this gets the length of the counter as a string but doesn't actually
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
395 allocate anything so we can make a string long enough */
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
396 counter_len = snprintf(NULL, 0, "%d", file_counter);
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
397 if (counter_len < 1)
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
398 do_error("snprintf failure: %s", strerror(errno));
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
399 len = lf + 1 + (size_t)counter_len + ls + 1;
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
400 name = lw_alloc(len);
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
401 /* it should be impossible for ths snprintf call to fail */
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
402 snprintf(name, len, "%s/%d%s", temp_directory, file_counter, nsuffix);
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
403
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
404 /* record the temporary file name for later */
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
405 lw_stringlist_addstring(tempfiles, name);
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
406 return name;
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
407 }
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
408
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
409 /* this calls the actual compiler, passing the contents of compiler_args
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
410 as arguments. It also adds the input file and output file. */
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
411 static int compile_file(const char *file, char *input, char **output, const char *suffix)
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
412 {
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
413 lw_stringlist_t args;
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
414 char *out;
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
415 int retval;
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
416 char *s;
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
417
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
418 args = lw_stringlist_create();
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
419
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
420 /* find the compiler executable and make that argv[0] */
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
421 s = find_file(compiler_program_name, program_dirs, X_OK);
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
422 lw_stringlist_addstring(args, s);
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
423 lw_free(s);
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
424
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
425 /* add all the saved compiler arguments to argv */
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
426 lw_stringlist_reset(compiler_args);
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
427 for (s = lw_stringlist_current(compiler_args); s; s = lw_stringlist_next(compiler_args))
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
428 {
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
429 lw_stringlist_addstring(args, s);
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
430 }
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
431 /* work out the output file name and add that to argv */
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
432 out = output_name(file, suffix, stop_after == PHASE_COMPILE);
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
433 lw_stringlist_addstring(args, "-o");
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
434 lw_stringlist_addstring(args, out);
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
435 /* add the input file to argv */
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
436 lw_stringlist_addstring(args, input);
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
437 /* if the input file name and the output file name pointers are the same
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
438 free the input one */
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
439 if (*output == input)
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
440 lw_free(input);
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
441 /* tell the caller what the output name is */
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
442 *output = out;
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
443 /* actually run the compiler */
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
444 retval = execute_program(args);
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
445
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
446 lw_stringlist_destroy(args);
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
447 return retval;
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
448 }
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
449
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
450 /* this calls the actual assembler, passing the contents of asm_args
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
451 as arguments. It also adds the input file and output file. */
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
452 static int assemble_file(const char *file, char *input, char **output, const char *suffix)
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
453 {
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
454 lw_stringlist_t args;
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
455 char *out;
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
456 int retval;
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
457 char *s;
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
458
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
459 args = lw_stringlist_create();
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
460
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
461 /* find the assembler binary and add that as argv[0] */
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
462 s = find_file(assembler_program_name, program_dirs, X_OK);
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
463 lw_stringlist_addstring(args, s);
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
464 lw_free(s);
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
465
504
16bd8effb2f6 Update lwcc driver to actually do something useful sometimes
William Astle <lost@l-w.ca>
parents: 496
diff changeset
466 /* add some necessary args */
16bd8effb2f6 Update lwcc driver to actually do something useful sometimes
William Astle <lost@l-w.ca>
parents: 496
diff changeset
467 lw_stringlist_addstring(args, "--format=obj");
16bd8effb2f6 Update lwcc driver to actually do something useful sometimes
William Astle <lost@l-w.ca>
parents: 496
diff changeset
468
288
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
469 /* add asm_args to argv */
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
470 lw_stringlist_reset(asm_args);
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
471 for (s = lw_stringlist_current(asm_args); s; s = lw_stringlist_next(asm_args))
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
472 {
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
473 lw_stringlist_addstring(args, s);
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
474 }
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
475 /* get an output file name and add that to argv */
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
476 out = output_name(file, ".o", stop_after == PHASE_ASSEMBLE);
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
477 lw_stringlist_addstring(args, "-o");
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
478 lw_stringlist_addstring(args, out);
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
479 /* finally, add the input file */
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
480 lw_stringlist_addstring(args, input);
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
481 /* clean up input file name if same as output pointer */
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
482 if (*output == input)
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
483 lw_free(input);
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
484 /* tell caller what file we made */
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
485 *output = out;
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
486 /* actually run the assembler */
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
487 retval = execute_program(args);
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
488
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
489 lw_stringlist_destroy(args);
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
490 return retval;
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
491 }
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
492
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
493 /* run the preprocessor. Pass along preproc_args and appropriate options
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
494 for all the include directories */
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
495 static int preprocess_file(const char *file, char *input, char **output, const char *suffix)
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
496 {
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
497 lw_stringlist_t args;
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
498 char *s;
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
499 char *out;
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
500 int retval;
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
501
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
502 args = lw_stringlist_create();
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
503
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
504 /* find the linker binary and make that argv[0] */
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
505 s = find_file(preprocessor_program_name, program_dirs, X_OK);
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
506 lw_stringlist_addstring(args, s);
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
507 lw_free(s);
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
508
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
509 /* add preproc_args to argv */
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
510 lw_stringlist_reset(preproc_args);
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
511 for (s = lw_stringlist_current(preproc_args); s; s = lw_stringlist_next(preproc_args))
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
512 {
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
513 lw_stringlist_addstring(args, s);
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
514 }
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
515
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
516 /* add the include files specified by -i */
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
517 lw_stringlist_reset(includes);
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
518 for (s = lw_stringlist_current(includes); s; s = lw_stringlist_next(includes))
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
519 {
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
520 lw_stringlist_addstring(args, "-i");
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
521 lw_stringlist_addstring(args, s);
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
522 }
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
523
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
524 /* add the include directories specified by -I */
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
525 lw_stringlist_reset(include_dirs);
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
526 for (s = lw_stringlist_current(include_dirs); s; s = lw_stringlist_next(include_dirs))
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
527 {
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
528 lw_stringlist_addstring(args, "-I");
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
529 lw_stringlist_addstring(args, s);
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
530 }
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
531
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
532 /* add the user specified system include directories (-isystem) */
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
533 lw_stringlist_reset(user_sysincdirs);
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
534 for (s = lw_stringlist_current(user_sysincdirs); s; s = lw_stringlist_next(user_sysincdirs))
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
535 {
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
536 lw_stringlist_addstring(args, "-S");
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
537 lw_stringlist_addstring(args, s);
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
538 }
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
539
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
540 /* and, if not -nostdinc, the standard system include directories */
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
541 if (!nostdinc)
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
542 {
291
83f682ed4d65 Make lwcc driver understand -B
William Astle <lost@l-w.ca>
parents: 288
diff changeset
543 lw_stringlist_reset(priv_sysincdirs);
83f682ed4d65 Make lwcc driver understand -B
William Astle <lost@l-w.ca>
parents: 288
diff changeset
544 for (s = lw_stringlist_current(priv_sysincdirs); s; s = lw_stringlist_next(priv_sysincdirs))
83f682ed4d65 Make lwcc driver understand -B
William Astle <lost@l-w.ca>
parents: 288
diff changeset
545 {
83f682ed4d65 Make lwcc driver understand -B
William Astle <lost@l-w.ca>
parents: 288
diff changeset
546 lw_stringlist_addstring(args, "-S");
83f682ed4d65 Make lwcc driver understand -B
William Astle <lost@l-w.ca>
parents: 288
diff changeset
547 lw_stringlist_addstring(args, s);
83f682ed4d65 Make lwcc driver understand -B
William Astle <lost@l-w.ca>
parents: 288
diff changeset
548 }
288
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
549 lw_stringlist_reset(sysincdirs);
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
550 for (s = lw_stringlist_current(sysincdirs); s; s = lw_stringlist_next(sysincdirs))
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
551 {
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
552 lw_stringlist_addstring(args, "-S");
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
553 lw_stringlist_addstring(args, s);
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
554 }
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
555 }
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
556
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
557 /* if we stop after preprocessing, output to stdout if no output file */
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
558 if (stop_after == PHASE_PREPROCESS && output_file == NULL)
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
559 {
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
560 out = lw_strdup("-");
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
561 }
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
562 else
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
563 {
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
564 /* otherwise, make an output file */
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
565 out = output_name(file, suffix, stop_after == PHASE_PREPROCESS);
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
566 }
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
567 /* if not stdout, add the output file to argv */
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
568 if (strcmp(out, "-") != 0)
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
569 {
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
570 lw_stringlist_addstring(args, "-o");
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
571 lw_stringlist_addstring(args, out);
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
572 }
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
573 /* add the input file name to argv */
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
574 lw_stringlist_addstring(args, input);
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
575
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
576 /* if input and output pointers are same, clean up input */
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
577 if (*output == input)
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
578 lw_free(input);
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
579 /* tell caller what our output file is */
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
580 *output = out;
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
581 /* finally, actually run the preprocessor */
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
582 retval = execute_program(args);
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
583
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
584 lw_stringlist_destroy(args);
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
585 return retval;
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
586 }
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
587
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
588 /*
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
589 handle an input file through the various stages of compilation. If any
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
590 stage decides to handle an input file, that fact is recorded. If control
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
591 reaches the end of the function without a file being handled, that
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
592 fact is mentioned to the user. Unknown files are passed to the linker
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
593 if nothing handles them and linking is to be done. It's possible the linker
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
594 will actually know what to do with them.
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
595 */
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
596 static int handle_input_file(const char *f)
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
597 {
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
598 const char *suffix;
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
599 char *src;
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
600 int handled, retval;
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
601
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
602 /* note: this needs to handle -x but for now, assume c for stdin */
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
603 if (strcmp(f, "-") == 0)
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
604 {
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
605 suffix = ".c";
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
606 }
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
607 else
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
608 {
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
609 /* work out the suffix on the file */
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
610 suffix = strrchr(f, '.');
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
611 if (suffix != NULL && strchr(suffix, '/') != NULL)
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
612 suffix = NULL;
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
613 if (suffix == NULL)
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
614 suffix = "";
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
615 }
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
616
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
617 /* make a copy of the file */
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
618 src = lw_strdup(f);
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
619
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
620 /* preprocess if appropriate */
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
621 if (strcmp(suffix, ".c") == 0)
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
622 {
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
623 /* preprocessed c input source goes to .i */
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
624 suffix = ".i";
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
625 retval = preprocess_file(f, src, &src, suffix);
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
626 if (retval)
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
627 goto done;
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
628 handled = 1;
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
629 }
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
630 else if (strcmp(suffix, ".S") == 0)
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
631 {
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
632 /* preprocessed asm source goes to .s */
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
633 suffix = ".s";
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
634 retval = preprocess_file(f, src, &src, suffix);
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
635 if (retval)
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
636 goto done;
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
637 handled = 1;
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
638 }
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
639 /* if we're only preprocessing, bail */
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
640 if (stop_after == PHASE_PREPROCESS)
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
641 goto done;
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
642
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
643 /* now on to compile if appropriate */
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
644 if (strcmp(suffix, ".i") == 0)
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
645 {
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
646 /* preprocessed c source goes to .s after compiling */
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
647 suffix = ".s";
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
648 retval = compile_file(f, src, &src, suffix);
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
649 if (retval)
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
650 goto done;
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
651 handled = 1;
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
652 }
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
653 /* bail if we're only compiling, not assembling */
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
654 if (stop_after == PHASE_COMPILE)
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
655 goto done;
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
656
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
657 /* assemble if appropriate */
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
658 if (strcmp(suffix, ".s") == 0)
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
659 {
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
660 /* assembler output is an object file */
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
661 suffix = ".o";
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
662 retval = assemble_file(f, src, &src, suffix);
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
663 if (retval)
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
664 goto done;
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
665 handled = 1;
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
666 }
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
667 /* bail if we're not linking */
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
668 if (stop_after == PHASE_ASSEMBLE)
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
669 goto done;
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
670
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
671 /* if we get here with a .o unhandled, pretend it is handled */
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
672 if (strcmp(suffix, ".o") == 0)
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
673 handled = 1;
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
674
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
675 /* add the final file name to the linker args */
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
676 lw_stringlist_addstring(linker_args, src);
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
677 done:
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
678 if (!handled && !retval)
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
679 {
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
680 /* carp about unhandled files if there is no error */
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
681 if (stop_after == PHASE_LINK)
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
682 {
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
683 do_warning("unknown suffix %s; passing file down to linker", suffix);
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
684 }
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
685 else
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
686 {
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
687 do_warning("unknown suffix %s; skipped", suffix);
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
688 }
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
689 }
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
690 /* clean up the file name */
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
691 lw_free(src);
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
692
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
693 return retval;
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
694 }
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
695
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
696 /*
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
697 This actually runs the linker. Along the way, all the files the linker
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
698 is supposed to handle will have been added to linker_args.
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
699 */
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
700 static int handle_linking(void)
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
701 {
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
702 lw_stringlist_t linker_flags;
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
703 char *s;
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
704 int retval;
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
705
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
706 linker_flags = lw_stringlist_create();
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
707
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
708 /* find the linker binary and make that argv[0] */
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
709 s = find_file(linker_program_name, program_dirs, X_OK);
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
710 lw_stringlist_addstring(linker_flags, s);
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
711 lw_free(s);
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
712
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
713 /* tell the linker about the output file name, if specified */
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
714 if (output_file)
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
715 {
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
716 lw_stringlist_addstring(linker_flags, "-o");
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
717 lw_stringlist_addstring(linker_flags, (char *)output_file);
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
718 }
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
719
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
720 /* add the standard library options if not -nostdlib */
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
721 if (!nostdlib)
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
722 {
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
723 }
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
724
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
725 /* add the standard startup files if not -nostartfiles */
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
726 if (!nostartfiles)
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
727 {
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
728 }
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
729
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
730 /* pass along the various input files, etc., to the linker */
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
731 lw_stringlist_reset(linker_args);
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
732 for (s = lw_stringlist_current(linker_args); s; s = lw_stringlist_next(linker_args))
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
733 {
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
734 lw_stringlist_addstring(linker_flags, s);
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
735 }
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
736
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
737 /* actually run the linker */
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
738 retval = execute_program(linker_flags);
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
739
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
740 lw_stringlist_destroy(linker_flags);
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
741 return retval;
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
742 }
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
743
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
744 /*
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
745 Do various setup tasks, process the command line, handle the input files,
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
746 and clean up.
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
747 */
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
748 int main(int argc, char **argv)
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
749 {
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
750 char *ap;
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
751 int retval;
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
752
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
753 input_files = lw_stringlist_create();
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
754 runtime_dirs = lw_stringlist_create();
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
755 lib_dirs = lw_stringlist_create();
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
756 program_dirs = lw_stringlist_create();
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
757 preproc_args = lw_stringlist_create();
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
758 include_dirs = lw_stringlist_create();
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
759 user_sysincdirs = lw_stringlist_create();
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
760 asm_args = lw_stringlist_create();
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
761 linker_args = lw_stringlist_create();
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
762 sysincdirs = lw_stringlist_create();
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
763 includes = lw_stringlist_create();
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
764 tempfiles = lw_stringlist_create();
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
765 compiler_args = lw_stringlist_create();
291
83f682ed4d65 Make lwcc driver understand -B
William Astle <lost@l-w.ca>
parents: 288
diff changeset
766 priv_sysincdirs = lw_stringlist_create();
83f682ed4d65 Make lwcc driver understand -B
William Astle <lost@l-w.ca>
parents: 288
diff changeset
767
288
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
768 parse_command_line(argc, argv);
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
769 if (stop_after == PHASE_DEFAULT)
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
770 stop_after = PHASE_LINK;
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
771
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
772 if (verbose_mode)
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
773 printf("%s\n", VERSTRING);
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
774
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
775 if (isysroot == NULL)
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
776 isysroot = sysroot;
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
777 expand_sysroot();
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
778
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
779 if (stop_after != PHASE_LINK && output_file && lw_stringlist_nstrings(input_files) > 1)
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
780 {
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
781 do_error("-o cannot be specified with multiple inputs unless linking");
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
782 }
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
783
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
784 // default to stdout for preprocessing
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
785 if (stop_after == PHASE_PREPROCESS && output_file == NULL)
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
786 output_file = "-";
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
787
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
788 if (lw_stringlist_nstrings(input_files) == 0)
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
789 do_error("No input files specified");
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
790
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
791 /* handle -B here */
291
83f682ed4d65 Make lwcc driver understand -B
William Astle <lost@l-w.ca>
parents: 288
diff changeset
792 ap = lw_alloc(strlen(basedir) + 10);
83f682ed4d65 Make lwcc driver understand -B
William Astle <lost@l-w.ca>
parents: 288
diff changeset
793 strcpy(ap, basedir);
83f682ed4d65 Make lwcc driver understand -B
William Astle <lost@l-w.ca>
parents: 288
diff changeset
794 strcat(ap, "/bin");
83f682ed4d65 Make lwcc driver understand -B
William Astle <lost@l-w.ca>
parents: 288
diff changeset
795 lw_stringlist_addstring(program_dirs, ap);
83f682ed4d65 Make lwcc driver understand -B
William Astle <lost@l-w.ca>
parents: 288
diff changeset
796 strcpy(ap, basedir);
83f682ed4d65 Make lwcc driver understand -B
William Astle <lost@l-w.ca>
parents: 288
diff changeset
797 strcat(ap, "/lib");
83f682ed4d65 Make lwcc driver understand -B
William Astle <lost@l-w.ca>
parents: 288
diff changeset
798 lw_stringlist_addstring(runtime_dirs, ap);
83f682ed4d65 Make lwcc driver understand -B
William Astle <lost@l-w.ca>
parents: 288
diff changeset
799 strcpy(ap, basedir);
83f682ed4d65 Make lwcc driver understand -B
William Astle <lost@l-w.ca>
parents: 288
diff changeset
800 strcat(ap, "/include");
83f682ed4d65 Make lwcc driver understand -B
William Astle <lost@l-w.ca>
parents: 288
diff changeset
801 lw_stringlist_addstring(priv_sysincdirs, ap);
83f682ed4d65 Make lwcc driver understand -B
William Astle <lost@l-w.ca>
parents: 288
diff changeset
802 lw_free(ap);
288
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
803
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
804 retval = 0;
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
805 /* make sure we exit if interrupted */
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
806 signal(SIGTERM, exit_on_signal);
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
807
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
808 /* handle input files */
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
809 lw_stringlist_reset(input_files);
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
810 for (ap = lw_stringlist_current(input_files); ap; ap = lw_stringlist_next(input_files))
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
811 {
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
812 if (handle_input_file(ap))
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
813 retval = 1;
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
814 }
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
815
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
816 if (!retval && stop_after >= PHASE_LINK)
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
817 {
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
818 retval = handle_linking();
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
819 }
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
820
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
821 /* if a signal nixed us, mention the fact */
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
822 if (sigterm_received)
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
823 do_warning("Terminating on signal");
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
824
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
825 /* clean up temporary files */
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
826 if (!save_temps)
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
827 {
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
828 lw_stringlist_reset(tempfiles);
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
829 for (ap = lw_stringlist_current(tempfiles); ap; ap = lw_stringlist_next(tempfiles))
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
830 {
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
831 if (unlink(ap) == -1)
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
832 {
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
833 do_warning("Removal of %s failed: %s", ap, strerror(errno));
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
834 }
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
835 }
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
836 if (temp_directory)
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
837 {
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
838 if (rmdir(temp_directory) == -1)
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
839 {
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
840 do_warning("Removal of temporary directory %s failed: %s", temp_directory, strerror(errno));
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
841 }
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
842 }
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
843 }
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
844
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
845 /* be polite and clean up all the string lists */
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
846 lw_stringlist_destroy(input_files);
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
847 lw_stringlist_destroy(runtime_dirs);
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
848 lw_stringlist_destroy(lib_dirs);
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
849 lw_stringlist_destroy(program_dirs);
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
850 lw_stringlist_destroy(preproc_args);
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
851 lw_stringlist_destroy(include_dirs);
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
852 lw_stringlist_destroy(user_sysincdirs);
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
853 lw_stringlist_destroy(asm_args);
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
854 lw_stringlist_destroy(linker_args);
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
855 lw_stringlist_destroy(sysincdirs);
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
856 lw_stringlist_destroy(includes);
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
857 lw_stringlist_destroy(tempfiles);
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
858 lw_stringlist_destroy(compiler_args);
291
83f682ed4d65 Make lwcc driver understand -B
William Astle <lost@l-w.ca>
parents: 288
diff changeset
859 lw_stringlist_destroy(priv_sysincdirs);
288
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
860 return retval;
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
861 }
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
862
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
863 struct option_e
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
864 {
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
865 char *optbase; // base name of option, with -
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
866 int needarg; // nonzero if option needs argument
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
867 int noextra; // nonzero if there must not be anything after optbase
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
868 int optcode; // option code (passed to fn)
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
869 void *optptr; // pointer for opt (passed to fn)
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
870 int (*fn)(char *, char *, int, void *); // function to handle argument, NULL to ignore it
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
871 };
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
872
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
873 enum CMD_MISC {
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
874 CMD_MISC_VERSION,
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
875 CMD_MISC_OPTIMIZE,
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
876 };
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
877
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
878 enum OPT_ARG {
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
879 OPT_ARG_OPT = 0, // argument is optional
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
880 OPT_ARG_SEP = 1, // argument may be separate
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
881 OPT_ARG_INC = 2, // argument must not be separate
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
882 };
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
883
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
884 /* set an integer at *optptr to optcode */
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
885 static int cmdline_set_int(char *opt, char *optarg, int optcode, void *optptr)
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
886 {
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
887 *((int *)optptr) = optcode;
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
888 return 0;
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
889 }
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
890
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
891 /* set a string at *optptr to optarg */
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
892 static int cmdline_set_string(char *opt, char *optarg, int optcode, void *optptr)
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
893 {
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
894 char **s = (char **)optptr;
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
895 *s = optarg;
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
896
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
897 return 0;
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
898 }
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
899
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
900 /* set a string at *optptr to optarg */
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
901 static int cmdline_set_stringifnull(char *opt, char *optarg, int optcode, void *optptr)
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
902 {
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
903 char **s = (char **)optptr;
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
904
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
905 if (*s)
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
906 do_error("Multiple %.*s options specified", optcode ? optcode : strlen(opt), opt);
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
907 *s = optarg;
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
908
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
909 return 0;
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
910 }
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
911
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
912 /* split arg on commas and add the results to string list *optptr */
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
913 static int cmdline_argsplit(char *opt, char *arg, int optcode, void *optptr)
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
914 {
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
915 lw_stringlist_t l = *(lw_stringlist_t *)optptr;
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
916 char *next;
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
917
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
918 for (; arg != NULL; arg = next)
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
919 {
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
920 next = strchr(arg, ',');
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
921 if (next != NULL)
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
922 *next++ = '\0';
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
923 lw_stringlist_addstring(l, arg);
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
924 }
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
925 return 0;
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
926 }
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
927
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
928 /* add opt to string list *optptr */
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
929 static int cmdline_arglist(char *opt, char *arg, int optcode, void *optptr)
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
930 {
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
931 lw_stringlist_t l = *(lw_stringlist_t *)optptr;
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
932
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
933 lw_stringlist_addstring(l, opt);
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
934 return 0;
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
935 }
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
936
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
937 /* add optarg to string list *optptr */
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
938 static int cmdline_optarglist(char *opt, char *optarg, int optcode, void *optptr)
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
939 {
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
940 lw_stringlist_t l = *(lw_stringlist_t *)optptr;
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
941
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
942 lw_stringlist_addstring(l, optarg);
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
943 return 0;
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
944 }
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
945
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
946 static int cmdline_misc(char *opt, char *optarg, int optcode, void *optptr)
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
947 {
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
948 switch (optcode)
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
949 {
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
950 case CMD_MISC_VERSION:
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
951 printf("%s\n", VERSTRING);
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
952 exit(0);
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
953
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
954 case CMD_MISC_OPTIMIZE:
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
955 if (!optarg)
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
956 return 0;
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
957 switch (*optarg)
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
958 {
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
959 case '0':
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
960 case '1':
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
961 case '2':
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
962 case '3':
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
963 case 's':
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
964 return 0;
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
965 }
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
966 return -1;
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
967
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
968 default:
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
969 return -1;
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
970 }
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
971 return 0;
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
972 }
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
973
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
974 static int cmdline_set_intifzero(char *opt, char *optarg, int optcode, void *optptr)
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
975 {
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
976 int *iv = (int *)optptr;
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
977
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
978 if (*iv && *iv != optcode)
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
979 {
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
980 do_error("conflicting compiler option specified: %s", opt);
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
981 }
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
982 *iv = optcode;
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
983 return 0;
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
984 }
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
985
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
986 struct option_e optionlist[] =
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
987 {
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
988 { "--version", OPT_ARG_OPT, 1, CMD_MISC_VERSION, NULL, cmdline_misc },
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
989 { "--sysroot=", OPT_ARG_INC, 0, 0, &sysroot, cmdline_set_string },
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
990 { "-B", OPT_ARG_INC, 0, 0, &basedir, cmdline_set_string },
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
991 { "-C", OPT_ARG_OPT, 1, 0, &preproc_args, cmdline_arglist },
504
16bd8effb2f6 Update lwcc driver to actually do something useful sometimes
William Astle <lost@l-w.ca>
parents: 496
diff changeset
992 { "-c", OPT_ARG_OPT, 1, PHASE_ASSEMBLE, &stop_after, cmdline_set_intifzero },
288
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
993 { "-D", OPT_ARG_INC, 0, 0, &preproc_args, cmdline_arglist },
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
994 { "-E", OPT_ARG_OPT, 1, PHASE_PREPROCESS, &stop_after, cmdline_set_intifzero },
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
995 { "-fPIC", OPT_ARG_OPT, 1, 2, &pic_mode, cmdline_set_int },
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
996 { "-fpic", OPT_ARG_OPT, 1, 1, &pic_mode, cmdline_set_int },
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
997 { "-g", OPT_ARG_OPT, 1, 1, &debug_mode, cmdline_set_int },
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
998 { "-I", OPT_ARG_SEP, 0, 0, &include_dirs, cmdline_optarglist },
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
999 { "-include", OPT_ARG_SEP, 1, 0, &includes, cmdline_optarglist },
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
1000 { "-isysroot", OPT_ARG_SEP, 1, 0, &isysroot, cmdline_set_string },
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
1001 { "-isystem", OPT_ARG_SEP, 1, 0, &user_sysincdirs, cmdline_optarglist },
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
1002 { "-M", OPT_ARG_OPT, 1, 0, &preproc_args, cmdline_arglist },
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
1003 { "-nostartfiles", OPT_ARG_OPT, 1, 1, &nostartfiles, cmdline_set_int },
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
1004 { "-nostdinc", OPT_ARG_OPT, 1, 1, &nostdinc, cmdline_set_int },
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
1005 { "-nostdlib", OPT_ARG_OPT, 1, 1, &nostdlib, cmdline_set_int },
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
1006 { "-O", OPT_ARG_OPT, 0, CMD_MISC_OPTIMIZE, NULL, cmdline_misc },
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
1007 { "-o", OPT_ARG_SEP, 0, 2, &output_file, cmdline_set_stringifnull },
504
16bd8effb2f6 Update lwcc driver to actually do something useful sometimes
William Astle <lost@l-w.ca>
parents: 496
diff changeset
1008 { "-S", OPT_ARG_OPT, 1, PHASE_COMPILE, &stop_after, cmdline_set_intifzero },
288
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
1009 { "-save-temps", OPT_ARG_OPT, 1, 1, &save_temps, cmdline_set_int },
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
1010 { "-trigraphs", OPT_ARG_OPT, 1, 0, &preproc_args, cmdline_arglist },
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
1011 { "-U", OPT_ARG_INC, 0, 0, &preproc_args, cmdline_arglist },
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
1012 { "-v", OPT_ARG_OPT, 1, 1, &verbose_mode, cmdline_set_int },
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
1013 { "-Wp,", OPT_ARG_INC, 0, 0, &preproc_args, cmdline_argsplit },
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
1014 { "-Wa,", OPT_ARG_INC, 0, 0, &asm_args, cmdline_argsplit },
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
1015 { "-Wl,", OPT_ARG_INC, 0, 0, &linker_args, cmdline_argsplit },
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
1016 { "-W", OPT_ARG_INC, 0, 0, NULL, NULL }, /* warning options */
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
1017 { "-x", OPT_ARG_SEP, 1, 0, NULL, NULL }, /* language options */
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
1018 { NULL, 0, 0 }
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
1019 };
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
1020
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
1021 static void parse_command_line(int argc, char **argv)
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
1022 {
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
1023 int i, j, olen, ilen;
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
1024 char *optarg;
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
1025
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
1026 for (i = 1; i < argc; i++)
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
1027 {
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
1028 if (argv[i][0] != '-' || argv[i][1] == '\0')
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
1029 {
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
1030 /* we have a non-option argument */
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
1031 lw_stringlist_addstring(input_files, argv[i]);
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
1032 continue;
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
1033 }
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
1034 olen = strlen(argv[i]);
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
1035 for (j = 0; optionlist[j].optbase; j++)
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
1036 {
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
1037 ilen = strlen(optionlist[j].optbase);
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
1038 /* if length of optbase is longer than argv[i], it can't match */
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
1039 if (ilen > olen)
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
1040 continue;
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
1041 /* does the base match? */
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
1042 if (strncmp(optionlist[j].optbase, argv[i], ilen) == 0)
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
1043 break;
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
1044 }
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
1045 if (optionlist[j].optbase == NULL)
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
1046 {
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
1047 do_error("Unsupported option %s", argv[i]);
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
1048 }
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
1049 /* is the option supposed to be exact? */
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
1050 if (optionlist[j].noextra && argv[i][ilen] != '\0')
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
1051 {
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
1052 do_error("Unsupported option %s", argv[i]);
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
1053 }
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
1054 /* is there an argument? */
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
1055 optarg = NULL;
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
1056 if (argv[i][ilen])
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
1057 optarg = argv[i] + ilen;
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
1058 if (!optarg && optionlist[j].needarg == 1)
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
1059 {
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
1060 if (i == argc)
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
1061 {
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
1062 do_error("Option %s requires an argument", argv[i]);
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
1063 }
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
1064 optarg = argv[++i];
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
1065 }
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
1066 if (!optarg && optionlist[j].needarg == 2)
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
1067 {
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
1068 do_error("Option %s requires an argument", argv[i]);
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
1069 }
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
1070 /* handle the option */
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
1071 if (optionlist[j].fn)
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
1072 {
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
1073 if ((*(optionlist[j].fn))(argv[i], optarg, optionlist[j].optcode, optionlist[j].optptr) != 0)
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
1074 do_error("Unsupported option %s %s", argv[i], optarg ? optarg : "");
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
1075 }
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
1076 }
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
1077 }