@@ -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 ):
@@ -3030,6 +3025,19 @@ def get_full_import_name(name):
3030
3025
return target , wasm_target
3031
3026
3032
3027
3028
+ def get_clang_output_extension (state ):
3029
+ if '-emit-llvm' in state .orig_args :
3030
+ if state .has_dash_S :
3031
+ return '.ll'
3032
+ else :
3033
+ return '.bc'
3034
+
3035
+ if state .has_dash_S :
3036
+ return '.s'
3037
+ else :
3038
+ return '.o'
3039
+
3040
+
3033
3041
@ToolchainProfiler .profile_block ('compile inputs' )
3034
3042
def phase_compile_inputs (options , state , newargs , input_files ):
3035
3043
def is_link_flag (flag ):
@@ -3064,40 +3072,62 @@ def get_language_mode(args):
3064
3072
language_mode = get_language_mode (newargs )
3065
3073
use_cxx = 'c++' in language_mode or run_via_emxx
3066
3074
3067
- def get_clang_command (src_file ):
3068
- return compiler + get_cflags (state .orig_args , use_cxx ) + compile_args + [ src_file ]
3075
+ def get_clang_command ():
3076
+ return compiler + get_cflags (state .orig_args , use_cxx ) + compile_args
3069
3077
3070
- def get_clang_command_preprocessed (src_file ):
3071
- return compiler + get_clang_flags (state .orig_args ) + compile_args + [ src_file ]
3078
+ def get_clang_command_preprocessed ():
3079
+ return compiler + get_clang_flags (state .orig_args ) + compile_args
3072
3080
3073
- def get_clang_command_asm (src_file ):
3074
- return compiler + get_target_flags () + compile_args + [ src_file ]
3081
+ def get_clang_command_asm ():
3082
+ return compiler + get_target_flags () + compile_args
3075
3083
3076
3084
# preprocessor-only (-E) support
3077
3085
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 )
3086
+ inputs = [ i [1 ] for i in input_files ]
3087
+ cmd = get_clang_command () + inputs
3088
+ if options .output_file :
3089
+ cmd += ['-o' , options .output_file ]
3090
+ # Do not compile, but just output the result from preprocessing stage or
3091
+ # output the dependency rule. Warning: clang and gcc behave differently
3092
+ # with -MF! (clang seems to not recognize it)
3093
+ logger .debug (('just preprocessor ' if state .has_dash_E else 'just dependencies: ' ) + ' ' .join (cmd ))
3094
+ shared .check_call (cmd )
3087
3095
return []
3088
3096
3089
3097
# Precompiled headers support
3090
3098
if state .mode == Mode .PCH :
3091
- headers = [header for _ , header in input_files ]
3092
- for header in headers :
3099
+ inputs = [i [ 1 ] for i in input_files ]
3100
+ for header in inputs :
3093
3101
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 []
3102
+ exit_with_error (f'cannot mix precompiled headers with non-header inputs: { inputs } : { header } ' )
3103
+ cmd = get_clang_command () + inputs
3104
+ if options .output_file :
3105
+ cmd += ['-o' , options .output_file ]
3106
+ logger .debug (f"running (for precompiled headers): { cmd [0 ]} { ' ' .join (cmd [1 :])} " )
3107
+ shared .check_call (cmd )
3108
+ return []
3109
+
3110
+ if state .mode == Mode .COMPILE_ONLY :
3111
+ inputs = [i [1 ] for i in input_files ]
3112
+ if all (get_file_suffix (i ) in ASSEMBLY_ENDINGS for i in inputs ):
3113
+ cmd = get_clang_command_asm () + inputs
3114
+ else :
3115
+ cmd = get_clang_command () + inputs
3116
+ if options .output_file :
3117
+ cmd += ['-o' , options .output_file ]
3118
+ if get_file_suffix (options .output_file ) == '.bc' and not settings .LTO and '-emit-llvm' not in state .orig_args :
3119
+ 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' )
3120
+ shared .check_call (cmd )
3121
+ if not options .output_file :
3122
+ # Rename object files to match --default-obj-ext
3123
+ # TODO: Remove '--default-obj-ext' to reduce this complexity
3124
+ ext = get_clang_output_extension (state )
3125
+ if options .default_object_extension != ext :
3126
+ for i in inputs :
3127
+ output = unsuffixed_basename (i ) + ext
3128
+ new_output = unsuffixed_basename (i ) + options .default_object_extension
3129
+ move_file (output , new_output )
3130
+ return []
3101
3131
3102
3132
linker_inputs = []
3103
3133
seen_names = {}
@@ -3108,32 +3138,21 @@ def uniquename(name):
3108
3138
return unsuffixed (name ) + '_' + seen_names [name ] + shared .suffix (name )
3109
3139
3110
3140
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 )
3141
+ return in_temp (unsuffixed (uniquename (input_file )) + options .default_object_extension )
3123
3142
3124
3143
def compile_source_file (i , input_file ):
3125
3144
logger .debug (f'compiling source file: { input_file } ' )
3126
3145
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 ))
3146
+ linker_inputs .append ((i , output_file ))
3129
3147
if get_file_suffix (input_file ) in ASSEMBLY_ENDINGS :
3130
- cmd = get_clang_command_asm (input_file )
3148
+ cmd = get_clang_command_asm ()
3131
3149
elif get_file_suffix (input_file ) in PREPROCESSED_ENDINGS :
3132
- cmd = get_clang_command_preprocessed (input_file )
3150
+ cmd = get_clang_command_preprocessed ()
3133
3151
else :
3134
- cmd = get_clang_command (input_file )
3152
+ cmd = get_clang_command ()
3135
3153
if get_file_suffix (input_file ) in ['.pcm' ]:
3136
3154
cmd = [c for c in cmd if not c .startswith ('-fprebuilt-module-path=' )]
3155
+ cmd += [input_file ]
3137
3156
if not state .has_dash_c :
3138
3157
cmd += ['-c' ]
3139
3158
cmd += ['-o' , output_file ]
0 commit comments