1 # This file is part of NIT ( http://www.nitlanguage.org ).
3 # Copyright 2013 Alexis Laferrière <alexis.laf@xymus.net>
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 # Offers the `PkgconfigPhase` to use the external program "pkg-config" in order
18 # to discover what options to pass to the C or C++ compiler.
22 private import annotation
23 private import literal
25 redef class ToolContext
26 var pkgconfig_phase
: Phase = new PkgconfigPhase(self, [literal_phase
])
29 # Detects the `pkgconfig` annotation on the module declaration only.
33 redef fun process_annotated_node
(nmoduledecl
, nat
)
35 # Skip if we are not interested
36 if nat
.name
!= "pkgconfig" then return
38 # Do some validity checks and print errors if the annotation is used incorrectly
39 var modelbuilder
= toolcontext
.modelbuilder
41 if not nmoduledecl
isa AModuledecl then
42 modelbuilder
.error
(nat
, "Syntax error: only the declaration of modules may use \"pkgconfig\
".")
47 var nmodule
= nmoduledecl
.parent
.as(AModule)
48 var mmodule
= nmodule
.mmodule
.as(not null)
51 var pkgs
= new Array[String]
56 pkgs
.add
(mmodule
.name
)
59 var pkg
= arg
.as_string
61 modelbuilder
.error
(nat
, "Syntax error: \"pkgconfig\
" expects its arguments to be the name of the package as String literals.")
69 # check availability of pkg-config
70 var proc_which
= new IProcess("which", "pkg-config")
72 var status
= proc_which
.status
74 modelbuilder
.error
(nat
, "Error: program pkg-config not found, make sure it is installed.")
79 var proc_exist
= new Process("pkg-config", "--exists", pkg
)
81 status
= proc_exist
.status
83 modelbuilder
.error
(nat
, "Error: package \"{pkg}\
" unknown by pkg-config, make sure the development package is be installed.")
85 else if status
!= 0 then
86 modelbuilder
.error
(nat
, "Error: something went wrong calling pkg-config, make sure it is correctly installed.")
90 mmodule
.pkgconfigs
.add pkg