/* Generated automatically by genconfig.  DO NOT EDIT */

/* The small program gauche-config is installed in the same place
   as gosh, and used to retrieve various configuration information
   later.  It is made a separate program from gosh for quicker
   startup and avoiding complications of dynamic library etc.
   It used to be a shell script, but turned into a C program
   so that it works on the platform that lacks sh. */

#if defined(__MINGW32__) || defined(_MSC_VER)
#define _CRT_SECURE_NO_DEPRECATE 1
#define _CRT_SECURE_NO_WARNINGS  1
#include <winsock2.h>  /* MinGW needs this before windows.h */
#include <windows.h>
#include <shlwapi.h>
#endif

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <stdarg.h>
#include <errno.h>
#include <ctype.h>

static void usage (void) {
  fputs("Usage: gauche-config [option ...]\n"
        "Multiple options can be given, except --fixup-extension.\n"
        "\n"
        "General parameter\n"
        "  -V   the current gauche version\n"
        "\n"
        "Parameters to compile an application using Gauche\n"
        "  -I   include paths required to compile programs using gauche\n"
        "       (Note: This doesn't work if Gauche installation directory\n"
        "       path contains whitespaces.  See --incdirs below.)\n"
        "  -L   library paths required to link programs using gauche\n"
        "       (Note: This doesn't work if Gauche installation directory\n"
        "       path contains whitespaces.  See --archdirs below.)\n"
        "  -l   libraries required to link programs using gauche\n"
        "  --cc name of the compiler\n"
        "  --ac directory that contains Gauche specific autoconf macro\n"
        "  --reconfigure\n"
        "       prints the command line used to configure the current\n"
        "       installation.\n"
        "  --arch\n"
        "       prints the architecture signature\n"
        "  --incdirs, --archdirs\n"
        "       prints the list of directory names to be looked for include files\n"
        "       and libraries, respectively.  Each directory name is quoted, as it\n"
        "       may contain spaces.\n"
        "\n"
        "Parameters to install files\n"
        "  --{sys|site|pkg}libdir\n"
        "       directories where system|site|package scheme files go\n"
        "  --{sys|site|pkg}archdir\n"
        "       directories where system|site|package DSO files go\n"
        "  --{sys|site|pkg}incdir\n"
        "       directories where system|site|package header files of extensions go\n"
        "  --mandir/--infodir\n"
        "       directories where gauche manpage and info docs are installed\n"
        "\n"
        "Parameters to help building extensions\n"
        "  --object-suffix\n"
        "       Returns extension of the compiled objects (e.g. 'o')\n"
        "  --executable-suffix\n"
        "       Returns extension of the executable (mostly empty, sometimes '.exe')\n"
        "  --so-suffix\n"
        "       Suffix for dynamically loadable (dlopen-able) modules\n"
        "  --so-cflags\n"
        "       CFLAGS to create dynamically loadable modules\n"
        "  --so-ldflags\n"
        "       LDFLAGS to create dynamically loadable modules\n"
        "  --so-libs\n"
        "       Required libraries to create dynamically loadable modules\n"
        "  --dylib-suffix\n"
        "       Suffix for dynamically linked libraries\n"
        "  --dylib-ldflags\n"
        "       LDFLAGS to create dynamically linked libraries\n"
        "  --rpath-flag\n"
        "       Compiler flag(s) to embed RPATH\n"
        "  --static-libs\n"
        "       Returns a list of libraries required to link Gauche statically.\n"
        "       Similar to '-l', but this includes the libraries that are used\n"
        "       for extension modules, and also the static library itself,\n"
        "       that is -lgauche-static-X.X.\n"
        ,stderr);
  exit(1);
}

