Permalink
Browse files

Branch wxc library out of wxcore.

Ignore-this: cf47c90ff869758823e19fcfd3f1aa20

Start of merging changes from Dave Tapley's repo for wxWidgets 2.9 support.
Because the branches are so far out of sync, changes are mainly being merged manually.
The following commit comments from Dave are included here:

Mon Dec 19 21:56:17 GMT 2011  dukedave@gmail.com
  * Added missing stc_gen.cpp file to extra-source-files
  he file stc_gen.cpp is unique at the moment in that it is the only .cpp file which
  is included in another .cpp file, thus it isn't included in x-dll-sources (because it
  isn't a separate compilation unit), but it still needs to be put in an sdist tarball.

on Dec 19 20:47:15 GMT 2011  dukedave@gmail.com
  * Added cpp files used in wxc to extra-source-files
  Installing from and sdist tarball would fail without this addition
  because the cpp files wouldn't be present in it.
  The duplicated list in wxc.cabal (for extra-source-files and x-dll-sources) is
  a bit unpleasant, but I feel it is important to make the distinction.

Wed Dec 14 17:06:18 GMT 2011  dukedave@gmail.com
  * Update path given to wxdirect to reflect changes made in other patch
  The wxc C++ files were moved to another project in the patch:
  "Move compilation of C++ code to new wxc project and use a shared library for it"

Wed Dec 14 07:11:35 GMT 2011  dukedave@gmail.com
  * Missed modified files in previous patch
  This is the secord part of the patch "Move compilation of C++ code to new wxc project and use a shared library for it"
  Unfortunately I missed these important files modifications, and darcs was waiting forever when I tried to unrecord or
  amend that patch.
  For further information please see email:
  [wxhaskell-devel] Using a shared library for the C++ in wxhaskell
  http://sourceforge.net/mailarchive/message.php?msg_id=28515489

Wed Dec 14 06:54:17 GMT 2011  dukedave@gmail.com
  * Move compilation of C++ code to new wxc project and use a shared library for it
  This substantial architectural

