mirror of
https://github.com/Nexoniarz/Finch.git
synced 2026-11-03 08:54:25 +00:00
-I <dir>: look for imported C headers there too (an SDK's headers)
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
parent
68637a35a7
commit
5f2ba99f2d
2 changed files with 6 additions and 2 deletions
|
|
@ -12,7 +12,7 @@ Everything in Finch on one page. For explanations, see the [guides](../../README
|
||||||
|---|---|
|
|---|---|
|
||||||
| `finch run file.fch [args…]` | compile and run (args go to the program) |
|
| `finch run file.fch [args…]` | compile and run (args go to the program) |
|
||||||
| `finch build file.fch [-o name]` | make a program (`name.exe` on Windows) |
|
| `finch build file.fch [-o name]` | make a program (`name.exe` on Windows) |
|
||||||
| `finch build file.fch --shared` | make a library (`libfile.so`, `file.dll`) that a C program loads; its `export fn`s are its C functions (numbers, bool, char, pointers) |
|
| `finch build file.fch --shared [-I dir]` | make a library (`libfile.so`, `file.dll`) that a C program loads; its `export fn`s are its C functions (numbers, bool, char, pointers) |
|
||||||
| `finch ir file.fch` | print the LLVM IR |
|
| `finch ir file.fch` | print the LLVM IR |
|
||||||
| `finch lsp` | the language server (editors use it) |
|
| `finch lsp` | the language server (editors use it) |
|
||||||
| `finch version` | version |
|
| `finch version` | version |
|
||||||
|
|
|
||||||
|
|
@ -42,6 +42,7 @@ static void usage() {
|
||||||
" finch lsp the language server, for editors (VS Code, Kate, ...)\n"
|
" finch lsp the language server, for editors (VS Code, Kate, ...)\n"
|
||||||
"\n"
|
"\n"
|
||||||
" -l <lib> link a C library, same as link \"lib\" in the file\n"
|
" -l <lib> link a C library, same as link \"lib\" in the file\n"
|
||||||
|
" -I <dir> also look for imported C headers in dir\n"
|
||||||
" --shared (build) a library with no main: lib<name>.so / <name>.dll, its export fn's callable from C\n"
|
" --shared (build) a library with no main: lib<name>.so / <name>.dll, its export fn's callable from C\n"
|
||||||
" --target <name> build for another system: windows, linux, arm64 (Linux), macos,\n"
|
" --target <name> build for another system: windows, linux, arm64 (Linux), macos,\n"
|
||||||
" or an LLVM triple\n"
|
" or an LLVM triple\n"
|
||||||
|
|
@ -281,7 +282,7 @@ int main(int argc, char **argv) {
|
||||||
std::string cmd = argv[1], file = argv[2];
|
std::string cmd = argv[1], file = argv[2];
|
||||||
if (cmd != "run" && cmd != "build" && cmd != "ir") usage();
|
if (cmd != "run" && cmd != "build" && cmd != "ir") usage();
|
||||||
std::string out = stem(file);
|
std::string out = stem(file);
|
||||||
std::vector<std::string> libs, programArgs;
|
std::vector<std::string> libs, programArgs, includeDirs;
|
||||||
std::string targetName;
|
std::string targetName;
|
||||||
bool optimizeCode = true, debug = false, outGiven = false;
|
bool optimizeCode = true, debug = false, outGiven = false;
|
||||||
for (int i = 3; i < argc; i++) {
|
for (int i = 3; i < argc; i++) {
|
||||||
|
|
@ -292,6 +293,8 @@ int main(int argc, char **argv) {
|
||||||
else if (a == "-O0") optimizeCode = false;
|
else if (a == "-O0") optimizeCode = false;
|
||||||
else if (a == "-g") debug = true;
|
else if (a == "-g") debug = true;
|
||||||
else if (a == "--shared" && cmd == "build") g_target.shared = true;
|
else if (a == "--shared" && cmd == "build") g_target.shared = true;
|
||||||
|
else if (a == "-I" && i + 1 < argc) includeDirs.push_back(argv[++i]);
|
||||||
|
else if (a.rfind("-I", 0) == 0 && a.size() > 2) includeDirs.push_back(a.substr(2));
|
||||||
else if (a == "-l" && i + 1 < argc) libs.push_back(argv[++i]);
|
else if (a == "-l" && i + 1 < argc) libs.push_back(argv[++i]);
|
||||||
else if (a.rfind("-l", 0) == 0 && a.size() > 2) libs.push_back(a.substr(2));
|
else if (a.rfind("-l", 0) == 0 && a.size() > 2) libs.push_back(a.substr(2));
|
||||||
else if (cmd == "run") programArgs.push_back(a);
|
else if (cmd == "run") programArgs.push_back(a);
|
||||||
|
|
@ -316,6 +319,7 @@ int main(int argc, char **argv) {
|
||||||
}
|
}
|
||||||
if (std::find(dirs.begin(), dirs.end(), dirOf(p.path)) == dirs.end()) dirs.push_back(dirOf(p.path));
|
if (std::find(dirs.begin(), dirs.end(), dirOf(p.path)) == dirs.end()) dirs.push_back(dirOf(p.path));
|
||||||
}
|
}
|
||||||
|
dirs.insert(dirs.end(), includeDirs.begin(), includeDirs.end()); // -I: after the files' own folders
|
||||||
CImports c = importHeaders(allImports, dirs);
|
CImports c = importHeaders(allImports, dirs);
|
||||||
LLVMContext ctx;
|
LLVMContext ctx;
|
||||||
TargetMachine *tm = targetMachine();
|
TargetMachine *tm = targetMachine();
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue