diff options
Diffstat (limited to 'cpp/src/slice2java/Main.cpp')
-rw-r--r-- | cpp/src/slice2java/Main.cpp | 114 |
1 files changed, 72 insertions, 42 deletions
diff --git a/cpp/src/slice2java/Main.cpp b/cpp/src/slice2java/Main.cpp index fd39fe0d277..6d234428ec1 100644 --- a/cpp/src/slice2java/Main.cpp +++ b/cpp/src/slice2java/Main.cpp @@ -50,6 +50,7 @@ main(int argc, char* argv[]) bool clone = false; bool debug = false; bool ice = false; + bool depend = false; int idx = 1; while(idx < argc) @@ -184,6 +185,15 @@ main(int argc, char* argv[]) } --argc; } + else if(strcmp(argv[idx], "--depend") == 0) + { + depend = true; + for(int i = idx ; i + 1 < argc ; ++i) + { + argv[i] = argv[i + 1]; + } + --argc; + } else if(argv[idx][0] == '-') { cerr << argv[0] << ": unknown option `" << argv[idx] << "'" @@ -233,62 +243,82 @@ main(int argc, char* argv[]) ifstream test(argv[idx]); if(!test) { - cerr << argv[0] << ": can't open `" << argv[idx] - << "' for reading: " << strerror(errno) << endl; + cerr << argv[0] << ": can't open `" << argv[idx] << "' for reading: " << strerror(errno) << endl; return EXIT_FAILURE; } test.close(); - string cmd = cpp + " " + argv[idx]; + if(depend) + { + string::size_type pos = base.rfind('/'); + if(pos != string::npos) + { + base.erase(0, pos + 1); + } + + string cmd = cpp + " -M -MT " + base + ".java " + argv[idx]; + #ifdef _WIN32 - FILE* cppHandle = _popen(cmd.c_str(), "r"); + FILE* cppHandle = _popen(cmd.c_str(), "w"); + _pclose(cppHandle); #else - FILE* cppHandle = popen(cmd.c_str(), "r"); + FILE* cppHandle = popen(cmd.c_str(), "w"); + pclose(cppHandle); #endif - if(cppHandle == 0) - { - cerr << argv[0] << ": can't run C++ preprocessor: " - << strerror(errno) << endl; - return EXIT_FAILURE; - } + } + else + { + string cmd = cpp + " " + argv[idx]; +#ifdef _WIN32 + FILE* cppHandle = _popen(cmd.c_str(), "r"); +#else + FILE* cppHandle = popen(cmd.c_str(), "r"); +#endif + if(cppHandle == 0) + { + cerr << argv[0] << ": can't run C++ preprocessor: " + << strerror(errno) << endl; + return EXIT_FAILURE; + } - UnitPtr unit = Unit::createUnit(false, false, ice); - int parseStatus = unit->parse(cppHandle, debug); + UnitPtr unit = Unit::createUnit(false, false, ice); + int parseStatus = unit->parse(cppHandle, debug); #ifdef _WIN32 - _pclose(cppHandle); + _pclose(cppHandle); #else - pclose(cppHandle); + pclose(cppHandle); #endif - if(parseStatus == EXIT_FAILURE) - { - status = EXIT_FAILURE; - } - else - { - Gen gen(argv[0], base, includePaths, package, output, clone); - if(!gen) - { - unit->destroy(); - return EXIT_FAILURE; - } - gen.generate(unit); - if(tie) - { - gen.generateTie(unit); - } - if(impl) - { - gen.generateImpl(unit); - } - if(implTie) - { - gen.generateImplTie(unit); - } - } + if(parseStatus == EXIT_FAILURE) + { + status = EXIT_FAILURE; + } + else + { + Gen gen(argv[0], base, includePaths, package, output, clone); + if(!gen) + { + unit->destroy(); + return EXIT_FAILURE; + } + gen.generate(unit); + if(tie) + { + gen.generateTie(unit); + } + if(impl) + { + gen.generateImpl(unit); + } + if(implTie) + { + gen.generateImplTie(unit); + } + } - unit->destroy(); + unit->destroy(); + } } return status; |