mirror of
https://github.com/mirror/tinycc.git
synced 2024-12-28 04:00:06 +08:00
macOS: get active SDK path from xcode-select
This commit is contained in:
parent
d5e4b258e1
commit
cca4ece0a8
29
libtcc.c
29
libtcc.c
@ -855,6 +855,29 @@ LIBTCCAPI void tcc_delete(TCCState *s1)
|
||||
#endif
|
||||
}
|
||||
|
||||
/* Looks for the active developer SDK set by xcode-select (or the default
|
||||
one set during installation.) */
|
||||
#define SZPAIR(s) s "", sizeof(s)-1
|
||||
ST_FUNC int tcc_add_macos_sdkpath(TCCState* s)
|
||||
{
|
||||
char *sdkroot = NULL, *pos = NULL;
|
||||
void* xcs = dlopen("libxcselect.dylib", RTLD_GLOBAL | RTLD_LAZY);
|
||||
CString path = {};
|
||||
int (*f)(unsigned int, char**) = dlsym(xcs, "xcselect_host_sdk_path");
|
||||
|
||||
if (f) f(1, &sdkroot);
|
||||
if (!sdkroot) return -1;
|
||||
pos = strstr(sdkroot,"SDKs/MacOSX");
|
||||
if (!pos) return -1;
|
||||
cstr_cat(&path, sdkroot, pos-sdkroot);
|
||||
cstr_cat(&path, SZPAIR("SDKs/MacOSX.sdk/usr/lib\0") );
|
||||
tcc_add_library_path(s, (char*)path.data);
|
||||
cstr_free(&path);
|
||||
tcc_free(sdkroot);
|
||||
return 0;
|
||||
}
|
||||
#undef SZPAIR
|
||||
|
||||
LIBTCCAPI int tcc_set_output_type(TCCState *s, int output_type)
|
||||
{
|
||||
s->output_type = output_type;
|
||||
@ -881,7 +904,11 @@ LIBTCCAPI int tcc_set_output_type(TCCState *s, int output_type)
|
||||
}
|
||||
|
||||
tcc_add_library_path(s, CONFIG_TCC_LIBPATHS);
|
||||
|
||||
#ifdef TCC_TARGET_MACHO
|
||||
if (tcc_add_macos_sdkpath(s) != 0) {
|
||||
tcc_add_library_path(s, CONFIG_OSX_SDK_FALLBACK);
|
||||
}
|
||||
#endif
|
||||
#ifdef TCC_TARGET_PE
|
||||
# ifdef _WIN32
|
||||
if (!s->nostdlib && output_type != TCC_OUTPUT_OBJ)
|
||||
|
24
tcc.h
24
tcc.h
@ -247,12 +247,6 @@ extern long double strtold (const char *__nptr, char **__endptr);
|
||||
# define ALSO_TRIPLET(s) s
|
||||
#endif
|
||||
|
||||
/* FIXME: do this at runtime instead; check output of `xcode-select -p`. libxcselect provides this stuff */
|
||||
#ifndef CONFIG_OSX_SDK1
|
||||
# define CONFIG_OSX_SDK1 "/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk"
|
||||
# define CONFIG_OSX_SDK2 "/Applications/Xcode.app/Developer/SDKs/MacOSX.sdk"
|
||||
#endif
|
||||
|
||||
/* path to find crt1.o, crti.o and crtn.o */
|
||||
#ifndef CONFIG_TCC_CRTPREFIX
|
||||
# define CONFIG_TCC_CRTPREFIX USE_TRIPLET(CONFIG_SYSROOT "/usr/" CONFIG_LDDIR)
|
||||
@ -281,18 +275,18 @@ extern long double strtold (const char *__nptr, char **__endptr);
|
||||
# ifdef TCC_TARGET_PE
|
||||
# define CONFIG_TCC_LIBPATHS "{B}/lib"
|
||||
# else
|
||||
# ifdef TCC_TARGET_MACHO
|
||||
# define CONFIG_TCC_LIBPATHS \
|
||||
ALSO_TRIPLET(CONFIG_SYSROOT "/usr/" CONFIG_LDDIR) \
|
||||
":" ALSO_TRIPLET(CONFIG_SYSROOT "/" CONFIG_LDDIR) \
|
||||
":" ALSO_TRIPLET(CONFIG_SYSROOT "/usr/local/" CONFIG_LDDIR)\
|
||||
":" ALSO_TRIPLET(CONFIG_OSX_SDK1 "/usr/" CONFIG_LDDIR) \
|
||||
":" ALSO_TRIPLET(CONFIG_OSX_SDK2 "/usr/" CONFIG_LDDIR)
|
||||
# else
|
||||
# define CONFIG_TCC_LIBPATHS \
|
||||
# define CONFIG_TCC_LIBPATHS \
|
||||
ALSO_TRIPLET(CONFIG_SYSROOT "/usr/" CONFIG_LDDIR) \
|
||||
":" ALSO_TRIPLET(CONFIG_SYSROOT "/" CONFIG_LDDIR) \
|
||||
":" ALSO_TRIPLET(CONFIG_SYSROOT "/usr/local/" CONFIG_LDDIR)
|
||||
# ifdef TCC_TARGET_MACHO
|
||||
# define CONFIG_OSX_SDK1 \
|
||||
"/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk"
|
||||
# define CONFIG_OSX_SDK2 \
|
||||
"/Applications/Xcode.app/Developer/SDKs/MacOSX.sdk"
|
||||
# define CONFIG_OSX_SDK_FALLBACK \
|
||||
ALSO_TRIPLET(CONFIG_OSX_SDK1 "/usr/" CONFIG_LDDIR) \
|
||||
":" ALSO_TRIPLET(CONFIG_OSX_SDK2 "/usr/" CONFIG_LDDIR)
|
||||
# endif
|
||||
# endif
|
||||
#endif
|
||||
|
Loading…
Reference in New Issue
Block a user