Skip to content

Commit ce21936

Browse files
author
Connor Harris
committed
Implemented this on linux going to see if it works on mac
1 parent 3e5c884 commit ce21936

File tree

1 file changed

+61
-0
lines changed

1 file changed

+61
-0
lines changed

src/helper/help.c

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -430,6 +430,67 @@ bool get_lib_paths(char *buffer, size_t buffer_size) {
430430
return false;
431431
}
432432

433+
#elif defined(__APPLE__)
434+
/**
435+
* @brief Links object file using clang on macOS
436+
*
437+
* @param obj_filename Path to the object file
438+
* @param exe_filename Path for the output executable
439+
* @return true if linking succeeded, false otherwise
440+
*/
441+
bool link_with_ld(const char *obj_filename, const char *exe_filename) {
442+
char command[4096];
443+
444+
snprintf(command, sizeof(command), "cc \"%s\" -o \"%s\"", obj_filename,
445+
exe_filename);
446+
447+
printf("Linking with: %s\n", command);
448+
return system(command) == 0;
449+
}
450+
451+
bool link_with_ld_simple(const char *obj_filename, const char *exe_filename) {
452+
return link_with_ld(obj_filename, exe_filename);
453+
}
454+
455+
bool get_gcc_file_path(const char *filename, char *buffer, size_t buffer_size) {
456+
char command[256];
457+
snprintf(command, sizeof(command), "cc -print-file-name=%s", filename);
458+
459+
FILE *fp = popen(command, "r");
460+
if (!fp)
461+
return false;
462+
463+
if (fgets(buffer, buffer_size, fp) != NULL) {
464+
size_t len = strlen(buffer);
465+
if (len > 0 && buffer[len - 1] == '\n') {
466+
buffer[len - 1] = '\0';
467+
}
468+
pclose(fp);
469+
return strcmp(buffer, filename) != 0;
470+
}
471+
472+
pclose(fp);
473+
return false;
474+
}
475+
476+
bool get_lib_paths(char *buffer, size_t buffer_size) {
477+
FILE *fp = popen("cc -print-search-dirs | grep '^libraries:' | cut -d'=' -f2", "r");
478+
if (!fp)
479+
return false;
480+
481+
if (fgets(buffer, buffer_size, fp) != NULL) {
482+
size_t len = strlen(buffer);
483+
if (len > 0 && buffer[len - 1] == '\n') {
484+
buffer[len - 1] = '\0';
485+
}
486+
pclose(fp);
487+
return true;
488+
}
489+
490+
pclose(fp);
491+
return false;
492+
}
493+
433494
#else
434495
/**
435496
* @brief Links object file using ld to create an executable (Unix/Linux)

0 commit comments

Comments
 (0)