[m-dev.] diff: fix bug with --parallel & C flags

Fergus Henderson fjh at cs.mu.OZ.AU
Fri Sep 15 01:30:09 AEDT 2000


Estimated hours taken: 2

Fix a bug: mmc wasn't passing the right flags to the C compiler
when `--parallel' was specified.

configure.in:
	Set CFLAGS_FOR_THREADS, using code adopted from the code
	in scripts/mgnuc.in.

scripts/mgnuc.in:
	Use CFLAGS_FOR_THREADS rather than doing the case analysis
	here.

scripts/mmc.in:
	Pass `--cflags-for-threads $CFLAGS_FOR_THREADS' to mercury_compile.

compiler/options.m:
	Add a new option `--cflags-for-threads', for use by scripts/mmc.in.

compiler/mercury_compile.m:
	If --parallel is enabled, pass the --cflags-for-threads
	options to the C compiler.

bindist/bindist.build_vars.in:
	Pass on CFLAGS_FOR_THREADS.

Workspace: /home/pgrad/fjh/ws/hg
Index: bindist/bindist.build_vars.in
===================================================================
RCS file: /home/mercury1/repository/mercury/bindist/bindist.build_vars.in,v
retrieving revision 1.13
diff -u -d -r1.13 bindist.build_vars.in
--- bindist/bindist.build_vars.in	2000/09/06 05:30:10	1.13
+++ bindist/bindist.build_vars.in	2000/09/14 14:18:05
@@ -19,6 +19,7 @@
 LOW_TAG_BITS="@LOW_TAG_BITS@"
 CFLAGS_FOR_REGS="@CFLAGS_FOR_REGS@"
 CFLAGS_FOR_GOTOS="@CFLAGS_FOR_GOTOS@"
+CFLAGS_FOR_THREADS="@CFLAGS_FOR_THREADS@"
 LINK_SHARED_OBJ="@LINK_SHARED_OBJ@"
 LINK_SHARED_OBJ_SH="@LINK_SHARED_OBJ_SH@"
 EXE_RPATH_OPT="@EXE_RPATH_OPT@"
Index: compiler/mercury_compile.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/mercury_compile.m,v
retrieving revision 1.175
diff -u -d -r1.175 mercury_compile.m
--- compiler/mercury_compile.m	2000/09/08 06:01:58	1.175
+++ compiler/mercury_compile.m	2000/09/14 13:44:25
@@ -2577,6 +2577,13 @@
 	;
 		AsmOpt = ""
 	},
+	globals__io_lookup_bool_option(parallel, Parallel),
+	( { Parallel = yes } ->
+		globals__io_lookup_string_option(cflags_for_threads,
+			CFLAGS_FOR_THREADS)
+	;
+		{ CFLAGS_FOR_THREADS = "" }
+	),
 	globals__io_get_gc_method(GC_Method),
 	{ GC_Method = conservative ->
 		GC_Opt = "-DCONSERVATIVE_GC "
@@ -2708,6 +2715,7 @@
 		HighLevelCodeOpt, NestedFunctionsOpt, HighLevelDataOpt,
 		RegOpt, GotoOpt, AsmOpt,
 		CFLAGS_FOR_REGS, " ", CFLAGS_FOR_GOTOS, " ",
+		CFLAGS_FOR_THREADS, " ",
 		GC_Opt, ProfileCallsOpt, ProfileTimeOpt, ProfileMemoryOpt,
 		PIC_Reg_Opt, TagsOpt, NumTagBitsOpt,
 		C_DebugOpt, LL_DebugOpt,
Index: compiler/options.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/options.m,v
retrieving revision 1.288
diff -u -d -r1.288 options.m
--- compiler/options.m	2000/09/06 05:21:00	1.288
+++ compiler/options.m	2000/09/14 13:57:49
@@ -267,6 +267,7 @@
 		;	cflags
 		;	cflags_for_regs
 		;	cflags_for_gotos
+		;	cflags_for_threads
 		;	c_debug
 		;	c_include_directory
 		;	c_flag_to_name_object_file
@@ -613,8 +614,9 @@
 	cflags			-	accumulating([]),
 	cflags_for_regs		-	string(""),
 	cflags_for_gotos	-	string(""),
+	cflags_for_threads	-	string(""),
 					% the `mmc' script will override the
