Skip to content

Commit

Permalink
Tweak the build so that the generated dylib on OSX has its full path
Browse files Browse the repository at this point in the history
as per where cabal installs the library.  This way of doing it should
be compatible with all versions of OSX.
  • Loading branch information
dagit committed Jun 23, 2011
1 parent 4465641 commit 8c46810
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 18 deletions.
2 changes: 1 addition & 1 deletion GLFW-b.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ library
else
if os(darwin)
extra-libraries: glfw
extra-lib-dirs: build/dynamic
extra-lib-dirs: build
else
if os(mingw32)
include-dirs:
Expand Down
9 changes: 2 additions & 7 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -13,22 +13,17 @@ C_SRC := $(wildcard $(SRC_DIR)/*.c)
GLFW_SRC := $(wildcard $(GLFW_DIR)/*.c)
OBJS := $(addprefix $(BUILD_DIR)/, $(OBJ_C_SRC:.m=.o) $(C_SRC:.c=.o))

all: $(BUILD_DIR)/static/libglfw.a $(BUILD_DIR)/dynamic/libglfw.dylib
all: $(BUILD_DIR)/libglfw.dylib

$(BUILD_DIR)/dynamic/libglfw.dylib: $(OBJS)
$(BUILD_DIR)/libglfw.dylib: $(OBJS)
$(CC) -dynamiclib -Wl,-single_module -compatibility_version 1 \
-current_version 1 \
$(GLFW_FLAG) -o $@ $(OBJS) $(GLFW_SRC) $(FRAMEWORK)

$(BUILD_DIR)/static/libglfw.a: $(OBJS)
ar -rcs $@ $(OBJS)

.PHONY: $(BUILD_DIR)/$(SRC_DIR)/.build-tag

$(BUILD_DIR)/$(SRC_DIR)/.build-tag:
mkdir -p $(BUILD_DIR)/$(SRC_DIR)
mkdir -p $(BUILD_DIR)/static
mkdir -p $(BUILD_DIR)/dynamic
touch $@

$(OBJS): $(BUILD_DIR)/$(SRC_DIR)/.build-tag
Expand Down
17 changes: 7 additions & 10 deletions Setup.hs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import Distribution.Simple.Setup ( ConfigFlags, fromFlag, configVerbosity
, CopyFlags(..)
, configProgramArgs )
import Distribution.Simple.Utils ( rawSystemExit, installOrdinaryFile )
import Distribution.Verbosity ( verbose )
import Distribution.Verbosity ( verbose, Verbosity )
import Distribution.Simple ( defaultMainWithHooks
, simpleUserHooks
, buildHook, Args, confHook
Expand All @@ -25,11 +25,8 @@ import Distribution.PackageDescription ( emptyBuildInfo
, PackageDescription )
import System.FilePath ( (</>) )

staticLibDir :: FilePath
staticLibDir = "build"</>"static"

dynamicLibDir :: FilePath
dynamicLibDir = "build"</>"dynamic"
dynamicLibDir = "build"

main :: IO ()
main = defaultMainWithHooks simpleUserHooks
Expand Down Expand Up @@ -75,7 +72,7 @@ glfwPkgDesc pkgDesc =
libDirGlfw :: HookedBuildInfo
libDirGlfw = (Just buildinfo, [])
where buildinfo = emptyBuildInfo
{ extraLibDirs = [ staticLibDir, dynamicLibDir ] }
{ extraLibDirs = [ dynamicLibDir ] }

postInstGlfw :: Args -> InstallFlags -> PackageDescription
-> LocalBuildInfo -> IO ()
Expand All @@ -99,14 +96,14 @@ postCopyGlfw _ flags pkgDesc lbi =
. fromFlag . copyDest $ flags
libPref = libdir installDirs
verbosity = fromFlag $ copyVerbosity flags
copyStatic dest f = installOrdinaryFile verbosity (staticLibDir</>f) (dest</>f)
copyDynamic dest f = installOrdinaryFile verbosity (dynamicLibDir</>f) (dest</>f)
maybe (return ()) (copyStatic libPref) (Just staticLibName)
maybe (return ()) (copyDynamic libPref) (Just dynamicLibName)
install_name_tool verbosity (libPref</>dynamicLibName)
_ -> return ()

staticLibName :: FilePath
staticLibName = "libglfw.a"
install_name_tool :: Verbosity -> FilePath -> IO ()
install_name_tool v fp = rawSystemExit v "env" $
["install_name_tool"] ++ ["-id"] ++ [fp] ++ [fp]

dynamicLibName :: FilePath
dynamicLibName = "libglfw.dylib"

0 comments on commit 8c46810

Please sign in to comment.