Add support for the -external-runtime argument and update all language modules to use it

git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@6993 626c5289-ae23-0410-ae9c-e8d60b6d4f22
This commit is contained in:
John Lenz 2005-02-23 22:40:51 +00:00
commit ef58056ffd
18 changed files with 233 additions and 46 deletions

View file

@ -93,6 +93,9 @@ protected:
String *chickenNameMapping(String *, String_or_char *);
String *chickenPrimitiveName(String *);
String *runtimeCode();
String *defaultExternalRuntimeFilename();
};
/* -----------------------------------------------------------------------
@ -1329,3 +1332,15 @@ CHICKEN::validIdentifier(String *s)
}
return n;
}
String *CHICKEN::runtimeCode() {
String *s = Swig_include_sys("chickenrun.swg");
if (!s) {
Printf(stderr, "*** Unable to open 'chickenrun.swg'\n");
s = NewString("");
}
}
String *CHICKEN::defaultExternalRuntimeFilename() {
return NewString("swigchickenrun.h");
}

View file

@ -1772,6 +1772,32 @@ public:
}
return 1;
}
String *runtimeCode() {
String *s;
if (use_scm_interface) {
s = Swig_include_sys("guile_scm_run.swg");
if (!s) {
Printf(stderr, "*** Unable to open 'guile_scm_run.swg");
s = NewString("");
}
} else {
s = Swig_include_sys("guile_gh_run.swg");
if (!s) {
Printf(stderr, "*** Unable to open 'guile_gh_run.swg");
s = NewString("");
}
}
return s;
}
String *defaultExternalRuntimeFilename() {
if (use_scm_interface) {
return NewString("swigguilerun.h");
} else {
return NewString("swigguileghrun.h");
}
}
};
/* -----------------------------------------------------------------------------

View file

@ -2915,3 +2915,11 @@ int Language::is_assignable(Node *n)
}
return 1;
}
String *Language::runtimeCode() {
return NewString("");
}
String *Language::defaultExternalRuntimeFilename() {
return 0;
}

View file

@ -128,6 +128,8 @@ static DOH *libfiles = 0;
static DOH *cpps = 0 ;
static String *dependencies_file = 0;
static File *f_dependencies_file = 0;
static int external_runtime = 0;
static String *external_runtime_name = 0;
// -----------------------------------------------------------------------------
// check_suffix(char *name)
@ -269,6 +271,56 @@ void SWIG_getfeatures(const char *c)
Delete(name);
}
/* This function handles the -external-runtime command option */
static void SWIG_dump_runtime() {
String *outfile;
File *runtime;
String *s;
outfile = external_runtime_name;
if (!outfile) {
outfile = lang->defaultExternalRuntimeFilename();
if (!outfile) {
Printf(stderr, "*** Please provide a filename for the external runtime\n");
SWIG_exit(EXIT_FAILURE);
}
}
runtime = NewFile(outfile, "w");
if (!runtime) {
Printf(stderr, "*** Unable to open '%s'\n", outfile);
Close(runtime);
SWIG_exit(EXIT_FAILURE);
}
Swig_banner(runtime);
s = Swig_include_sys("swigrun.swg");
if (!s) {
Printf(stderr, "*** Unable to open 'swigrun.swg'\n");
Close(runtime);
SWIG_exit(EXIT_FAILURE);
}
Printf(runtime, "%s", s);
Delete(s);
s = lang->runtimeCode();
Printf(runtime, "%s", s);
Delete(s);
s = Swig_include_sys("runtime.swg");
if (!s) {
Printf(stderr, "*** Unable to open 'runtime.swg'\n");
Close(runtime);
SWIG_exit(EXIT_FAILURE);
}
Printf(runtime, "%s", s);
Delete(s);
Close(runtime);
SWIG_exit(EXIT_SUCCESS);
}
void SWIG_getoptions(int argc, char *argv[])
{
int i;
@ -341,6 +393,14 @@ void SWIG_getoptions(int argc, char *argv[])
Swig_mark_arg(i);
Swig_warning(WARN_DEPRECATED_OPTC, "SWIG",1, "-c, -runtime, -noruntime command line options are deprecated.\n");
SwigRuntime = 2;
} else if (strcmp(argv[i], "-external-runtime") == 0) {
external_runtime = 1;
Swig_mark_arg(i);
if (argv[i+1]) {
external_runtime_name = NewString(argv[i+1]);
Swig_mark_arg(i+1);
i++;
}
} else if ((strcmp(argv[i],"-make_default") == 0) || (strcmp(argv[i],"-makedefault") == 0)) {
GenerateDefault = 1;
Swig_mark_arg(i);
@ -645,7 +705,8 @@ int SWIG_main(int argc, char *argv[], Language *l) {
}
// Check all of the options to make sure we're cool.
Swig_check_options();
// Don't check for an input file if -external-runtime is passed
Swig_check_options(external_runtime ? 0 : 1);
install_opts(argc, argv);
@ -674,6 +735,10 @@ int SWIG_main(int argc, char *argv[], Language *l) {
}
}
// handle the -external-runtime argument
if (external_runtime)
SWIG_dump_runtime();
// If we made it this far, looks good. go for it....
input_file = argv[argc-1];

