ni_nitdoc: added fast copy past utility to signatures.
[nit.git] / src / separate_options.nit
1 # This file is part of NIT ( http://www.nitlanguage.org ).
2 #
3 # Copyright 2012 Jean Privat <jean@pryen.org>
4 #
5 # Licensed under the Apache License, Version 2.0 (the "License");
6 # you may not use this file except in compliance with the License.
7 # You may obtain a copy of the License at
8 #
9 # http://www.apache.org/licenses/LICENSE-2.0
10 #
11 # Unless required by applicable law or agreed to in writing, software
12 # distributed under the License is distributed on an "AS IS" BASIS,
13 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 # See the License for the specific language governing permissions and
15 # limitations under the License.
16
17 # module adding separate specification of opts to compiler
18 module separate_options
19
20 import mmloader
21 import compiling
22
23 # only to order correctly redefs of compile_separate_module
24 import native_interface
25 import ffi
26
27 redef class ToolContext
28 # all ops precised in .ops files
29 var separate_options : OptionContext = new OptionContext
30 var opt_cc_lib_paths: OptionArray = new OptionArray("Path to libraries for C compiler", "--cc-lib-path")
31 var opt_cc_libs: OptionArray = new OptionArray("Name of library to use for C compiler", "--cc-lib-name")
32 var opt_cc_include_paths: OptionArray = new OptionArray("Path to .h files for C compiler", "--cc-header-path")
33
34 redef init
35 do
36 super
37
38 separate_options.add_option( opt_cc_lib_paths )
39 separate_options.add_option( opt_cc_libs )
40 separate_options.add_option( opt_cc_include_paths )
41 end
42
43 fun integrate_separate_options( options : String, mod : MMModule )
44 do
45 for line in options.split_with('\n') do
46 line = line.strip_extension( "\n" )
47 separate_options.parse( line.split_with( ' ' ) )
48 var rest = new Array[String]
49 for s in separate_options.rest do if s.length > 0 then rest.add( s )
50 if rest.length > 0 then
51 error( null, "module \"{mod}\" args file has unknown args: {rest.join(", ")}" )
52 end
53 end
54
55 cc_lib_paths.append( opt_cc_lib_paths.value )
56 cc_libs.append( opt_cc_libs.value )
57 cc_include_paths.append( opt_cc_include_paths.value )
58 end
59 end
60
61 redef class MMSrcModule
62
63 redef fun compile_separate_module(cprogram)
64 do
65 super
66
67 # extract options from file
68 var options_path = "{location.file.filename}.args"
69 if options_path.file_exists then
70 var option_file = new IFStream.open( options_path )
71 var option_content = option_file.read_all
72 option_file.close
73
74 cprogram.program.tc.integrate_separate_options( option_content, self )
75 cprogram.program.tc.check_errors
76 end
77 end
78 end