/* Apple Macintosh PowerPC systems running Linux */

#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 GCCDIR
#define GCCDIR LOCALDIR "lib/gcc-lib/ppc-redhat-linux/2.95.2/"
#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! */
	"-DPPC",
	"-D_ARCH_PPC",
	"-D_BIG_ENDIAN",
	"-D_CALL_SYSV",
	"-D__BIG_ENDIAN__",
	"-D__ELF__",
	"-D__PPC",
	"-D__PPC__",
	"-D__linux__",
	"-D__powerpc",
	"-D__powerpc__",
	"-D__unix__",
	"-Dlinux",
	"-Dpowerpc",
	"-Dunix",
	/* "-Acpu(powerpc)", */
	/* "-Amachine(bigendian)", */
	/* "-Amachine(powerpc)", */
	/* "-Asystem(posix)", */
	/* "-Asystem(unix)", */
	/* "-D__CHAR_UNSIGNED__", */	/* lcc has signed chars by default */
	/* "-D__GNUC_MINOR__=95", */
	/* "-D__GNUC__=2", */
	"$1", "$2", "$3", 0 };

char *include[] = {
	"-I" LCCDIR "include",
	"-I" LOCALDIR "include",
	"-I" GCCDIR "include",
	"-I" GCCDIR "../../../../ppc-redhat-linux/include",
	"-I/usr/include",
	0 };

char *com[] = {LCCDIR "rcc", "-target=sparc/linux", "$1", "$2", "$3", 0 };

char *as[] = { "/usr/bin/as", "-o", "$3", "$1", "$2", 0 };

char *ld[] = {
	/* 0 */ GCCDIR "collect2",
		"-m",
		"elf32ppclinux",
		"-dynamic-linker",
	/* 4 */ "/lib/ld.so.1",
		"-o",
		"$3",
	/* 7 */ "/usr/lib/crt1.o",
		"/usr/lib/crti.o",
		GCCDIR "crtbegin.o",
		"$1",
		"$2",
	/* 12*/ "-L" LCCDIR,
	/* 13*/ "-L" LOCALDIR "lib ",
	/* 14*/ "-llcc",
		"",
		"-lc",
		"-lm",
	/* 18*/ "",
		 GCCDIR "crtend.o",
		 "/usr/lib/crtn.o",
		0
	};

extern char *concat(char *, char *);

int option(char *arg) {
  	if (strncmp(arg, "-lccdir=", 8) == 0) {
		cpp[0] = concat(&arg[8], "/cpp");
		include[0] = concat("-I", concat(&arg[8], "/include"));
		ld[12] =  concat("-L", &arg[8]);
		com[0] = concat(&arg[8], "/rcc");
	} 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] = "/usr/lib/gcrt1.o";
		ld[18] = "";	/* 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)
	        ;			/* default */
	else if (strcmp(arg, "-static") == 0) {
	        ld[3] = "-static";
	        ld[4] = "";
	        ld[14] = "-L" GCCDIR;
	        ld[15] = "-lgcc";
	} else
		return 0;
	return 1;
}
