Skip to content
Browse files

Added a CPP example, and tidied the plain one

  • Loading branch information...
1 parent 389078d commit 4f56f9d0ce53424a195e5d261568391ca30946a9 Andy Gimblett committed Feb 4, 2010
View
14 examples/README
@@ -0,0 +1,14 @@
+cabal-macosx Examples
+=====================
+
+ wxHello - basic wx example, demonstrating ordinary usage.
+
+ wxHello-cpp - same, but with wxHello.cabal and Setup.hs modified so
+ that the dependency on cabal-macosx only exists on OSX.
+
+--
+
+The application icon used for these examples is taken from the
+"Mechnoid Icons" iconset by "Flax Creations" at
+http://pixelgirlpresents.com/node/6738 (with a little help from
+http://www.macosxhints.com/article.php?story=20070318161305596 ).
View
34 examples/wxHello-cpp/LICENSE
@@ -0,0 +1,34 @@
+Copyright (c) 2009, Andy Gimblett
+All rights reserved.
+
+Developed by:
+
+ Andy Gimblett <haskell@gimbo.org.uk>
+
+Redistribution and use in source and binary forms, with or without
+modification, are permitted provided that the following conditions are
+met:
+
+ * Redistributions of source code must retain the above copyright
+ notice, this list of conditi ons and the following disclaimer.
+
+ * Redistributions in binary form must reproduce the above
+ copyright notice, this list of conditions and the following
+ disclaimer in the documentation and/or other materials provided
+ with the distribution.
+
+ * Neither the name of Andy Gimblett, nor the names of its
+ contributors may be used to endorse or promote products derived
+ from this software without specific prior written permission.
+
+THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
View
29 examples/wxHello-cpp/README
@@ -0,0 +1,29 @@
+Example: wxHello-cpp
+====================
+
+This is a modified version of the wxHello example which shows how to
+remove the dependency on cabal-macosx when on non-OSX platforms.
+
+cabal-macosx is only relevant on OSX; if used on any other platform,
+it does nothing. Thus, you can always safely include it in your
+program's Build-Depends and Setup.hs, whatever the target platform.
+However, you might not want to do that. This example shows how to
+modify your .cabal file and your Setup.hs so that cabal-macosx is only
+required on OSX.
+
+There are three changes necessary to create this platform-sensitivity:
+
+ 1. wxHello.cabal is modified so that cabal-macosx is only in the
+ Build-Depends list if the O/S is darwin.
+
+ 2. Setup.hs is modified so that cabal-macosx code is only imported
+ and compiled if the O/S is darwin.
+
+ 3. Calls to runghc Setup.hs are given the -cpp flag to invoke the C
+ preprocessor, eg: "runghc -cpp Setup configure".
+
+In all other respects this example is identical to the plain wxHello
+example.
+
+Please see the README for the plain wxHello example for any further
+information.
View
26 examples/wxHello-cpp/Setup.hs
@@ -0,0 +1,26 @@
+-- Example Setup.hs for the wxHello app, which only attempts to use
+-- cabal-macosx machinery if on OSX.
+
+#if darwin_HOST_OS == 1
+import Distribution.MacOSX
+#endif
+import Distribution.Simple
+-- import System.Info (os)
+
+main :: IO ()
+#if darwin_HOST_OS == 1
+main = defaultMainWithHooks $ simpleUserHooks {
+ postBuild = appBundleBuildHook guiApps
+ }
+
+guiApps :: [MacApp]
+guiApps = [MacApp "WxHello"
+ (Just "resources/WxHello.icns")
+ Nothing -- Build a default Info.plist for the icon.
+ [] -- No other resources.
+ [] -- No other binaries.
+ DoNotChase -- Try changing to ChaseWithDefaults
+ ]
+#else
+main = defaultMain
+#endif
View
BIN examples/wxHello-cpp/resources/WxHello.icns
Binary file not shown.
View
11 examples/wxHello-cpp/src/Main.hs
@@ -0,0 +1,11 @@
+module Main where
+
+import Graphics.UI.WX
+
+main :: IO ()
+main = start gui
+
+gui :: IO ()
+gui = do f <- frame [text := "Hello World!"]
+ staticText f [text := "How you doing?"]
+ return ()
View
25 examples/wxHello-cpp/wxHello.cabal
@@ -0,0 +1,25 @@
+Name: wxHello
+Version: 0.1.0
+Stability: Alpha
+Synopsis: Platform-sensitive version of wxHello example.
+Description:
+ Modified version of wxHello example demonstrating how to make
+ dependency on cabal-macosx platform senstitive. Please see the
+ README for more information.
+Category: Data
+License: BSD3
+License-file: LICENSE
+Copyright: Andy Gimblett <haskell@gimbo.org.uk>
+Author: Andy Gimblett <haskell@gimbo.org.uk>
+Maintainer: Andy Gimblett <haskell@gimbo.org.uk>
+Build-Type: Custom
+Cabal-Version: >=1.6
+
+Executable WxHello
+ hs-source-dirs: src
+ Main-is: Main.hs
+ if os(darwin)
+ Build-Depends: base >= 3 && < 5, cabal-macosx, wx
+ else
+ Build-Depends: base >= 3 && < 5, wx
+ ghc-options: -fwarn-tabs -threaded -Wall
View
12 examples/wxHello/Setup.hs
@@ -2,26 +2,16 @@
import Distribution.MacOSX
import Distribution.Simple
--- import System.Info (os)
main :: IO ()
main = defaultMainWithHooks $ simpleUserHooks {
postBuild = appBundleBuildHook guiApps
}
--- Checking by hand for OSX in Setup.hs no longer necessary.
-
--- main = defaultMainWithHooks $ addMacHook simpleUserHooks
--- where addMacHook h =
--- case os of
--- -- Here darwin == Mac OS X. Is that OK?
--- "darwin" -> h { postBuild = appBundleBuildHook guiApps }
--- _ -> h
-
guiApps :: [MacApp]
guiApps = [MacApp "WxHello"
(Just "resources/WxHello.icns")
- (Just "resources/WxHello.plist")
+ Nothing -- Build a default Info.plist for the icon.
[] -- No other resources.
[] -- No other binaries.
DoNotChase -- Try changing to ChaseWithDefaults
View
BIN examples/wxHello/resources/WxHello.icns
Binary file not shown.
View
30 examples/wxHello/resources/WxHello.plist
@@ -1,30 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
-<plist version="1.0">
-<dict>
- <key>CFBundleDevelopmentRegion</key>
- <string>English</string>
- <key>CFBundleExecutable</key>
- <string>WxHello</string>
- <key>CFBundleGetInfoString</key>
- <string>WxHello</string>
- <key>CFBundleIconFile</key>
- <string>WxHello.icns</string>
- <key>CFBundleName</key>
- <string>WxHello</string>
- <key>CFBundlePackageType</key>
- <string>APPL</string>
- <key>CFBundleShortVersionString</key>
- <string>0</string>
- <key>CFBundleSignature</key>
- <string>????</string>
- <key>CFBundleVersion</key>
- <string>0</string>
- <key>CSResourcesFileMapped</key>
- <true/>
- <key>LSRequiresCarbon</key>
- <true/>
- <key>NSHumanReadableCopyright</key>
- <string>Copyright 2009 Andy Gimblett</string>
-</dict>
-</plist>
View
6 examples/wxHello/wxHello.cabal
@@ -1,10 +1,10 @@
Name: wxHello
Version: 0.1.0
Stability: Alpha
-Synopsis: wxWidgets `Hello World' example for osxSetup.hs
+Synopsis: wxWidgets `Hello World' example for cabal-macosx
Description:
- An example of using osxSetup.hs, to build an application bundle
- for a simple `Hello World' program using the wxWidgets GUI
+ Example showing how to use cabal-macosx to build an application
+ bundle for a simple `Hello World' program using the wxWidgets GUI
toolkit.
Category: Data
License: BSD3

0 comments on commit 4f56f9d

Please sign in to comment.
Something went wrong with that request. Please try again.