for review: fix for "Including .c files in libraries."

Fergus Henderson fjh at cs.mu.OZ.AU
Mon Jan 26 03:23:38 AEDT 1998


Tyson, can you please review this fix?

On 20-Jan-1998, Tyson Dowd <trd at cs.mu.OZ.AU> wrote:
> If you're creating a Mercury package, and want to link in a .c
> file as part of the package, the MLLIBS mechanism mentioned in C
> interface section of the Mercury Language Reference manual doesn't work
> very well.
> 
> It doesn't add any dependency of the library on the .o file (which you
> can fix, but it's not documented), and, worse, only puts it in the .so,
> not the .a (MLLIBS is not used to build in the .a - and rightly so).
> It also doesn't handle the PIC regs trickery required under
> Linux -- you need to add a .pic_o dependency yourself (and as my
> previous bug report indicated, this causes mmake to delete your .c
> file).

Add support to Mmake for new variables MLOBJS and MLPICOBJS,
since simply listing object files in MLLIBS doesn't do the
right thing in the case when you're building a library package
rather than a program.

scripts/Mmake.vars.in:
	Add definitions of MLOBJS and MLPICOBJS.

compiler/modules.m:
	Add code to use the $(MLOBJS) and $(MLPICOBJS) variables
	to the rules for building programs and libraries that are
	output in the generated `.dep' files.

doc/user_guide.texi:
	Document the use of MLOBJS and MLPICOBJS.

cvs diff  compiler/modules.m doc/user_guide.texi scripts/Mmake.vars.in
Index: compiler/modules.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/modules.m,v
retrieving revision 1.53
diff -u -r1.53 modules.m
--- modules.m	1998/01/25 06:58:01	1.53
+++ modules.m	1998/01/25 16:22:20
@@ -1142,10 +1142,10 @@
 
 	io__write_strings(DepStream, [
 		ModuleName, " : $(", ModuleName, ".os) ",
-		ModuleName, "_init.o\n",
+		ModuleName, "_init.o $(MLOBJS)\n",
 		"\t$(ML) $(GRADEFLAGS) $(MLFLAGS) -o ", ModuleName, " ",
 		ModuleName, "_init.o \\\n",
-		"\t$(", ModuleName, ".os) $(MLLIBS)\n\n"
+		"\t	$(", ModuleName, ".os) $(MLOBJS) $(MLLIBS)\n\n"
 	]),
 
 	io__write_strings(DepStream, [
@@ -1153,13 +1153,14 @@
 				ModuleName, "_init.o\n",
 		"\t$(ML) $(GRADEFLAGS) $(MLFLAGS) -o ", ModuleName, ".split ",
 			ModuleName, "_init.o \\\n",
-			"\t", ModuleName, ".split.a $(MLLIBS)\n\n"
+		"\t	", ModuleName, ".split.a $(MLLIBS)\n\n"
 	]),
 
 	io__write_strings(DepStream, [
-		ModuleName, ".split.a : $(", ModuleName, ".dir_os)\n",
+		ModuleName, ".split.a : $(", ModuleName, ".dir_os) ",
+				"$(MLOBJS)\n",
 		"\trm -f ", ModuleName, ".split.a\n",
-		"\t$(AR) $(ARFLAGS) ", ModuleName, ".split.a\n",
+		"\t$(AR) $(ARFLAGS) ", ModuleName, ".split.a $(MLOBJS)\n",
 		"\tfor dir in $(", ModuleName, ".dirs); do \\\n",
 		"\t	$(AR) q ", ModuleName, ".split.a $$dir/*.o; \\\n",
 		"\tdone\n",
@@ -1176,17 +1177,18 @@
 	]),
 
 	io__write_strings(DepStream, [
-		"lib", ModuleName, ".so : $(", ModuleName, ".pic_os)\n",
+		"lib", ModuleName, ".so : $(", ModuleName, ".pic_os) ",
+				"$(MLPICOBJS)\n",
 		"\t$(ML) --make-shared-lib $(GRADEFLAGS) $(MLFLAGS) -o ",
 			"lib", ModuleName, ".so \\\n",
-		"\t\t$(", ModuleName, ".pic_os) $(MLLIBS)\n\n"
+		"\t\t$(", ModuleName, ".pic_os) $(MLPICOBJS) $(MLLIBS)\n\n"
 	]),
 
 	io__write_strings(DepStream, [
-		"lib", ModuleName, ".a : $(", ModuleName, ".os)\n",
+		"lib", ModuleName, ".a : $(", ModuleName, ".os) $(MLOBJS)\n",
 		"\trm -f ", ModuleName, ".a\n",
 		"\t$(AR) $(ARFLAGS) lib", ModuleName, ".a ",
-			"$(", ModuleName, ".os)\n",
+			"$(", ModuleName, ".os) $(MLOBJS)\n",
 		"\t$(RANLIB) $(RANLIBFLAGS) lib", ModuleName, ".a\n\n"
 	]),
 
Index: doc/user_guide.texi
===================================================================
RCS file: /home/mercury1/repository/mercury/doc/user_guide.texi,v
retrieving revision 1.115
diff -u -r1.115 user_guide.texi
--- user_guide.texi	1998/01/25 15:11:59	1.115
+++ user_guide.texi	1998/01/25 15:59:13
@@ -861,6 +861,13 @@
 @item MLFLAGS and EXTRA_MLFLAGS
 Flags to pass to the linker.
 
+ at item MLLIBS
+A list of @samp{-l} options specifying libraries used by the program
+(or library) that you are building.  @xref{Using libraries}.
+
+ at item MLOBJS
+A list of extra object files to link into any programs or libraries
+that you are building.
 @end table
 
 Other variables also exist - see
@@ -945,12 +952,12 @@
 
 libmypackage.a: $(mypackage.os)
 	rm -f libmypackage.a
-	$(AR) $(ARFLAGS) libmypackage.a $(mypackage.os)
+	$(AR) $(ARFLAGS) libmypackage.a $(mypackage.os) $(MLOBJS)
 	$(RANLIB) $(RANLIBFLAGS) mypackage.a
 
 libmypackage.so: $(mypackage.pic_os)
 	$(ML) $(MLFLAGS) --make-shared-lib -o libmypackage.so \
-		$(mypackage.pic_os) $(MLLIBS)
+		$(mypackage.pic_os) $(MLPICOBJS) $(MLLIBS)
 
 libmypackage.init:
 	...
@@ -959,11 +966,15 @@
 	rm -f libmypackage.a libmypackage.so
 @end example
 
-If necessary, you can override the default definitions of the
-variables such as @samp{ML}, @samp{MLFLAGS}, and @samp{MLLIBS}
-to customize the way shared libraries are built.  Similarly
- at samp{AR}, @samp{ARFLAGS}, @samp{RANLIB}, and @samp{RANLIBFLAGS}
-control the way static libraries are built.
+If necessary, you can override the default definitions of the variables
+such as @samp{ML}, @samp{MLFLAGS}, @samp{MLPICOBJS}, and @samp{MLLIBS}
+to customize the way shared libraries are built.  Similarly @samp{AR},
+ at samp{ARFLAGS}, @samp{MLOBJS}, @samp{RANLIB}, and @samp{RANLIBFLAGS}
+control the way static libraries are built.  (The @samp{MLOBJS} variable
+is supposed to contain a list of additional object files to link into
+the library, while the @samp{MLLIBS} variable should contain a list of
+ at samp{-l} options naming other libraries used by this library.
+ at samp{MLPICOBJS} is described below.)
 
 Note that to use a library, as well as the shared or static object library,
 you also need the interface files.  That's why the
@@ -987,9 +998,12 @@
 On these platforms, @code{Mmake} will create @file{.pic_o} files,
 and @samp{$(mypackage.pic_os)} will contain a list of the @file{.pic_o} files
 for the library whose top-level module is @samp{mypackage}.
+In addition, @samp{$(MLPICOBJS)} will be set to @samp{$MLOBJS} with
+all occurrences of @samp{.o} replaced with @samp{.pic_o}.
 On other platforms, position independent code is the default,
-and @samp{$(mypackage.pic_os)} will just be the same as @samp{$(mypackage.os)},
-which contains a list of the @file{.o} files for that module.
+so @samp{$(mypackage.pic_os)} will just be the same as @samp{$(mypackage.os)},
+which contains a list of the @file{.o} files for that module,
+and @samp{$(MLPICOBJS)} will be the same as @samp{$(MLOBJS)}.
 
 @node Installing libraries
 @section Installing libraries
Index: scripts/Mmake.vars.in
===================================================================
RCS file: /home/mercury1/repository/mercury/scripts/Mmake.vars.in,v
retrieving revision 1.13
diff -u -r1.13 Mmake.vars.in
--- Mmake.vars.in	1998/01/14 02:21:46	1.13
+++ Mmake.vars.in	1998/01/25 15:27:33
@@ -54,6 +54,9 @@
 MGNUCFLAGS	= $(EXTRA_MGNUCFLAGS) $(EXTRA_CFLAGS) 
 ML		= ml
 MLFLAGS		= $(EXTRA_MLFLAGS)
+MLOBJS		=
+MLPICOBJS	= $(MLOBJS:.o=.$(EXT_FOR_PIC_OBJECTS))
+MLLIBS		=
 MNC		= mnc
 MNCFLAGS	= $(EXTRA_MNCFLAGS)
 MNL		= mnl
-- 
Fergus Henderson <fjh at cs.mu.oz.au>   |  "I have always known that the pursuit
WWW: <http://www.cs.mu.oz.au/~fjh>   |  of excellence is a lethal habit"
PGP: finger fjh at 128.250.37.3         |     -- the last words of T. S. Garp.



More information about the developers mailing list