+maybeCreateManifest
+ :: DynFlags
+ -> FilePath -- filename of executable
+ -> IO [FilePath] -- extra objects to embed, maybe
+#ifndef mingw32_TARGET_OS
+maybeCreateManifest _ _ = do
+ return []
+#else
+maybeCreateManifest dflags exe_filename = do
+ if not (dopt Opt_GenManifest dflags) then return [] else do
+
+ let manifest_filename = exe_filename <.> "manifest"
+
+ writeFile manifest_filename $
+ "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>\n"++
+ " <assembly xmlns=\"urn:schemas-microsoft-com:asm.v1\" manifestVersion=\"1.0\">\n"++
+ " <assemblyIdentity version=\"1.0.0.0\"\n"++
+ " processorArchitecture=\"X86\"\n"++
+ " name=\"" ++ dropExtension exe_filename ++ "\"\n"++
+ " type=\"win32\"/>\n\n"++
+ " <trustInfo xmlns=\"urn:schemas-microsoft-com:asm.v3\">\n"++
+ " <security>\n"++
+ " <requestedPrivileges>\n"++
+ " <requestedExecutionLevel level=\"asInvoker\" uiAccess=\"false\"/>\n"++
+ " </requestedPrivileges>\n"++
+ " </security>\n"++
+ " </trustInfo>\n"++
+ "</assembly>\n"
+
+ -- Windows will find the manifest file if it is named foo.exe.manifest.
+ -- However, for extra robustness, and so that we can move the binary around,
+ -- we can embed the manifest in the binary itself using windres:
+ if not (dopt Opt_EmbedManifest dflags) then return [] else do
+
+ rc_filename <- newTempName dflags "rc"
+ rc_obj_filename <- newTempName dflags (objectSuf dflags)
+
+ writeFile rc_filename $
+ "1 24 MOVEABLE PURE " ++ show manifest_filename ++ "\n"
+ -- magic numbers :-)
+ -- show is a bit hackish above, but we need to escape the
+ -- backslashes in the path.
+
+ let wr_opts = getOpts dflags opt_windres
+ runWindres dflags $ map SysTools.Option $
+ ["--input="++rc_filename,
+ "--output="++rc_obj_filename,
+ "--output-format=coff"]
+ ++ wr_opts
+ -- no FileOptions here: windres doesn't like seeing
+ -- backslashes, apparently
+
+ removeFile manifest_filename
+
+ return [rc_obj_filename]
+#endif
+