niti, nitg & rta: use lookup_first_definition
[nit.git] / src / separate_options.nit
1 # module adding separate specification of opts to compiler
2
3 import mmloader
4 import compiling
5
6 # only to order correctly redefs of compile_separate_module
7 import native_interface
8
9 redef class ToolContext
10 # all ops precised in .ops files
11 var separate_options : OptionContext = new OptionContext
12 var opt_cc_lib_paths: OptionArray = new OptionArray("Path to libraries for C compiler", "--cc-lib-path")
13 var opt_cc_libs: OptionArray = new OptionArray("Name of library to use for C compiler", "--cc-lib-name")
14 var opt_cc_include_paths: OptionArray = new OptionArray("Path to .h files for C compiler", "--cc-header-path")
15
16 redef init
17 do
18 super
19
20 separate_options.add_option( opt_cc_lib_paths )
21 separate_options.add_option( opt_cc_libs )
22 separate_options.add_option( opt_cc_include_paths )
23 end
24
25 fun integrate_separate_options( options : String, mod : MMModule )
26 do
27 for line in options.split do
28 line = line.strip_extension( "\n" )
29 separate_options.parse( line.split_with( ' ' ) )
30 var rest = new Array[String]
31 for s in separate_options.rest do if s.length > 0 then rest.add( s )
32 if rest.length > 0 then
33 error( null, "module \"{mod}\" args file has unknown args: {rest.join(", ")}" )
34 end
35 end
36
37 cc_lib_paths.append( opt_cc_lib_paths.value )
38 cc_libs.append( opt_cc_libs.value )
39 cc_include_paths.append( opt_cc_include_paths.value )
40 end
41 end
42
43 redef class MMSrcModule
44
45 redef fun compile_separate_module(cprogram)
46 do
47 super
48
49 # extract options from file
50 var options_path = "{location.file.filename}.args"
51 if options_path.file_exists then
52 var option_file = new IFStream.open( options_path )
53 var option_content = option_file.read_all
54 option_file.close
55
56 cprogram.program.tc.integrate_separate_options( option_content, self )
57 cprogram.program.tc.check_errors
58 end
59 end
60 end