@@ -91,9 +91,7 @@ function (gen_rst_file_from_td output_file td_option source)
9191 list (APPEND LLVM_TABLEGEN_FLAGS "-I${CMAKE_CURRENT_SOURCE_DIR} /../../clang/include/clang/Driver/" )
9292 clang_tablegen(Source /${output_file} ${td_option} SOURCE ${source} TARGET "gen-${output_file} " )
9393 # clang_tablegen() does not create the output directory automatically,
94- # so we have to create it explicitly. Note that copy-flang-src-docs below
95- # does create the output directory, but it is not necessarily run
96- # before RST generation.
94+ # so we have to create it explicitly.
9795 add_custom_target (create-flang-rst-output -dir
9896 COMMAND ${CMAKE_COMMAND} -E make_directory ${CMAKE_CURRENT_BINARY_DIR} /Source
9997 )
@@ -110,28 +108,56 @@ if (LLVM_ENABLE_SPHINX)
110108 # Generate the RST file from TableGen (shared by both HTML and MAN builds)
111109 gen_rst_file_from_td(FlangCommandLineReference.rst -gen-opt-docs FlangOptionsDocs.td)
112110
113- # Copy the flang/docs directory and the generated FIRLangRef.md file to a place in the binary directory.
114- # Having all the files in a single directory makes it possible for Sphinx to process them together.
115- # Add a dependency to the flang-doc target to ensure that the FIRLangRef.md file is generated before the copying happens.
116- add_custom_target (copy-flang-src-docs
117- COMMAND "${CMAKE_COMMAND} " -E copy_directory
118- "${CMAKE_CURRENT_SOURCE_DIR} "
119- "${CMAKE_CURRENT_BINARY_DIR} /Source"
120- DEPENDS flang-doc gen-FlangCommandLineReference.rst)
121-
122- # Run Python preprocessing to prepend header to FIRLangRef.md
123- add_custom_command (TARGET copy-flang-src-docs
124- COMMAND "${Python3_EXECUTABLE} "
125- ARGS ${CMAKE_CURRENT_BINARY_DIR} /Source /FIR/CreateFIRLangRef.py)
126-
127111 if (${SPHINX_OUTPUT_HTML} )
112+ message (STATUS "Using index.md for html build" )
113+
114+ # Copy the entire flang/docs directory to the build Source dir,
115+ # then remove the index.rst file, to avoid clash with index.md
116+ # which is used for the HTML build.
117+ add_custom_target (copy-flang-src-docs-html
118+ COMMAND "${CMAKE_COMMAND} " -E copy_directory
119+ "${CMAKE_CURRENT_SOURCE_DIR} "
120+ "${CMAKE_CURRENT_BINARY_DIR} /Source"
121+ COMMAND "${CMAKE_COMMAND} " -E remove
122+ "${CMAKE_CURRENT_BINARY_DIR} /Source/index.rst"
123+ DEPENDS flang-doc gen-FlangCommandLineReference.rst)
124+
125+ # Run Python preprocessing ONLY for HTML build
126+ # This script prepends headers to FIRLangRef.md for proper formatting
127+ add_custom_command (TARGET copy-flang-src-docs-html
128+ COMMAND "${Python3_EXECUTABLE} "
129+ ARGS ${CMAKE_CURRENT_BINARY_DIR} /Source /FIR/CreateFIRLangRef.py)
130+
128131 add_sphinx_target(html flang SOURCE_DIR "${CMAKE_CURRENT_BINARY_DIR} /Source" )
129- add_dependencies (docs-flang-html copy-flang-src-docs)
132+ add_dependencies (docs-flang-html copy-flang-src-docs-html )
130133 endif ()
134+
135+ # ----------------------------
136+ # MAN BUILD SETUP
137+ # ----------------------------
131138 if (${SPHINX_OUTPUT_MAN} )
132139 message (STATUS "NOTE: The Flang man page is currently a placeholder with a TODO. See docs/index.rst for details" )
140+
141+ # Create minimal Source dir with ONLY the files needed for man build:
142+ # - conf.py (Sphinx config)
143+ # - index.rst (top-level man page)
144+ # - FlangCommandLineReference.rst (generated reference)
145+ add_custom_target (copy-flang-src-docs-man
146+ COMMAND "${CMAKE_COMMAND} " -E make_directory
147+ "${CMAKE_CURRENT_BINARY_DIR} /Source"
148+ COMMAND "${CMAKE_COMMAND} " -E copy
149+ "${CMAKE_CURRENT_SOURCE_DIR} /conf.py"
150+ "${CMAKE_CURRENT_BINARY_DIR} /Source/conf.py"
151+ COMMAND "${CMAKE_COMMAND} " -E copy
152+ "${CMAKE_CURRENT_SOURCE_DIR} /index.rst"
153+ "${CMAKE_CURRENT_BINARY_DIR} /Source/index.rst"
154+ COMMAND "${CMAKE_COMMAND} " -E copy
155+ "${CMAKE_CURRENT_BINARY_DIR} /Source/FlangCommandLineReference.rst"
156+ "${CMAKE_CURRENT_BINARY_DIR} /Source/FlangCommandLineReference.rst"
157+ DEPENDS flang-doc gen-FlangCommandLineReference.rst)
158+
133159 add_sphinx_target(man flang SOURCE_DIR "${CMAKE_CURRENT_BINARY_DIR} /Source" )
134- add_dependencies (docs-flang-man copy-flang-src-docs)
160+ add_dependencies (docs-flang-man copy-flang-src-docs-man )
135161 endif ()
136162 endif ()
137163endif ()
0 commit comments