[m-rev.] diff: building libraries with `mmc --make'
Simon Taylor
stayl at cs.mu.OZ.AU
Mon May 6 21:44:16 AEST 2002
Estimated hours taken: 2.5
Branches: main
Complete the support for building libraries with `mmc --make'.
compiler/make.m:
compiler/make.module_target.m:
compiler/mercury_compile.m:
compiler/compile_target_code.m:
Generate the `.pic_o' files needed to build shared libraries.
scripts/mmc.in:
Add `--pic-object-extension', `--create-archive-command'
`--create-archive-command-output-flag',
`--create-archive-commandflags' and `--ranlib-command'
options to DEFAULT_MCFLAGS.
Allow DEFAULT_MCFLAGS to be overridden in the environment,
for consistency with the other *FLAGS variables.
Index: scripts/mmc.in
===================================================================
RCS file: /home/mercury1/repository/mercury/scripts/mmc.in,v
retrieving revision 1.24
diff -u -u -r1.24 mmc.in
--- scripts/mmc.in 19 Apr 2002 14:59:36 -0000 1.24
+++ scripts/mmc.in 6 May 2002 09:04:22 -0000
@@ -33,7 +33,7 @@
#
# The default optimization level should be after
# all the options that describe the machine configuration.
-DEFAULT_MCFLAGS="\
+DEFAULT_MCFLAGS=${DEFAULT_MCFLAGS="\
$MERCURY_ALL_MC_C_INCL_DIRS \
--cc \"${MERCURY_C_COMPILER=@CC@}\" \
--grade \"${MERCURY_DEFAULT_GRADE=@DEFAULT_GRADE@}\" \
@@ -43,6 +43,11 @@
--cflags-for-pic \"@CFLAGS_FOR_PIC@\" \
--c-flag-to-name-object-file \"@OBJFILE_OPT@\" \
--object-file-extension \". at OBJ_SUFFIX@\" \
+ --pic-object-file-extension \". at EXT_FOR_PIC_OBJECTS@\" \
+ --create-archive-command \"@AR@\" \
+ --create-archive-command-output-flag \"@AR_LIBFILE_OPT@\" \
+ --create-archive-command-flags \"@ARFLAGS@\" \
+ --ranlib-command \"@RANLIB@\" \
--fullarch \"@FULLARCH@\" \
--num-real-r-regs \"@NUM_REAL_R_REGS@\" \
--num-real-r-temps \"@NUM_REAL_R_TEMPS@\" \
@@ -53,8 +58,8 @@
@HAVE_DELAY_SLOT@ \
@HAVE_BOXED_FLOATS@ \
${MERCURY_DEFAULT_OPT_LEVEL=-O2} \
- $STDLIB_DIR_OPT
- "
+ $STDLIB_DIR_OPT \
+ "}
export DEFAULT_MCFLAGS
case $# in
Index: compiler/compile_target_code.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/compile_target_code.m,v
retrieving revision 1.6
diff -u -u -r1.6 compile_target_code.m
--- compiler/compile_target_code.m 24 Apr 2002 08:42:34 -0000 1.6
+++ compiler/compile_target_code.m 6 May 2002 08:19:42 -0000
@@ -18,19 +18,30 @@
:- import_module bool, list, io, std_util.
- % compile_c_file(ErrorStream, CFile, ObjFile, Succeeded).
-:- pred compile_c_file(io__output_stream, string, string, bool,
+
+ % Are we generating position indepedent code (for use in a
+ % shared library)? On some architectures, pic and non-pic
+ % code is incompatible, so we need to generate `.o' and `.pic_o'
+ % files.
+:- type pic
+ ---> pic
+ ; non_pic
+ .
+
+ % compile_c_file(ErrorStream, PIC, CFile, ObjFile, Succeeded).
+:- pred compile_c_file(io__output_stream, pic, string, string, bool,
io__state, io__state).
-:- mode compile_c_file(in, in, in, out, di, uo) is det.
+:- mode compile_c_file(in, in, in, in, out, di, uo) is det.
- % compile_c_file(ErrorStream, ModuleName, Succeeded).
-:- pred compile_c_file(io__output_stream, module_name, bool,
+ % compile_c_file(ErrorStream, PIC, ModuleName, Succeeded).
+:- pred compile_c_file(io__output_stream, pic, module_name, bool,
io__state, io__state).
-:- mode compile_c_file(in, in, out, di, uo) is det.
+:- mode compile_c_file(in, in, in, out, di, uo) is det.
- % assemble(ErrorStream, ModuleName, Succeeded).
-:- pred assemble(io__output_stream, module_name, bool, io__state, io__state).
-:- mode assemble(in, in, out, di, uo) is det.
+ % assemble(ErrorStream, PIC, ModuleName, Succeeded).
+:- pred assemble(io__output_stream, pic, module_name,
+ bool, io__state, io__state).
+:- mode assemble(in, in, in, out, di, uo) is det.
% compile_java_file(ErrorStream, ModuleName, Succeeded).
:- pred compile_java_file(io__output_stream, module_name, bool,
@@ -249,7 +260,7 @@
".c", C_File),
module_name_to_split_c_file_name(ModuleName, Chunk,
Obj, O_File),
- compile_c_file(ErrorStream,
+ compile_c_file(ErrorStream, non_pic,
C_File, O_File, Succeeded0),
( { Succeeded0 = no } ->
{ Succeeded = no }
@@ -265,13 +276,20 @@
:- type compiler_type ---> gcc ; lcc ; unknown.
-compile_c_file(ErrorStream, ModuleName, Succeeded) -->
+compile_c_file(ErrorStream, PIC, ModuleName, Succeeded) -->
module_name_to_file_name(ModuleName, ".c", yes, C_File),
- globals__io_lookup_string_option(object_file_extension, ObjExt),
+ (
+ { PIC = pic },
+ globals__io_lookup_string_option(pic_object_file_extension,
+ ObjExt)
+ ;
+ { PIC = non_pic },
+ globals__io_lookup_string_option(object_file_extension, ObjExt)
+ ),
module_name_to_file_name(ModuleName, ObjExt, yes, O_File),
- compile_c_file(ErrorStream, C_File, O_File, Succeeded).
+ compile_c_file(ErrorStream, PIC, C_File, O_File, Succeeded).
-compile_c_file(ErrorStream, C_File, O_File, Succeeded) -->
+compile_c_file(ErrorStream, PIC, C_File, O_File, Succeeded) -->
globals__io_lookup_bool_option(verbose, Verbose),
globals__io_lookup_string_option(c_flag_to_name_object_file,
NameObjectFile),
@@ -281,6 +299,15 @@
globals__io_lookup_string_option(cc, CC),
globals__io_lookup_accumulating_option(cflags, C_Flags_List),
{ join_string_list(C_Flags_List, "", "", " ", CFLAGS) },
+
+ (
+ { PIC = pic },
+ globals__io_lookup_string_option(cflags_for_pic,
+ CFLAGS_FOR_PIC)
+ ;
+ { PIC = non_pic },
+ { CFLAGS_FOR_PIC = "" }
+ ),
globals__io_lookup_bool_option(use_subdirs, UseSubdirs),
globals__io_lookup_bool_option(split_c_files, SplitCFiles),
@@ -505,7 +532,7 @@
HighLevelCodeOpt, NestedFunctionsOpt, HighLevelDataOpt,
RegOpt, GotoOpt, AsmOpt,
CFLAGS_FOR_REGS, " ", CFLAGS_FOR_GOTOS, " ",
- CFLAGS_FOR_THREADS, " ",
+ CFLAGS_FOR_THREADS, " ", CFLAGS_FOR_PIC, " ",
GC_Opt, ProfileCallsOpt, ProfileTimeOpt, ProfileMemoryOpt,
ProfileDeepOpt, PIC_Reg_Opt, TagsOpt, NumTagBitsOpt,
Target_DebugOpt, LL_DebugOpt,
@@ -555,9 +582,15 @@
%-----------------------------------------------------------------------------%
-assemble(ErrorStream, ModuleName, Succeeded) -->
+assemble(ErrorStream, PIC, ModuleName, Succeeded) -->
globals__io_lookup_bool_option(pic, Pic),
- { AsmExt = (Pic = yes -> ".pic_s" ; ".s") },
+ { ( Pic = yes ; PIC = pic ) ->
+ AsmExt = ".pic_s",
+ GCCFLAGS_FOR_PIC = ""
+ ;
+ AsmExt = ".s",
+ GCCFLAGS_FOR_PIC = "-fpic"
+ },
module_name_to_file_name(ModuleName, AsmExt, no, AsmFile),
globals__io_lookup_string_option(object_file_extension, Obj),
module_name_to_file_name(ModuleName, Obj, yes, ObjFile),
@@ -575,7 +608,7 @@
{ join_string_list(C_Flags_List, "", "", " ", CFLAGS) },
% Be careful with the order here.
% Also be careful that each option is separated by spaces.
- { string__append_list([CC, " ", CFLAGS,
+ { string__append_list([CC, " ", CFLAGS, " ", GCCFLAGS_FOR_PIC,
" -c ", AsmFile, " ", NameObjectFile, ObjFile], Command) },
invoke_system_command(ErrorStream, verbose_commands,
Command, Succeeded).
@@ -741,7 +774,7 @@
maybe_write_string(Verbose,
"% Compiling initialization file...\n"),
- compile_c_file(ErrorStream, InitCFileName,
+ compile_c_file(ErrorStream, non_pic, InitCFileName,
InitObjFileName, CompileOK),
maybe_report_stats(Stats),
( { CompileOK = no } ->
@@ -844,12 +877,11 @@
globals__io_lookup_string_option(
create_archive_command_output_flag, ArOutputFlag),
globals__io_lookup_string_option(ranlib_command, RanLib),
- { list__append(
- [ArCmd, " ", ArFlags, " ", ArOutputFlag, " ",
- LibFileName, " " | ObjectList],
- [" && ", RanLib, " ", LibFileName],
- MakeLibCmdList) },
- { string__append_list(MakeLibCmdList, MakeLibCmd) },
+ { join_string_list(ObjectList, "", "", " ", Objects) },
+ { MakeLibCmd = string__append_list([
+ ArCmd, " ", ArFlags, " ", ArOutputFlag, " ",
+ LibFileName, " ", Objects,
+ " && ", RanLib, " ", LibFileName]) },
invoke_system_command(ErrorStream, verbose_commands,
MakeLibCmd, MakeLibCmdOK).
Index: compiler/make.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/make.m,v
retrieving revision 1.4
diff -u -u -r1.4 make.m
--- compiler/make.m 1 May 2002 17:09:18 -0000 1.4
+++ compiler/make.m 6 May 2002 07:45:29 -0000
@@ -115,7 +115,10 @@
:- type compilation_task_type
---> process_module(module_compilation_task_type)
- ; target_code_to_object_code
+
+ % The `pic' argument is only used for
+ % `--target c' and `--target asm'.
+ ; target_code_to_object_code(pic)
.
:- type module_compilation_task_type
@@ -144,15 +147,6 @@
; java_code
; asm_code(pic)
; object_code(pic)
- .
-
- % Are we generating position indepedent code (for use in a
- % shared library)? On some architectures, pic and non-pic
- % code is incompatible, so we need to generate `.o' and `.pic_o'
- % files.
-:- type pic
- ---> pic
- ; non_pic
.
% :- type linked_target_type in mercury_compile.m.
Index: compiler/make.module_target.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/make.module_target.m,v
retrieving revision 1.4
diff -u -u -r1.4 make.module_target.m
--- compiler/make.module_target.m 23 Apr 2002 20:41:46 -0000 1.4
+++ compiler/make.module_target.m 6 May 2002 07:49:21 -0000
@@ -261,7 +261,7 @@
[]
).
-build_target_2(ModuleName, target_code_to_object_code,
+build_target_2(ModuleName, target_code_to_object_code(PIC),
Imports, _, ErrorStream, Succeeded, Info0, Info) -->
get_target_code_to_object_code_foreign_files(ModuleName,
ForeignCodeFiles, Info0, Info),
@@ -269,9 +269,9 @@
{ CompileTargetCode =
(pred(Succeeded1::out, di, uo) is det -->
- build_object_code(ModuleName, CompilationTarget,
+ build_object_code(ModuleName, CompilationTarget, PIC,
ErrorStream, Imports, Succeeded0),
- list__map_foldl(compile_foreign_code_file(ErrorStream),
+ list__map_foldl(compile_foreign_code_file(ErrorStream, PIC),
ForeignCodeFiles, ForeignCodeSucceeded),
{
Succeeded0 = yes,
@@ -289,37 +289,40 @@
call_in_forked_process(CompileTargetCode,
CompileTargetCode, Succeeded).
-:- pred build_object_code(module_name::in, compilation_target::in,
+:- pred build_object_code(module_name::in, compilation_target::in, pic::in,
io__output_stream::in, module_imports::in, bool::out,
io__state::di, io__state::uo) is det.
-build_object_code(ModuleName, c, ErrorStream, _Imports, Succeeded) -->
- compile_target_code__compile_c_file(ErrorStream, ModuleName, Succeeded).
-build_object_code(ModuleName, asm, ErrorStream, _Imports, Succeeded) -->
- compile_target_code__assemble(ErrorStream, ModuleName, Succeeded).
-build_object_code(ModuleName, java, ErrorStream, _Imports, Succeeded) -->
- compile_target_code__compile_java_file(ErrorStream, ModuleName, Succeeded).
-build_object_code(ModuleName, il, ErrorStream, Imports, Succeeded) -->
+build_object_code(ModuleName, c, PIC, ErrorStream, _Imports, Succeeded) -->
+ compile_target_code__compile_c_file(ErrorStream, PIC, ModuleName,
+ Succeeded).
+build_object_code(ModuleName, asm, PIC, ErrorStream, _Imports, Succeeded) -->
+ compile_target_code__assemble(ErrorStream, PIC, ModuleName,
+ Succeeded).
+build_object_code(ModuleName, java, _, ErrorStream, _Imports, Succeeded) -->
+ compile_target_code__compile_java_file(ErrorStream,
+ ModuleName, Succeeded).
+build_object_code(ModuleName, il, _, ErrorStream, Imports, Succeeded) -->
compile_target_code__il_assemble(ErrorStream, ModuleName,
Imports ^ has_main, Succeeded).
-:- pred compile_foreign_code_file(io__output_stream::in, foreign_code_file::in,
- bool::out, io__state::di, io__state::uo) is det.
+:- pred compile_foreign_code_file(io__output_stream::in, pic::in,
+ foreign_code_file::in, bool::out, io__state::di, io__state::uo) is det.
-compile_foreign_code_file(ErrorStream, foreign_code_file(c, CFile, ObjFile),
- Succeeded) -->
- compile_target_code__compile_c_file(ErrorStream,
+compile_foreign_code_file(ErrorStream, PIC,
+ foreign_code_file(c, CFile, ObjFile), Succeeded) -->
+ compile_target_code__compile_c_file(ErrorStream, PIC,
CFile, ObjFile, Succeeded).
-compile_foreign_code_file(ErrorStream, foreign_code_file(il, ILFile, DLLFile),
- Succeeded) -->
+compile_foreign_code_file(ErrorStream, _,
+ foreign_code_file(il, ILFile, DLLFile), Succeeded) -->
compile_target_code__il_assemble(ErrorStream, ILFile, DLLFile,
no_main, Succeeded).
-compile_foreign_code_file(ErrorStream,
+compile_foreign_code_file(ErrorStream, _,
foreign_code_file(managed_cplusplus, MCPPFile, DLLFile),
Succeeded) -->
compile_target_code__compile_managed_cplusplus_file(ErrorStream,
MCPPFile, DLLFile, Succeeded).
-compile_foreign_code_file(ErrorStream,
+compile_foreign_code_file(ErrorStream, _,
foreign_code_file(csharp, CSharpFile, DLLFile),
Succeeded) -->
compile_target_code__compile_csharp_file(ErrorStream,
@@ -419,14 +422,14 @@
["--compile-to-c"].
compilation_task(_, il_code) = process_module(compile_to_target_code) -
["--il-only"].
-compilation_task(_, il_asm) = target_code_to_object_code - [].
+compilation_task(_, il_asm) = target_code_to_object_code(non_pic) - [].
compilation_task(_, java_code) = process_module(compile_to_target_code) -
["--java-only"].
compilation_task(_, asm_code(PIC)) =
process_module(compile_to_target_code) -
( PIC = pic -> ["--pic"] ; [] ).
compilation_task(Globals, object_code(PIC)) =
- target_code_to_object_code - Flags :-
+ target_code_to_object_code(PIC) - Flags :-
globals__get_target(Globals, Target),
( PIC = pic ->
Flags = ( Target = asm -> ["--pic"] ; ["--pic-reg"] )
@@ -575,7 +578,7 @@
{ TouchedFileNames = list__condense([ForeignCodeFiles,
TimestampFileNames]) }.
-touched_files(TargetFile, target_code_to_object_code,
+touched_files(TargetFile, target_code_to_object_code(_),
[TargetFile], ForeignObjectFiles, Info0, Info) -->
{ TargetFile = ModuleName - _ },
get_target_code_to_object_code_foreign_files(ModuleName,
Index: compiler/mercury_compile.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/mercury_compile.m,v
retrieving revision 1.249
diff -u -u -r1.249 mercury_compile.m
--- compiler/mercury_compile.m 6 May 2002 06:53:48 -0000 1.249
+++ compiler/mercury_compile.m 6 May 2002 07:51:24 -0000
@@ -383,7 +383,7 @@
( { Result = ok, TargetCodeOnly = no } ->
io__output_stream(OutputStream),
compile_target_code__assemble(OutputStream,
- ModuleName, _AssembleOK)
+ non_pic, ModuleName, _AssembleOK)
;
[]
)
@@ -1176,8 +1176,9 @@
yes, CCode_O_File),
io__output_stream(OutputStream),
compile_target_code__compile_c_file(
- OutputStream, CCode_C_File,
- CCode_O_File, _CompileOK),
+ OutputStream, non_pic,
+ CCode_C_File, CCode_O_File,
+ _CompileOK),
% add this object file to the list
% of extra object files to link in
globals__io_lookup_accumulating_option(
@@ -1204,7 +1205,7 @@
O_File),
io__output_stream(OutputStream),
compile_target_code__compile_c_file(
- OutputStream, C_File, O_File,
+ OutputStream, non_pic, C_File, O_File,
_CompileOK)
)
;
@@ -3376,7 +3377,7 @@
globals__io_lookup_string_option(object_file_extension, Obj),
module_name_to_file_name(ModuleName, ".c", no, C_File),
module_name_to_file_name(ModuleName, Obj, yes, O_File),
- compile_target_code__compile_c_file(ErrorStream,
+ compile_target_code__compile_c_file(ErrorStream, non_pic,
C_File, O_File, Succeeded)
).
--------------------------------------------------------------------------
mercury-reviews mailing list
post: mercury-reviews at cs.mu.oz.au
administrative address: owner-mercury-reviews at cs.mu.oz.au
unsubscribe: Address: mercury-reviews-request at cs.mu.oz.au Message: unsubscribe
subscribe: Address: mercury-reviews-request at cs.mu.oz.au Message: subscribe
--------------------------------------------------------------------------
More information about the reviews
mailing list