History

macOS: get active SDK path from xcode-select

Sushant Pandurangi committed 5 years ago

Commit cca4ece1 parent d5e4b252 files · +37 −16Browse files

Unified · Split

2 files
  1. libtcc.c +28 −1
  2. tcc.h +9 −15
libtcc.c+28−1
@@ -855,6 +855,29 @@ LIBTCCAPI void tcc_delete(TCCState *s1) · 854 unmodified lines
855#endif855#endif
856}856}
857 857
858/* Looks for the active developer SDK set by xcode-select (or the default
859 one set during installation.) */
860#define SZPAIR(s) s "", sizeof(s)-1
861ST_FUNC int tcc_add_macos_sdkpath(TCCState* s)
862{
863 char *sdkroot = NULL, *pos = NULL;
864 void* xcs = dlopen("libxcselect.dylib", RTLD_GLOBAL | RTLD_LAZY);
865 CString path = {};
866 int (*f)(unsigned int, char**) = dlsym(xcs, "xcselect_host_sdk_path");
867
868 if (f) f(1, &sdkroot);
869 if (!sdkroot) return -1;
870 pos = strstr(sdkroot,"SDKs/MacOSX");
871 if (!pos) return -1;
872 cstr_cat(&path, sdkroot, pos-sdkroot);
873 cstr_cat(&path, SZPAIR("SDKs/MacOSX.sdk/usr/lib\0") );
874 tcc_add_library_path(s, (char*)path.data);
875 cstr_free(&path);
876 tcc_free(sdkroot);
877 return 0;
878}
879#undef SZPAIR
880
858LIBTCCAPI int tcc_set_output_type(TCCState *s, int output_type)881LIBTCCAPI int tcc_set_output_type(TCCState *s, int output_type)
859{882{
860 s->output_type = output_type;883 s->output_type = output_type;
@@ -881,7 +904,11 @@ LIBTCCAPI int tcc_set_output_type(TCCState *s, int output_type) · 20 unmodified lines
881 }904 }
882 905
883 tcc_add_library_path(s, CONFIG_TCC_LIBPATHS);906 tcc_add_library_path(s, CONFIG_TCC_LIBPATHS);
884 907#ifdef TCC_TARGET_MACHO
908 if (tcc_add_macos_sdkpath(s) != 0) {
909 tcc_add_library_path(s, CONFIG_OSX_SDK_FALLBACK);
910 }
911#endif
885#ifdef TCC_TARGET_PE912#ifdef TCC_TARGET_PE
886# ifdef _WIN32913# ifdef _WIN32
887 if (!s->nostdlib && output_type != TCC_OUTPUT_OBJ)914 if (!s->nostdlib && output_type != TCC_OUTPUT_OBJ)
tcc.h+9−15
@@ -247,12 +247,6 @@ extern long double strtold (const char *__nptr, char **__endptr); · 246 unmodified lines
247# define ALSO_TRIPLET(s) s247# define ALSO_TRIPLET(s) s
248#endif248#endif
249 249
250/* FIXME: do this at runtime instead; check output of `xcode-select -p`. libxcselect provides this stuff */
251#ifndef CONFIG_OSX_SDK1
252# define CONFIG_OSX_SDK1 "/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk"
253# define CONFIG_OSX_SDK2 "/Applications/Xcode.app/Developer/SDKs/MacOSX.sdk"
254#endif
255
256/* path to find crt1.o, crti.o and crtn.o */250/* path to find crt1.o, crti.o and crtn.o */
257#ifndef CONFIG_TCC_CRTPREFIX251#ifndef CONFIG_TCC_CRTPREFIX
258# define CONFIG_TCC_CRTPREFIX USE_TRIPLET(CONFIG_SYSROOT "/usr/" CONFIG_LDDIR)252# define CONFIG_TCC_CRTPREFIX USE_TRIPLET(CONFIG_SYSROOT "/usr/" CONFIG_LDDIR)
@@ -281,18 +275,18 @@ extern long double strtold (const char *__nptr, char **__endptr); · 22 unmodified lines
281# ifdef TCC_TARGET_PE275# ifdef TCC_TARGET_PE
282# define CONFIG_TCC_LIBPATHS "{B}/lib"276# define CONFIG_TCC_LIBPATHS "{B}/lib"
283# else277# else
284# ifdef TCC_TARGET_MACHO278# define CONFIG_TCC_LIBPATHS \
285# define CONFIG_TCC_LIBPATHS \
286 ALSO_TRIPLET(CONFIG_SYSROOT "/usr/" CONFIG_LDDIR) \
287 ":" ALSO_TRIPLET(CONFIG_SYSROOT "/" CONFIG_LDDIR) \
288 ":" ALSO_TRIPLET(CONFIG_SYSROOT "/usr/local/" CONFIG_LDDIR)\
289 ":" ALSO_TRIPLET(CONFIG_OSX_SDK1 "/usr/" CONFIG_LDDIR) \
290 ":" ALSO_TRIPLET(CONFIG_OSX_SDK2 "/usr/" CONFIG_LDDIR)
291# else
292# define CONFIG_TCC_LIBPATHS \
293 ALSO_TRIPLET(CONFIG_SYSROOT "/usr/" CONFIG_LDDIR) \279 ALSO_TRIPLET(CONFIG_SYSROOT "/usr/" CONFIG_LDDIR) \
294 ":" ALSO_TRIPLET(CONFIG_SYSROOT "/" CONFIG_LDDIR) \280 ":" ALSO_TRIPLET(CONFIG_SYSROOT "/" CONFIG_LDDIR) \
295 ":" ALSO_TRIPLET(CONFIG_SYSROOT "/usr/local/" CONFIG_LDDIR)281 ":" ALSO_TRIPLET(CONFIG_SYSROOT "/usr/local/" CONFIG_LDDIR)
282# ifdef TCC_TARGET_MACHO
283# define CONFIG_OSX_SDK1 \
284 "/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk"
285# define CONFIG_OSX_SDK2 \
286 "/Applications/Xcode.app/Developer/SDKs/MacOSX.sdk"
287# define CONFIG_OSX_SDK_FALLBACK \
288 ALSO_TRIPLET(CONFIG_OSX_SDK1 "/usr/" CONFIG_LDDIR) \
289 ":" ALSO_TRIPLET(CONFIG_OSX_SDK2 "/usr/" CONFIG_LDDIR)
296# endif290# endif
297# endif291# endif
298#endif292#endif

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t