waf

FORK: waf with some random patches
git clone https://git.neptards.moe/neptards/waf.git
Log | Files | Refs | README

clang_cross.py (2550B)


      1 #!/usr/bin/env python
      2 # encoding: utf-8
      3 # Krzysztof KosiƄski 2014
      4 # DragoonX6 2018
      5 
      6 """
      7 Detect the Clang C compiler
      8 This version is an attempt at supporting the -target and -sysroot flag of Clang.
      9 """
     10 
     11 from waflib.Tools import ccroot, ar, gcc
     12 from waflib.Configure import conf
     13 import waflib.Context
     14 import waflib.extras.clang_cross_common
     15 
     16 def options(opt):
     17 	"""
     18 	Target triplet for clang::
     19 			$ waf configure --clang-target-triple=x86_64-pc-linux-gnu
     20 	"""
     21 	cc_compiler_opts = opt.add_option_group('Configuration options')
     22 	cc_compiler_opts.add_option('--clang-target-triple', default=None,
     23 		help='Target triple for clang',
     24 		dest='clang_target_triple')
     25 	cc_compiler_opts.add_option('--clang-sysroot', default=None,
     26 		help='Sysroot for clang',
     27 		dest='clang_sysroot')
     28 
     29 @conf
     30 def find_clang(conf):
     31 	"""
     32 	Finds the program clang and executes it to ensure it really is clang
     33 	"""
     34 
     35 	import os
     36 
     37 	cc = conf.find_program('clang', var='CC')
     38 
     39 	if conf.options.clang_target_triple != None:
     40 		conf.env.append_value('CC', ['-target', conf.options.clang_target_triple])
     41 
     42 	if conf.options.clang_sysroot != None:
     43 		sysroot = str()
     44 
     45 		if os.path.isabs(conf.options.clang_sysroot):
     46 			sysroot = conf.options.clang_sysroot
     47 		else:
     48 			sysroot = os.path.normpath(os.path.join(os.getcwd(), conf.options.clang_sysroot))
     49 
     50 		conf.env.append_value('CC', ['--sysroot', sysroot])
     51 
     52 	conf.get_cc_version(cc, clang=True)
     53 	conf.env.CC_NAME = 'clang'
     54 
     55 @conf
     56 def clang_modifier_x86_64_w64_mingw32(conf):
     57 	conf.gcc_modifier_win32()
     58 
     59 @conf
     60 def clang_modifier_i386_w64_mingw32(conf):
     61 	conf.gcc_modifier_win32()
     62 
     63 @conf
     64 def clang_modifier_x86_64_windows_msvc(conf):
     65 	conf.clang_modifier_msvc()
     66 
     67 	# Allow the user to override any flags if they so desire.
     68 	clang_modifier_user_func = getattr(conf, 'clang_modifier_x86_64_windows_msvc_user', None)
     69 	if clang_modifier_user_func:
     70 		clang_modifier_user_func()
     71 
     72 @conf
     73 def clang_modifier_i386_windows_msvc(conf):
     74 	conf.clang_modifier_msvc()
     75 
     76 	# Allow the user to override any flags if they so desire.
     77 	clang_modifier_user_func = getattr(conf, 'clang_modifier_i386_windows_msvc_user', None)
     78 	if clang_modifier_user_func:
     79 		clang_modifier_user_func()
     80 
     81 def configure(conf):
     82 	conf.find_clang()
     83 	conf.find_program(['llvm-ar', 'ar'], var='AR')
     84 	conf.find_ar()
     85 	conf.gcc_common_flags()
     86 	# Allow the user to provide flags for the target platform.
     87 	conf.gcc_modifier_platform()
     88 	# And allow more fine grained control based on the compiler's triplet.
     89 	conf.clang_modifier_target_triple()
     90 	conf.cc_load_tools()
     91 	conf.cc_add_flags()
     92 	conf.link_add_flags()