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;
184
187
// -----------------------------------------------------------------------------
185
// check_suffix(char *name)
187
190
// Checks the suffix of a file to see if we should emit extern declarations.
188
191
// -----------------------------------------------------------------------------
190
static int check_suffix(const char *name) {
193
static int check_suffix(String *filename) {
194
const char *name = Char(filename);
939
954
s = Swig_include(input_file);
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);
943
FILE *f = fopen(outfile, "r");
958
FILE *f = Swig_open(outfile);
946
fprintf(stderr, "File '%s' already exists. Checkout aborted.\n", outfile);
961
Printf(stderr, "File '%s' already exists. Checkout aborted.\n", outfile);
948
f = fopen(outfile, "w");
950
fprintf(stderr, "Unable to create file '%s'\n", outfile);
953
fprintf(stdout, "'%s' checked out from the SWIG library.\n", input_file);
963
File *f_outfile = NewFile(outfile, "w", SWIG_output_files());
965
FileErrorDisplay(outfile);
966
SWIG_exit(EXIT_FAILURE);
969
Printf(stdout, "'%s' checked out from the SWIG library.\n", outfile);
970
Printv(f_outfile, s, NIL);
960
// Check the suffix for a .c file. If so, we're going to
961
// declare everything we see as "extern"
963
ForceExtern = check_suffix(input_file);
965
976
// Run the preprocessor
967
978
printf("Preprocessing...\n");
971
982
String *fs = NewString("");
972
983
FILE *df = Swig_open(input_file);
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);
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");
992
Printf(stderr, "Unable to find file '%s'.\n", input_file);
994
SWIG_exit(EXIT_FAILURE);
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
981
SWIG_exit(EXIT_FAILURE);
985
1001
Printf(fs, "%%include <swig.swg>\n");
987
1003
Printf(fs, "%%include <allkw.swg>\n");
1008
1024
SWIG_exit(EXIT_SUCCESS);
1012
if (!outfile_name) {
1013
if (CPlusPlus || lang->cplus_runtime_mode()) {
1014
outfile = NewStringf("%s_wrap.%s", Swig_file_basename(input_file), cpp_extension);
1016
outfile = NewStringf("%s_wrap.c", Swig_file_basename(input_file));
1019
outfile = NewString(outfile_name);
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);
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);
1035
f_dependencies_file = stdout;
1036
if (dependencies_target) {
1037
Printf(f_dependencies_file, "%s: ", dependencies_target);
1039
Printf(f_dependencies_file, "%s: ", outfile);
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));
1047
Printf(f_dependencies_file, "\n");
1048
if (f_dependencies_file != stdout)
1049
Close(f_dependencies_file);
1051
SWIG_exit(EXIT_SUCCESS);
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);
1035
outfile = NewStringf("%s_wrap.c", basename);
1038
outfile = NewString(outfile_name);
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);
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);
1054
f_dependencies_file = stdout;
1055
if (dependencies_target) {
1056
Printf(f_dependencies_file, "%s: ", dependencies_target);
1058
Printf(f_dependencies_file, "%s: ", outfile);
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));
1066
Printf(f_dependencies_file, "\n");
1067
if (f_dependencies_file != stdout)
1068
Close(f_dependencies_file);
1070
SWIG_exit(EXIT_SUCCESS);
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);
1053
1077
Seek(cpps, 0, SEEK_SET);
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);
1132
1156
/* Set some filename information on the object */
1133
Setattr(top, "infile", input_file);
1157
String *infile = scanner_get_main_input_file();
1159
Printf(stderr, "Missing input file in preprocessed output.\n");
1160
SWIG_exit(EXIT_FAILURE);
1162
Setattr(top, "infile", infile); // Note: if nopreprocess then infile is the original input file, otherwise input_file
1163
Setattr(top, "inputfile", input_file);
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));
1138
Setattr(top, "outfile", NewStringf("%s_wrap.c", Swig_file_basename(input_file)));
1170
Setattr(top, "outfile", NewStringf("%s_wrap.c", basename));
1141
1173
Setattr(top, "outfile", outfile_name);
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));
1146
1178
Setattr(top, "outfile_h", outfile_name_h);