aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlon Zakai <alonzakai@gmail.com>2013-09-25 10:09:02 -0700
committerAlon Zakai <alonzakai@gmail.com>2013-09-25 10:09:02 -0700
commitc2473a658d70f84e629bd7d9e65cb65fc1b1b8d9 (patch)
tree9bf4821e59d4fcb66f4e623369e2bbf661499084
parent690f8c8f80661b0c6f9e731a3ff9da31fecfa7fa (diff)
parent794624d29502ab22d520f7a3d986bde403e198eb (diff)
Merge pull request #1653 from juj/fix_ar_handling
Fix ar handling
-rw-r--r--cmake/Platform/Emscripten.cmake4
-rwxr-xr-xemcc74
2 files changed, 50 insertions, 28 deletions
diff --git a/cmake/Platform/Emscripten.cmake b/cmake/Platform/Emscripten.cmake
index 73f2c8ad..7c8e83fa 100644
--- a/cmake/Platform/Emscripten.cmake
+++ b/cmake/Platform/Emscripten.cmake
@@ -104,8 +104,8 @@ set(CMAKE_C_RESPONSE_FILE_LINK_FLAG "@")
set(CMAKE_CXX_RESPONSE_FILE_LINK_FLAG "@")
# Specify the program to use when building static libraries. Force Emscripten-related command line options to clang.
-set(CMAKE_CXX_ARCHIVE_CREATE "${CMAKE_CXX_COMPILER} ${CMAKE_START_TEMP_FILE} -o <TARGET> -emit-llvm <LINK_FLAGS> <OBJECTS>${CMAKE_END_TEMP_FILE}")
-set(CMAKE_C_ARCHIVE_CREATE "${CMAKE_C_COMPILER} ${CMAKE_START_TEMP_FILE} -o <TARGET> -emit-llvm <LINK_FLAGS> <OBJECTS>${CMAKE_END_TEMP_FILE}")
+set(CMAKE_CXX_ARCHIVE_CREATE "${CMAKE_AR} rc <TARGET> ${CMAKE_START_TEMP_FILE} <LINK_FLAGS> <OBJECTS>${CMAKE_END_TEMP_FILE}")
+set(CMAKE_C_ARCHIVE_CREATE "${CMAKE_AR} rc <TARGET> ${CMAKE_START_TEMP_FILE} <LINK_FLAGS> <OBJECTS>${CMAKE_END_TEMP_FILE}")
# Set a global EMSCRIPTEN variable that can be used in client CMakeLists.txt to detect when building using Emscripten.
# There seems to be some kind of bug with CMake, so you might need to define this manually on the command line with "-DEMSCRIPTEN=1".
diff --git a/emcc b/emcc
index cd42d49a..d4889b58 100755
--- a/emcc
+++ b/emcc
@@ -720,6 +720,13 @@ else:
def in_temp(name):
return os.path.join(temp_dir, os.path.basename(name))
+# Parses the essential suffix of a filename, discarding Unix-style version numbers in the name. For example for 'libz.so.1.2.8' returns '.so'
+def filename_type_suffix(filename):
+ for i in reversed(filename.split('.')[1:]):
+ if not i.isdigit():
+ return '.' + i
+ return ''
+
try:
call = CXX if use_cxx else CC
@@ -974,35 +981,45 @@ try:
if i > 0:
prev = newargs[i-1]
- if prev in ['-MT', '-MF', '-MQ', '-D', '-U', '-o', '-x', '-Xpreprocessor', '-include', '-imacros', '-idirafter', '-iprefix', '-iwithprefix', '-iwithprefixbefore', '-isysroot', '-imultilib', '-A', '-isystem', '-iquote', '-install_name', '-I', '-L']: continue # ignore this gcc-style argument
+ if prev in ['-MT', '-MF', '-MQ', '-D', '-U', '-o', '-x', '-Xpreprocessor', '-include', '-imacros', '-idirafter', '-iprefix', '-iwithprefix', '-iwithprefixbefore', '-isysroot', '-imultilib', '-A', '-isystem', '-iquote', '-install_name', '-compatibility_version', '-current_version', '-I', '-L']: continue # ignore this gcc-style argument
if (os.path.islink(arg) and os.path.realpath(arg).endswith(SOURCE_SUFFIXES + BITCODE_SUFFIXES + DYNAMICLIB_SUFFIXES + ASSEMBLY_SUFFIXES)):
arg = os.path.realpath(arg)
- if not arg.startswith('-') and (arg.endswith(SOURCE_SUFFIXES + BITCODE_SUFFIXES + DYNAMICLIB_SUFFIXES + ASSEMBLY_SUFFIXES) or shared.Building.is_ar(arg)): # we already removed -o <target>, so all these should be inputs
- newargs[i] = ''
- if os.path.exists(arg):
- if arg.endswith(SOURCE_SUFFIXES):
+ if not arg.startswith('-'):
+ if not os.path.exists(arg):
+ logging.error(arg + ': No such file or directory')
+ exit(1)
+
+ arg_suffix = filename_type_suffix(arg)
+ if arg_suffix.endswith(SOURCE_SUFFIXES + BITCODE_SUFFIXES + DYNAMICLIB_SUFFIXES + ASSEMBLY_SUFFIXES) or shared.Building.is_ar(arg): # we already removed -o <target>, so all these should be inputs
+ newargs[i] = ''
+ if arg_suffix.endswith(SOURCE_SUFFIXES):
input_files.append(arg)
has_source_inputs = True
+ elif arg_suffix.endswith(ASSEMBLY_SUFFIXES) or shared.Building.is_bitcode(arg): # this should be bitcode, make sure it is valid
+ input_files.append(arg)
+ elif arg_suffix.endswith(STATICLIB_SUFFIXES + DYNAMICLIB_SUFFIXES):
+ # if it's not, and it's a library, just add it to libs to find later
+ l = unsuffixed_basename(arg)
+ for prefix in LIB_PREFIXES:
+ if not prefix: continue
+ if l.startswith(prefix):
+ l = l[len(prefix):]
+ break
+ libs.append(l)
+ newargs[i] = ''
else:
- # this should be bitcode, make sure it is valid
- if arg.endswith(ASSEMBLY_SUFFIXES) or shared.Building.is_bitcode(arg):
- input_files.append(arg)
- elif arg.endswith(STATICLIB_SUFFIXES + DYNAMICLIB_SUFFIXES):
- # if it's not, and it's a library, just add it to libs to find later
- l = unsuffixed_basename(arg)
- for prefix in LIB_PREFIXES:
- if not prefix: continue
- if l.startswith(prefix):
- l = l[len(prefix):]
- break
- libs.append(l)
- newargs[i] = ''
+ logging.warning(arg + ' is not valid LLVM bitcode')
+ elif arg_suffix.endswith(STATICLIB_SUFFIXES):
+ if not shared.Building.is_ar(arg):
+ if shared.Building.is_bitcode(arg):
+ logging.error(arg + ': File has a suffix of a static library ' + str(STATICLIB_SUFFIXES) + ', but instead is an LLVM bitcode file! When linking LLVM bitcode files, use one of the suffixes ' + str(BITCODE_SUFFIXES))
else:
- logging.warning(arg + ' is not valid LLVM bitcode')
+ logging.error(arg + ': Unknown format, not a static library!')
+ exit(1)
else:
- logging.error(arg + ': No such file or directory')
+ logging.error(arg + ": Input file has an unknown suffix, don't know what to do with it!")
exit(1)
elif arg.startswith('-L'):
lib_dirs.append(arg[2:])
@@ -1151,13 +1168,14 @@ try:
# First, generate LLVM bitcode. For each input file, we get base.o with bitcode
for input_file in input_files:
- if input_file.endswith(SOURCE_SUFFIXES):
+ file_suffix = filename_type_suffix(input_file)
+ if file_suffix.endswith(SOURCE_SUFFIXES):
logging.debug('compiling source file: ' + input_file)
input_file = shared.Building.preprocess(input_file, in_temp(uniquename(input_file)))
output_file = in_temp(unsuffixed(uniquename(input_file)) + '.o')
temp_files.append(output_file)
args = newargs + ['-emit-llvm', '-c', input_file, '-o', output_file]
- if input_file.endswith(CXX_SUFFIXES):
+ if file_suffix.endswith(CXX_SUFFIXES):
args += shared.EMSDK_CXX_OPTS
logging.debug("running: " + call + ' ' + ' '.join(args))
execute([call] + args) # let compiler frontend print directly, so colors are saved (PIPE kills that)
@@ -1165,17 +1183,17 @@ try:
logging.error('compiler frontend failed to generate LLVM bitcode, halting')
sys.exit(1)
else: # bitcode
- if input_file.endswith(BITCODE_SUFFIXES):
+ if file_suffix.endswith(BITCODE_SUFFIXES):
logging.debug('copying bitcode file: ' + input_file)
temp_file = in_temp(unsuffixed(uniquename(input_file)) + '.o')
shutil.copyfile(input_file, temp_file)
temp_files.append(temp_file)
- elif input_file.endswith(DYNAMICLIB_SUFFIXES) or shared.Building.is_ar(input_file):
+ elif file_suffix.endswith(DYNAMICLIB_SUFFIXES) or shared.Building.is_ar(input_file):
logging.debug('copying library file: ' + input_file)
temp_file = in_temp(uniquename(input_file))
shutil.copyfile(input_file, temp_file)
temp_files.append(temp_file)
- else: #.ll
+ elif file_suffix.endswith(ASSEMBLY_SUFFIXES):
if not LEAVE_INPUTS_RAW:
# Note that by assembling the .ll file, then disassembling it later, we will
# remove annotations which is a good thing for compilation time
@@ -1183,6 +1201,9 @@ try:
temp_file = in_temp(unsuffixed(uniquename(input_file)) + '.o')
shared.Building.llvm_as(input_file, temp_file)
temp_files.append(temp_file)
+ else:
+ logging.error(input_file + ': Unknown file suffix when compiling to LLVM bitcode!')
+ sys.exit(1)
if not LEAVE_INPUTS_RAW:
assert len(temp_files) == len(input_files)
@@ -1190,7 +1211,8 @@ try:
# Optimize source files
if llvm_opts > 0:
for i, input_file in enumerate(input_files):
- if input_file.endswith(SOURCE_SUFFIXES):
+ file_suffix = filename_type_suffix(input_file)
+ if file_suffix.endswith(SOURCE_SUFFIXES):
temp_file = temp_files[i]
logging.debug('optimizing %s with -O%d' % (input_file, llvm_opts))
shared.Building.llvm_opt(temp_file, llvm_opts)