/* DEC ALPHAs running GNU/Linux 2.2.19-6.2.1 at University of Utah */

#include <lcc-conf.h>

#include <string.h>

static char rcsid[] = "$Id: linux.c,v 1.1.1.1 2002/04/21 13:25:10 peter Exp $";

#ifndef LOCALDIR
#define LOCALDIR "/usr/local/"
#endif

#ifndef LCCDIR
#define LCCDIR LOCALDIR "lib/lcc/"
#endif

char *suffixes[] = { ".c", ".i", ".s", ".o", ".out", 0 };
char inputs[256] = "";
char *cpp[] = {	LCCDIR "cpp",
       	"-U__GNUC__", "-D_POSIX_SOURCE", "-D__STDC__=1", "-D__STRICT_ANSI__",
	/* Match the following -Dxxx=yyy values to what gcc -v reports! */
	"-DLANGUAGE_C",
	"-D__ELF__",
	"-D__LANGUAGE_C",
	"-D__LANGUAGE_C__",
	"-D__alpha",
	"-D__alpha__",
	"-D__alpha_ev4__",
	"-D__linux",
	"-D__linux__",
	"-D__unix",
	"-D__unix__",
	"-Dlinux",
	"-Dunix",
	"$1", "$2", "$3", 0 };
char *com[] =  { LCCDIR "rcc", "-target=alpha/linux", "$1", "$2", "$3", "", 0 };
char *include[] = {
	"-I" LCCDIR "include",
	"-I/usr/local/include",
	"-I/usr/alpha-redhat-linux/include",
	"-I" GCCDIR "include",
	"-I/usr/include",
	0 };

char *as[] =  { "/usr/local/bin/as", "-o", "$3", "", "$1", "-nocpp",
		"-no-warn", /* Until gas gets some bug fixes to eliminate bogus 
			       warnings, suppress them entirely */
		"$2", 0 };
char *ld[] =  {
	/* 0 */ "/usr/bin/ld",
		"-o",
		"$3",
		"-m",
	/* 4 */	"elf64alpha",
		"-dynamic-linker",
		"/lib/ld-linux.so.2",
		"/usr/lib/crt1.o",
	/* 8 */	"/usr/lib/crti.o",
		"/usr/lib/crtbegin.o",
		"$1",
		"$2",
	/*12*/	"",
		"",
		"-L" LOCALDIR,
		"-L" LCCDIR,
	/*16*/	"-L" GCCDIR,
		"-L/usr/alpha-redhat-linux/lib",
		"-llcc",
		"-lgcc",
	/*20*/	"-lc",
		"-lgcc",
		"-lm",
		"",
	/*24*/	"/usr/lib/crtend.o",
		"/usr/lib/crtn.o",
		0
	};

extern char *concat(char *, char *);
extern int access(const char *, int);

int option(char *arg) {
	if (strncmp(arg, "-lccdir=", 8) == 0) {
		cpp[0] = concat(&arg[8], "/cpp");
		include[0] = concat("-I", concat(&arg[8], "/include"));
		com[0] = concat(&arg[8], "/rcc");
		ld[15] = concat("-L", &arg[8]);
	} else if (strncmp(arg, "-as=", 4) == 0) {
		as[0] = concat(&arg[4], "");
	} else if (strncmp(arg, "-cpp=", 5) == 0) {
		cpp[0] = concat(&arg[5], "");
	} else if (strncmp(arg, "-ld=", 4) == 0) {
		ld[0] = concat(&arg[4],"");
	} else if (strncmp(arg, "-rcc=", 5) == 0) {
		com[0] = concat(&arg[5],"");
	} else if (strcmp(arg, "-p") == 0 || strcmp(arg, "-pg") == 0) {
		ld[7] = LIBDIR "gcrt1.o";
		ld[23] = "";	/* normally "-lgmon", but not needed on GNU/Linux */
	} else if (strcmp(arg, "-b") == 0)
		;
	else if (strcmp(arg, "-g") == 0)
		;
	else if (strcmp(arg, "-dynamic") == 0) {
	        ld[5] = "-dynamic-linker";
	        ld[6] = "/lib/ld-linux.so.2";
	} else if (strcmp(arg, "-static") == 0) {
	        ld[5] = "-static";
	        ld[6] = "";
	} else
		return 0;
	return 1;
}