Wed Nov 16 09:42:39 GMT 2011  jeremy.odonoghue@gmail.com
  * Reinstate OpenGL support for wxWidgets 2.9.

  OpenGL support compiles and links (at least for wxWidgets 2.9 on Ubuntu
  against Dave Tapley's repo), but sample code doesn't work yet - investigating
  whether this is due to wx API changes or a problem in wxcore OpenGL support.

darcs-hash:20120311122652-75908-8488b6ea785f73a27fba46c87f99e3ca366a588e.gz
  • Loading branch information...
1 parent 84fc801 commit f8af539014daf0980fea8e7a24091da6263a55c0 @jodonoghue committed Mar 11, 2012
Showing with 1,134 additions and 0 deletions.
  1. +573 −0 wxc/LICENSE
  2. +287 −0 wxc/Setup.hs
  3. 0 {wxcore → wxc}/src/cpp/apppath.cpp
  4. 0 {wxcore → wxc}/src/cpp/defs.cpp
  5. 0 {wxcore → wxc}/src/cpp/dragimage.cpp
  6. 0 {wxcore → wxc}/src/cpp/eljaccelerator.cpp
  7. 0 {wxcore → wxc}/src/cpp/eljartprov.cpp
  8. 0 {wxcore → wxc}/src/cpp/eljbitmap.cpp
  9. 0 {wxcore → wxc}/src/cpp/eljbrush.cpp
  10. 0 {wxcore → wxc}/src/cpp/eljbusyinfo.cpp
  11. 0 {wxcore → wxc}/src/cpp/eljbutton.cpp
  12. 0 {wxcore → wxc}/src/cpp/eljcalendarctrl.cpp
  13. 0 {wxcore → wxc}/src/cpp/eljcaret.cpp
  14. 0 {wxcore → wxc}/src/cpp/eljcheckbox.cpp
  15. 0 {wxcore → wxc}/src/cpp/eljchecklistbox.cpp
  16. 0 {wxcore → wxc}/src/cpp/eljchoice.cpp
  17. 0 {wxcore → wxc}/src/cpp/eljclipboard.cpp
  18. 0 {wxcore → wxc}/src/cpp/eljcoldata.cpp
  19. 0 {wxcore → wxc}/src/cpp/eljcolour.cpp
  20. 0 {wxcore → wxc}/src/cpp/eljcolourdlg.cpp
  21. 0 {wxcore → wxc}/src/cpp/eljcombobox.cpp
  22. 0 {wxcore → wxc}/src/cpp/eljcommand.cpp
  23. 0 {wxcore → wxc}/src/cpp/eljconfigbase.cpp
  24. 0 {wxcore → wxc}/src/cpp/eljcontrol.cpp
  25. 0 {wxcore → wxc}/src/cpp/eljctxhelp.cpp
  26. 0 {wxcore → wxc}/src/cpp/eljcursor.cpp
  27. 0 {wxcore → wxc}/src/cpp/eljdataformat.cpp
  28. 0 {wxcore → wxc}/src/cpp/eljdatetime.cpp
  29. 0 {wxcore → wxc}/src/cpp/eljdc.cpp
  30. 0 {wxcore → wxc}/src/cpp/eljdcsvg.cpp
  31. 0 {wxcore → wxc}/src/cpp/eljdialog.cpp
  32. 0 {wxcore → wxc}/src/cpp/eljdialup.cpp
  33. 0 {wxcore → wxc}/src/cpp/eljdirdlg.cpp
  34. 0 {wxcore → wxc}/src/cpp/eljdnd.cpp
  35. 0 {wxcore → wxc}/src/cpp/eljdrawing.cpp
  36. 0 {wxcore → wxc}/src/cpp/eljevent.cpp
  37. 0 {wxcore → wxc}/src/cpp/eljfiledialog.cpp
  38. 0 {wxcore → wxc}/src/cpp/eljfilehist.cpp
  39. 0 {wxcore → wxc}/src/cpp/eljfindrepldlg.cpp
  40. 0 {wxcore → wxc}/src/cpp/eljfont.cpp
  41. 0 {wxcore → wxc}/src/cpp/eljfontdata.cpp
  42. 0 {wxcore → wxc}/src/cpp/eljfontdlg.cpp
  43. 0 {wxcore → wxc}/src/cpp/eljframe.cpp
  44. 0 {wxcore → wxc}/src/cpp/eljgauge.cpp
  45. 0 {wxcore → wxc}/src/cpp/eljgizmos.cpp
  46. 0 {wxcore → wxc}/src/cpp/eljgrid.cpp
  47. 0 {wxcore → wxc}/src/cpp/eljhelpcontroller.cpp
  48. 0 {wxcore → wxc}/src/cpp/eljicnbndl.cpp
  49. 0 {wxcore → wxc}/src/cpp/eljicon.cpp
  50. 0 {wxcore → wxc}/src/cpp/eljimage.cpp
  51. 0 {wxcore → wxc}/src/cpp/eljimagelist.cpp
  52. 0 {wxcore → wxc}/src/cpp/eljipc.cpp
  53. 0 {wxcore → wxc}/src/cpp/eljjoystick.cpp
  54. 0 {wxcore → wxc}/src/cpp/eljlayoutconstraints.cpp
  55. 0 {wxcore → wxc}/src/cpp/eljlistbox.cpp
  56. 0 {wxcore → wxc}/src/cpp/eljlistctrl.cpp
  57. 0 {wxcore → wxc}/src/cpp/eljlocale.cpp
  58. 0 {wxcore → wxc}/src/cpp/eljlog.cpp
  59. 0 {wxcore → wxc}/src/cpp/eljmask.cpp
  60. 0 {wxcore → wxc}/src/cpp/eljmdi.cpp
  61. 0 {wxcore → wxc}/src/cpp/eljmenu.cpp
  62. 0 {wxcore → wxc}/src/cpp/eljmenubar.cpp
  63. 0 {wxcore → wxc}/src/cpp/eljmessagedialog.cpp
  64. 0 {wxcore → wxc}/src/cpp/eljmime.cpp
  65. 0 {wxcore → wxc}/src/cpp/eljminiframe.cpp
  66. 0 {wxcore → wxc}/src/cpp/eljnotebook.cpp
  67. 0 {wxcore → wxc}/src/cpp/eljpalette.cpp
  68. 0 {wxcore → wxc}/src/cpp/eljpanel.cpp
  69. 0 {wxcore → wxc}/src/cpp/eljpen.cpp
  70. 0 {wxcore → wxc}/src/cpp/eljplot.cpp
  71. 0 {wxcore → wxc}/src/cpp/eljprintdlg.cpp
  72. 0 {wxcore → wxc}/src/cpp/eljprinting.cpp
  73. 0 {wxcore → wxc}/src/cpp/eljprocess.cpp
  74. 0 {wxcore → wxc}/src/cpp/eljradiobox.cpp
  75. 0 {wxcore → wxc}/src/cpp/eljradiobutton.cpp
  76. 0 {wxcore → wxc}/src/cpp/eljrc.cpp
  77. 0 {wxcore → wxc}/src/cpp/eljregion.cpp
  78. 0 {wxcore → wxc}/src/cpp/eljregioniter.cpp
  79. 0 {wxcore → wxc}/src/cpp/eljsash.cpp
  80. 0 {wxcore → wxc}/src/cpp/eljscrollbar.cpp
  81. 0 {wxcore → wxc}/src/cpp/eljscrolledwindow.cpp
  82. 0 {wxcore → wxc}/src/cpp/eljsingleinst.cpp
  83. 0 {wxcore → wxc}/src/cpp/eljsizer.cpp
  84. 0 {wxcore → wxc}/src/cpp/eljslider.cpp
  85. 0 {wxcore → wxc}/src/cpp/eljspinctrl.cpp
  86. 0 {wxcore → wxc}/src/cpp/eljsplitterwindow.cpp
  87. 0 {wxcore → wxc}/src/cpp/eljstaticbox.cpp
  88. 0 {wxcore → wxc}/src/cpp/eljstaticline.cpp
  89. 0 {wxcore → wxc}/src/cpp/eljstatictext.cpp
  90. 0 {wxcore → wxc}/src/cpp/eljstatusbar.cpp
  91. 0 {wxcore → wxc}/src/cpp/eljsystemsettings.cpp
  92. 0 {wxcore → wxc}/src/cpp/eljtextctrl.cpp
  93. 0 {wxcore → wxc}/src/cpp/eljtglbtn.cpp
  94. 0 {wxcore → wxc}/src/cpp/eljthread.cpp
  95. 0 {wxcore → wxc}/src/cpp/eljtimer.cpp
  96. 0 {wxcore → wxc}/src/cpp/eljtipwnd.cpp
  97. 0 {wxcore → wxc}/src/cpp/eljtoolbar.cpp
  98. 0 {wxcore → wxc}/src/cpp/eljvalidator.cpp
  99. 0 {wxcore → wxc}/src/cpp/eljwindow.cpp
  100. 0 {wxcore → wxc}/src/cpp/eljwizard.cpp
  101. 0 {wxcore → wxc}/src/cpp/ewxw_main.cpp
  102. 0 {wxcore → wxc}/src/cpp/extra.cpp
  103. 0 {wxcore → wxc}/src/cpp/glcanvas.cpp
  104. 0 {wxcore → wxc}/src/cpp/graphicscontext.cpp
  105. 0 {wxcore → wxc}/src/cpp/image.cpp
  106. 0 {wxcore → wxc}/src/cpp/managed.cpp
  107. 0 {wxcore → wxc}/src/cpp/mediactrl.cpp
  108. 0 {wxcore → wxc}/src/cpp/previewframe.cpp
  109. 0 {wxcore → wxc}/src/cpp/printout.cpp
  110. 0 {wxcore → wxc}/src/cpp/sckaddr.cpp
  111. 0 {wxcore → wxc}/src/cpp/socket.cpp
  112. 0 {wxcore → wxc}/src/cpp/sound.cpp
  113. 0 {wxcore → wxc}/src/cpp/stc.cpp
  114. 0 {wxcore → wxc}/src/cpp/stc_gen.cpp
  115. 0 {wxcore → wxc}/src/cpp/std.cpp
  116. 0 {wxcore → wxc}/src/cpp/taskbaricon.cpp
  117. 0 {wxcore → wxc}/src/cpp/textstream.cpp
  118. 0 {wxcore → wxc}/src/cpp/treectrl.cpp
  119. 0 {wxcore → wxc}/src/cpp/wrapper.cpp
  120. 0 {wxcore → wxc}/src/include/dragimage.h
  121. 0 {wxcore → wxc}/src/include/eljgrid.h
  122. 0 {wxcore → wxc}/src/include/ewxw_def.h
  123. 0 {wxcore → wxc}/src/include/glcanvas.h
  124. 0 {wxcore → wxc}/src/include/graphicscontext.h
  125. 0 {wxcore → wxc}/src/include/managed.h
  126. 0 {wxcore → wxc}/src/include/mediactrl.h
  127. 0 {wxcore → wxc}/src/include/previewframe.h
  128. 0 {wxcore → wxc}/src/include/printout.h
  129. 0 {wxcore → wxc}/src/include/sound.h
  130. 0 {wxcore → wxc}/src/include/stc.h
  131. 0 {wxcore → wxc}/src/include/stc_gen.h
  132. 0 {wxcore → wxc}/src/include/textstream.h
  133. 0 {wxcore → wxc}/src/include/wrapper.h
  134. 0 {wxcore → wxc}/src/include/wxc.h
  135. 0 {wxcore → wxc}/src/include/wxc_glue.h
  136. 0 {wxcore → wxc}/src/include/wxc_types.h
  137. +274 −0 wxc/wxc.cabal
View

Large diffs are not rendered by default.

Oops, something went wrong.
View
@@ -0,0 +1,287 @@
+import Control.Monad (mapM_, when)
+import Data.List (foldl', intersperse, intercalate, nub, lookup, isPrefixOf)
+import Data.Maybe (fromJust)
+import Distribution.PackageDescription
+import Distribution.Simple
+import Distribution.Simple.InstallDirs (InstallDirs(..))
+import Distribution.Simple.LocalBuildInfo (LocalBuildInfo, localPkgDescr, installedPkgs, withPrograms, buildDir, absoluteInstallDirs)
+import Distribution.Simple.PackageIndex(SearchResult (..), searchByName )
+import Distribution.Simple.Program (ConfiguredProgram (..), lookupProgram, runProgram, simpleProgram, locationPath)
+import Distribution.Simple.Setup (ConfigFlags, BuildFlags, InstallFlags, CopyDest(..), fromFlag, installVerbosity)
+import Distribution.Simple.Utils (installOrdinaryFile)
+import Distribution.System (OS (..), Arch (..), buildOS, buildArch)
+import Distribution.Verbosity (normal, verbose)
+import System (ExitCode (..))
+import System.Cmd (system)
+import System.Directory (createDirectoryIfMissing, doesFileExist, getCurrentDirectory, getModificationTime)
+import System.Environment (getEnv)
+import System.FilePath.Posix ((</>), (<.>), replaceExtension, takeFileName, dropFileName, addExtension)
+import System.IO.Unsafe (unsafePerformIO)
+import System.Process (readProcess)
+
+-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
+
+main :: IO ()
+main = defaultMainWithHooks simpleUserHooks { confHook = myConfHook, buildHook = myBuildHook, instHook = myInstHook }
+
+-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
+
+sourceDirectory :: FilePath
+includeDirectory :: FilePath
+
+sourceDirectory = "cpp"
+includeDirectory = "include"
+
+-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
+
+-- Comment out type signature because of a Cabal API change from 1.6 to 1.7
+myConfHook (pkg0, pbi) flags = do
+
+ lbi <- confHook simpleUserHooks (pkg0, pbi) flags
+ let lpd = localPkgDescr lbi
+ let lib = fromJust (library lpd)
+ let libbi = libBuildInfo lib
+ let custom_bi = customFieldsBI libbi
+
+ wx <- fmap parseWxConfig readWxConfig
+
+ let libbi' = libbi
+ { extraLibDirs = extraLibDirs libbi ++ extraLibDirs wx
+ , extraLibs = extraLibs libbi ++ reverse (extraLibs wx)
+ , ldOptions = ldOptions libbi ++ ldOptions wx
+ , frameworks = frameworks libbi ++ frameworks wx
+ , includeDirs = includeDirs libbi ++ includeDirs wx
+ , ccOptions = ccOptions libbi ++ ccOptions wx ++ ["-DwxcREFUSE_MEDIACTRL"]
+ }
+
+ let lib' = lib { libBuildInfo = libbi' }
+ let lpd' = lpd { library = Just lib' }
+
+ return $ lbi { localPkgDescr = lpd' }
+
+-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
+
+-- Make sure the right version of wx widgets is installed and return the
+readWxConfig :: IO String
+readWxConfig = do
+ -- Try to force version and see if we have it
+ let wxRequiredVersion = "2.9"
+
+ -- The Windows port of wx-config doesn't let you specify a version, nor query the full version,
+ -- accordingly we just check what version is installed (which is returned with --release)
+ wxVersion <- case buildOS of
+ Windows -> readProcess "wx-config" ["--release"] ""
+ _ -> readProcess "wx-config" ["--version=" ++ wxRequiredVersion, "--version-full"] ""
+
+ if wxRequiredVersion `isPrefixOf` wxVersion
+ then putStrLn ("Configuring wxc to build against wx " ++ wxVersion)
+ else error ("This version of wxcore requires wx " ++ wxRequiredVersion ++ " to be available")
+
+ -- The Windows port of wx-config doesn't let you specify a version (yet)
+ output <- case buildOS of
+ -- TODO: Nasty Windows hack: wx-config-win barfs if --cppflags comes after --libs :-(
+ Windows -> readProcess "wx-config" ["--cppflags", "--libs", "all"] ""
+ _ -> readProcess "wx-config" ["--version=" ++ wxRequiredVersion, "--libs", "all", "--cppflags"] ""
+ return output
+
+parseWxConfig :: String -> BuildInfo
+parseWxConfig s =
+ helper emptyBuildInfo (words s)
+ where
+ helper b ("-framework":w:ws) = helper (b { frameworks = w : frameworks b }) ws
+ helper b (w:ws) = helper (f b w) ws
+ helper b [] = b
+ f b w =
+ case w of
+ ('-':'L':v) -> b { extraLibDirs = v : extraLibDirs b }
+ ('-':'l':v) -> b { extraLibs = v : extraLibs b }
+ ('-':'I':v) -> b { includeDirs = v : includeDirs b }
+ ('-':'D':_) -> b { ccOptions = w : ccOptions b }
+ _ -> b
+
+-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
+
+-- | Extend the standard build hook to build a shared library for wxc - this will statically link
+-- any libraries which are unavailable as shared variants. This is mainly a work-around for the
+-- fact that GHCi needs to load shared libraries at run-time, and that the Windows MinGW environment
+-- is shipped with only a static version of libstdc++.
+-- TODO: Does not currently create the build output directory.
+myBuildHook :: PackageDescription -> LocalBuildInfo -> UserHooks -> BuildFlags -> IO ()
+myBuildHook pkg_descr local_bld_info user_hooks bld_flags =
+ do
+ -- Extract the custom fields customFieldsPD where field name is x-cpp-dll-sources
+ let lib = fromJust (library pkg_descr)
+ lib_bi = libBuildInfo lib
+ custom_bi = customFieldsBI lib_bi
+ dll_name = fromJust (lookup "x-dll-name" custom_bi)
+ dll_srcs = (lines . fromJust) (lookup "x-dll-sources" custom_bi)
+ dll_libs = (lines . fromJust) (lookup "x-dll-extra-libraries" custom_bi)
+ cc_opts = ccOptions lib_bi
+ ld_opts = ldOptions lib_bi
+ inc_dirs = includeDirs lib_bi
+ lib_dirs = extraLibDirs lib_bi
+ libs = extraLibs lib_bi
+ bld_dir = buildDir local_bld_info
+ progs = withPrograms local_bld_info
+ gcc = fromJust (lookupProgram (simpleProgram "gcc") progs)
+ ver = (pkgVersion . package) pkg_descr
+ -- Compile C/C++ sources - output directory is dist/build/src/cpp
+ putStrLn "Building wxc"
+ objs <- mapM (compileCxx gcc cc_opts inc_dirs bld_dir) dll_srcs
+ -- Link C/C++ sources as a DLL - output directory is dist/build
+ putStrLn "Linking wxc"
+ linkSharedLib gcc ld_opts lib_dirs (libs ++ dll_libs) objs ver bld_dir dll_name
+
+-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
+
+-- | Return any compiler options required to support shared library creation
+osCompileOpts :: [String] -- ^ Platform-specific compile options
+osCompileOpts =
+ case buildOS of
+ Windows -> ["-DBUILD_DLL"]
+ OSX -> ["-fPIC"]
+ _ -> ["-fPIC"]
+
+sharedLibName :: Version -- ^ Version information to be used for Unix shared libraries
+ -> String -- ^ Name of the shared library
+ -> String
+sharedLibName ver basename =
+ case buildOS of
+ Windows -> addExtension basename ".dll"
+ OSX -> addExtension basename ".so"
+ _ -> "lib" ++ basename ++ ".so." ++ full_ver
+ where
+ full_ver = (concat . intersperse "." . map show . versionBranch) ver
+
+-- | Return any linker options required to support shared library creation
+linkCxxOpts :: Version -- ^ Version information to be used for Unix shared libraries
+ -> FilePath -- ^ Directory in which library will be built
+ -> String -- ^ Name of the shared library
+ -> [String] -- ^ List of options which can be applied to 'runProgram'
+linkCxxOpts ver out_dir basename =
+ let dll_pathname = normalisePath (out_dir </> addExtension basename ".dll")
+ implib_pathname = normalisePath (out_dir </> "lib" ++ addExtension basename ".a") in
+ case buildOS of
+ Windows -> ["--dll", "-shared",
+ "-o " ++ out_dir </> sharedLibName ver basename,
+ "-Wl,--out-implib," ++ "lib" ++ addExtension basename ".a",
+ "-Wl,--export-all-symbols", "-Wl,--enable-auto-import"]
+ OSX -> ["-dynamiclib",
+ "-o " ++ out_dir </> sharedLibName ver basename,
+ "-Wl,undefined,dynamic_lookup"]
+ _ -> ["-shared",
+ "-Wl,-soname,lib" ++ basename ++ ".so",
+ "-o " ++ out_dir </> sharedLibName ver basename]
+
+-- | Compile a single source file using the configured gcc, if the object file does not yet
+-- exist, or is older than the source file.
+-- TODO: Does not do dependency resolution properly
+compileCxx :: ConfiguredProgram -- ^ Program used to perform C/C++ compilation (gcc)
+ -> [String] -- ^ Compile options provided by Cabal and wxConfig
+ -> [String] -- ^ Include paths provided by Cabal and wxConfig
+ -> FilePath -- ^ Base output directory
+ -> FilePath -- ^ Path to source file
+ -> IO FilePath -- ^ Path to generated object code
+compileCxx gcc opts incls out_path cxx_src =
+ do
+ let includes = map ("-I" ++) incls
+ out_path' = normalisePath out_path
+ cxx_src' = normalisePath cxx_src
+ out_file = out_path' </> dropFileName cxx_src </> replaceExtension (takeFileName cxx_src) ".o"
+ out = ["-c", cxx_src', "-o", out_file]
+ opts' = opts ++ osCompileOpts
+ do_it <- needsCompiling cxx_src out_file
+ when do_it $ createDirectoryIfMissing True (dropFileName out_file) >>
+ runProgram verbose gcc (includes ++ opts' ++ out)
+ return out_file
+
+-- | Return True if obj does not exist or is older than src.
+-- Real dependency checking would be nice here...
+needsCompiling :: FilePath -- ^ Path to source file
+ -> FilePath -- ^ Path to object file
+ -> IO Bool -- ^ True if compilation required
+needsCompiling src obj =
+ do
+ has_obj <- doesFileExist obj
+ if has_obj
+ then do
+ mtime_src <- getModificationTime src
+ mtime_obj <- getModificationTime obj
+ if mtime_obj < mtime_src then return True else return False
+ else
+ return True
+
+-- | Create a dynamically linked library using the configured ld.
+linkSharedLib :: ConfiguredProgram -- ^ Program used to perform linking
+ -> [String] -- ^ Linker options supplied by Cabal
+ -> [FilePath] -- ^ Library directories
+ -> [String] -- ^ Libraries
+ -> [String] -- ^ Objects
+ -> Version -- ^ wxCore version (wxC has same version number)
+ -> FilePath -- ^ Directory in which library will be generated
+ -> String -- ^ Name of the shared library
+ -> IO ()
+linkSharedLib gcc opts lib_dirs libs objs ver out_dir dll_name =
+ do
+ let lib_dirs' = map (\d -> "-L" ++ normalisePath d) lib_dirs
+ out_dir' = normalisePath out_dir
+ opts' = opts ++ linkCxxOpts ver (out_dir') dll_name
+ objs' = map normalisePath objs
+ libs' = ["-lstdc++"] ++ map ("-l" ++) libs
+ --runProgram verbose gcc (opts' ++ objs' ++ lib_dirs' ++ libs')
+ let cmd_line = unwords ([show . locationPath . programLocation $ gcc] ++ opts' ++ objs' ++ lib_dirs' ++ libs')
+ system $ (unwords ([show . locationPath . programLocation $ gcc] ++ opts' ++ objs' ++ lib_dirs' ++ libs'))
+ return ()
+
+-- | The 'normalise' implementation in System.FilePath does not meet the requirements of
+-- calling and/or running external programs on Windows particularly well as it does not
+-- normalise the '/' character to '\\'. The problem is that some MinGW programs do not
+-- like to see paths with a mixture of '/' and '\\'. Sine we are calling out to these,
+-- we require a stricter normalisation.
+normalisePath :: FilePath -> FilePath
+normalisePath = case buildOS of
+ Windows -> dosifyFilePath
+ _ -> unixifyFilePath
+
+-- | Replace a character in a String with some other character
+replace :: Char -- ^ Character to replace
+ -> Char -- ^ Character with which to replace
+ -> String -- ^ String in which to replace
+ -> String -- ^ Transformed string
+replace old new = map replace'
+ where
+ replace' elem = if elem == old then new else elem
+
+unixifyFilePath = replace '\\' '/'
+dosifyFilePath = replace '/' '\\'
+
+-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
+
+-- | Run ldconfig in `path` and return a list of all the links which were created
+ldconfig :: FilePath -> IO ()
+ldconfig path = case buildOS of
+ Windows -> return ()
+ OSX -> return ()
+ _ -> system ("ldconfig -n " ++ path) >> return ()
+
+myInstHook :: PackageDescription -> LocalBuildInfo -> UserHooks -> InstallFlags -> IO ()
+myInstHook pkg_descr local_bld_info user_hooks inst_flags =
+ do
+ -- Perform simpleUserHooks instHook (to copy installIncludes)
+ instHook simpleUserHooks pkg_descr local_bld_info user_hooks inst_flags
+
+ -- Copy shared library
+ let bld_dir = buildDir local_bld_info
+
+ ver = (pkgVersion . package) pkg_descr
+ lib = fromJust (library pkg_descr)
+ lib_bi = libBuildInfo lib
+ custom_bi = customFieldsBI lib_bi
+ dll_name = fromJust (lookup "x-dll-name" custom_bi)
+ lib_name = sharedLibName ver dll_name
+
+ inst_lib_dir = libdir $ absoluteInstallDirs pkg_descr local_bld_info NoCopyDest
+
+ installOrdinaryFile (fromFlag (installVerbosity inst_flags)) (bld_dir </> lib_name) (inst_lib_dir </> lib_name)
+ ldconfig inst_lib_dir
+
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Oops, something went wrong.

0 comments on commit f8af539

Please sign in to comment.