summaryrefslogtreecommitdiff
path: root/mld/main.c
blob: 675a056b34b0a748594798a53b53cf6edb10277b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
#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");
	printf("\t-f\t\tmake this binary freestanding (no runtime)\n");
}

int main(int argc, char **argv) {

	struct linker_arguments args = {
		.in_files = NULL,
		.in_count = 0,
		.out_file = "a.out",
		.freestanding = false,
	};

	int c;

	while ((c = getopt(argc, argv, "ho:f")) != 1) {
		switch(c) {
		case 'h':
			help();
			return M_SUCCESS;
		case 'o':
			args.out_file = optarg;
			break;
		case 'f':
			args.freestanding = true;
			break;
		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);
}