View file

@ -798,6 +798,19 @@ public:
}
return 1;
}
String *runtimeCode() {
String *s = Swig_include_sys("mzrun.swg");
if (!s) {
Printf(stderr, "*** Unable to open 'mzrun.swg'\n");
s = NewString("");
}
return s;
}
String *defaultExternalRuntimeFilename() {
return NewString("swigmzrun.h");
}
};
/* -----------------------------------------------------------------------------

View file

@ -1931,6 +1931,19 @@ public:
}
return SWIG_OK;
}
String *runtimeCode() {
String *s = Swig_include_sys("ocaml.swg");
if (!s) {
Printf(stderr, "*** Unable to open 'ocaml.swg'\n");
s = NewString("");
}
return s;
}
String *defaultExternalRuntimeFilename() {
return NewString("swigocamlrun.h");
}
};
/* -------------------------------------------------------------------------

View file

@ -1527,6 +1527,19 @@ public:
}
return SWIG_OK;
}
String *runtimeCode() {
String *s = Swig_include_sys("perlrun.swg");
if (!s) {
Printf(stderr, "*** Unable to open 'perlrun.swg'\n");
s = NewString("");
}
return s;
}
String *defaultExternalRuntimeFilename() {
return NewString("swigperlrun.h");
}
};
/* -----------------------------------------------------------------------------

View file

@ -2470,6 +2470,20 @@ public:
}
return SWIG_OK;
}
virtual String *runtimeCode() {
String *s = Swig_include_sys("pyrun.swg");
if (!s) {
Printf(stderr, "*** Unable to open 'pyrun.swg'\n");
s = NewString("");
}
return s;
}
virtual String *defaultExternalRuntimeFilename() {
return NewString("swigpyrun.h");
}
};
/* ---------------------------------------------------------------

View file

@ -2470,6 +2470,19 @@ public:
p = nextSibling(p);
}
}
String *runtimeCode() {
String *s = Swig_include_sys("rubydef.swg");
if (!s) {
Printf(stderr, "*** Unable to open 'rubydef.swg'\n");
s = NewString("");
}
return s;
}
String *defaultExternalRuntimeFilename() {
return NewString("swigrubyrun.h");
}
}; /* class RUBY */
/* -----------------------------------------------------------------------------

View file

@ -224,6 +224,8 @@ public:
virtual Node *enumLookup(SwigType *s); /* Enum lookup */
virtual int abstractClassTest(Node *n); /* Is class really abstract? */
virtual int is_assignable(Node *n); /* Is variable assignable? */
virtual String *runtimeCode(); /* returns the language specific runtime code */
virtual String *defaultExternalRuntimeFilename(); /* the default filename for the external runtime */
/* Allow director related code generation */
void allow_directors(int val = 1);

View file

@ -1219,6 +1219,19 @@ public:
}
return Char(temp);
}
String *runtimeCode() {
String *s = Swig_include_sys("swigtcl8.swg");
if (!s) {
Printf(stderr, "*** Unable to open 'swigtcl8.swg'\n");
s = NewString("");
}
return s;
}
String *defaultExternalRuntimeFilename() {
return NewString("swigtclrun.h");
}
};
/* ----------------------------------------------------------------------