[m-rev.] for review: fix bug #288

Julien Fischer jfischer at opturion.com
Thu Jun 20 18:13:10 AEST 2013


For review by anyone.

Fix bug #288.

Components of the Mercury system that were implemented directly in C were not
respecting the mmake LDFLAGS and EXTRA_LDFLAGS variables (or LD_LIBFLAGS,
EXTRA_LDLIBFLAGS for libraries).

The following patch was contributed by Keri Harris -- I have extended it
slightly to fix some omissions in the handling of .dylib files (i.e.  Mac OS X
style shared libraries).

NEWS:
     Announce the resolution of bug #288.

boehm_gc/Makefile.direct:
runtime/Mmakefile
trace/Mmakefile:
util/Mmakefile:
 	Pass options set via LD_FLAGS or EXTRA_LDFLAGS (or the library
 	versions) to the linker when building executables (or shared
 	libraries) in these directories.

Julien.

diff --git a/NEWS b/NEWS
index b357d4e..d3c6eac 100644
--- a/NEWS
+++ b/NEWS
@@ -6,6 +6,10 @@ This is a bug-fix release.
  * The following functions in the standard library's cord module now use
    constant stack space: list/1, rev_list/1, cord_list_to_cord/1 and
    cord_list_to_list/1.
+* Linker options set via the LDFLAGS and EXTRA_LDFLAGS mmake variables
+  are now applied to all executables in the Mercury system.  Likewise, 
+  for shared libraries and the LD_LIBFLAGS and EXTRA_LD_LIBFLAGS mmake
+  variables.  (Bug #288)


  NEWS for Mercury 13.05.1
diff --git a/boehm_gc/Makefile.direct b/boehm_gc/Makefile.direct
index 373bf84..6046446 100644
--- a/boehm_gc/Makefile.direct
+++ b/boehm_gc/Makefile.direct
@@ -359,17 +359,18 @@ lib$(GC_GRADE).so: $(OBJS) $(UTILS) # dyn_load_sunos53.o
  	./if_mach SPARC SOLARIS $(MAKE) dyn_load_sunos53.o
  	./if_mach SPARC SOLARIS \
  	$(LINK_SHARED_OBJ) -o lib$(GC_GRADE).so $(OBJS) dyn_load_sunos53.o \
-		-ldl $(MAYBE_THREAD_LIBS)
+		-ldl $(MAYBE_THREAD_LIBS) $(LD_LIBFLAGS) $(EXTRA_LD_LIBFLAGS)
  	./if_not_there on_sparc_sunos5_so $(MAKE) dyn_load.o
  	./if_not_there on_sparc_sunos5_so \
  	$(LINK_SHARED_OBJ) -o lib$(GC_GRADE).so $(OBJS) dyn_load.o \
-		-lc $(MAYBE_THREAD_LIBS)
+		-lc $(MAYBE_THREAD_LIBS) $(LD_LIBFLAGS) $(EXTRA_LD_LIBFLAGS)

+# Mercury-specific target:
  # Darwin shared library version of the gc.
  lib$(GC_GRADE).dylib: $(OBJS) $(UTILS)
  	$(LINK_SHARED_OBJ) -install_name \
  		$(FINAL_INSTALL_MERC_GC_LIB_DIR)/lib$(GC_GRADE).dylib \
-		-o lib$(GC_GRADE).dylib $(OBJS) dyn_load.o -lc
+		-o lib$(GC_GRADE).dylib $(OBJS) dyn_load.o -lc $(LD_LIBFLAGS) $(EXTRA_LD_LIBFLAGS)

  # SunOS5 shared library version of the collector
  sunos5gc.so: $(OBJS) dyn_load_sunos53.o
diff --git a/runtime/Mmakefile b/runtime/Mmakefile
index f6908cf..6d9c672 100644
--- a/runtime/Mmakefile
+++ b/runtime/Mmakefile
@@ -248,7 +248,7 @@ MGNUCFLAGS	+= --c-debug --no-ansi
  OBJS		= $(CFILES:.c=.$O)
  PIC_OBJS	= $(CFILES:.c=.$(EXT_FOR_PIC_OBJECTS))

-LDFLAGS		= -L$(BOEHM_GC_DIR) -L/usr/local/lib
+LD_LIBFLAGS	= -L$(BOEHM_GC_DIR) -L/usr/local/lib
  LDLIBS		= $(SHARED_GC_LIBS) $(MATH_LIB)

  THREADLIBS	= \
@@ -392,7 +392,7 @@ lib$(RT_LIB_NAME).so: $(PIC_OBJS)
  	$(LINK_SHARED_OBJ) $(ERROR_UNDEFINED)				\
  		-o lib$(RT_LIB_NAME).so $(PIC_OBJS)			\
  		$(SHLIB_RPATH_OPT)$(FINAL_INSTALL_MERC_GC_LIB_DIR)	\
-		$(LDFLAGS) $(LDLIBS) $(THREADLIBS)			\
+		$(ALL_LD_LIBFLAGS) $(LDLIBS) $(THREADLIBS)			\
  		$(SHARED_LIBS)

  # For Darwin we should pass the -install_name option.
@@ -401,7 +401,7 @@ lib$(RT_LIB_NAME).dylib: $(PIC_OBJS)
  		-o lib$(RT_LIB_NAME).dylib $(PIC_OBJS)			\
  		-install_name 						\
  			$(FINAL_INSTALL_MERC_LIB_DIR)/lib$(RT_LIB_NAME).dylib \
-		$(LDFLAGS) $(LDLIBS) $(THREADLIBS)			\
+		$(ALL_LD_LIBFLAGS) $(LDLIBS) $(THREADLIBS)			\
  		$(SHARED_LIBS)

  endif
diff --git a/trace/Mmakefile b/trace/Mmakefile
index 3138bba..79e00c4 100644
--- a/trace/Mmakefile
+++ b/trace/Mmakefile
@@ -273,14 +273,16 @@ lib$(TRACE_LIB_NAME).so: $(TRACE_PIC_OBJS) lib$(EVENTSPEC_LIB_NAME).so
  	$(LINK_SHARED_OBJ) $(ERROR_UNDEFINED)				\
  		-o lib$(TRACE_LIB_NAME).so $(TRACE_PIC_OBJS)		\
  		$(RPATH_1)$(RPATH_2)					\
-		$(TRACE_LDFLAGS) $(TRACE_LDLIBS) $(THREADLIBS)		\
+		$(ALL_LD_LIBFLAGS) $(TRACE_LDFLAGS)			\
+		$(TRACE_LDLIBS) $(THREADLIBS)				\
  		$(SHARED_LIBS)

  lib$(EVENTSPEC_LIB_NAME).so: $(EVENTSPEC_PIC_OBJS)
  	$(LINK_SHARED_OBJ) $(ERROR_UNDEFINED)				\
  		-o lib$(EVENTSPEC_LIB_NAME).so $(EVENTSPEC_PIC_OBJS)	\
  		$(RPATH_1)$(RPATH_2)					\
-		$(EVENTSPEC_LDFLAGS) $(EVENTSPEC_LDLIBS) $(THREADLIBS)	\
+		$(ALL_LD_LIBFLAGS) $(EVENTSPEC_LDFLAGS)			\
+		$(EVENTSPEC_LDLIBS) $(THREADLIBS)			\
  		$(SHARED_LIBS)

  # For Darwin:
@@ -289,7 +291,8 @@ lib$(TRACE_LIB_NAME).dylib: $(TRACE_PIC_OBJS) lib$(EVENTSPEC_LIB_NAME).dylib
  		-o lib$(TRACE_LIB_NAME).dylib $(TRACE_PIC_OBJS)		\
  		-install_name 						\
  		$(FINAL_INSTALL_MERC_LIB_DIR)/lib$(TRACE_LIB_NAME).dylib \
-		$(TRACE_LDFLAGS) $(TRACE_LDLIBS) $(THREADLIBS)		\
+		$(ALL_LD_LIBFLAGS) $(TRACE_LDFLAGS)			\
+		$(TRACE_LDLIBS) $(THREADLIBS)				\
  		$(SHARED_LIBS)

  lib$(EVENTSPEC_LIB_NAME).dylib: $(EVENTSPEC_PIC_OBJS)
@@ -297,7 +300,8 @@ lib$(EVENTSPEC_LIB_NAME).dylib: $(EVENTSPEC_PIC_OBJS)
  		-o lib$(EVENTSPEC_LIB_NAME).dylib $(EVENTSPEC_PIC_OBJS)	\
  		-install_name 						\
  		$(FINAL_INSTALL_MERC_LIB_DIR)/lib$(EVENTSPEC_LIB_NAME).dylib \
-		$(EVENTSPEC_LDFLAGS) $(EVENTSPEC_LDLIBS) $(THREADLIBS)	\
+		$(ALL_LD_LIBFLAGS) $(EVENTSPEC_LDFLAGS)			\
+		$(EVENTSPEC_LDLIBS) $(THREADLIBS)			\
  		$(SHARED_LIBS)

  .PHONY: cs
diff --git a/util/Mmakefile b/util/Mmakefile
index c3ff7aa..80ba6d2 100644
--- a/util/Mmakefile
+++ b/util/Mmakefile
@@ -51,30 +51,30 @@ all:	$(PROGFILENAMES) $(TAGS_FILE_EXISTS)
  ifeq ($(USING_MICROSOFT_CL_COMPILER),yes)
  .c$(EXT_FOR_EXE):
  	$(MGNUC) --no-mercury-stdlib-dir \
-		$(GRADEFLAGS) $(ALL_MGNUCFLAGS) -Fe$@ $< $(GETOPT_SRC)
+		$(GRADEFLAGS) $(ALL_MGNUCFLAGS) $(ALL_LDFLAGS) -Fe$@ $< $(GETOPT_SRC)

  mkinit$(EXT_FOR_EXE): mkinit.c mkinit_common.c mkinit_common.h
  	$(MGNUC) --no-mercury-stdlib-dir \
-		$(GRADEFLAGS) $(ALL_MGNUCFLAGS) -Fe$@ \
+		$(GRADEFLAGS) $(ALL_MGNUCFLAGS) $(ALL_LDFLAGS) -Fe$@ \
  			mkinit.c mkinit_common.c $(GETOPT_SRC)

  mkinit_erl$(EXT_FOR_EXE): mkinit_erl.c mkinit_common.c mkinit_common.h
  	$(MGNUC) --no-mercury-stdlib-dir \
-		$(GRADEFLAGS) $(ALL_MGNUCFLAGS) -Fe$@ \
+		$(GRADEFLAGS) $(ALL_MGNUCFLAGS) $(ALL_LDFLAGS) -Fe$@ \
  			mkinit_erl.c mkinit_common.c $(GETOPT_SRC)
  else
  .c$(EXT_FOR_EXE):
  	$(MGNUC) --no-mercury-stdlib-dir \
-		$(GRADEFLAGS) $(ALL_MGNUCFLAGS) -o $@ $< $(GETOPT_SRC)
+		$(GRADEFLAGS) $(ALL_MGNUCFLAGS) $(ALL_LDFLAGS) -o $@ $< $(GETOPT_SRC)

  mkinit$(EXT_FOR_EXE): mkinit.c mkinit_common.c mkinit_common.h
  	$(MGNUC) --no-mercury-stdlib-dir \
-		$(GRADEFLAGS) $(ALL_MGNUCFLAGS) -o $@ \
+		$(GRADEFLAGS) $(ALL_MGNUCFLAGS) $(ALL_LDFLAGS) -o $@ \
  			mkinit.c mkinit_common.c $(GETOPT_SRC)

  mkinit_erl$(EXT_FOR_EXE): mkinit_erl.c mkinit_common.c mkinit_common.h
  	$(MGNUC) --no-mercury-stdlib-dir \
-		$(GRADEFLAGS) $(ALL_MGNUCFLAGS) -o $@ \
+		$(GRADEFLAGS) $(ALL_MGNUCFLAGS) $(ALL_LDFLAGS) -o $@ \
  			mkinit_erl.c mkinit_common.c $(GETOPT_SRC)

  endif



More information about the reviews mailing list