root/src/gauche-config.c

/* [<][>][^][v][top][bottom][index][help] */

DEFINITIONS

This source file includes following definitions.
  1. usage
  2. print_output
  3. fixup_extension
  4. main

   1 /* Generated automatically by genconfig.  DO NOT EDIT */
   2 
   3 /* The small program gauche-config is installed in the same place
   4    as gosh, and used to retrieve various configuration information
   5    later.  It is made a separate program from gosh for quicker
   6    startup and avoiding complications of dynamic library etc.
   7    It used to be a shell script, but turned into a C program
   8    so that it works on the platform that lacks sh. */
   9 
  10 #include <stdio.h>
  11 #include <stdlib.h>
  12 #include <string.h>
  13 #include <errno.h>
  14 #include <ctype.h>
  15 
  16 #ifdef __MINGW32__
  17 #include <windows.h>
  18 #include <shlwapi.h>
  19 #endif
  20 
  21 static void usage (void) {
  22    puts("Usage: gauche-config [option]\n"
  23         "\n"
  24         "General parameter\n"
  25         "  -V   the current gauche version\n"
  26         "\n"
  27         "Parameters to compile an application using Gauche\n"
  28         "  -I   include paths required to compile programs using gauche\n"
  29         "  -L   library paths required to link programs using gauche\n"
  30         "  -l   libraries required to link programs using gauche\n"
  31         "  --cc name of the compiler\n"
  32         "  --ac directory that contains Gauche specific autoconf macro\n"
  33         "  --reconfigure\n"
  34         "       prints the command line used to configure the current\n"
  35         "       installation.\n"
  36         "  --arch\n"
  37         "       prints the architecture signature\n"
  38         "\n"
  39         "Parameters to install files\n"
  40         "  --{sys|site|pkg}libdir\n"
  41         "       directories where system|site|package scheme files go\n"
  42         "  --{sys|site|pkg}archdir\n"
  43         "       directories where system|site|package DSO files go\n"
  44         "  --{sys|site|pkg}incdir\n"
  45         "       directories where system|site|package header files of extensions go\n"
  46         "  --mandir/--infodir\n"
  47         "       directories where gauche manpage and info docs are installed\n"
  48         "\n"
  49         "Parameters to help building extensions\n"
  50         "  --object-suffix\n"
  51         "       Returns extension of the compiled objects (e.g. \"o\")\n"
  52         "  --executable-suffix\n"
  53         "       Returns extension of the executable (mostly empty, sometimes \".exe\")\n"
  54         "  --so-suffix\n"
  55         "       Suffix for dynamically loadable (dlopen-able) modules\n"
  56         "  --so-cflags\n"
  57         "       CFLAGS to create dynamically loadable modules\n"
  58         "  --so-ldflags\n"
  59         "       LDFLAGS to create dynamically loadable modules\n"
  60         "  --so-libs\n"
  61         "       Required libraries to create dynamically loadable modules\n"
  62         "  --dylib-suffix\n"
  63         "       Suffix for dynamically linked libraries\n"
  64         "  --dylib-ldflags\n"
  65         "       LDFLAGS to create dynamically linked libraries\n"
  66         "  --fixup-extension FILE [MODULE]\n"
  67         "       creates FILE_head.c and FILE_tail.c.  They are required for GC\n"
  68         "       to work properly on some platforms.  MODULE must be the extension\n"
  69         "       module's name, and has to match the name given to the\n"
  70         "       SCM_INIT_EXTENSION macro in the extension initialization code. \n"
  71         "       If MODULE is omitted, FILE is used as the module's name.\n"
  72         );
  73     exit(1);
  74 }
  75 
  76 static struct cmd_rec {
  77     const char *cmd;
  78     const char *value;
  79 } cmds[] = {
  80     { "-V", "0.8.6" },
  81     { "-I", "-I'/usr/local/lib/gauche/0.8.6/include'" },
  82     { "-L", "-L'/usr/local/lib/gauche/0.8.6/i686-pc-linux-gnu' " },
  83     { "--ac", "/usr/local/share/gauche/0.8.6/" },
  84     { "-l", "-lgauche -ldl -lcrypt -lutil -lm  -lpthread" },
  85     { "--cc", "gcc" },
  86     { "--reconfigure", "./configure '--enable-multibyte=utf-8' '--enable-threads=pthreads' 'CFLAGS=-g -O0'" },
  87 
  88     { "--prefix",      "/usr/local" },
  89     { "--sysincdir",   "/usr/local/lib/gauche/0.8.6/include" },
  90     { "--siteincdir",  "/usr/local/lib/gauche/site/include" },
  91     { "--pkgincdir",   "${libdir}/gauche/site/include" },
  92     { "--syslibdir",   "/usr/local/share/gauche/0.8.6/lib" },
  93     { "--sitelibdir",  "/usr/local/share/gauche/site/lib" },
  94     { "--pkglibdir",   "${datadir}/gauche/site/lib" },
  95     { "--sysarchdir",  "/usr/local/lib/gauche/0.8.6/i686-pc-linux-gnu" },
  96     { "--sitearchdir", "/usr/local/lib/gauche/site/0.8.6/i686-pc-linux-gnu" },
  97     { "--pkgarchdir",  "${libdir}/gauche/site/0.8.6/i686-pc-linux-gnu" },
  98     { "--mandir",      "/usr/local/man" },
  99     { "--infodir",     "/usr/local/info" },
 100     { "--arch",        "i686-pc-linux-gnu" },
 101 
 102     { "--local-incdir", "" },
 103     { "--local-libdir", "" },
 104 
 105     { "--default-cflags", "-g -O0" },
 106 
 107     { "--object-suffix",  "o" },
 108     { "--executable-suffix", "" },
 109     { "--so-suffix",      "so" },
 110     { "--so-cflags",      "-fPIC" },
 111     { "--so-ldflags",     " -shared -o" },
 112     { "--so-libs",        "" },
 113     { "--dylib-suffix",   "so" },
 114     { "--dylib-ldflags",  " -shared -o" },
 115     { "--libgauche-so",   "libgauche.so" },
 116 
 117     { NULL, NULL }
 118 };
 119 
 120 static void print_output(struct cmd_rec *cmd) 
 121 {
 122 #if !defined(__MINGW32__)
 123     printf("%s\n", cmd->value);
 124 #else   /* __MINGW32__ */
 125     const char *dir_mark;
 126 
 127     if ((dir_mark = strchr(cmd->value, '@')) == NULL) {
 128         printf("%s\n", cmd->value);
 129     } else {
 130         HMODULE mod;
 131         DWORD r;
 132         char path[MAX_PATH];
 133         char *p;
 134 
 135         mod = GetModuleHandle(NULL);
 136         if (mod == NULL) {
 137             fprintf(stderr, "GetModuleHandle failed");
 138             exit(1);
 139         }
 140         r = GetModuleFileName(mod, path, MAX_PATH);
 141         if (r == 0) {
 142             fprintf(stderr, "GetModuleFileName failed");
 143             exit(1);
 144         }
 145         /* remove \gauche-config.exe */
 146         if (!PathRemoveFileSpec(path)) {
 147             fprintf(stderr, "PathRemoveFileSpec failed on %s", path);
 148             exit(1);
 149         }
 150         /* remobe \bin */
 151         if (!PathRemoveFileSpec(path)) {
 152             fprintf(stderr, "PathRemoveFileSpec failed on %s", path);
 153             exit(1);
 154         }
 155         
 156         fwrite(cmd->value, dir_mark - cmd->value, 1, stdout);
 157         fprintf(stdout, "%s%s\n", path, dir_mark+1);
 158     }
 159 #endif  /* __MINGW32__ */
 160 }
 161 
 162 static void fixup_extension(int argc, char **argv)
 163 {
 164     const char *file, *module;
 165     char *outfile, *m = NULL;
 166     FILE *fp;
 167 
 168     if (argc < 3) usage();
 169     file = argv[2];
 170     if (argc > 3) {
 171         module = argv[3];
 172     } else {
 173         const char *f;
 174         char *mm;
 175         m = (char *)malloc(strlen(file)+1);
 176         for (f = file, mm = m; *f; f++, mm++) {
 177            if (isalnum(*f)) *mm = *f;
 178            else *mm = '_';
 179         }
 180         *mm = '\0';
 181         module = m;
 182     }
 183     
 184     outfile = (char *)malloc(strlen(file) + sizeof("_head.c") + 1);
 185     strcpy(outfile, file);
 186     strcat(outfile, "_head.c");
 187     fp = fopen(outfile, "w");
 188     if (fp == NULL) {
 189         fprintf(stderr, "gauche-config: couldn't create %s: %s",
 190                 outfile, strerror(errno));
 191         exit(1);
 192     }
 193     fprintf(fp, "void *Scm__datastart_%s = (void*)&Scm__datastart_%s;\n",
 194             module, module);
 195     fprintf(fp, "void *Scm__bssstart_%s;\n", module);
 196     fclose(fp);
 197 
 198     strcpy(outfile, file);
 199     strcat(outfile, "_tail.c");
 200     fp = fopen(outfile, "w");
 201     if (fp == NULL) {
 202         fprintf(stderr, "gauche-config: couldn't create %s: %s",
 203                 outfile, strerror(errno));
 204         exit(1);
 205     }
 206     fprintf(fp, "void *Scm__dataend_%s = (void*)&Scm__dataend_%s;\n",
 207             module, module);
 208     fprintf(fp, "void *Scm__bssend_%s;\n", module);
 209     fclose(fp);
 210 
 211     free(outfile);
 212     if (m) free(m);
 213 }
 214 
 215 int main(int argc, char **argv)
 216 {
 217     if (argc < 2) usage();
 218     if (strcmp(argv[1], "--fixup-extension") == 0) {
 219         fixup_extension(argc, argv);
 220     } else {
 221         struct cmd_rec *cp = cmds;
 222 
 223         while (cp->cmd != NULL) {
 224             if (strcmp(cp->cmd, argv[1]) == 0) {
 225                 print_output(cp);
 226                 exit(0);
 227             }
 228             cp++;
 229         }
 230         usage();
 231     }
 232     return 0;
 233 }
 234 

/* [<][>][^][v][top][bottom][index][help] */