-					% above two defaults with values
+					% above three defaults with values
 					% determined at configuration time
 	c_debug			-	bool(no),
 	c_include_directory	-	accumulating([]),
@@ -991,6 +993,7 @@
 long_option("cflags",			cflags).
 long_option("cflags-for-regs",		cflags_for_regs).
 long_option("cflags-for-gotos",		cflags_for_gotos).
+long_option("cflags-for-threads",	cflags_for_threads).
 long_option("c-debug",			c_debug).
 long_option("c-include-directory",	c_include_directory).
 long_option("c-flag-to-name-object-file", c_flag_to_name_object_file).
@@ -2063,7 +2066,8 @@
 
 		"--cflags <options>",
 		"\tSpecify options to be passed to the C compiler.",
-		% The --cflags-for-regs and --cflags-for-gotos options
+		% The --cflags-for-regs, --cflags-for-gotos,
+		% and --cflags-for-threads options
 		% are reserved for use by the `mmc' script;
 		% they are deliberately not documented.
 
Index: configure.in
===================================================================
RCS file: /home/mercury1/repository/mercury/configure.in,v
retrieving revision 1.222
diff -u -d -r1.222 configure.in
--- configure.in	2000/09/06 11:53:02	1.222
+++ configure.in	2000/09/14 14:00:24
@@ -1631,6 +1631,59 @@
 	AC_DEFINE(MR_DIGITAL_UNIX_PTHREADS)
 fi
 
+# Figure out what options we need to pass to the C compiler
+# for multithreading.   We may need to pass different
+# options to tell (a) the Mercury runtime & library
+# (b) the boehm collector and (c) the C library
+# that they need to be thread-safe.
+case "$host" in
+	*solaris*)
+		CFLAGS_FOR_THREADS="-DMR_THREAD_SAFE -DSOLARIS_THREADS \
+			-D_SOLARIS_PTHREADS -D_REENTRANT"
+		;;
+
+	*linux*)
+		CFLAGS_FOR_THREADS="-DMR_THREAD_SAFE -DLINUX_THREADS \
+			-D_THREAD_SAFE -D_REENTRANT"
+		# Note that for old versions of Linux / glibc,
+		# you may also need to make sure that you don't
+		# pass -ansi to gcc.
+		;;
+
+	*cygwin*)
+		case "$CC" in
+			*cl*)	# cl is the Microsoft C compiler
+				CFLAGS_FOR_THREADS="-DMR_THREAD_SAFE -DWIN32_THREADS /MD" ;;
+			*)
+				CFLAGS_FOR_THREADS="" ;;
+		esac
+		;;
+
+###	# The threads stuff on Digital Unix (OSF) is not yet enabled because
+###	# the Boehm garbage collector doesn't support threads on that platform
+###	# XXX probably we should enable it but report an error if you try to
+###	#     use an *.par.gc* grade
+###	*-osf*)
+###		CFLAGS_FOR_THREADS="-DMR_THREAD_SAFE"
+###		;;
+
+###	# The threads stuff on IRIX is not yet enabled because
+###	# we don't have an IRIX box to test it on.
+###	# (XXX perhaps we should enable it anyway, so it is easier to test?)
+###	*irix*)
+###		CFLAGS_FOR_THREADS="-DMR_THREAD_SAFE -DIRIX_THREADS"
+###		;;
+
+	*)	
+		# Multithreading not (yet) supported on other architectures.
+		# For multithreading, we need (1) Posix threads and
+		# (2) a port of the Boehm gc for that architecture
+		# that works with threads.
+		CFLAGS_FOR_THREADS=""
+		;;
+esac
+AC_SUBST(CFLAGS_FOR_THREADS)
+
 #-----------------------------------------------------------------------------#
 
 #
Index: scripts/mgnuc.in
===================================================================
RCS file: /home/mercury1/repository/mercury/scripts/mgnuc.in,v
retrieving revision 1.71
diff -u -d -r1.71 mgnuc.in
--- scripts/mgnuc.in	2000/09/06 11:04:42	1.71
+++ scripts/mgnuc.in	2000/09/14 14:05:39
@@ -26,6 +26,7 @@
 CC=${MERCURY_C_COMPILER="@CC@"}
 CFLAGS_FOR_REGS="@CFLAGS_FOR_REGS@"
 CFLAGS_FOR_GOTOS="@CFLAGS_FOR_GOTOS@"
+CFLAGS_FOR_THREADS="@CFLAGS_FOR_THREADS@"
 AS="@AS@"
 
 case "$CC" in
@@ -256,29 +257,16 @@
 esac
 
 case $thread_safe in
-	true)
-	case $FULLARCH in
-		*solaris*) THREAD_OPTS="-DMR_THREAD_SAFE -DSOLARIS_THREADS \
-				-D_SOLARIS_PTHREADS -D_REENTRANT"
-			;;
-
-		*linux*) THREAD_OPTS="-DMR_THREAD_SAFE -DLINUX_THREADS \
-				-D_THREAD_SAFE -D_REENTRANT"
-				# Don't use -ansi under Linux or we get
-				# parse errors at sigset_t in the pthreads
-				# headers.
-			ANSI_OPTS=""
-			;;
-
-		*cygwin32*)
-			case $COMPILER in
-				cl) THREAD_OPTS="-DMR_THREAD_SAFE /MD"
-				;;
-			esac
-			;;
-		*)		THREAD_OPTS=""
-			;;
-	esac ;;
+	true)		THREAD_OPTS="$CFLAGS_FOR_THREADS"
+			case $FULLARCH in *linux*) 
+				# Don't use -ansi under Linux or we get parse
+				# errors at sigset_t in the pthreads headers.
+				# This doesn't seem to be necessary for recent
+				# versions of Linux/glibc (e.g. glibc 2.1.2),
+				# but I've left it in so we can remain
+				# compatible with older versions.
+				ANSI_OPTS=""
+			esac ;;
 	false)		THREAD_OPTS="" ;;
 esac
 
Index: scripts/mmc.in
===================================================================
RCS file: /home/mercury1/repository/mercury/scripts/mmc.in,v
retrieving revision 1.12
diff -u -d -r1.12 mmc.in
--- scripts/mmc.in	2000/07/07 11:11:35	1.12
+++ scripts/mmc.in	2000/09/14 13:41:52
@@ -23,6 +23,7 @@
 CC=${MERCURY_C_COMPILER="@CC@"}
 CFLAGS_FOR_REGS="@CFLAGS_FOR_REGS@"
 CFLAGS_FOR_GOTOS="@CFLAGS_FOR_GOTOS@"
+CFLAGS_FOR_THREADS="@CFLAGS_FOR_THREADS@"
 CFLAG_TO_NAME_OBJECT_FILE="@OBJFILE_OPT@"
 OBJECT_FILE_EXTENSION="@OBJ_SUFFIX@"
 LOW_TAG_BITS=@LOW_TAG_BITS@
@@ -43,6 +44,7 @@
 		--cc "$CC" --grade "$DEFAULT_GRADE" \
 		--cflags-for-regs "$CFLAGS_FOR_REGS" \
 		--cflags-for-gotos "$CFLAGS_FOR_GOTOS" \
+		--cflags-for-threads "$CFLAGS_FOR_THREADS" \
 		--c-flag-to-name-object-file "$CFLAG_TO_NAME_OBJECT_FILE" \
 		--object-file-extension "$OBJECT_FILE_EXTENSION" \
 		--num-real-r-regs "$NUM_REAL_R_REGS" \
@@ -60,6 +62,7 @@
 		--cc "$CC" --grade "$DEFAULT_GRADE" \
 		--cflags-for-regs "$CFLAGS_FOR_REGS" \
 		--cflags-for-gotos "$CFLAGS_FOR_GOTOS" \
+		--cflags-for-threads "$CFLAGS_FOR_THREADS" \
 		--c-flag-to-name-object-file "$CFLAG_TO_NAME_OBJECT_FILE" \
 		--object-file-extension "$OBJECT_FILE_EXTENSION" \
 		--num-real-r-regs "$NUM_REAL_R_REGS" \

-- 
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.
--------------------------------------------------------------------------
mercury-developers mailing list
Post messages to:       mercury-developers at cs.mu.oz.au
Administrative Queries: owner-mercury-developers at cs.mu.oz.au
Subscriptions:          mercury-developers-request at cs.mu.oz.au
--------------------------------------------------------------------------



More information about the developers mailing list