Made the parser more path compatible to other OS\'s, especially Windows. (0.13.0)
This commit is contained in:
parent
3282a2c098
commit
08b1680bc6
3 changed files with 46 additions and 18 deletions
|
|
@ -1,5 +1,5 @@
|
||||||
cmake_minimum_required(VERSION 3.16)
|
cmake_minimum_required(VERSION 3.16)
|
||||||
project(fun VERSION 0.12.6 LANGUAGES C)
|
project(fun VERSION 0.13.0 LANGUAGES C)
|
||||||
|
|
||||||
set(CMAKE_C_STANDARD 11)
|
set(CMAKE_C_STANDARD 11)
|
||||||
set(CMAKE_C_STANDARD_REQUIRED ON)
|
set(CMAKE_C_STANDARD_REQUIRED ON)
|
||||||
|
|
@ -69,7 +69,7 @@ install(TARGETS fun
|
||||||
|
|
||||||
# Libs
|
# Libs
|
||||||
install(DIRECTORY lib/
|
install(DIRECTORY lib/
|
||||||
DESTINATION /usr/lib/fun
|
DESTINATION /usr/share/fun/lib
|
||||||
FILES_MATCHING PATTERN "*.fun")
|
FILES_MATCHING PATTERN "*.fun")
|
||||||
|
|
||||||
# Optionally install example scripts
|
# Optionally install example scripts
|
||||||
|
|
|
||||||
15
Makefile
15
Makefile
|
|
@ -10,6 +10,21 @@ CMAKE_FLAGS ?= -DFUN_DEBUG=OFF
|
||||||
ifneq ($(strip $(DEFAULT_LIB_DIR)),)
|
ifneq ($(strip $(DEFAULT_LIB_DIR)),)
|
||||||
CMAKE_FLAGS += -DCMAKE_C_FLAGS="$(CMAKE_C_FLAGS) -DDEFAULT_LIB_DIR=\\\"$(DEFAULT_LIB_DIR)/\\\""
|
CMAKE_FLAGS += -DCMAKE_C_FLAGS="$(CMAKE_C_FLAGS) -DDEFAULT_LIB_DIR=\\\"$(DEFAULT_LIB_DIR)/\\\""
|
||||||
CMAKE_FLAGS += -DCMAKE_CXX_FLAGS="$(CMAKE_CXX_FLAGS) -DDEFAULT_LIB_DIR=\\\"$(DEFAULT_LIB_DIR)/\\\""
|
CMAKE_FLAGS += -DCMAKE_CXX_FLAGS="$(CMAKE_CXX_FLAGS) -DDEFAULT_LIB_DIR=\\\"$(DEFAULT_LIB_DIR)/\\\""
|
||||||
|
else
|
||||||
|
# Provide OS-specific defaults for Windows, macOS, Linux/Unix
|
||||||
|
ifeq ($(OS),Windows_NT)
|
||||||
|
CMAKE_FLAGS += -DCMAKE_C_FLAGS="$(CMAKE_C_FLAGS) -DDEFAULT_LIB_DIR=\\\"C:/Users/Public/fun/lib/\\\""
|
||||||
|
CMAKE_FLAGS += -DCMAKE_CXX_FLAGS="$(CMAKE_CXX_FLAGS) -DDEFAULT_LIB_DIR=\\\"C:/Users/Public/fun/lib/\\\""
|
||||||
|
else
|
||||||
|
UNAME_S := $(shell uname -s)
|
||||||
|
ifeq ($(UNAME_S),Darwin)
|
||||||
|
CMAKE_FLAGS += -DCMAKE_C_FLAGS="$(CMAKE_C_FLAGS) -DDEFAULT_LIB_DIR=\\\"/Library/Application Support/fun/lib/\\\""
|
||||||
|
CMAKE_FLAGS += -DCMAKE_CXX_FLAGS="$(CMAKE_CXX_FLAGS) -DDEFAULT_LIB_DIR=\\\"/Library/Application Support/fun/lib/\\\""
|
||||||
|
else
|
||||||
|
CMAKE_FLAGS += -DCMAKE_C_FLAGS="$(CMAKE_C_FLAGS) -DDEFAULT_LIB_DIR=\\\"/usr/share/fun/lib/\\\""
|
||||||
|
CMAKE_FLAGS += -DCMAKE_CXX_FLAGS="$(CMAKE_CXX_FLAGS) -DDEFAULT_LIB_DIR=\\\"/usr/share/fun/lib/\\\""
|
||||||
|
endif
|
||||||
|
endif
|
||||||
endif
|
endif
|
||||||
|
|
||||||
.PHONY: all configure build fun fun_test test_opcodes clean distclean install repl run
|
.PHONY: all configure build fun fun_test test_opcodes clean distclean install repl run
|
||||||
|
|
|
||||||
|
|
@ -265,7 +265,7 @@ static char *preprocess_includes_internal(const char *src, int depth) {
|
||||||
|
|
||||||
/* Build-time default, can be overridden by compiler define -DDEFAULT_LIB_DIR=".../" */
|
/* Build-time default, can be overridden by compiler define -DDEFAULT_LIB_DIR=".../" */
|
||||||
#ifndef DEFAULT_LIB_DIR
|
#ifndef DEFAULT_LIB_DIR
|
||||||
#define DEFAULT_LIB_DIR "/usr/lib/fun/"
|
#define DEFAULT_LIB_DIR "/usr/share/fun/lib/"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
const char *env_lib = getenv("FUN_LIB_DIR");
|
const char *env_lib = getenv("FUN_LIB_DIR");
|
||||||
|
|
@ -316,37 +316,50 @@ static char *preprocess_includes_internal(const char *src, int depth) {
|
||||||
char *inc = NULL;
|
char *inc = NULL;
|
||||||
|
|
||||||
if (opener == '<') {
|
if (opener == '<') {
|
||||||
/* Attempt environment override if provided */
|
/* Angle-bracket include resolution order:
|
||||||
|
* 1) FUN_LIB_DIR (env), respecting '/' or '\' endings
|
||||||
|
* 2) DEFAULT_LIB_DIR (compile-time define)
|
||||||
|
* 3) "lib/" under current working directory (developer fallback)
|
||||||
|
*
|
||||||
|
* Always assign 'resolved' to the last attempted candidate so errors are informative.
|
||||||
|
*/
|
||||||
|
resolved[0] = '\0';
|
||||||
|
|
||||||
|
/* 1) FUN_LIB_DIR */
|
||||||
if (env_lib && env_lib[0]) {
|
if (env_lib && env_lib[0]) {
|
||||||
size_t elen = strlen(env_lib);
|
size_t elen = strlen(env_lib);
|
||||||
int needs_slash = (elen > 0 && env_lib[elen - 1] != '/');
|
char last = env_lib[elen ? (elen - 1) : 0];
|
||||||
if (needs_slash)
|
int needs_sep = !(last == '/' || last == '\\');
|
||||||
snprintf(resolved, sizeof(resolved), "%s/%s", env_lib, path);
|
char sep = (last == '\\') ? '\\' : '/';
|
||||||
|
if (needs_sep)
|
||||||
|
snprintf(resolved, sizeof(resolved), "%s%c%s", env_lib, sep, path);
|
||||||
else
|
else
|
||||||
snprintf(resolved, sizeof(resolved), "%s%s", env_lib, path);
|
snprintf(resolved, sizeof(resolved), "%s%s", env_lib, path);
|
||||||
inc = read_file_all(resolved, &inc_len);
|
inc = read_file_all(resolved, &inc_len);
|
||||||
}
|
}
|
||||||
/* Fallback to default lib dir */
|
|
||||||
|
/* 2) DEFAULT_LIB_DIR */
|
||||||
if (!inc) {
|
if (!inc) {
|
||||||
snprintf(resolved2, sizeof(resolved2), "%s%s", DEFAULT_LIB_DIR, path);
|
snprintf(resolved, sizeof(resolved), "%s%s", DEFAULT_LIB_DIR, path);
|
||||||
inc = read_file_all(resolved2, &inc_len);
|
inc = read_file_all(resolved, &inc_len);
|
||||||
if (inc) {
|
|
||||||
/* reflect the actual resolved path in annotations */
|
|
||||||
strncpy(resolved, resolved2, sizeof(resolved) - 1);
|
|
||||||
resolved[sizeof(resolved) - 1] = '\0';
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* 3) project-local dev fallback: lib/<path> */
|
||||||
|
if (!inc) {
|
||||||
|
snprintf(resolved, sizeof(resolved), "lib/%s", path);
|
||||||
|
inc = read_file_all(resolved, &inc_len);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
/* quoted include: relative path */
|
/* quoted include: relative path (cwd) */
|
||||||
snprintf(resolved, sizeof(resolved), "%s", path);
|
snprintf(resolved, sizeof(resolved), "%s", path);
|
||||||
inc = read_file_all(resolved, &inc_len);
|
inc = read_file_all(resolved, &inc_len);
|
||||||
}
|
}
|
||||||
free(path);
|
free(path);
|
||||||
|
|
||||||
if (!inc) {
|
if (!inc) {
|
||||||
fprintf(stderr, "Include error: cannot read '%s'\n", resolved);
|
fprintf(stderr, "Include error: cannot read '%s'\n", resolved[0] ? resolved : "(unresolved)");
|
||||||
sb_append(&out, "// include error: cannot read ");
|
sb_append(&out, "// include error: cannot read ");
|
||||||
sb_append(&out, resolved);
|
sb_append(&out, resolved[0] ? resolved : "(unresolved)");
|
||||||
sb_append(&out, "\n");
|
sb_append(&out, "\n");
|
||||||
} else {
|
} else {
|
||||||
char *exp = preprocess_includes_internal(inc, depth + 1);
|
char *exp = preprocess_includes_internal(inc, depth + 1);
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue