Mercurial > hg > index.cgi
comparison lwcc/driver/main.c @ 291:83f682ed4d65 ccdev
Make lwcc driver understand -B
Make the lwcc driver program actually do something with -B. Also teach it
about its own default base directory.
author | William Astle <lost@l-w.ca> |
---|---|
date | Sun, 08 Sep 2013 17:08:50 -0600 |
parents | fc76f1a0dc49 |
children |
comparison
equal
deleted
inserted
replaced
290:c648fc4bd006 | 291:83f682ed4d65 |
---|---|
32 #include <lw_alloc.h> | 32 #include <lw_alloc.h> |
33 #include <lw_string.h> | 33 #include <lw_string.h> |
34 #include <lw_stringlist.h> | 34 #include <lw_stringlist.h> |
35 | 35 |
36 #define VERSTRING "lwcc from " PACKAGE_STRING | 36 #define VERSTRING "lwcc from " PACKAGE_STRING |
37 #define S(x) S2(x) | |
38 #define S2(x) #x | |
39 | |
40 #define BASEDIR S(LWCC_LIBDIR) | |
37 | 41 |
38 /* list of compilation phases */ | 42 /* list of compilation phases */ |
39 enum phase_t { | 43 enum phase_t { |
40 PHASE_DEFAULT = 0, | 44 PHASE_DEFAULT = 0, |
41 PHASE_PREPROCESS, | 45 PHASE_PREPROCESS, |
75 int debug_mode = 0; // set if -g specified | 79 int debug_mode = 0; // set if -g specified |
76 int pic_mode = 0; // set to 1 if -fpic, 2 if -fPIC; last one specified wins | 80 int pic_mode = 0; // set to 1 if -fpic, 2 if -fPIC; last one specified wins |
77 const char *output_file; // set to the value of the -o option (output file) | 81 const char *output_file; // set to the value of the -o option (output file) |
78 | 82 |
79 /* compiler base directory - from -B */ | 83 /* compiler base directory - from -B */ |
80 const char *basedir = NULL; | 84 const char *basedir = BASEDIR; |
81 | 85 |
82 /* used to ensure a unique temporary file at every stage */ | 86 /* used to ensure a unique temporary file at every stage */ |
83 static int file_counter = 0; | 87 static int file_counter = 0; |
84 | 88 |
85 /* these are various string lists used to keep track of things, mostly | 89 /* these are various string lists used to keep track of things, mostly |
96 lw_stringlist_t asm_args; // recorded arguments to pass through to the assembler | 100 lw_stringlist_t asm_args; // recorded arguments to pass through to the assembler |
97 lw_stringlist_t linker_args; // recorded arguments to pass through to the linker | 101 lw_stringlist_t linker_args; // recorded arguments to pass through to the linker |
98 lw_stringlist_t sysincdirs; // the standard system include directories | 102 lw_stringlist_t sysincdirs; // the standard system include directories |
99 lw_stringlist_t tempfiles; // a list of temporary files created which need to be cleaned up | 103 lw_stringlist_t tempfiles; // a list of temporary files created which need to be cleaned up |
100 lw_stringlist_t compiler_args; // recorded arguments to pass through to the compiler | 104 lw_stringlist_t compiler_args; // recorded arguments to pass through to the compiler |
105 lw_stringlist_t priv_sysincdirs; // system include directories for lwcc itself | |
101 | 106 |
102 /* forward delcarations */ | 107 /* forward delcarations */ |
103 static void parse_command_line(int, char **); | 108 static void parse_command_line(int, char **); |
104 | 109 |
105 /* signal handler for SIGTERM - all it does is record the fact that | 110 /* signal handler for SIGTERM - all it does is record the fact that |
154 isysroot settings. Note that it does NOT apply to the compiler | 159 isysroot settings. Note that it does NOT apply to the compiler |
155 program search path */ | 160 program search path */ |
156 static void expand_sysroot(void) | 161 static void expand_sysroot(void) |
157 { | 162 { |
158 /* list of path lists to process for replacements of = */ | 163 /* list of path lists to process for replacements of = */ |
159 lw_stringlist_t *lists[] = { &runtime_dirs, &sysincdirs, &include_dirs, &user_sysincdirs, &lib_dirs, NULL }; | 164 lw_stringlist_t *lists[] = { &sysincdirs, &include_dirs, &user_sysincdirs, &lib_dirs, NULL }; |
160 /* list of replacement strings for = in the same order */ | 165 /* list of replacement strings for = in the same order */ |
161 const char *sysroots[] = { sysroot, isysroot, isysroot, isysroot, sysroot, NULL }; | 166 const char *sysroots[] = { isysroot, isysroot, isysroot, sysroot, NULL }; |
162 size_t i, sysroot_len, value_len; | 167 size_t i, sysroot_len, value_len; |
163 char *path; | 168 char *path; |
164 lw_stringlist_t newlist; | 169 lw_stringlist_t newlist; |
165 lw_stringlist_t working; | 170 lw_stringlist_t working; |
166 char *s; | 171 char *s; |
528 } | 533 } |
529 | 534 |
530 /* and, if not -nostdinc, the standard system include directories */ | 535 /* and, if not -nostdinc, the standard system include directories */ |
531 if (!nostdinc) | 536 if (!nostdinc) |
532 { | 537 { |
538 lw_stringlist_reset(priv_sysincdirs); | |
539 for (s = lw_stringlist_current(priv_sysincdirs); s; s = lw_stringlist_next(priv_sysincdirs)) | |
540 { | |
541 lw_stringlist_addstring(args, "-S"); | |
542 lw_stringlist_addstring(args, s); | |
543 } | |
533 lw_stringlist_reset(sysincdirs); | 544 lw_stringlist_reset(sysincdirs); |
534 for (s = lw_stringlist_current(sysincdirs); s; s = lw_stringlist_next(sysincdirs)) | 545 for (s = lw_stringlist_current(sysincdirs); s; s = lw_stringlist_next(sysincdirs)) |
535 { | 546 { |
536 lw_stringlist_addstring(args, "-S"); | 547 lw_stringlist_addstring(args, "-S"); |
537 lw_stringlist_addstring(args, s); | 548 lw_stringlist_addstring(args, s); |
745 linker_args = lw_stringlist_create(); | 756 linker_args = lw_stringlist_create(); |
746 sysincdirs = lw_stringlist_create(); | 757 sysincdirs = lw_stringlist_create(); |
747 includes = lw_stringlist_create(); | 758 includes = lw_stringlist_create(); |
748 tempfiles = lw_stringlist_create(); | 759 tempfiles = lw_stringlist_create(); |
749 compiler_args = lw_stringlist_create(); | 760 compiler_args = lw_stringlist_create(); |
750 | 761 priv_sysincdirs = lw_stringlist_create(); |
762 | |
751 parse_command_line(argc, argv); | 763 parse_command_line(argc, argv); |
752 if (stop_after == PHASE_DEFAULT) | 764 if (stop_after == PHASE_DEFAULT) |
753 stop_after = PHASE_LINK; | 765 stop_after = PHASE_LINK; |
754 | 766 |
755 if (verbose_mode) | 767 if (verbose_mode) |
770 | 782 |
771 if (lw_stringlist_nstrings(input_files) == 0) | 783 if (lw_stringlist_nstrings(input_files) == 0) |
772 do_error("No input files specified"); | 784 do_error("No input files specified"); |
773 | 785 |
774 /* handle -B here */ | 786 /* handle -B here */ |
787 ap = lw_alloc(strlen(basedir) + 10); | |
788 strcpy(ap, basedir); | |
789 strcat(ap, "/bin"); | |
790 lw_stringlist_addstring(program_dirs, ap); | |
791 strcpy(ap, basedir); | |
792 strcat(ap, "/lib"); | |
793 lw_stringlist_addstring(runtime_dirs, ap); | |
794 strcpy(ap, basedir); | |
795 strcat(ap, "/include"); | |
796 lw_stringlist_addstring(priv_sysincdirs, ap); | |
797 lw_free(ap); | |
775 | 798 |
776 retval = 0; | 799 retval = 0; |
777 /* make sure we exit if interrupted */ | 800 /* make sure we exit if interrupted */ |
778 signal(SIGTERM, exit_on_signal); | 801 signal(SIGTERM, exit_on_signal); |
779 | 802 |
826 lw_stringlist_destroy(linker_args); | 849 lw_stringlist_destroy(linker_args); |
827 lw_stringlist_destroy(sysincdirs); | 850 lw_stringlist_destroy(sysincdirs); |
828 lw_stringlist_destroy(includes); | 851 lw_stringlist_destroy(includes); |
829 lw_stringlist_destroy(tempfiles); | 852 lw_stringlist_destroy(tempfiles); |
830 lw_stringlist_destroy(compiler_args); | 853 lw_stringlist_destroy(compiler_args); |
831 | 854 lw_stringlist_destroy(priv_sysincdirs); |
832 return retval; | 855 return retval; |
833 } | 856 } |
834 | 857 |
835 struct option_e | 858 struct option_e |
836 { | 859 { |