Commit 14a39043
14a39043ba59Merged
Yukihiro "Matz" Matsumoto <[email protected]> · 8 months ago · 1 file · ~1 modified
Description
Auto-detect lib/ next to spinel binary as default --lib path
No need to specify --lib=lib/ explicitly. The compiler automatically searches <exe_dir>/lib/ for require resolution.
Co-Authored-By: Claude Opus 4.6 (1M context) [email protected]
Details
- Commit
- 14a39043ba59
- Parent
- e7bed1a38e26
src/main.cmodifiedView file
@@ -7,6 +7,7 @@
77
#include <stdio.h>88
#include <stdlib.h>99
#include <string.h>10+
#include <limits.h>1011
#include <prism.h>1112
#include "codegen.h"1213
@@ -71,6 +72,17 @@
7172
return 1;7273
}7374
75+
/* Default lib path: <exe_dir>/lib/ */76+
if (lib_path_count == 0) {77+
static char default_lib[4096];78+
char exe_dir[4096];79+
snprintf(exe_dir, sizeof(exe_dir), "%s", argv[0]);80+
char *slash = strrchr(exe_dir, '/');81+
if (slash) *slash = '\0'; else snprintf(exe_dir, sizeof(exe_dir), ".");82+
snprintf(default_lib, sizeof(default_lib), "%s/lib", exe_dir);83+
lib_paths[lib_path_count++] = default_lib;84+
}85+
7486
/* Read source file */7587
size_t source_len;7688
char *source = read_file(source_path, &source_len);