Skip to content

Commit 6366fcc

Browse files
committed
Store compiler path inside OS dependant code.
1 parent 636e9b4 commit 6366fcc

3 files changed

Lines changed: 23 additions & 13 deletions

File tree

src/compiler/main.cc

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -78,13 +78,11 @@ static std::string to_lower(std::string in)
7878
int main(int argc, char **argv)
7979
{
8080
// OS specific initializations
81-
os::init();
81+
os::init(argv[0]);
8282

83-
auto program_name = std::string(argv[0]);
84-
// Tries to guess install folder given the program name
85-
auto install_folder = os::dir_name(program_name);
86-
auto syntax_folder = os::full_path(install_folder, "syntax");
87-
auto target_folder = install_folder;
83+
// Default folders for target and syntax files
84+
auto syntax_folder = os::compiler_path("syntax");
85+
auto target_folder = os::compiler_path("");
8886
std::vector<std::string> args(argv + 1, argv + argc);
8987
std::string out_name;
9088
std::string exe_name;
@@ -283,9 +281,9 @@ int main(int argc, char **argv)
283281
std::cerr << e.what() << "\n";
284282
return 1;
285283
}
286-
std::string lib_name = os::full_path(install_folder, tgt.lib());
284+
std::string lib_name = os::compiler_path(tgt.lib());
287285
std::string cfg_file =
288-
cfg_file_def.size() ? cfg_file_def : os::full_path(install_folder, tgt.cfg());
286+
cfg_file_def.size() ? cfg_file_def : os::compiler_path(tgt.cfg());
289287
asm_opts.insert(asm_opts.end(), tgt.ca65_args().begin(), tgt.ca65_args().end());
290288

291289
// Guess final exe file name
@@ -308,13 +306,13 @@ int main(int argc, char **argv)
308306
}
309307
for(auto &f : asm_files)
310308
{
311-
auto ca65 = os::full_path(install_folder, "ca65");
309+
auto ca65 = os::compiler_path("ca65");
312310
auto asm_name = std::get<0>(f), obj_name = std::get<1>(f);
313311
auto lst_name = os::add_extension(obj_name, ".lst");
314312

315313
std::cerr << "ASM assemble '" << asm_name << "' to '" << obj_name << "'\n";
316314
std::vector<std::string> args{
317-
"ca65", "-I", os::full_path(install_folder, "asminc"), "-o", obj_name};
315+
"ca65", "-I", os::compiler_path("asminc"), "-o", obj_name};
318316
if(do_listing)
319317
args.insert(args.end(), {"-l", lst_name});
320318
for(auto &o : asm_opts)
@@ -328,7 +326,7 @@ int main(int argc, char **argv)
328326
}
329327
if(link_files.size())
330328
{
331-
auto ld65 = os::full_path(install_folder, "ld65");
329+
auto ld65 = os::compiler_path("ld65");
332330
//$LD65" -C "$CFGFILE" "$@" -o "$XEX" -Ln "$LBL" "$FB.lib"
333331
std::cerr << "LINK " << exe_name << "\n";
334332
std::vector<std::string> args{"ld65",

src/compiler/os.cc

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,8 @@ static const char *path_sep = "\\/";
3333
static const char *path_sep = "/";
3434
#endif
3535

36+
static std::string compiler_search_path;
37+
3638
bool os::path_absolute(const std::string &path)
3739
{
3840
if(path.find_first_of(path_sep) == 0)
@@ -100,14 +102,21 @@ std::string os::get_extension_lower(std::string name)
100102
return ret;
101103
}
102104

103-
void os::init()
105+
void os::init(const std::string &prog)
104106
{
105107
#ifdef _WIN32
106108
// On windows, we need to set console output to UTF-8:
107109
SetConsoleOutputCP(CP_UTF8);
108110
#else
109111
// No init needed.
110112
#endif
113+
// Store out program name
114+
compiler_search_path = dir_name(prog);
115+
}
116+
117+
std::string os::compiler_path(const std::string &filename)
118+
{
119+
return full_path(compiler_search_path, filename);
111120
}
112121

113122
int os::prog_exec(std::string exe, std::vector<std::string> &args)

src/compiler/os.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,9 @@
2424

2525
namespace os
2626
{
27+
// Locates a file or folder in the compiler data and
28+
// returns the path
29+
std::string compiler_path(const std::string &filename);
2730
// Appends a file name to a path
2831
std::string full_path(const std::string &path, const std::string &filename);
2932
// Returns the file name from a full path
@@ -41,7 +44,7 @@ std::string get_extension_lower(std::string name);
4144
// Execute external program, waiting for the result
4245
int prog_exec(std::string exe, std::vector<std::string> &args);
4346
// OS specific initializations
44-
void init();
47+
void init(const std::string &prog);
4548
// Remove a file
4649
void remove_file(const std::string &path);
4750

0 commit comments

Comments
 (0)