@@ -540,6 +540,15 @@ for i in range(len(sys.argv)-1):
540540 sys .argv = sys .argv [:i ] + sys .argv [i + 2 :]
541541 break
542542
543+ specified_target = target
544+ target = specified_target if specified_target is not None else 'a.out.js' # specified_target is the user-specified one, target is what we will generate
545+ target_basename = unsuffixed_basename (target )
546+
547+ if '.' in target :
548+ final_suffix = target .split ('.' )[- 1 ]
549+ else :
550+ final_suffix = ''
551+
543552if header : # header or such
544553 if len (sys .argv ) >= 3 : # if there is a source and a target, then copy, otherwise do nothing
545554 sys .argv = filter (lambda arg : not arg .startswith ('-I' ), sys .argv )
@@ -789,6 +798,17 @@ try:
789798
790799 newargs = [ arg for arg in newargs if arg is not '' ]
791800
801+ # -c means do not link in gcc, and for us, the parallel is to not go all the way to JS, but stop at bitcode
802+ has_dash_c = '-c' in newargs
803+ if has_dash_c :
804+ assert has_source_inputs , 'Must have source code inputs to use -c'
805+ target = target_basename + '.o'
806+ final_suffix = 'o'
807+
808+ # do not link in libs when just generating object code (not an 'executable', i.e. JS, or a library)
809+ if ('.' + final_suffix ) in BITCODE_SUFFIXES :
810+ libs = []
811+
792812 # Find library files
793813 for lib in libs :
794814 if DEBUG : print >> sys .stderr , 'emcc: looking for library "%s"' % lib
@@ -816,22 +836,6 @@ try:
816836
817837 newargs += CC_ADDITIONAL_ARGS
818838
819- specified_target = target
820- target = specified_target if specified_target is not None else 'a.out.js' # specified_target is the user-specified one, target is what we will generate
821-
822- target_basename = unsuffixed_basename (target )
823-
824- # -c means do not link in gcc, and for us, the parallel is to not go all the way to JS, but stop at bitcode
825- has_dash_c = '-c' in newargs
826- if has_dash_c :
827- assert has_source_inputs , 'Must have source code inputs to use -c'
828- target = target_basename + '.o'
829-
830- if '.' in target :
831- final_suffix = target .split ('.' )[- 1 ]
832- else :
833- final_suffix = ''
834-
835839 assert not (Compression .on and final_suffix != 'html' ), 'Compression only works when generating HTML'
836840
837841 # If we are using embind and generating JS, now is the time to link in bind.cpp
904908 assert len (original_input_files ) == 1 or not has_dash_c , 'fatal error: cannot specify -o with -c with multiple files' + str (sys .argv ) + ':' + str (original_input_files )
905909 # We have a specified target (-o <target>), which is not JavaScript or HTML, and
906910 # we have multiple files: Link them
907- if DEBUG : print >> sys .stderr , 'emcc: link: ' + str (temp_files )
911+ if DEBUG : print >> sys .stderr , 'emcc: link: ' + str (temp_files ), specified_target
908912 shared .Building .link (temp_files , specified_target , remove_duplicates = remove_duplicates )
909913 exit (0 )
910914
0 commit comments