1 # This file is part of NIT ( http://www.nitlanguage.org ).
3 # Copyright 2012 Jean Privat <jean@pryen.org>
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
9 # http://www.apache.org/licenses/LICENSE-2.0
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.
17 # module adding separate specification of opts to compiler
18 module separate_options
23 # only to order correctly redefs of compile_separate_module
24 import native_interface
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")
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
)
43 fun integrate_separate_options
( options
: String, mod
: MMModule )
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(", ")}" )
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
)
61 redef class MMSrcModule
63 redef fun compile_separate_module
(cprogram
)
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
74 cprogram
.program
.tc
.integrate_separate_options
( option_content
, self )
75 cprogram
.program
.tc
.check_errors