#include <SWI-Prolog.h>
#include <stdio.h>
#include <libgen.h>

int main(int argc, char *argv[]) {
    int n_argc = argc + 5;
    char *n_argv[n_argc];
    int s = 0;
    int d = 0;
    
    if (argc <= 2) {
	printf(	"Usage:\n"
		"	%s <output.prc> <input.pl> [...]\n", basename(argv[0]));
	return(1);
    }

    n_argv[d++]	= argv[s++];
    n_argv[d++]	= "-O";
    n_argv[d++]	= "-o";
    n_argv[d++]	= argv[s++];
    n_argv[d++]	= "-b";
    n_argv[d++]	= PLHOME "/boot/init.pl";
    n_argv[d++]	= "-c";
    
    while (s < argc)
	n_argv[d++] = argv[s++];

    if (PL_initialise(n_argc, n_argv) == TRUE)
	return(PL_halt(0));

    return(1);
}
