diff --git a/clang/include/clang/Driver/Options.td b/clang/include/clang/Driver/Options.td --- a/clang/include/clang/Driver/Options.td +++ b/clang/include/clang/Driver/Options.td @@ -4522,6 +4522,9 @@ def fget_symbols_sources : Flag<["-"], "fget-symbols-sources">, Group, HelpText<"Dump symbols and their source code locations">; +def module_suffix : Separate<["-"], "module-suffix">, Group, MetaVarName<"">, + HelpText<"Use as the suffix for module files (the default value is `.mod`)">; + } //===----------------------------------------------------------------------===// diff --git a/flang/include/flang/Frontend/CompilerInvocation.h b/flang/include/flang/Frontend/CompilerInvocation.h --- a/flang/include/flang/Frontend/CompilerInvocation.h +++ b/flang/include/flang/Frontend/CompilerInvocation.h @@ -69,6 +69,8 @@ // of options. std::string moduleDir_ = "."; + std::string moduleFileSuffix_ = ".mod"; + bool debugModuleDir_ = false; bool warnAsErr_ = false; @@ -97,6 +99,9 @@ std::string &moduleDir() { return moduleDir_; } const std::string &moduleDir() const { return moduleDir_; } + std::string &moduleFileSuffix() { return moduleFileSuffix_; } + const std::string &moduleFileSuffix() const { return moduleFileSuffix_; } + bool &debugModuleDir() { return debugModuleDir_; } const bool &debugModuleDir() const { return debugModuleDir_; } @@ -129,6 +134,10 @@ /// Useful setters void SetModuleDir(std::string &moduleDir) { moduleDir_ = moduleDir; } + void SetModuleFileSuffix(const char *moduleFileSuffix) { + moduleFileSuffix_ = std::string(moduleFileSuffix); + } + void SetDebugModuleDir(bool flag) { debugModuleDir_ = flag; } void SetWarnAsErr(bool flag) { warnAsErr_ = flag; } diff --git a/flang/lib/Frontend/CompilerInvocation.cpp b/flang/lib/Frontend/CompilerInvocation.cpp --- a/flang/lib/Frontend/CompilerInvocation.cpp +++ b/flang/lib/Frontend/CompilerInvocation.cpp @@ -392,6 +392,12 @@ res.SetDebugModuleDir(true); } + // -module-suffix + if (const auto *moduleSuffix = + args.getLastArg(clang::driver::options::OPT_module_suffix)) { + res.SetModuleFileSuffix(moduleSuffix->getValue()); + } + return diags.getNumErrors() == numErrorsBefore; } @@ -639,5 +645,6 @@ semanticsContext_->set_moduleDirectory(moduleDir()) .set_searchDirectories(fortranOptions.searchDirectories) .set_warnOnNonstandardUsage(enableConformanceChecks()) - .set_warningsAreErrors(warnAsErr()); + .set_warningsAreErrors(warnAsErr()) + .set_moduleFileSuffix(moduleFileSuffix()); } diff --git a/flang/test/Driver/driver-help.f90 b/flang/test/Driver/driver-help.f90 --- a/flang/test/Driver/driver-help.f90 +++ b/flang/test/Driver/driver-help.f90 @@ -106,6 +106,7 @@ ! HELP-FC1-NEXT: -help Display available options ! HELP-FC1-NEXT: -I Add directory to the end of the list of include search paths ! HELP-FC1-NEXT: -module-dir Put MODULE files in +! HELP-FC1-NEXT: -module-suffix Use as the suffix for module files (the default value is `.mod`) ! HELP-FC1-NEXT: -nocpp Disable predefined and command line preprocessor macros ! HELP-FC1-NEXT: -o Write output to ! HELP-FC1-NEXT: -pedantic Warn on language extensions diff --git a/flang/test/Driver/module-suffix.f90 b/flang/test/Driver/module-suffix.f90 new file mode 100644 --- /dev/null +++ b/flang/test/Driver/module-suffix.f90 @@ -0,0 +1,16 @@ +! Tests `-module-suffix` frontend option + +!-------------------------- +! RUN lines +!-------------------------- +! RUN: rm -rf %t && mkdir -p %t/dir-flang/ +! RUN: cd %t && %flang_fc1 -fsyntax-only -module-suffix .f18.mod -module-dir %t/dir-flang %s +! RUN: ls %t/dir-flang/testmodule.f18.mod && not ls %t/dir-flang/testmodule.mod + +!-------------------------- +! INPUT +!-------------------------- +module testmodule + type::t2 + end type +end