~ubuntu-branches/ubuntu/oneiric/swig1.3/oneiric

« back to all changes in this revision

Viewing changes to Source/Modules/main.cxx

  • Committer: Bazaar Package Importer
  • Author(s): Benjamin Drung
  • Date: 2009-11-15 14:00:28 UTC
  • mfrom: (1.2.9 upstream) (2.1.4 squeeze)
  • Revision ID: james.westby@ubuntu.com-20091115140028-me7amr2rie8zz1xn
Tags: 1.3.40-2ubuntu1
* Merge from Debian testing (LP: #356529), remaining changes:
  - Drop libchicken-dev from the build-depends (it's in universe)
  - Remove Pike from package description and from configure flags
  - drop "--without-mzscheme", we don't have it in our build-depends
  - use php-config5
  - Clean Runtime/ as well.
  - debian/rules (clean): Remove Lib/ocaml/swigp4.ml.
* debian/rules: Remove hardcoded python version.
* Remove upper limit for python from Build-Depends.

Show diffs side-by-side

added added

removed removed

Lines of Context:
7
7
 * Main entry point to the SWIG core.
8
8
 * ----------------------------------------------------------------------------- */
9
9
 
10
 
char cvsroot_main_cxx[] = "$Id: main.cxx 10580 2008-06-24 21:53:12Z wsfulton $";
 
10
char cvsroot_main_cxx[] = "$Id: main.cxx 11135 2009-02-20 20:55:16Z wsfulton $";
11
11
 
12
12
#include "swigconfig.h"
13
13
 
117
117
                        -fastdispatch -fvirtual \n\
118
118
     -o <outfile>    - Set name of the output file to <outfile>\n\
119
119
     -oh <headfile>  - Set name of the output header file to <headfile>\n\
120
 
     -outdir <dir>   - Set language specific files output directory <dir>\n\
 
120
     -outcurrentdir  - Set default output dir to current dir instead of input file's path\n\
 
121
     -outdir <dir>   - Set language specific files output directory to <dir>\n\
121
122
     -small          - Compile in virtual elimination & compact mode\n\
122
123
     -swiglib        - Report location of SWIG library and exit\n\
123
124
     -templatereduce - Reduce all the typedefs in templates\n\
153
154
static char *depends_extension = (char *) "d";
154
155
static String *outdir = 0;
155
156
static String *xmlout = 0;
 
157
static int outcurrentdir = 0;
156
158
static int help = 0;
157
159
static int checkout = 0;
158
160
static int cpp_only = 0;
180
182
static int external_runtime = 0;
181
183
static String *external_runtime_name = 0;
182
184
enum { STAGE1=1, STAGE2=2, STAGE3=4, STAGE4=8, STAGEOVERFLOW=16 };
 
185
static List *all_output_files = 0;
183
186
 
184
187
// -----------------------------------------------------------------------------
185
 
// check_suffix(char *name)
 
188
// check_suffix()
186
189
//
187
190
// Checks the suffix of a file to see if we should emit extern declarations.
188
191
// -----------------------------------------------------------------------------
189
192
 
190
 
static int check_suffix(const char *name) {
 
193
static int check_suffix(String *filename) {
 
194
  const char *name = Char(filename);
191
195
  const char *c;
192
196
  if (!name)
193
197
    return 0;
281
285
}
282
286
 
283
287
/* This function sets the name of the configuration file */
284
 
void SWIG_config_file(const String_or_char *filename) {
 
288
void SWIG_config_file(const_String_or_char_ptr filename) {
285
289
  lang_config = NewString(filename);
286
290
}
287
291
 
300
304
  cpp_extension = (char *) ext;
301
305
}
302
306
 
 
307
List *SWIG_output_files() {
 
308
  assert(all_output_files);
 
309
  return all_output_files;
 
310
}
 
311
 
303
312
void SWIG_setfeature(const char *cfeature, const char *cvalue) {
304
313
  Hash *features_hash = Swig_cparse_features();
305
314
  String *name = NewString("");
363
372
    }
364
373
  }
365
374
 
366
 
  runtime = NewFile(outfile, "w");
 
375
  runtime = NewFile(outfile, "w", SWIG_output_files());
367
376
  if (!runtime) {
368
377
    FileErrorDisplay(outfile);
369
378
    SWIG_exit(EXIT_FAILURE);
370
379
  }
371
380
 
372
381
  Swig_banner(runtime);
 
382
  Printf(runtime, "\n");
373
383
 
374
384
  s = Swig_include_sys("swiglabels.swg");
375
385
  if (!s) {
688
698
        } else {
689
699
          Swig_arg_error();
690
700
        }
 
701
      } else if (strcmp(argv[i], "-outcurrentdir") == 0) {
 
702
        Swig_mark_arg(i);
 
703
        outcurrentdir = 1;
691
704
      } else if (strcmp(argv[i], "-Wall") == 0) {
692
705
        Swig_mark_arg(i);
693
706
        Swig_warnall();
867
880
  }
868
881
 
869
882
  libfiles = NewList();
 
883
  all_output_files = NewList();
870
884
 
871
885
  /* Check for SWIG_FEATURES environment variable */
872
886
 
924
938
 
925
939
  // If we made it this far, looks good. go for it....
926
940
 
927
 
  input_file = argv[argc - 1];
 
941
  input_file = NewString(argv[argc - 1]);
 
942
  Swig_filename_correct(input_file);
928
943
 
929
944
  // If the user has requested to check out a file, handle that
930
945
  if (checkout) {
931
946
    DOH *s;
932
 
    char *outfile = input_file;
 
947
    char *outfile = Char(input_file);
933
948
    if (outfile_name)
934
949
      outfile = outfile_name;
935
950
 
938
953
 
939
954
    s = Swig_include(input_file);
940
955
    if (!s) {
941
 
      fprintf(stderr, "Unable to locate '%s' in the SWIG library.\n", input_file);
 
956
      Printf(stderr, "Unable to locate '%s' in the SWIG library.\n", input_file);
942
957
    } else {
943
 
      FILE *f = fopen(outfile, "r");
 
958
      FILE *f = Swig_open(outfile);
944
959
      if (f) {
945
960
        fclose(f);
946
 
        fprintf(stderr, "File '%s' already exists. Checkout aborted.\n", outfile);
 
961
        Printf(stderr, "File '%s' already exists. Checkout aborted.\n", outfile);
947
962
      } else {
948
 
        f = fopen(outfile, "w");
949
 
        if (!f) {
950
 
          fprintf(stderr, "Unable to create file '%s'\n", outfile);
951
 
        } else {
952
 
          if (Verbose)
953
 
            fprintf(stdout, "'%s' checked out from the SWIG library.\n", input_file);
954
 
          fputs(Char(s), f);
955
 
          fclose(f);
956
 
        }
 
963
        File *f_outfile = NewFile(outfile, "w", SWIG_output_files());
 
964
        if (!f_outfile) {
 
965
          FileErrorDisplay(outfile);
 
966
          SWIG_exit(EXIT_FAILURE);
 
967
        } else {
 
968
          if (Verbose)
 
969
            Printf(stdout, "'%s' checked out from the SWIG library.\n", outfile);
 
970
          Printv(f_outfile, s, NIL);
 
971
          Close(f_outfile);
 
972
        }
957
973
      }
958
974
    }
959
975
  } else {
960
 
    // Check the suffix for a .c file.  If so, we're going to
961
 
    // declare everything we see as "extern"
962
 
 
963
 
    ForceExtern = check_suffix(input_file);
964
 
 
965
976
    // Run the preprocessor
966
977
    if (Verbose)
967
978
      printf("Preprocessing...\n");
971
982
      String *fs = NewString("");
972
983
      FILE *df = Swig_open(input_file);
973
984
      if (!df) {
974
 
        char *cfile = Char(input_file);
975
 
        if (cfile && cfile[0] == '-') {
976
 
          Printf(stderr, "Unable to find option or file '%s', ", input_file);
977
 
          Printf(stderr, "use 'swig -help' for more information.\n");
 
985
        df = Swig_include_open(input_file);
 
986
        if (!df) {
 
987
          char *cfile = Char(input_file);
 
988
          if (cfile && cfile[0] == '-') {
 
989
            Printf(stderr, "Unable to find option or file '%s', ", input_file);
 
990
            Printf(stderr, "use 'swig -help' for more information.\n");
 
991
          } else {
 
992
            Printf(stderr, "Unable to find file '%s'.\n", input_file);
 
993
          }
 
994
          SWIG_exit(EXIT_FAILURE);
978
995
        } else {
979
 
          Printf(stderr, "Unable to find file '%s'.\n", input_file);
 
996
          Swig_warning(WARN_DEPRECATED_INPUT_FILE, "SWIG", 1, "Use of the include path to find the input file is deprecated and will not work with ccache. Please include the path when specifying the input file.\n"); // so that behaviour is like c/c++ compilers
980
997
        }
981
 
        SWIG_exit(EXIT_FAILURE);
982
998
      }
983
 
      fclose(df);
984
999
      if (!no_cpp) {
 
1000
        fclose(df);
985
1001
        Printf(fs, "%%include <swig.swg>\n");
986
1002
        if (allkw) {
987
1003
          Printf(fs, "%%include <allkw.swg>\n");
989
1005
        if (lang_config) {
990
1006
          Printf(fs, "\n%%include <%s>\n", lang_config);
991
1007
        }
992
 
        Printf(fs, "%%include \"%s\"\n", Swig_last_file());
 
1008
        Printf(fs, "%%include(maininput=\"%s\") \"%s\"\n", Swig_filename_escape(input_file), Swig_last_file());
993
1009
        for (i = 0; i < Len(libfiles); i++) {
994
1010
          Printf(fs, "\n%%include \"%s\"\n", Getitem(libfiles, i));
995
1011
        }
997
1013
        cpps = Preprocessor_parse(fs);
998
1014
        Delete(fs);
999
1015
      } else {
1000
 
        df = Swig_open(input_file);
1001
 
        cpps = NewFileFromFile(df);
 
1016
        cpps = Swig_read_file(df);
 
1017
        fclose(df);
1002
1018
      }
1003
1019
      if (Swig_error_count()) {
1004
1020
        SWIG_exit(EXIT_FAILURE);
1008
1024
        SWIG_exit(EXIT_SUCCESS);
1009
1025
      }
1010
1026
      if (depend) {
1011
 
        String *outfile;
1012
 
        if (!outfile_name) {
1013
 
          if (CPlusPlus || lang->cplus_runtime_mode()) {
1014
 
            outfile = NewStringf("%s_wrap.%s", Swig_file_basename(input_file), cpp_extension);
1015
 
          } else {
1016
 
            outfile = NewStringf("%s_wrap.c", Swig_file_basename(input_file));
1017
 
          }
1018
 
        } else {
1019
 
          outfile = NewString(outfile_name);
1020
 
        }
1021
 
        if (dependencies_file && Len(dependencies_file) != 0) {
1022
 
          f_dependencies_file = NewFile(dependencies_file, "w");
1023
 
          if (!f_dependencies_file) {
1024
 
            FileErrorDisplay(dependencies_file);
1025
 
            SWIG_exit(EXIT_FAILURE);
1026
 
          }
1027
 
        } else if (!depend_only) {
1028
 
          String *filename = NewStringf("%s_wrap.%s", Swig_file_basename(input_file), depends_extension);
1029
 
          f_dependencies_file = NewFile(filename, "w");
1030
 
          if (!f_dependencies_file) {
1031
 
            FileErrorDisplay(filename);
1032
 
            SWIG_exit(EXIT_FAILURE);
1033
 
          }
1034
 
        } else
1035
 
          f_dependencies_file = stdout;
1036
 
        if (dependencies_target) {
1037
 
          Printf(f_dependencies_file, "%s: ", dependencies_target);
1038
 
        } else {
1039
 
          Printf(f_dependencies_file, "%s: ", outfile);
1040
 
        }
1041
 
        List *files = Preprocessor_depend();
1042
 
        for (int i = 0; i < Len(files); i++) {
1043
 
          if ((depend != 2) || ((depend == 2) && (Strncmp(Getitem(files, i), SwigLib, Len(SwigLib)) != 0))) {
1044
 
            Printf(f_dependencies_file, "\\\n %s ", Getitem(files, i));
1045
 
          }
1046
 
        }
1047
 
        Printf(f_dependencies_file, "\n");
1048
 
        if (f_dependencies_file != stdout)
1049
 
          Close(f_dependencies_file);
1050
 
        if (depend_only)
1051
 
          SWIG_exit(EXIT_SUCCESS);
 
1027
        if (!no_cpp) {
 
1028
          String *outfile;
 
1029
 
 
1030
          char *basename = Swig_file_basename(outcurrentdir ? Swig_file_filename(input_file): Char(input_file));
 
1031
          if (!outfile_name) {
 
1032
            if (CPlusPlus || lang->cplus_runtime_mode()) {
 
1033
              outfile = NewStringf("%s_wrap.%s", basename, cpp_extension);
 
1034
            } else {
 
1035
              outfile = NewStringf("%s_wrap.c", basename);
 
1036
            }
 
1037
          } else {
 
1038
            outfile = NewString(outfile_name);
 
1039
          }
 
1040
          if (dependencies_file && Len(dependencies_file) != 0) {
 
1041
            f_dependencies_file = NewFile(dependencies_file, "w", SWIG_output_files());
 
1042
            if (!f_dependencies_file) {
 
1043
              FileErrorDisplay(dependencies_file);
 
1044
              SWIG_exit(EXIT_FAILURE);
 
1045
            }
 
1046
          } else if (!depend_only) {
 
1047
            String *filename = NewStringf("%s_wrap.%s", basename, depends_extension);
 
1048
            f_dependencies_file = NewFile(filename, "w", SWIG_output_files());
 
1049
            if (!f_dependencies_file) {
 
1050
              FileErrorDisplay(filename);
 
1051
              SWIG_exit(EXIT_FAILURE);
 
1052
            }
 
1053
          } else
 
1054
            f_dependencies_file = stdout;
 
1055
          if (dependencies_target) {
 
1056
            Printf(f_dependencies_file, "%s: ", dependencies_target);
 
1057
          } else {
 
1058
            Printf(f_dependencies_file, "%s: ", outfile);
 
1059
          }
 
1060
          List *files = Preprocessor_depend();
 
1061
          for (int i = 0; i < Len(files); i++) {
 
1062
            if ((depend != 2) || ((depend == 2) && (Strncmp(Getitem(files, i), SwigLib, Len(SwigLib)) != 0))) {
 
1063
              Printf(f_dependencies_file, "\\\n %s ", Getitem(files, i));
 
1064
            }
 
1065
          }
 
1066
          Printf(f_dependencies_file, "\n");
 
1067
          if (f_dependencies_file != stdout)
 
1068
            Close(f_dependencies_file);
 
1069
          if (depend_only)
 
1070
            SWIG_exit(EXIT_SUCCESS);
 
1071
        } else {
 
1072
          Printf(stderr, "Cannot generate dependencies with -nopreprocess\n");
 
1073
          // Actually we could but it would be inefficient when just generating dependencies, as it would be done after Swig_cparse
 
1074
          SWIG_exit(EXIT_FAILURE);
 
1075
        }
1052
1076
      }
1053
1077
      Seek(cpps, 0, SEEK_SET);
1054
1078
    }
1126
1150
    }
1127
1151
    if (top) {
1128
1152
      if (!Getattr(top, "name")) {
1129
 
        Printf(stderr, "*** No module name specified using %%module or -module.\n");
 
1153
        Printf(stderr, "No module name specified using %%module or -module.\n");
1130
1154
        SWIG_exit(EXIT_FAILURE);
1131
1155
      } else {
1132
1156
        /* Set some filename information on the object */
1133
 
        Setattr(top, "infile", input_file);
 
1157
        String *infile = scanner_get_main_input_file();
 
1158
        if (!infile) {
 
1159
          Printf(stderr, "Missing input file in preprocessed output.\n");
 
1160
          SWIG_exit(EXIT_FAILURE);
 
1161
        }
 
1162
        Setattr(top, "infile", infile); // Note: if nopreprocess then infile is the original input file, otherwise input_file
 
1163
        Setattr(top, "inputfile", input_file);
 
1164
 
 
1165
        char *basename = Swig_file_basename(outcurrentdir ? Swig_file_filename(infile): Char(infile));
1134
1166
        if (!outfile_name) {
1135
1167
          if (CPlusPlus || lang->cplus_runtime_mode()) {
1136
 
            Setattr(top, "outfile", NewStringf("%s_wrap.%s", Swig_file_basename(input_file), cpp_extension));
 
1168
            Setattr(top, "outfile", NewStringf("%s_wrap.%s", basename, cpp_extension));
1137
1169
          } else {
1138
 
            Setattr(top, "outfile", NewStringf("%s_wrap.c", Swig_file_basename(input_file)));
 
1170
            Setattr(top, "outfile", NewStringf("%s_wrap.c", basename));
1139
1171
          }
1140
1172
        } else {
1141
1173
          Setattr(top, "outfile", outfile_name);
1142
1174
        }
1143
1175
        if (!outfile_name_h) {
1144
 
          Setattr(top, "outfile_h", NewStringf("%s_wrap.%s", Swig_file_basename(input_file), hpp_extension));
 
1176
          Setattr(top, "outfile_h", NewStringf("%s_wrap.%s", basename, hpp_extension));
1145
1177
        } else {
1146
1178
          Setattr(top, "outfile_h", outfile_name_h);
1147
1179
        }
1149
1181
        if (Swig_contract_mode_get()) {
1150
1182
          Swig_contracts(top);
1151
1183
        }
 
1184
 
 
1185
        // Check the suffix for a c/c++ file.  If so, we're going to declare everything we see as "extern"
 
1186
        ForceExtern = check_suffix(input_file);
 
1187
 
1152
1188
        lang->top(top);
 
1189
 
1153
1190
        if (browse) {
1154
1191
          Swig_browser(top, 0);
1155
1192
        }
1173
1210
  if (memory_debug)
1174
1211
    DohMemoryDebug();
1175
1212
 
 
1213
  char *outfiles = getenv("CCACHE_OUTFILES");
 
1214
  if (outfiles) {
 
1215
    File *f_outfiles = NewFile(outfiles, "w", 0);
 
1216
    if (!f_outfiles) {
 
1217
      Printf(stderr, "Failed to write list of output files to the filename '%s' specified in CCACHE_OUTFILES environment variable - ", outfiles);
 
1218
      FileErrorDisplay(outfiles);
 
1219
      SWIG_exit(EXIT_FAILURE);
 
1220
    } else {
 
1221
      int i;
 
1222
      for (i = 0; i < Len(all_output_files); i++)
 
1223
        Printf(f_outfiles, "%s\n", Getitem(all_output_files, i));
 
1224
      Close(f_outfiles);
 
1225
    }
 
1226
  }
 
1227
 
1176
1228
  // Deletes
1177
1229
  Delete(libfiles);
1178
1230
  Preprocessor_delete();