[flang] Create a throwaway wrapper for the throwaway driver.
authorSteve Scalpone <sscalpone@nvidia.com>
Tue, 13 Aug 2019 04:40:03 +0000 (21:40 -0700)
committerSteve Scalpone <sscalpone@nvidia.com>
Tue, 13 Aug 2019 04:40:03 +0000 (21:40 -0700)
Add a script called flang to the bin directory that calls
f18 with the -I option pointing to the module files for the
predefined modules. The wrapper also sets the module suffix
to .fmf to avoid naming conflicts with module files generated
by other compilers. Now, the build creates and installs both
.mod and .fmf files for the predefined module files to
accommodate the flang script.

Original-commit: flang-compiler/f18@b6c30284e7876f6ccd4bb024bd5f349128e99b7c
Reviewed-on: https://github.com/flang-compiler/f18/pull/653
Tree-same-pre-rewrite: false

flang/tools/f18/CMakeLists.txt
flang/tools/f18/flang.sh [new file with mode: 0644]

index 9c74048..6f58438 100644 (file)
@@ -55,10 +55,28 @@ foreach(filename ${MODULES})
     WORKING_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/include"
     DEPENDS f18 ${PROJECT_SOURCE_DIR}/module/${filename}.f90
   )
+  add_custom_command(OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/include/${filename}.fmf
+    COMMAND f18 -fparse-only -fdebug-semantics -module-suffix .fmf ${PROJECT_SOURCE_DIR}/module/${filename}.f90
+    WORKING_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/include"
+    DEPENDS f18 ${PROJECT_SOURCE_DIR}/module/${filename}.f90
+  )
   list(APPEND MODULE_FILES "${CMAKE_CURRENT_BINARY_DIR}/include/${filename}.mod")
+  list(APPEND MODULE_FILES "${CMAKE_CURRENT_BINARY_DIR}/include/${filename}.fmf")
   install(FILES ${CMAKE_CURRENT_BINARY_DIR}/include/${filename}.mod DESTINATION include)
+  install(FILES ${CMAKE_CURRENT_BINARY_DIR}/include/${filename}.fmf DESTINATION include)
 endforeach()
 
 add_custom_target(module_files ALL DEPENDS ${MODULE_FILES})
 
 install(TARGETS f18 f18-parse-demo DESTINATION bin)
+
+file(COPY flang.sh
+  DESTINATION "${CMAKE_CURRENT_BINARY_DIR}/bin"
+  FILE_PERMISSIONS
+    OWNER_READ OWNER_WRITE OWNER_EXECUTE
+    GROUP_READ GROUP_EXECUTE
+    WORLD_READ WORLD_EXECUTE
+)
+file(RENAME "${CMAKE_CURRENT_BINARY_DIR}/bin/flang.sh" "${CMAKE_CURRENT_BINARY_DIR}/bin/flang")
+
+install(PROGRAMS flang.sh DESTINATION bin RENAME flang)
diff --git a/flang/tools/f18/flang.sh b/flang/tools/f18/flang.sh
new file mode 100644 (file)
index 0000000..77b22d5
--- /dev/null
@@ -0,0 +1,22 @@
+#!/bin/bash
+
+function abspath() {
+  pushd . > /dev/null;
+  if [ -d "$1" ]; then
+    cd "$1";
+    dirs -l +0;
+  else
+    cd "`dirname \"$1\"`";
+    cur_dir=`dirs -l +0`;
+    if [ "$cur_dir" == "/" ]; then
+      echo "$cur_dir`basename \"$1\"`";
+    else
+      echo "$cur_dir/`basename \"$1\"`";
+    fi;
+  fi;
+  popd > /dev/null;
+}
+
+wd=`abspath $(dirname "$0")/..`
+
+$wd/bin/f18 -fdebug-semantics -module-suffix .fmf -I $wd/include $*