@@ -1332,9 +1332,6 @@ def run(args):
1332
1332
logger .debug ('stopping after compile phase' )
1333
1333
for flag in state .link_flags :
1334
1334
diagnostics .warning ('unused-command-line-argument' , "argument unused during compilation: '%s'" % flag [1 ])
1335
- for f in linker_inputs :
1336
- diagnostics .warning ('unused-command-line-argument' , "%s: linker input file unused because linking not done" % f [1 ])
1337
-
1338
1335
return 0
1339
1336
1340
1337
# We have now passed the compile phase, allow reading/writing of all settings.
@@ -1627,8 +1624,6 @@ def phase_setup(options, state, newargs):
1627
1624
elif '-M' in newargs or '-MM' in newargs :
1628
1625
options .default_object_extension = '.mout' # not bitcode, not js; but just dependency rule of the input file
1629
1626
1630
- if options .output_file and len (input_files ) > 1 :
1631
- exit_with_error ('cannot specify -o with -c/-S/-E/-M and multiple source files' )
1632
1627
else :
1633
1628
for arg in state .orig_args :
1634
1629
if any (arg .startswith (f ) for f in COMPILE_ONLY_FLAGS ):
@@ -3064,40 +3059,68 @@ def get_language_mode(args):
3064
3059
language_mode = get_language_mode (newargs )
3065
3060
use_cxx = 'c++' in language_mode or run_via_emxx
3066
3061
3067
- def get_clang_command (src_file ):
3068
- return compiler + get_cflags (state .orig_args , use_cxx ) + compile_args + [ src_file ]
3062
+ def get_clang_command ():
3063
+ return compiler + get_cflags (state .orig_args , use_cxx ) + compile_args
3069
3064
3070
- def get_clang_command_preprocessed (src_file ):
3071
- return compiler + get_clang_flags (state .orig_args ) + compile_args + [ src_file ]
3065
+ def get_clang_command_preprocessed ():
3066
+ return compiler + get_clang_flags (state .orig_args ) + compile_args
3072
3067
3073
- def get_clang_command_asm (src_file ):
3074
- return compiler + get_target_flags () + compile_args + [ src_file ]
3068
+ def get_clang_command_asm ():
3069
+ return compiler + get_target_flags () + compile_args
3075
3070
3076
3071
# preprocessor-only (-E) support
3077
3072
if state .mode == Mode .PREPROCESS_ONLY :
3078
- for input_file in [ x [1 ] for x in input_files ]:
3079
- cmd = get_clang_command (input_file )
3080
- if options .output_file :
3081
- cmd += ['-o' , options .output_file ]
3082
- # Do not compile, but just output the result from preprocessing stage or
3083
- # output the dependency rule. Warning: clang and gcc behave differently
3084
- # with -MF! (clang seems to not recognize it)
3085
- logger .debug (('just preprocessor ' if state .has_dash_E else 'just dependencies: ' ) + ' ' .join (cmd ))
3086
- shared .check_call (cmd )
3073
+ inputs = [ i [1 ] for i in input_files ]
3074
+ cmd = get_clang_command () + inputs
3075
+ if options .output_file :
3076
+ cmd += ['-o' , options .output_file ]
3077
+ # Do not compile, but just output the result from preprocessing stage or
3078
+ # output the dependency rule. Warning: clang and gcc behave differently
3079
+ # with -MF! (clang seems to not recognize it)
3080
+ logger .debug (('just preprocessor ' if state .has_dash_E else 'just dependencies: ' ) + ' ' .join (cmd ))
3081
+ shared .check_call (cmd )
3087
3082
return []
3088
3083
3089
3084
# Precompiled headers support
3090
3085
if state .mode == Mode .PCH :
3091
- headers = [header for _ , header in input_files ]
3092
- for header in headers :
3086
+ inputs = [i [ 1 ] for i in input_files ]
3087
+ for header in inputs :
3093
3088
if not shared .suffix (header ) in HEADER_ENDINGS :
3094
- exit_with_error (f'cannot mix precompiled headers with non-header inputs: { headers } : { header } ' )
3095
- cmd = get_clang_command (header )
3096
- if options .output_file :
3097
- cmd += ['-o' , options .output_file ]
3098
- logger .debug (f"running (for precompiled headers): { cmd [0 ]} { ' ' .join (cmd [1 :])} " )
3099
- shared .check_call (cmd )
3100
- return []
3089
+ exit_with_error (f'cannot mix precompiled headers with non-header inputs: { inputs } : { header } ' )
3090
+ cmd = get_clang_command () + inputs
3091
+ if options .output_file :
3092
+ cmd += ['-o' , options .output_file ]
3093
+ logger .debug (f"running (for precompiled headers): { cmd [0 ]} { ' ' .join (cmd [1 :])} " )
3094
+ shared .check_call (cmd )
3095
+ return []
3096
+
3097
+ if state .mode == Mode .COMPILE_ONLY :
3098
+ inputs = [i [1 ] for i in input_files ]
3099
+ if all (get_file_suffix (i ) in ASSEMBLY_ENDINGS for i in inputs ):
3100
+ cmd = get_clang_command_asm () + inputs
3101
+ else :
3102
+ cmd = get_clang_command () + inputs
3103
+ if options .output_file :
3104
+ cmd += ['-o' , options .output_file ]
3105
+ if get_file_suffix (options .output_file ) == '.bc' and not settings .LTO and '-emit-llvm' not in state .orig_args :
3106
+ diagnostics .warning ('emcc' , '.bc output file suffix used without -flto or -emit-llvm. Consider using .o extension since emcc will output an object file, not a bitcode file' )
3107
+ shared .check_call (cmd )
3108
+ if not options .output_file :
3109
+ # Rename object files to match --default-obj-ext
3110
+ # TODO: Remove '--default-obj-ext' to reduce this complexity
3111
+ if '-emit-llvm' in state .orig_args :
3112
+ if state .has_dash_S :
3113
+ clang_object_extension = '.ll'
3114
+ else :
3115
+ clang_object_extension = '.bc'
3116
+ else :
3117
+ clang_object_extension = '.o'
3118
+ if options .default_object_extension != clang_object_extension :
3119
+ for i in inputs :
3120
+ output = unsuffixed_basename (i ) + clang_object_extension
3121
+ new_output = unsuffixed_basename (i ) + options .default_object_extension
3122
+ move_file (output , new_output )
3123
+ return []
3101
3124
3102
3125
linker_inputs = []
3103
3126
seen_names = {}
@@ -3108,32 +3131,21 @@ def uniquename(name):
3108
3131
return unsuffixed (name ) + '_' + seen_names [name ] + shared .suffix (name )
3109
3132
3110
3133
def get_object_filename (input_file ):
3111
- if state .mode == Mode .COMPILE_ONLY :
3112
- # In compile-only mode we don't use any temp file. The object files
3113
- # are written directly to their final output locations.
3114
- if options .output_file :
3115
- assert len (input_files ) == 1
3116
- if get_file_suffix (options .output_file ) == '.bc' and not settings .LTO and '-emit-llvm' not in state .orig_args :
3117
- diagnostics .warning ('emcc' , '.bc output file suffix used without -flto or -emit-llvm. Consider using .o extension since emcc will output an object file, not a bitcode file' )
3118
- return options .output_file
3119
- else :
3120
- return unsuffixed_basename (input_file ) + options .default_object_extension
3121
- else :
3122
- return in_temp (unsuffixed (uniquename (input_file )) + options .default_object_extension )
3134
+ return in_temp (unsuffixed (uniquename (input_file )) + options .default_object_extension )
3123
3135
3124
3136
def compile_source_file (i , input_file ):
3125
3137
logger .debug (f'compiling source file: { input_file } ' )
3126
3138
output_file = get_object_filename (input_file )
3127
- if state .mode not in (Mode .COMPILE_ONLY , Mode .PREPROCESS_ONLY ):
3128
- linker_inputs .append ((i , output_file ))
3139
+ linker_inputs .append ((i , output_file ))
3129
3140
if get_file_suffix (input_file ) in ASSEMBLY_ENDINGS :
3130
- cmd = get_clang_command_asm (input_file )
3141
+ cmd = get_clang_command_asm ()
3131
3142
elif get_file_suffix (input_file ) in PREPROCESSED_ENDINGS :
3132
- cmd = get_clang_command_preprocessed (input_file )
3143
+ cmd = get_clang_command_preprocessed ()
3133
3144
else :
3134
- cmd = get_clang_command (input_file )
3145
+ cmd = get_clang_command ()
3135
3146
if get_file_suffix (input_file ) in ['.pcm' ]:
3136
3147
cmd = [c for c in cmd if not c .startswith ('-fprebuilt-module-path=' )]
3148
+ cmd += [input_file ]
3137
3149
if not state .has_dash_c :
3138
3150
cmd += ['-c' ]
3139
3151
cmd += ['-o' , output_file ]
0 commit comments