#include <stdio.h>

#define YES 1
#define NO  0

#include "../conf/site.conf"
#include "../conf/defaults.conf"

main(argc, argv)
int argc;
char **argv;
{
	FILE *hp;
	FILE *cp;
	int k;

	if (argc != 3)
	 { fprintf (stderr, "Usage: %s <h-configFile> <c-configFile>\n", 
			     argv[0]);
	 }
	if ((hp = fopen(argv[1],"w")) == NULL)
	 { fprintf (stderr, "Error: cannot open h-configFile %s\n", argv[1]);
	 }
	if ((cp = fopen(argv[2],"w")) == NULL)
	 { fprintf (stderr, "Error: cannot open c-configFile %s\n", argv[2]);
	 }
		
	fprintf(hp, "#ifndef _RCICONFIG_H_\n");
	fprintf(hp, "#define _RCICONFIG_H_\n");

	fprintf(hp, "\n");

#if VxWorksSupport
	fprintf(hp, "#ifndef VXWORKS_CFG\n");
	fprintf(hp, "\n");
#endif

	fprintf(hp, "/* target system %s */\n", TargetSystem);
	fprintf(hp, "\n");

	fprintf(hp, "#define ARBITER_CPU       0\n");
	fprintf(hp, "#define ARBITER_MASK      (1<<ARBITER_CPU)\n");
	fprintf(hp, "#define AUXILIARY_MASK    (~ARBITER_MASK)\n");
	fprintf(hp, "#define NUM_AUX_CPUS      %d\n", NumberOfAuxCpus);
	fprintf(hp, "#define MAX_CPUS          %d\n", NumberOfAuxCpus+1);
	fprintf(hp, "\n");
	fprintf(hp, "#define HOST_BUS_BASE     0x%x\n", HostBusBase);
	fprintf(hp, "#define HOST_IOPAGE_BASE  0x%x\n", HostIOPageBase);
	fprintf(hp, "\n");
#if VxWorksSupport
	fprintf(hp, "\n");
	fprintf(hp, "#else\n");
	fprintf(hp, "\n");
	fprintf(hp, "#define ARBITER_CPU       0\n");
	fprintf(hp, "#define ARBITER_MASK      (1<<ARBITER_CPU)\n");
	fprintf(hp, "#define AUXILIARY_MASK    (~ARBITER_MASK)\n");
	fprintf(hp, "#define NUM_AUX_CPUS      %d\n", 0);
	fprintf(hp, "#define MAX_CPUS          %d\n", 1);
	fprintf(hp, "\n");
	fprintf(hp, "#define HOST_BUS_BASE     0x%x\n", VxwHostBusBase);
	fprintf(hp, "#define HOST_IOPAGE_BASE  0x%x\n", VxwHostIOPageBase);
	fprintf(hp, "\n");
	fprintf(hp, "#endif\n");
#endif
	fprintf(hp, "\n");
	/* MS */
#if LinuxConfig

	fprintf(hp, "#define TRC004_BASE  0x%x\n", TRC004Base);

#endif
	fprintf(hp, "#endif /*_RCICONFIG_H_*/\n");
	fclose(hp);	/* that's it for the h config file */

	fprintf(cp, "#include \"../h/rciConfig.h\"\n");
	fprintf(cp, "\n");
#if VxWorksSupport
	fprintf(cp, "#ifndef VXWORKS_CFG\n");
	fprintf(cp, "\n");
#endif
	fprintf(cp, "int cpuExportSizes[MAX_CPUS] = {\n");
	fprintf(cp, "\t0x%x,\n", HostExportSize);
	for (k=0; k<NumberOfAuxCpus; k++)
	 { fprintf(cp, "\t0x%x,\n", AuxExportSize); 
	 }
	fprintf(cp, "};\n");
#if VxWorksSupport
	fprintf(cp, "\n");
	fprintf(cp, "#else\n");
	fprintf(cp, "\n");
	fprintf(cp, "int cpuExportSizes[MAX_CPUS] = {\n");
	fprintf(cp, "\t0x%x,\n", VxwHostExportSize);
	fprintf(cp, "};\n");
	fprintf(cp, "\n");
	fprintf(cp, "#endif\n");
#endif

	exit(0);
}
