Build library packages as shared libs
authorDuncan Coutts <duncan@well-typed.com>
Wed, 29 Apr 2009 15:15:53 +0000 (15:15 +0000)
committerDuncan Coutts <duncan@well-typed.com>
Wed, 29 Apr 2009 15:15:53 +0000 (15:15 +0000)
when we configure ghc with --enable-shared

ghc.mk
rules/build-package-data.mk
rules/build-package-way.mk
rules/build-package.mk

diff --git a/ghc.mk b/ghc.mk
index c9b2809..f49ca13 100644 (file)
--- a/ghc.mk
+++ b/ghc.mk
@@ -320,8 +320,11 @@ PACKAGES += haskeline
 
 BOOT_PKGS = Cabal hpc extensible-exceptions
 
 
 BOOT_PKGS = Cabal hpc extensible-exceptions
 
-# The actual .a files: needed for dependencies.
+# The actual .a and .so/.dll files: needed for dependencies.
 ALL_LIBS  = $(foreach lib,$(PACKAGES),$(libraries/$(lib)_dist-install_v_LIB))
 ALL_LIBS  = $(foreach lib,$(PACKAGES),$(libraries/$(lib)_dist-install_v_LIB))
+ifeq "$(BuildSharedLibs)" "YES"
+ALL_LIBS += $(foreach lib,$(PACKAGES),$(libraries/$(lib)_dist-install_dyn_LIB))
+endif
 BOOT_LIBS = $(foreach lib,$(BOOT_PKGS),$(libraries/$(lib)_dist-boot_v_LIB))
 
 OTHER_LIBS = libffi/libHSffi.a libffi/HSffi.o
 BOOT_LIBS = $(foreach lib,$(BOOT_PKGS),$(libraries/$(lib)_dist-boot_v_LIB))
 
 OTHER_LIBS = libffi/libHSffi.a libffi/HSffi.o
index a260138..2f1a83a 100644 (file)
 
 define build-package-data # args: $1 = dir, $2 = distdir
 
 
 define build-package-data # args: $1 = dir, $2 = distdir
 
+ifeq "$(BuildSharedLibs)" "YES"
+$1_$2_CONFIGURE_FLAGS += --enable-shared
+endif
+
 ifeq "$(HSCOLOUR_SRCS)" "YES"
 $1_$2_CONFIGURE_FLAGS += --with-hscolour="$$(HSCOLOUR)"
 endif
 ifeq "$(HSCOLOUR_SRCS)" "YES"
 $1_$2_CONFIGURE_FLAGS += --with-hscolour="$$(HSCOLOUR)"
 endif
index 5fb3cdf..41496db 100644 (file)
@@ -26,6 +26,16 @@ $1_$2_$3_MKSTUBOBJS = find $1/$2/build -name "*_stub.$$($3_osuf)" -print
 # HACK ^^^ we tried to use $(wildcard), but apparently it fails due to
 # make using cached directory contents, or something.
 
 # HACK ^^^ we tried to use $(wildcard), but apparently it fails due to
 # make using cached directory contents, or something.
 
+ifeq "$3" "dyn"
+# Link a dynamic library
+$$($1_$2_$3_LIB) : $$($1_$2_$3_HS_OBJS) $$($1_$2_dyn_C_OBJS) $$($1_$2_dyn_S_OBJS) $$(ALL_RTS_LIBS)
+       $$(RM) $$@
+       $$($1_$2_HC) $$($1_$2_dyn_C_OBJS) $$($1_$2_dyn_S_OBJS) $$($1_$2_$3_HS_OBJS) \
+         `$$($1_$2_$3_MKSTUBOBJS)` \
+         -shared -dynamic \
+         -no-auto-link-packages $$(addprefix -package,$$($1_$2_DEPS)) \
+         -o $$@
+else
 # Build the ordinary .a library
 ifeq "$$($1_$2_SplitObjs)" "YES"
 $$($1_$2_$3_LIB) : $$($1_$2_$3_HS_OBJS) $$($1_$2_v_C_OBJS) $$($1_$2_v_S_OBJS)
 # Build the ordinary .a library
 ifeq "$$($1_$2_SplitObjs)" "YES"
 $$($1_$2_$3_LIB) : $$($1_$2_$3_HS_OBJS) $$($1_$2_v_C_OBJS) $$($1_$2_v_S_OBJS)
@@ -36,6 +46,7 @@ $$($1_$2_$3_LIB) : $$($1_$2_$3_HS_OBJS) $$($1_$2_v_C_OBJS) $$($1_$2_v_S_OBJS)
        $$(RM) $$@
        echo $$($1_$2_v_C_OBJS) $$($1_$2_v_S_OBJS) $$($1_$2_$3_HS_OBJS) `$$($1_$2_$3_MKSTUBOBJS)` | xargs $$(AR) $$(EXTRA_AR_ARGS) $$@
 endif
        $$(RM) $$@
        echo $$($1_$2_v_C_OBJS) $$($1_$2_v_S_OBJS) $$($1_$2_$3_HS_OBJS) `$$($1_$2_$3_MKSTUBOBJS)` | xargs $$(AR) $$(EXTRA_AR_ARGS) $$@
 endif
+endif
 
 $(call all-target,$1_$2,all_$1_$2_$3)
 $(call all-target,$1_$2_$3,$$($1_$2_$3_LIB))
 
 $(call all-target,$1_$2,all_$1_$2_$3)
 $(call all-target,$1_$2_$3,$$($1_$2_$3_LIB))
index 863dc73..fb7d9d2 100644 (file)
@@ -28,8 +28,6 @@
 # libraries/base_dist_CC_OPTS = -Iinclude ...
 # libraries/base_dist_LD_OPTS = -package ghc-prim-0.1.0.0
 
 # libraries/base_dist_CC_OPTS = -Iinclude ...
 # libraries/base_dist_LD_OPTS = -package ghc-prim-0.1.0.0
 
-# TODO: soext
-
 define build-package
 # $1 = dir
 # $2 = distdir
 define build-package
 # $1 = dir
 # $2 = distdir
@@ -123,10 +121,14 @@ $1_$2_SplitObjs = NO
 endif
 endif
 
 endif
 endif
 
-# C and S files are built the "v" vanlilla way
+# C and S files are built the "v" vanlilla way and possibly also the "dyn" way.
 $(call c-objs,$1,$2,v)
 $(call distdir-opts,$1,$2,$3)
 $(call c-suffix-rules,$1,$2,v,YES)
 $(call c-objs,$1,$2,v)
 $(call distdir-opts,$1,$2,$3)
 $(call c-suffix-rules,$1,$2,v,YES)
+ifeq "$(BuildSharedLibs)" "YES"
+$(call c-objs,$1,$2,dyn)
+$(call c-suffix-rules,$1,$2,dyn,YES)
+endif
 
 # Now generate all the build rules for each way in this directory:
 $$(foreach way,$$($1_$2_WAYS),$$(eval $$(call build-package-way,$1,$2,$$(way),$3)))
 
 # Now generate all the build rules for each way in this directory:
 $$(foreach way,$$($1_$2_WAYS),$$(eval $$(call build-package-way,$1,$2,$$(way),$3)))