annotate lwcc/driver-main.c @ 496:a38542cf4cc6

Make lwcc stuff compile (on Linux anyway)
author William Astle <lost@l-w.ca>
date Mon, 05 Aug 2019 21:30:50 -0600
parents 4b17780f2777
children 16bd8effb2f6
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";
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
55 const char *compiler_program_name = "lwcc1";
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";
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
57 const char *preprocessor_program_name = "lwcpp";
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 {
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
253 argv[result] = s;
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
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
466 /* add asm_args to argv */
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
467 lw_stringlist_reset(asm_args);
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
468 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
469 {
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
470 lw_stringlist_addstring(args, s);
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
471 }
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
472 /* 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
473 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
474 lw_stringlist_addstring(args, "-o");
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
475 lw_stringlist_addstring(args, out);
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
476 /* finally, add the input file */
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
477 lw_stringlist_addstring(args, input);
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
478 /* 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
479 if (*output == input)
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
480 lw_free(input);
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
481 /* 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
482 *output = out;
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
483 /* actually run the assembler */
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
484 retval = execute_program(args);
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
485
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
486 lw_stringlist_destroy(args);
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
487 return retval;
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
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
490 /* 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
491 for all the include directories */
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
492 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
493 {
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
494 lw_stringlist_t args;
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
495 char *s;
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
496 char *out;
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
497 int retval;
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
498
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
499 args = lw_stringlist_create();
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
500
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
501 /* 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
502 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
503 lw_stringlist_addstring(args, s);
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
504 lw_free(s);
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
505
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
506 /* add preproc_args to argv */
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
507 lw_stringlist_reset(preproc_args);
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
508 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
509 {
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
510 lw_stringlist_addstring(args, s);
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
511 }
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 /* 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
514 lw_stringlist_reset(includes);
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
515 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
516 {
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
517 lw_stringlist_addstring(args, "-i");
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
518 lw_stringlist_addstring(args, s);
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
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
521 /* 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
522 lw_stringlist_reset(include_dirs);
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
523 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
524 {
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
525 lw_stringlist_addstring(args, "-I");
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
526 lw_stringlist_addstring(args, s);
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
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
529 /* 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
530 lw_stringlist_reset(user_sysincdirs);
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
531 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
532 {
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
533 lw_stringlist_addstring(args, "-S");
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
534 lw_stringlist_addstring(args, s);
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
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
537 /* 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
538 if (!nostdinc)
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
539 {
291
83f682ed4d65 Make lwcc driver understand -B
William Astle <lost@l-w.ca>
parents: 288
diff changeset
540 lw_stringlist_reset(priv_sysincdirs);
83f682ed4d65 Make lwcc driver understand -B
William Astle <lost@l-w.ca>
parents: 288
diff changeset
541 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
542 {
83f682ed4d65 Make lwcc driver understand -B
William Astle <lost@l-w.ca>
parents: 288
diff changeset
543 lw_stringlist_addstring(args, "-S");
83f682ed4d65 Make lwcc driver understand -B
William Astle <lost@l-w.ca>
parents: 288
diff changeset
544 lw_stringlist_addstring(args, s);
83f682ed4d65 Make lwcc driver understand -B
William Astle <lost@l-w.ca>
parents: 288
diff changeset
545 }
288
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
546 lw_stringlist_reset(sysincdirs);
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
547 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
548 {
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
549 lw_stringlist_addstring(args, "-S");
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
550 lw_stringlist_addstring(args, s);
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 }
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
553
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
554 /* 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
555 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
556 {
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
557 out = lw_strdup("-");
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
558 }
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
559 else
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
560 {
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
561 /* otherwise, make an output file */
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
562 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
563 }
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
564 /* 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
565 if (strcmp(out, "-") != 0)
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 lw_stringlist_addstring(args, "-o");
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
568 lw_stringlist_addstring(args, out);
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 /* 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
571 lw_stringlist_addstring(args, input);
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 /* 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
574 if (*output == input)
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
575 lw_free(input);
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
576 /* 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
577 *output = out;
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
578 /* finally, actually run the preprocessor */
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
579 retval = execute_program(args);
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
580
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
581 lw_stringlist_destroy(args);
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
582 return retval;
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
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
585 /*
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
586 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
587 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
588 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
589 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
590 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
591 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
592 */
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
593 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
594 {
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
595 const char *suffix;
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
596 char *src;
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
597 int handled, retval;
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
598
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
599 /* 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
600 if (strcmp(f, "-") == 0)
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 suffix = ".c";
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
603 }
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
604 else
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
605 {
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
606 /* 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
607 suffix = strrchr(f, '.');
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
608 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
609 suffix = NULL;
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
610 if (suffix == NULL)
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
611 suffix = "";
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
612 }
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
613
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
614 /* 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
615 src = lw_strdup(f);
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 /* preprocess if appropriate */
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
618 if (strcmp(suffix, ".c") == 0)
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 /* 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
621 suffix = ".i";
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
622 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
623 if (retval)
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
624 goto done;
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
625 handled = 1;
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
626 }
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
627 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
628 {
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
629 /* 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
630 suffix = ".s";
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
631 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
632 if (retval)
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
633 goto done;
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
634 handled = 1;
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
635 }
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
636 /* 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
637 if (stop_after == PHASE_PREPROCESS)
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
638 goto done;
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
639
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
640 /* 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
641 if (strcmp(suffix, ".i") == 0)
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 /* 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
644 suffix = ".s";
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
645 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
646 if (retval)
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
647 goto done;
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
648 handled = 1;
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
649 }
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
650 /* 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
651 if (stop_after == PHASE_COMPILE)
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
652 goto done;
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
653
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
654 /* assemble if appropriate */
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
655 if (strcmp(suffix, ".s") == 0)
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 /* 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
658 suffix = ".o";
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
659 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
660 if (retval)
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
661 goto done;
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
662 handled = 1;
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
663 }
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
664 /* 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
665 if (stop_after == PHASE_ASSEMBLE)
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
666 goto done;
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
667
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
668 /* 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
669 if (strcmp(suffix, ".o") == 0)
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
670 handled = 1;
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
671
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
672 /* 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
673 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
674 done:
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
675 if (!handled && !retval)
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
676 {
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
677 /* 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
678 if (stop_after == PHASE_LINK)
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 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
681 }
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
682 else
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
683 {
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
684 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
685 }
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 /* clean up the file name */
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
688 lw_free(src);
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 return retval;
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
691 }
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 /*
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
694 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
695 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
696 */
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
697 static int handle_linking(void)
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
698 {
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
699 lw_stringlist_t linker_flags;
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
700 char *s;
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
701 int retval;
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
702
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
703 linker_flags = lw_stringlist_create();
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
704
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
705 /* 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
706 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
707 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
708 lw_free(s);
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
709
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
710 /* 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
711 if (output_file)
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 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
714 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
715 }
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
716
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
717 /* 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
718 if (!nostdlib)
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 }
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
721
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
722 /* 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
723 if (!nostartfiles)
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 }
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
726
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
727 /* 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
728 lw_stringlist_reset(linker_args);
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
729 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
730 {
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
731 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
732 }
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 /* actually run the linker */
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
735 retval = execute_program(linker_flags);
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 lw_stringlist_destroy(linker_flags);
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
738 return retval;
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
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
741 /*
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
742 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
743 and clean up.
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 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
746 {
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
747 char *ap;
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
748 int retval;
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 input_files = lw_stringlist_create();
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
751 runtime_dirs = lw_stringlist_create();
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
752 lib_dirs = lw_stringlist_create();
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
753 program_dirs = lw_stringlist_create();
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
754 preproc_args = lw_stringlist_create();
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
755 include_dirs = lw_stringlist_create();
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
756 user_sysincdirs = lw_stringlist_create();
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
757 asm_args = lw_stringlist_create();
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
758 linker_args = lw_stringlist_create();
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
759 sysincdirs = lw_stringlist_create();
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
760 includes = lw_stringlist_create();
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
761 tempfiles = lw_stringlist_create();
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
762 compiler_args = lw_stringlist_create();
291
83f682ed4d65 Make lwcc driver understand -B
William Astle <lost@l-w.ca>
parents: 288
diff changeset
763 priv_sysincdirs = lw_stringlist_create();
83f682ed4d65 Make lwcc driver understand -B
William Astle <lost@l-w.ca>
parents: 288
diff changeset
764
288
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
765 parse_command_line(argc, argv);
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
766 if (stop_after == PHASE_DEFAULT)
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
767 stop_after = PHASE_LINK;
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
768
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
769 if (verbose_mode)
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
770 printf("%s\n", VERSTRING);
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 (isysroot == NULL)
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
773 isysroot = sysroot;
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
774 expand_sysroot();
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
775
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
776 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
777 {
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
778 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
779 }
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 // default to stdout for preprocessing
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
782 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
783 output_file = "-";
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
784
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
785 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
786 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
787
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
788 /* handle -B here */
291
83f682ed4d65 Make lwcc driver understand -B
William Astle <lost@l-w.ca>
parents: 288
diff changeset
789 ap = lw_alloc(strlen(basedir) + 10);
83f682ed4d65 Make lwcc driver understand -B
William Astle <lost@l-w.ca>
parents: 288
diff changeset
790 strcpy(ap, basedir);
83f682ed4d65 Make lwcc driver understand -B
William Astle <lost@l-w.ca>
parents: 288
diff changeset
791 strcat(ap, "/bin");
83f682ed4d65 Make lwcc driver understand -B
William Astle <lost@l-w.ca>
parents: 288
diff changeset
792 lw_stringlist_addstring(program_dirs, ap);
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, "/lib");
83f682ed4d65 Make lwcc driver understand -B
William Astle <lost@l-w.ca>
parents: 288
diff changeset
795 lw_stringlist_addstring(runtime_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, "/include");
83f682ed4d65 Make lwcc driver understand -B
William Astle <lost@l-w.ca>
parents: 288
diff changeset
798 lw_stringlist_addstring(priv_sysincdirs, ap);
83f682ed4d65 Make lwcc driver understand -B
William Astle <lost@l-w.ca>
parents: 288
diff changeset
799 lw_free(ap);
288
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
800
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
801 retval = 0;
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
802 /* 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
803 signal(SIGTERM, exit_on_signal);
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
804
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
805 /* handle input files */
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
806 lw_stringlist_reset(input_files);
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
807 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
808 {
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
809 if (handle_input_file(ap))
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
810 retval = 1;
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
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
813 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
814 {
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
815 retval = handle_linking();
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
816 }
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 /* 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
819 if (sigterm_received)
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
820 do_warning("Terminating on signal");
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
821
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
822 /* clean up temporary files */
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
823 if (!save_temps)
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 lw_stringlist_reset(tempfiles);
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
826 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
827 {
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
828 if (unlink(ap) == -1)
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
829 {
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
830 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
831 }
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 if (temp_directory)
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 if (rmdir(temp_directory) == -1)
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
836 {
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
837 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
838 }
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 }
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 /* 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
843 lw_stringlist_destroy(input_files);
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
844 lw_stringlist_destroy(runtime_dirs);
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
845 lw_stringlist_destroy(lib_dirs);
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
846 lw_stringlist_destroy(program_dirs);
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
847 lw_stringlist_destroy(preproc_args);
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
848 lw_stringlist_destroy(include_dirs);
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
849 lw_stringlist_destroy(user_sysincdirs);
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
850 lw_stringlist_destroy(asm_args);
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
851 lw_stringlist_destroy(linker_args);
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
852 lw_stringlist_destroy(sysincdirs);
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
853 lw_stringlist_destroy(includes);
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
854 lw_stringlist_destroy(tempfiles);
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
855 lw_stringlist_destroy(compiler_args);
291
83f682ed4d65 Make lwcc driver understand -B
William Astle <lost@l-w.ca>
parents: 288
diff changeset
856 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
857 return retval;
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
858 }
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
859
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
860 struct option_e
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 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
863 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
864 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
865 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
866 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
867 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
868 };
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
869
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
870 enum CMD_MISC {
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
871 CMD_MISC_VERSION,
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
872 CMD_MISC_OPTIMIZE,
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
873 };
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
874
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
875 enum OPT_ARG {
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
876 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
877 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
878 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
879 };
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
880
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
881 /* 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
882 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
883 {
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
884 *((int *)optptr) = optcode;
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
885 return 0;
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
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
888 /* 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
889 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
890 {
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
891 char **s = (char **)optptr;
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
892 *s = optarg;
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 return 0;
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
895 }
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 /* 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
898 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
899 {
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
900 char **s = (char **)optptr;
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
901
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
902 if (*s)
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
903 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
904 *s = optarg;
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
905
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
906 return 0;
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
907 }
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 /* 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
910 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
911 {
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
912 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
913 char *next;
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 for (; arg != NULL; arg = next)
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
916 {
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
917 next = strchr(arg, ',');
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
918 if (next != NULL)
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
919 *next++ = '\0';
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
920 lw_stringlist_addstring(l, arg);
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
921 }
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
922 return 0;
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
923 }
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 /* 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
926 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
927 {
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
928 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
929
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
930 lw_stringlist_addstring(l, opt);
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
931 return 0;
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
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
934 /* 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
935 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
936 {
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
937 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
938
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
939 lw_stringlist_addstring(l, optarg);
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
940 return 0;
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
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
943 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
944 {
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
945 switch (optcode)
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
946 {
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
947 case CMD_MISC_VERSION:
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
948 printf("%s\n", VERSTRING);
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
949 exit(0);
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
950
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
951 case CMD_MISC_OPTIMIZE:
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
952 if (!optarg)
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
953 return 0;
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
954 switch (*optarg)
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
955 {
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
956 case '0':
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
957 case '1':
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
958 case '2':
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
959 case '3':
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
960 case 's':
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
961 return 0;
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
962 }
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
963 return -1;
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
964
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
965 default:
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 return 0;
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
969 }
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 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
972 {
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
973 int *iv = (int *)optptr;
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
974
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
975 if (*iv && *iv != optcode)
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
976 {
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
977 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
978 }
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
979 *iv = optcode;
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
980 return 0;
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
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
983 struct option_e optionlist[] =
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 { "--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
986 { "--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
987 { "-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
988 { "-C", 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
989 { "-c", OPT_ARG_OPT, 1, PHASE_COMPILE, &stop_after, cmdline_set_intifzero },
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
990 { "-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
991 { "-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
992 { "-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
993 { "-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
994 { "-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
995 { "-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
996 { "-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
997 { "-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
998 { "-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
999 { "-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
1000 { "-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
1001 { "-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
1002 { "-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
1003 { "-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
1004 { "-o", OPT_ARG_SEP, 0, 2, &output_file, cmdline_set_stringifnull },
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
1005 { "-S", OPT_ARG_OPT, 1, PHASE_ASSEMBLE, &stop_after, cmdline_set_intifzero },
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
1006 { "-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
1007 { "-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
1008 { "-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
1009 { "-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
1010 { "-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
1011 { "-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
1012 { "-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
1013 { "-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
1014 { "-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
1015 { NULL, 0, 0 }
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
1016 };
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
1017
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
1018 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
1019 {
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
1020 int i, j, olen, ilen;
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
1021 char *optarg;
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 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
1024 {
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
1025 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
1026 {
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
1027 /* 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
1028 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
1029 continue;
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
1030 }
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
1031 olen = strlen(argv[i]);
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
1032 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
1033 {
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
1034 ilen = strlen(optionlist[j].optbase);
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
1035 /* 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
1036 if (ilen > olen)
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
1037 continue;
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
1038 /* does the base match? */
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
1039 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
1040 break;
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
1041 }
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
1042 if (optionlist[j].optbase == NULL)
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
1043 {
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
1044 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
1045 }
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
1046 /* 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
1047 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
1048 {
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
1049 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
1050 }
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
1051 /* is there an argument? */
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
1052 optarg = NULL;
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
1053 if (argv[i][ilen])
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
1054 optarg = argv[i] + ilen;
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
1055 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
1056 {
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
1057 if (i == argc)
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
1058 {
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
1059 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
1060 }
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
1061 optarg = argv[++i];
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
1062 }
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
1063 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
1064 {
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
1065 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
1066 }
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
1067 /* handle the option */
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
1068 if (optionlist[j].fn)
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 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
1071 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
1072 }
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
1073 }
fc76f1a0dc49 Initial version of lwcc compiler driver and Makefile infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
1074 }