Mercurial > hg-old > index.cgi
annotate lwlink/main.c @ 180:6ebb93b409ba
Added library paths and --section-base
author | lost |
---|---|
date | Thu, 05 Mar 2009 02:23:25 +0000 |
parents | 3706ede361ea |
children | 833d392fec82 |
rev | line source |
---|---|
112 | 1 /* |
2 main.c | |
118 | 3 Copyright © 2009 William Astle |
112 | 4 |
5 This file is part of LWLINK. | |
6 | |
7 LWLINK is free software: you can redistribute it and/or modify it under the | |
8 terms of the GNU General Public License as published by the Free Software | |
9 Foundation, either version 3 of the License, or (at your option) any later | |
10 version. | |
11 | |
12 This program is distributed in the hope that it will be useful, but WITHOUT | |
13 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | |
14 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for | |
15 more details. | |
16 | |
17 You should have received a copy of the GNU General Public License along with | |
18 this program. If not, see <http://www.gnu.org/licenses/>. | |
19 | |
20 | |
21 Implements the program startup code | |
22 | |
23 */ | |
24 | |
25 #ifdef HAVE_CONFIG_H | |
26 #include "config.h" | |
27 #endif | |
28 | |
29 #include <argp.h> | |
30 #include <errno.h> | |
31 #include <stdio.h> | |
32 #include <stdlib.h> | |
33 | |
34 #include "lwlink.h" | |
35 | |
36 // command line option handling | |
142 | 37 const char *argp_program_version = "LWLINK from " PACKAGE_STRING; |
112 | 38 const char *argp_program_bug_address = PACKAGE_BUGREPORT; |
39 | |
40 static error_t parse_opts(int key, char *arg, struct argp_state *state) | |
41 { | |
42 switch (key) | |
43 { | |
44 case 'o': | |
45 // output | |
46 outfile = arg; | |
47 break; | |
48 | |
117 | 49 case 's': |
50 // script file | |
51 scriptfile = arg; | |
52 break; | |
53 | |
112 | 54 case 'd': |
55 // debug | |
56 debug_level++; | |
57 break; | |
58 | |
59 case 'b': | |
60 // decb output | |
61 outformat = OUTPUT_DECB; | |
62 break; | |
63 | |
64 case 'r': | |
65 // raw binary output | |
66 outformat = OUTPUT_RAW; | |
67 break; | |
68 | |
69 case 'f': | |
70 // output format | |
71 if (!strcasecmp(arg, "decb")) | |
72 outformat = OUTPUT_DECB; | |
73 else if (!strcasecmp(arg, "raw")) | |
74 outformat = OUTPUT_RAW; | |
75 else | |
76 { | |
77 fprintf(stderr, "Invalid output format: %s\n", arg); | |
78 exit(1); | |
79 } | |
80 break; | |
81 case ARGP_KEY_END: | |
82 // done; sanity check | |
83 if (!outfile) | |
84 outfile = "a.out"; | |
85 break; | |
86 | |
180 | 87 case 'l': |
88 add_input_library(arg); | |
89 break; | |
90 | |
91 case 'L': | |
92 add_library_search(arg); | |
93 break; | |
94 | |
95 case 0x100: | |
96 add_section_base(arg); | |
97 break; | |
98 | |
112 | 99 case ARGP_KEY_ARG: |
114
c65fcec346cd
Handle input files on command line and add some memory management utility functions
lost
parents:
112
diff
changeset
|
100 add_input_file(arg); |
112 | 101 break; |
102 | |
103 default: | |
104 return ARGP_ERR_UNKNOWN; | |
105 } | |
106 return 0; | |
107 } | |
108 | |
109 static struct argp_option options[] = | |
110 { | |
111 { "output", 'o', "FILE", 0, | |
112 "Output to FILE"}, | |
113 { "debug", 'd', 0, 0, | |
114 "Set debug mode"}, | |
115 { "format", 'f', "TYPE", 0, | |
149 | 116 "Select output format: decb, raw"}, |
112 | 117 { "decb", 'b', 0, 0, |
118 "Generate DECB .bin format output, equivalent of --format=decb"}, | |
119 { "raw", 'r', 0, 0, | |
120 "Generate raw binary format output, equivalent of --format=raw"}, | |
125
f9bfc2986023
Actually allow script file to be specified and fix segfault on parsing script file
lost
parents:
121
diff
changeset
|
121 { "script", 's', "FILE", 0, |
180 | 122 "Specify the linking script (overrides the built in defaults)"}, |
123 { "library", 'l', "LIBSPEC", 0, | |
124 "Read library libLIBSPEC.a from the search path" }, | |
125 { "library-path", 'L', "DIR", 0, | |
126 "Add DIR to the library search path" }, | |
127 { "section-base", 0x100, "SECT=BASE", 0, | |
128 "Load section SECT at BASE" }, | |
112 | 129 { 0 } |
130 }; | |
131 | |
132 static struct argp argp = | |
133 { | |
134 options, | |
135 parse_opts, | |
136 "<input file> ...", | |
137 "LWLINK, a HD6309 and MC6809 cross-linker" | |
138 }; | |
139 | |
115 | 140 extern void read_files(void); |
117 | 141 extern void setup_script(void); |
119 | 142 extern void resolve_sections(void); |
121 | 143 extern void resolve_references(void); |
144 extern void do_output(void); | |
115 | 145 |
112 | 146 // main function; parse command line, set up assembler state, and run the |
147 // assembler on the first file | |
148 int main(int argc, char **argv) | |
149 { | |
150 argp_parse(&argp, argc, argv, 0, 0, NULL); | |
114
c65fcec346cd
Handle input files on command line and add some memory management utility functions
lost
parents:
112
diff
changeset
|
151 if (ninputfiles == 0) |
c65fcec346cd
Handle input files on command line and add some memory management utility functions
lost
parents:
112
diff
changeset
|
152 { |
c65fcec346cd
Handle input files on command line and add some memory management utility functions
lost
parents:
112
diff
changeset
|
153 fprintf(stderr, "No input files\n"); |
c65fcec346cd
Handle input files on command line and add some memory management utility functions
lost
parents:
112
diff
changeset
|
154 exit(1); |
c65fcec346cd
Handle input files on command line and add some memory management utility functions
lost
parents:
112
diff
changeset
|
155 } |
115 | 156 |
119 | 157 // handle the linker script |
117 | 158 setup_script(); |
159 | |
115 | 160 // read the input files |
161 read_files(); | |
114
c65fcec346cd
Handle input files on command line and add some memory management utility functions
lost
parents:
112
diff
changeset
|
162 |
119 | 163 // resolve section bases and section order |
164 resolve_sections(); | |
165 | |
121 | 166 // resolve incomplete references |
167 resolve_references(); | |
168 | |
169 // do the actual output | |
170 do_output(); | |
171 | |
112 | 172 exit(0); |
173 } |