Index: flang/test/Driver/version_test.f90 =================================================================== --- flang/test/Driver/version_test.f90 +++ flang/test/Driver/version_test.f90 @@ -1,7 +1,10 @@ ! Check that lit configuration works by checking the compiler version -! RUN: %f18 -V 2>&1 | FileCheck -check-prefix=VERSION %s ! VERSION-NOT:{{![[:space:]]}} ! VERSION:{{[[:space:]]}} -! VERSION-SAME:f18 compiler (under development) +! VERSION-SAME:f18 compiler (under development), version {{[1-9][0-9]*.[0-9]*.[0-9]*}} ! VERSION-EMPTY: + +! RUN: %f18 -V 2>&1 | FileCheck -check-prefix=VERSION %s +! RUN: %f18 -v 2>&1 | FileCheck -check-prefix=VERSION %s +! RUN: %f18 --version 2>&1 | FileCheck -check-prefix=VERSION %s Index: flang/test/Preprocessing/compiler_defined_macros.F90 =================================================================== --- flang/test/Preprocessing/compiler_defined_macros.F90 +++ flang/test/Preprocessing/compiler_defined_macros.F90 @@ -0,0 +1,7 @@ +! Check that the macros that give the verion number are set properly + +! RUN: %f18 %s -E | grep -i -E '"MAJOR" [1-9][0-9]* "MINOR" [0-9]* "PATCH" [0-9]*' + +#ifdef __flang__ + "MAJOR" __flang_major__ "MINOR" __flang_minor__ "PATCH" __flang_patchlevel__ +#endif Index: flang/tools/f18/CMakeLists.txt =================================================================== --- flang/tools/f18/CMakeLists.txt +++ flang/tools/f18/CMakeLists.txt @@ -61,6 +61,7 @@ set(FLANG_INTRINSIC_MODULES_DIR ${FLANG_BINARY_DIR}/include/flang) configure_file(${CMAKE_CURRENT_SOURCE_DIR}/flang.sh.in ${CMAKE_BINARY_DIR}/tools/flang/bin/flang @ONLY) file(COPY ${CMAKE_BINARY_DIR}/tools/flang/bin/flang DESTINATION ${CMAKE_BINARY_DIR}/bin FILE_PERMISSIONS OWNER_EXECUTE OWNER_READ OWNER_WRITE) +configure_file(${CMAKE_CURRENT_SOURCE_DIR}/f18_version.h.in ${CMAKE_CURRENT_BINARY_DIR}/f18_version.h @ONLY) # The flang script to be installed needs a different path to the headers. set(FLANG_INTRINSIC_MODULES_DIR ${CMAKE_INSTALL_PREFIX}/include/flang) configure_file(${CMAKE_CURRENT_SOURCE_DIR}/flang.sh.in ${FLANG_BINARY_DIR}/bin/flang-install.sh @ONLY) Index: flang/tools/f18/f18.cpp =================================================================== --- flang/tools/f18/f18.cpp +++ flang/tools/f18/f18.cpp @@ -38,6 +38,8 @@ #include #include +#include "f18_version.h" + static std::list argList(int argc, char *const argv[]) { std::list result; for (int j = 0; j < argc; ++j) { @@ -386,6 +388,13 @@ } } +int printVersion() { + llvm::errs() << "\nf18 compiler (under development), version " + << __FLANG_MAJOR__ << "." << __FLANG_MINOR__ << "." + << __FLANG_PATCHLEVEL__ << "\n"; + return exitStatus; +} + int main(int argc, char *const argv[]) { atexit(CleanUpAtExit); @@ -402,10 +411,11 @@ driver.prefix = prefix.data(); Fortran::parser::Options options; - options.predefinitions.emplace_back("__F18", "1"); - options.predefinitions.emplace_back("__F18_MAJOR__", "1"); - options.predefinitions.emplace_back("__F18_MINOR__", "1"); - options.predefinitions.emplace_back("__F18_PATCHLEVEL__", "1"); + options.predefinitions.emplace_back("__flang__", __FLANG__); + options.predefinitions.emplace_back("__flang_major__", __FLANG_MAJOR__); + options.predefinitions.emplace_back("__flang_minor__", __FLANG_MINOR__); + options.predefinitions.emplace_back( + "__flang_patchlevel__", __FLANG_PATCHLEVEL__); #if __x86_64__ options.predefinitions.emplace_back("__x86_64__", "1"); #endif @@ -622,13 +632,16 @@ << " -help print this again\n" << "Other options are passed through to the compiler.\n"; return exitStatus; - } else if (arg == "-V") { - llvm::errs() << "\nf18 compiler (under development)\n"; - return exitStatus; + } else if (arg == "-V" || arg == "--version") { + return printVersion(); } else { driver.F18_FCArgs.push_back(arg); if (arg == "-v") { - driver.verbose = true; + if (args.size() > 1) { + driver.verbose = true; + } else { + return printVersion(); + } } else if (arg == "-I") { driver.F18_FCArgs.push_back(args.front()); driver.searchDirectories.push_back(args.front()); Index: flang/tools/f18/f18_version.h.in =================================================================== --- flang/tools/f18/f18_version.h.in +++ flang/tools/f18/f18_version.h.in @@ -0,0 +1,9 @@ +#ifndef _F18_H_ +#define _F18_H_ + +#define __FLANG__ "1" +#define __FLANG_MAJOR__ "@LLVM_VERSION_MAJOR@" +#define __FLANG_MINOR__ "@LLVM_VERSION_MINOR@" +#define __FLANG_PATCHLEVEL__ "@LLVM_VERSION_PATCH@" + +#endif // _F18_H_