static struct cmd_rec {
    const char *cmd;
    const char *value;
} cmds[] = {
    { "-V", "0.9.10" },
    { "-I", "-I/usr/pkg/lib/gauche-0.97/0.9.10/include" },
    { "-L", "-L/usr/pkg/lib/gauche-0.97/0.9.10/alpha--netbsd " },
    { "--ac", "/usr/pkg/share/gauche-0.97/0.9.10/" },
    { "-l", "-lgauche-0.97 -lcrypt -lutil -lrt -lm  -lpthread" },
    { "--cc", "gcc" },
    { "--reconfigure", "./configure  '--enable-multibyte=utf8' '--with-slib=/usr/pkg/share/slib' '--enable-threads=pthreads' '--with-iconv=/usr' '--with-zlib=/usr' '--prefix=/usr/pkg' '--build=alpha--netbsd' '--host=alpha--netbsd' '--infodir=/usr/pkg/info' '--mandir=/usr/pkg/man' 'build_alias=alpha--netbsd' 'host_alias=alpha--netbsd' 'CC=gcc' 'CFLAGS=-O2 -mieee -I/usr/pkg/include -I/usr/include' 'LDFLAGS=-L/usr/pkg/lib -Wl,-R/usr/pkg/lib -L/usr/lib -Wl,-R/usr/lib' 'LIBS=' 'CPPFLAGS=-I/usr/pkg/include -I/usr/include'" },

    { "--prefix",      "/usr/pkg" },
    { "--sysincdir",   "/usr/pkg/lib/gauche-0.97/0.9.10/include" },
    { "--siteincdir",  "/usr/pkg/lib/gauche-0.97/site/include" },
    { "--pkgincdir",   "${libdir}/gauche-0.97/site/include" },
    { "--syslibdir",   "/usr/pkg/share/gauche-0.97/0.9.10/lib" },
    { "--sitelibdir",  "/usr/pkg/share/gauche-0.97/site/lib" },
    { "--pkglibdir",   "${datadir}/gauche-0.97/site/lib" },
    { "--sysarchdir",  "/usr/pkg/lib/gauche-0.97/0.9.10/alpha--netbsd" },
    { "--sitearchdir", "/usr/pkg/lib/gauche-0.97/site/alpha--netbsd" },
    { "--pkgarchdir",  "${libdir}/gauche-0.97/site/alpha--netbsd" },
    { "--mandir",      "/usr/pkg/man" },
    { "--infodir",     "/usr/pkg/info" },
    { "--arch",        "alpha--netbsd" },
    { "--incdirs",     "/usr/pkg/lib/gauche-0.97/0.9.10/include:/usr/pkg/lib/gauche-0.97/site/include" },
    { "--archdirs",    "/usr/pkg/lib/gauche-0.97/0.9.10/alpha--netbsd:/usr/pkg/lib/gauche-0.97/site/alpha--netbsd" },

    { "--local-incdir", "" },
    { "--local-libdir", "" },

    { "--default-cflags", "-O2 -mieee -I/usr/pkg/include -I/usr/include -Wall -Wextra -Wno-unused-label" },

    { "--object-suffix",  "o" },
    { "--executable-suffix", "" },
    { "--rpath-flag",     "-Wl,--rpath=" },
    { "--so-suffix",      "so" },
    { "--so-cflags",      "-fPIC -DPIC" },
    { "--so-ldflags",     " -shared -o" },
    { "--so-libs",        "" },
    { "--dylib-suffix",   "so" },
    { "--dylib-ldflags",  " -shared -o" },
    { "--libgauche-so",   "libgauche-0.97.so" },
    { "--static-libs",    "-lgauche-static-0.97   -lgdbm   -lz    -lcrypt -lutil -lrt -lm  -lpthread" },

    { NULL, NULL }
};

#if (defined(__MINGW32__) || defined(_MSC_VER)) && defined(UNICODE)
/* mbs <-> wcs stuff */
#include "win-compat.c"
static void errfn(const char *fmt,...); /*definition in paths.c*/
#define SCM_MBS2WCS(s)   mbs2wcs(s, FALSE, errfn)
#define SCM_WCS2MBS(s)   wcs2mbs(s, FALSE, errfn)
#else  /* !(defined(__MINGW32__) || defined(_MSC_VER)) && defined(UNICODE) */
#define SCM_MBS2WCS(s)  (s)
#define SCM_WCS2MBS(s)  (s)
#endif /* !(defined(__MINGW32__) || defined(_MSC_VER)) && defined(UNICODE) */

#include "paths.c"

static int process(const char *arg, int check)
{
    struct cmd_rec *cp = cmds;
    while (cp->cmd != NULL) {
        if (strcmp(cp->cmd, arg) == 0) {
            if (!check) printf("%s\n", replace_install_dir(cp->value));
            return 1;
        }
        cp++;
    }
    return 0;
}

int main(int argc, char **argv)
{
#if (defined(__MINGW32__) || defined(_MSC_VER)) && defined(UNICODE)
    (void)&mbs2wcs; /* suppress unused function warning */
    (void)&wcs2mbs;
#endif /* (defined(__MINGW32__) || defined(_MSC_VER)) && defined(UNICODE) */
    (void)get_libgauche_path();	 /* ditto */

    if (argc < 2) usage();
    if (strcmp(argv[1], "--fixup-extension") == 0) {
        fprintf(stderr, "(fixup-extension is no longer needed.)\n");
    } else {
        char **av;
        for (av = argv+1; *av; av++) {
            if (!process(*av, 1)) usage();
        }
        for (av = argv+1; *av; av++) {
            process(*av, 0);
        }
    }
    return 0;
}

