2024-09-21 00:46:37 +00:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <unistd.h>
|
|
|
|
#include <merror.h>
|
|
|
|
#include <string.h>
|
|
|
|
|
|
|
|
#include "link.h"
|
|
|
|
|
|
|
|
void help(void) {
|
|
|
|
printf("usage: mld [options] objfile...\n\n");
|
|
|
|
printf("options:\n");
|
|
|
|
printf("\t-h\t\tprints this help message\n");
|
|
|
|
printf("\t-o <output>\tselect a output file destination\n");
|
2024-09-23 03:39:22 +00:00
|
|
|
printf("\t-f\t\tmake this binary freestanding (no runtime)\n");
|
2024-09-21 00:46:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int main(int argc, char **argv) {
|
|
|
|
|
|
|
|
struct linker_arguments args = {
|
|
|
|
.in_files = NULL,
|
|
|
|
.in_count = 0,
|
|
|
|
.out_file = "a.out",
|
2024-09-23 03:39:22 +00:00
|
|
|
.freestanding = false,
|
2024-09-21 00:46:37 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
int c;
|
|
|
|
|
2024-09-23 03:39:22 +00:00
|
|
|
while ((c = getopt(argc, argv, "ho:f")) != 1) {
|
2024-09-21 00:46:37 +00:00
|
|
|
switch(c) {
|
|
|
|
case 'h':
|
|
|
|
help();
|
|
|
|
return M_SUCCESS;
|
|
|
|
case 'o':
|
|
|
|
args.out_file = optarg;
|
|
|
|
break;
|
2024-09-23 03:39:22 +00:00
|
|
|
case 'f':
|
|
|
|
args.freestanding = true;
|
|
|
|
break;
|
2024-09-21 00:46:37 +00:00
|
|
|
case '?':
|
|
|
|
return M_ERROR;
|
|
|
|
default:
|
|
|
|
goto next;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
next:
|
|
|
|
if (optind >= argc) {
|
|
|
|
ERROR("no object files passed");
|
|
|
|
return M_ERROR;
|
|
|
|
}
|
|
|
|
|
|
|
|
args.in_files = &argv[optind];
|
|
|
|
args.in_count = argc - optind;
|
|
|
|
|
|
|
|
return link_files(args);
|
|
|
|
}
|