@@ -534,6 +534,13 @@ def run(args):
534
534
''' )
535
535
return 0
536
536
537
+ ## Process argument and setup the compiler
538
+ state = EmccState (args )
539
+ options , newargs = phase_parse_arguments (state )
540
+
541
+ if not shared .SKIP_SUBPROCS :
542
+ shared .check_sanity ()
543
+
537
544
if '--version' in args :
538
545
print (version_string ())
539
546
print ('''\
@@ -566,13 +573,6 @@ def run(args):
566
573
print (shared .shlex_join (parts [1 :]))
567
574
return 0
568
575
569
- ## Process argument and setup the compiler
570
- state = EmccState (args )
571
- options , newargs = phase_parse_arguments (state )
572
-
573
- if not shared .SKIP_SUBPROCS :
574
- shared .check_sanity ()
575
-
576
576
if 'EMMAKEN_NO_SDK' in os .environ :
577
577
exit_with_error ('EMMAKEN_NO_SDK is no longer supported. The standard -nostdlib and -nostdinc flags should be used instead' )
578
578
@@ -618,9 +618,6 @@ def run(args):
618
618
print (libname )
619
619
return 0
620
620
621
- if not input_files and not state .link_flags :
622
- exit_with_error ('no input files' )
623
-
624
621
if options .reproduce :
625
622
create_reproduce_file (options .reproduce , args )
626
623
@@ -641,8 +638,6 @@ def run(args):
641
638
return link .run (linker_inputs , options , state , newargs )
642
639
else :
643
640
logger .debug ('stopping after compile phase' )
644
- for flag in state .link_flags :
645
- diagnostics .warning ('unused-command-line-argument' , "argument unused during compilation: '%s'" % flag [1 ])
646
641
return 0
647
642
648
643
@@ -670,9 +665,9 @@ def phase_parse_arguments(state):
670
665
newargs = diagnostics .capture_warnings (newargs )
671
666
672
667
for i in range (len (newargs )):
673
- if newargs [i ] in ('-l' , '-L' , '-I' ):
674
- # Scan for individual -l/-L/-I arguments and concatenate the next arg on
675
- # if there is no suffix
668
+ if newargs [i ] in ('-l' , '-L' , '-I' , '-z' ):
669
+ # Scan for flags that can be written as either one or two arguments
670
+ # and normalize them to the single argument form.
676
671
newargs [i ] += newargs [i + 1 ]
677
672
newargs [i + 1 ] = ''
678
673
@@ -764,33 +759,24 @@ def phase_setup(options, state, newargs):
764
759
input_files .append ((i , arg ))
765
760
elif arg .startswith ('-L' ):
766
761
state .add_link_flag (i , arg )
767
- newargs [i ] = ''
768
762
elif arg .startswith ('-l' ):
769
763
state .add_link_flag (i , arg )
770
- newargs [i ] = ''
771
764
elif arg == '-z' :
772
765
state .add_link_flag (i , newargs [i ])
773
766
state .add_link_flag (i + 1 , newargs [i + 1 ])
774
- newargs [i ] = ''
775
- newargs [i + 1 ] = ''
776
767
elif arg .startswith ('-z' ):
777
768
state .add_link_flag (i , newargs [i ])
778
- newargs [i ] = ''
779
769
elif arg .startswith ('-Wl,' ):
780
770
# Multiple comma separated link flags can be specified. Create fake
781
771
# fractional indices for these: -Wl,a,b,c,d at index 4 becomes:
782
772
# (4, a), (4.25, b), (4.5, c), (4.75, d)
783
773
link_flags_to_add = arg .split (',' )[1 :]
784
774
for flag_index , flag in enumerate (link_flags_to_add ):
785
775
state .add_link_flag (i + float (flag_index ) / len (link_flags_to_add ), flag )
786
- newargs [i ] = ''
787
776
elif arg == '-Xlinker' :
788
777
state .add_link_flag (i + 1 , newargs [i + 1 ])
789
- newargs [i ] = ''
790
- newargs [i + 1 ] = ''
791
778
elif arg == '-s' :
792
779
state .add_link_flag (i , newargs [i ])
793
- newargs [i ] = ''
794
780
elif arg == '-' :
795
781
input_files .append ((i , arg ))
796
782
newargs [i ] = ''
@@ -950,11 +936,6 @@ def get_clang_output_extension(state):
950
936
951
937
@ToolchainProfiler .profile_block ('compile inputs' )
952
938
def phase_compile_inputs (options , state , newargs , input_files ):
953
- def is_link_flag (flag ):
954
- if flag in ('-nostdlib' , '-nostartfiles' , '-nolibc' , '-nodefaultlibs' ):
955
- return True
956
- return flag .startswith (('-l' , '-L' , '-Wl,' ))
957
-
958
939
if shared .run_via_emxx :
959
940
compiler = [shared .CLANG_CXX ]
960
941
else :
@@ -964,7 +945,7 @@ def is_link_flag(flag):
964
945
logger .debug ('using compiler wrapper: %s' , config .COMPILER_WRAPPER )
965
946
compiler .insert (0 , config .COMPILER_WRAPPER )
966
947
967
- compile_args = [ a for a in newargs if a and not is_link_flag ( a )]
948
+ compile_args = newargs
968
949
system_libs .ensure_sysroot ()
969
950
970
951
def get_language_mode (args ):
@@ -1002,7 +983,7 @@ def get_clang_command_asm():
1002
983
# with -MF! (clang seems to not recognize it)
1003
984
logger .debug (('just preprocessor ' if state .has_dash_E else 'just dependencies: ' ) + ' ' .join (cmd ))
1004
985
shared .check_call (cmd )
1005
- return []
986
+ sys . exit ( 0 )
1006
987
1007
988
# Precompiled headers support
1008
989
if state .mode == Mode .PCH :
@@ -1015,7 +996,7 @@ def get_clang_command_asm():
1015
996
cmd += ['-o' , options .output_file ]
1016
997
logger .debug (f"running (for precompiled headers): { cmd [0 ]} { ' ' .join (cmd [1 :])} " )
1017
998
shared .check_call (cmd )
1018
- return []
999
+ sys . exit ( 0 )
1019
1000
1020
1001
if state .mode == Mode .COMPILE_ONLY :
1021
1002
inputs = [i [1 ] for i in input_files ]
@@ -1027,18 +1008,24 @@ def get_clang_command_asm():
1027
1008
cmd += ['-o' , options .output_file ]
1028
1009
if get_file_suffix (options .output_file ) == '.bc' and not settings .LTO and '-emit-llvm' not in state .orig_args :
1029
1010
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' )
1011
+ ext = get_clang_output_extension (state )
1030
1012
shared .check_call (cmd )
1031
- if not options .output_file :
1032
- # Rename object files to match --default-obj-ext
1033
- # TODO: Remove '--default-obj-ext' to reduce this complexity
1034
- ext = get_clang_output_extension (state )
1035
- if options .default_object_extension != ext :
1036
- for i in inputs :
1037
- output = unsuffixed_basename (i ) + ext
1038
- new_output = unsuffixed_basename (i ) + options .default_object_extension
1039
- shutil .move (output , new_output )
1040
- return []
1013
+ if not options .output_file and options .default_object_extension != ext :
1014
+ for i in inputs :
1015
+ output = unsuffixed_basename (i ) + ext
1016
+ new_output = unsuffixed_basename (i ) + options .default_object_extension
1017
+ shutil .move (output , new_output )
1018
+ sys .exit (0 )
1019
+
1020
+ # In COMPILE_AND_LINK we need to compile source files too, but we also need to
1021
+ # filter out the link flags
1022
+
1023
+ def is_link_flag (flag ):
1024
+ if flag in ('-nostdlib' , '-nostartfiles' , '-nolibc' , '-nodefaultlibs' , '-s' ):
1025
+ return True
1026
+ return flag .startswith (('-l' , '-L' , '-Wl,' , '-z' ))
1041
1027
1028
+ compile_args = [a for a in compile_args if a and not is_link_flag (a )]
1042
1029
linker_inputs = []
1043
1030
seen_names = {}
1044
1031
0 commit comments