wxc 0.92.2.0 → 0.92.3.0
raw patch · 5 files changed
+137/−94 lines, 5 filessetup-changed
Files
- Setup.hs +106/−91
- src/cpp/wrapper.cpp +13/−0
- src/include/wrapper.h +2/−0
- src/include/wxc_glue.h +1/−1
- wxc.cabal +15/−2
Setup.hs view
@@ -1,7 +1,7 @@ {-# LANGUAGE CPP #-} -import Control.Monad (filterM, join, mapM_, when) +import Control.Monad (filterM, join, mapM_, when, liftM2) import qualified Data.ByteString.Lazy as B import Data.Char ( ord ) import Data.Functor ( (<$>) ) @@ -23,7 +23,7 @@ import Distribution.System (OS (..), Arch (..), buildOS, buildArch) import Distribution.Verbosity (Verbosity, normal, verbose) import Distribution.Compat.Exception (catchIO) -import System.Process (system) +import System.Process (system, readProcess) import System.Directory ( createDirectoryIfMissing, doesFileExist , findExecutable, getCurrentDirectory , getDirectoryContents, getModificationTime @@ -42,14 +42,6 @@ -- Some utility functions -readProcess :: FilePath -> [String] -> String -> IO String -readProcess cmd args stdin = - Process.readProcess cmd args stdin - `E.catch` \(E.SomeException err) -> do - hPutStrLn stderr $ "readProcess failed: " ++ show err - E.throwIO err - - whenM :: Monad m => m Bool -> m () -> m () whenM mp e = mp >>= \p -> when p e @@ -60,17 +52,17 @@ findM mp (x : xs) = do r <- mp x - if r + if r then return $ Just x else findM mp xs - + main :: IO () main = defaultMainWithHooks simpleUserHooks - { confHook = myConfHook + { confHook = myConfHook , buildHook = myBuildHook - , copyHook = myCopyHook - , instHook = myInstHook + , copyHook = myCopyHook + , instHook = myInstHook } -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- @@ -95,16 +87,20 @@ -- Comment out type signature because of a Cabal API change from 1.6 to 1.7 myConfHook (pkg0, pbi) flags = do - mswMsys <- isWindowsMsys + let whenExecutableNotFound = whenM (isNothing <$> findExecutable "wx-config") + mswMsys <- isWindowsMsys if mswMsys then do - (r, e, c) <- rawShellSystemStdInOut normal "wx-config" ["--release"] - unless (c == ExitSuccess) $ do - putStrLn ("Error: MSYS environment wx-config script not found, please install wx-config before installing wxc" ++ "\n" - ++ e ++ "\n" - ++ show c) - exitFailure + (r, e, c) <- rawShellSystemStdInOut normal "wx-config" ["--release"] + unless (c == ExitSuccess) $ + -- In case you use Stack on Windows which internally use MSYS. + -- From Windows Console rawShellSystemStdInOut doesn't work + whenExecutableNotFound $ do + putStrLn ("Error: MSYS environment wx-config script not found, please install wx-config before installing wxc" ++ "\n" + ++ e ++ "\n" + ++ show c) + exitFailure else - whenM (isNothing <$> findExecutable "wx-config") $ + whenExecutableNotFound $ do putStrLn "Error: wx-config not found, please install wx-config before installing wxc" exitFailure @@ -137,8 +133,8 @@ , ccOptions = ccOptions libbi ++ ccOptions wx ++ ["-DwxcREFUSE_MEDIACTRL"] } - let lib' = lib { libBuildInfo = libbi' } - let lpd' = lpd { library = Just lib' } + let lib' = lib { libBuildInfo = libbi' } + let lpd' = lpd { library = Just lib' } return $ lbi { localPkgDescr = lpd' } @@ -164,6 +160,10 @@ -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- +{- + Bitness check +-} + data Bitness = Bits32 | Bits64 @@ -216,7 +216,7 @@ -- N.B. Might need an update when Windows runs on ARM let machineOffsetList = reverse $ take 4 $ drop 0x3C $ contents let machineOffset = listToInt machineOffsetList + 4 - return $ + return $ case contents !! machineOffset of 0x4C -> Bits32 -- "The file is 32 bit" 0x64 -> Bits64 -- "The file is 64 bit" @@ -225,7 +225,7 @@ listToInt :: Integral a => [a] -> Int listToInt xs = foldl1 (\x y -> 256 * x + y) (map fromIntegral xs) - + compareBitness :: Bitness -> CheckResult compareBitness thatBitness = if thatBitness == Unknown @@ -330,7 +330,7 @@ case maybeWxVersion of Nothing -> - error ("This version of wxc requires one of the following wxWidgets versions to be available: " + error ("This version of wxc requires one of the following wxWidgets versions to be available: " ++ show wxCompatibleVersions ) Just wxVersion -> @@ -344,28 +344,46 @@ do putStrLn ("Configuring wxc to build against wxWidgets " ++ wxVersion) +#if defined(freebsd_HOST_OS) || defined (netbsd_HOST_OS) + putStrLn "defined(freebsd_HOST_OS) || defined (netbsd_HOST_OS)" + -- find GL/glx.h on non-Linux systems + let glIncludeDirs = readProcess "pkg-config" ["--cflags", "gl"] "" `E.onException` return "" +#else + let glIncludeDirs = return "" +#endif + + -- Additional libraries that are needed for wxc + -- Note: "all" option doesn't bring them on the popular wx-config-win + -- (https://github.com/wxHaskell/wxHaskell/tree/master/wx-config-win, + -- other versions can be found at https://github.com/kowey/wx-config-win + -- and branches of it) + let neededLibs = [intercalate "," ["richtext", "xrc", "qa", "html", "adv", "core", "xml", "net", "base", "aui", "propgrid", "ribbon", "gl", "stc"]] + -- The Windows port of wx-config doesn't let you specify a version (yet) isMsys <- isWindowsMsys - case (buildOS,isMsys) of + case (buildOS, isMsys) of -- wx-config-win does not list all libraries if --cppflags comes after --libs :-( - (Windows,False) -> wx_config ["--cppflags", "--libs", "all"] - (Windows,True) -> wx_config ["--libs", "all", "--gl-libs", "--cppflags"] - _ -> wx_config ["--version=" ++ wxVersion, "--libs", "all", "--cppflags"] + (Windows, False) -> liftM2 (++) glIncludeDirs (wx_config $ ["--cppflags", "--libs"] ++ neededLibs) + (Windows, True) -> wx_config (["--gl-libs", "--cppflags", "--libs"] ++ neededLibs) + _ -> liftM2 (++) glIncludeDirs (wx_config ["--version=" ++ wxVersion, "--libs", "all", "--cppflags"]) wx_config :: [String] -> IO String wx_config parms = do + let runExecutable failureAction = + readProcess "wx-config" parms "" `E.onException` failureAction + b <- isWindowsMsys - if b + if b then do (r, e, c) <- rawShellSystemStdInOut normal "wx-config" parms - unless (c == ExitSuccess) $ do - putStrLn $ "Error: Failed to execute wx-config command \n" ++ e - exitFailure - return r - else - readProcess "wx-config" parms "" - `E.onException` return "" + if c == ExitSuccess then + return r + else runExecutable $ do + putStrLn $ "Error: Failed to execute wx-config\n" ++ e + exitFailure + else + runExecutable $ return "" -- Try to find a compatible version of wxWidgets @@ -375,7 +393,7 @@ if buildOS == Windows -- 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) - then checkCompatibility <$> readVersionWindows + then checkCompatibility <$> readVersionWindows else findM (fmap isCompatible . readVersion) wxCompatibleVersions where readVersionWindows :: IO String @@ -393,7 +411,7 @@ checkCompatibility :: String -> Maybe String checkCompatibility version = if isCompatible version - then Just version + then Just version else Nothing @@ -415,13 +433,13 @@ deMsysPaths :: BuildInfo -> IO BuildInfo deMsysPaths bi = do b <- isWindowsMsys - if b + if b then do let cor ph = do - (r, e, c ) <- rawSystemStdInOut normal "sh" ["-c", "cd " ++ ph ++ "; pwd -W"] Nothing Nothing Nothing False + (r, e, c ) <- rawSystemStdInOut normal "sh" ["-c", "cd " ++ ph ++ "; pwd -W"] Nothing Nothing Nothing False unless (c == ExitSuccess) (putStrLn ("Error: failed to convert MSYS path to native path \n" ++ e) >> exitFailure) return . head . lines $ r - elds <- mapM cor (extraLibDirs bi) + elds <- mapM cor (extraLibDirs bi) incds <- mapM cor (includeDirs bi) return $ bi {extraLibDirs = elds, includeDirs = incds} else @@ -457,7 +475,7 @@ -- 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 if buildOS == Windows then do -- Since we removed wx libraries in myConfHook we need to add them here when linking wxc.dll @@ -472,40 +490,38 @@ osCompileOpts = case buildOS of Windows -> ["-DBUILD_DLL"] - OSX -> ["-fPIC"] - _ -> ["-fPIC"] + OSX -> ["-fPIC"] + _ -> ["-fPIC"] sharedLibName :: Version -- ^ Version information to be used for Unix shared libraries - -> String -- ^ Name of the shared library + -> String -- ^ Name of the shared library -> String sharedLibName ver basename = case buildOS of Windows -> addExtension basename ".dll" - OSX -> "lib" ++ addExtension basename ".dylib" - _ -> "lib" ++ basename ++ ".so." ++ full_ver + OSX -> "lib" ++ addExtension basename ".dylib" + _ -> "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 +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 -- ^ Absolute path of the shared library + -> String -- ^ Name of the shared library + -> String -- ^ Absolute path of the shared library -> [String] -- ^ List of options which can be applied to 'runProgram' linkCxxOpts ver out_dir basename basepath = - -- let dll_pathname = normalisePath (out_dir </> addExtension basename ".dll") - -- implib_ pathname = normalisePath (out_dir </> "lib" ++ addExtension basename ".a") in case buildOS of - Windows -> ["-Wl,--dll", "-shared", + Windows -> ["-Wl,--dll", "-shared", "-o", out_dir </> sharedLibName ver basename, "-Wl,--out-implib," ++ "lib" ++ addExtension basename ".a", "-Wl,--export-all-symbols", "-Wl,--enable-auto-import", "-Wl,-no-undefined,--enable-runtime-pseudo-reloc"] - OSX -> ["-dynamiclib", + OSX -> ["-dynamiclib", "-o", out_dir </> sharedLibName ver basename, "-install_name", basepath </> sharedLibName ver basename, "-Wl,-undefined,dynamic_lookup"] - _ -> ["-shared", + _ -> ["-shared", "-Wl,-soname,lib" ++ basename ++ ".so", "-o", out_dir </> sharedLibName ver basename] @@ -513,19 +529,19 @@ -- 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 wx-config - -> [String] -- ^ Include paths provided by Cabal and wx-config - -> FilePath -- ^ Base output directory - -> FilePath -- ^ Path to source file - -> IO FilePath -- ^ Path to generated object code + -> [String] -- ^ Compile options provided by Cabal and wx-config + -> [String] -- ^ Include paths provided by Cabal and wx-config + -> 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 + 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 + 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) @@ -535,7 +551,7 @@ -- Real dependency checking would be nice here... needsCompiling :: FilePath -- ^ Path to source file -> FilePath -- ^ Path to object file - -> IO Bool -- ^ True if compilation required + -> IO Bool -- ^ True if compilation required needsCompiling src obj = do has_obj <- doesFileExist obj @@ -566,22 +582,21 @@ objs' = map normalisePath objs libs' = ["-lstdc++"] ++ map ("-l" ++) libs target = out_dir' </> sharedLibName ver dll_name - link <- linkingNeeded target objs' + link <- linkingNeeded target objs' when link $ do putStrLn "Linking wxc" runProgram verbose gcc (opts' ++ objs' ++ lib_dirs' ++ libs') - --system $ (unwords ([show . locationPath . programLocation $ gcc] ++ opts' ++ objs' ++ lib_dirs' ++ libs')) --- | Check if one of the input files is more recent then the output file +-- | Check if one of the input files is more recent then the output file linkingNeeded :: FilePath -> [FilePath] -> IO Bool -linkingNeeded output input = +linkingNeeded output input = do fileExists <- doesFileExist output - if not fileExists + if not fileExists then return True - else + else do mostRecentModificationTime <- maximum <$> mapM getModificationTime input outputModificationTime <- getModificationTime output @@ -596,11 +611,11 @@ normalisePath :: FilePath -> FilePath normalisePath = case buildOS of Windows -> dosifyFilePath - _ -> unixifyFilePath + _ -> unixifyFilePath -- | Replace a character in a String with some other character -replace :: Char -- ^ Character to replace - -> Char -- ^ Character with which to replace +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' @@ -616,9 +631,10 @@ ldconfig :: FilePath -> IO () ldconfig path = case buildOS of Windows -> return () - OSX -> return () - _ -> do - ld_exit_code <- system ("/sbin/ldconfig -n " ++ path) + OSX -> return () + _ -> + do + ld_exit_code <- system ("/sbin/ldconfig -n " ++ path) case ld_exit_code of ExitSuccess -> return () otherwise -> error "Couldn't execute ldconfig, ensure it is on your path" @@ -631,7 +647,7 @@ hookHelper :: (a -> Verbosity) -> - (a -> CopyDest) -> + (a -> CopyDest) -> (PackageDescription -> LocalBuildInfo -> UserHooks -> a -> IO ()) -> PackageDescription -> LocalBuildInfo -> UserHooks -> a -> IO () hookHelper verbosity copydest origHook pkg_descr local_bld_info user_hooks flags = @@ -640,17 +656,16 @@ origHook pkg_descr local_bld_info user_hooks flags -- Copy shared library - let bld_dir = buildDir local_bld_info + 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 + 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 (copydest flags) installOrdinaryFile (verbosity flags) (bld_dir </> lib_name) (inst_lib_dir </> lib_name) ldconfig inst_lib_dir -
src/cpp/wrapper.cpp view
@@ -2,6 +2,7 @@ #include "wx/tooltip.h" #include "wx/dynlib.h" #include "wx/fs_zip.h" +#include "wx/cmdline.h" /* quantize is not supported on wxGTK 2.4.0 */ #if !defined(__WXGTK__) || (wxVERSION_NUMBER > 2400) @@ -104,6 +105,18 @@ else if (callback) { callback->Invoke( &_evt ); /* normal: invoke the callback function */ } +} + +/* override to prevent parent wxApp failing to parse Haskell cmdline args */ +void ELJApp::OnInitCmdLine(wxCmdLineParser& parser) +{ + parser.SetCmdLine(""); +} + +/* override to prevent parent wxApp from further processing of parsed cmdline */ +bool ELJApp::OnCmdLineParsed(wxCmdLineParser& parser) +{ + return true; } /*-----------------------------------------------------------------------------
src/include/wrapper.h view
@@ -151,6 +151,8 @@ void HandleEvent(wxEvent& _evt); void InitZipFileSystem(); void InitImageHandlers(); + void OnInitCmdLine(wxCmdLineParser& parser); + bool OnCmdLineParsed(wxCmdLineParser& parser); };
src/include/wxc_glue.h view
@@ -4834,7 +4834,7 @@ /* wxSize */ TClassDef(wxSize) TClass(wxSize) wxSize_Create( TSize(w,h) ); -void wxSize_Destroy( TSelf(wxSize) _obj ); +void wxSize_Delete( TSelf(wxSize) _obj ); int wxSize_GetHeight( TSelf(wxSize) _obj ); int wxSize_GetWidth( TSelf(wxSize) _obj ); void wxSize_SetHeight( TSelf(wxSize) _obj, int h );
wxc.cabal view
@@ -1,5 +1,5 @@ name: wxc -version: 0.92.2.0 +version: 0.92.3.0 license: OtherLicense license-file: LICENSE maintainer: wxhaskell-devel@lists.sourceforge.net @@ -19,7 +19,7 @@ homepage: https://wiki.haskell.org/WxHaskell bug-reports: http://sourceforge.net/p/wxhaskell/bugs/ -cabal-version: >= 1.2 +cabal-version: >= 1.23 build-type: Custom extra-source-files: @@ -143,6 +143,9 @@ library + -- Just to suppress warnings + default-language: + Haskell2010 include-dirs: src/include @@ -297,3 +300,13 @@ x-dll-extra-libraries: + +custom-setup + setup-depends: + base, + Cabal, + bytestring, + split, + process, + directory, + filepath