1 //
2 // aegis - project change supervisor
3 // Copyright (C) 2008, 2010-2012 Peter Miller
4 //
5 // This program is free software; you can redistribute it and/or modify
6 // it under the terms of the GNU General Public License as published by
7 // the Free Software Foundation; either version 3 of the License, or (at
8 // your option) any later version.
9 //
10 // This program is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13 // General Public License for more details.
14 //
15 // You should have received a copy of the GNU General Public License along
16 // with this program. If not, see <http://www.gnu.org/licenses/>.
17 //
18 
19 #include <common/ac/assert.h>
20 #include <common/ac/ctype.h>
21 
22 #include <libaegis/project.h>
23 
24 #include <aemakegen/target/pkg-config.h>
25 #include <aemakegen/util.h>
26 
27 
~target_pkg_config()28 target_pkg_config::~target_pkg_config()
29 {
30 }
31 
32 
target_pkg_config(change_identifier & a_cid)33 target_pkg_config::target_pkg_config(change_identifier &a_cid) :
34     target(a_cid)
35 {
36 }
37 
38 
39 target::pointer
create(change_identifier & a_cid)40 target_pkg_config::create(change_identifier &a_cid)
41 {
42     return pointer(new target_pkg_config(a_cid));
43 }
44 
45 
46 static nstring
first_line_only(const nstring & s)47 first_line_only(const nstring &s)
48 {
49     unsigned max = 67;
50     const char *start = s.c_str();
51     const char *end = start + s.size();
52     if (s.size() > max)
53     end = start + max;
54     const char *cp = start;
55     while (cp < end)
56     {
57         unsigned char c = *cp;
58         // tabs are OK, newlines are not
59         if (c == '\t' || isprint(c))
60             ++cp;
61         else
62             break;
63     }
64     return nstring(start, cp - start);
65 }
66 
67 
68 void
process3_end(void)69 target_pkg_config::process3_end(void)
70 {
71     op->fprintf("prefix=@prefix@\n");
72     op->fprintf("exec_prefix=@exec_prefix@\n");
73     op->fprintf("bindir=@bindir@\n");
74     op->fprintf("libdir=@libdir@\n");
75     if (data.seen_install_mandir())
76         op->fprintf("mandir=@mandir@\n");
77     if (data.seen_datadir())
78         op->fprintf("datadir=@datadir@\n");
79     op->fprintf("datarootdir=@datarootdir@\n");
80     if (data.seen_install_include())
81         op->fprintf("includedir=@includedir@\n");
82     op->fprintf("\n");
83 
84     nstring source_name = get_project_name();
85     op->fprintf("Name: %s\n", source_name.c_str());
86 
87     nstring source_description =
88         nstring(project_brief_description_get(get_pp()->trunk_get()));
89     source_description = first_line_only(source_description).trim();
90     op->fprintf("Description: %s\n", source_description.c_str());
91 
92     op->fprintf("Version: %s\n", get_cp()->version_debian_get().c_str());
93 
94     nstring homepage =
95         get_cp()->pconf_attributes_find("aemakegen:debian:homepage");
96     if (!homepage.empty())
97         op->fprintf("URL: %s\n", homepage.c_str());
98 
99     nstring requires =
100         get_cp()->pconf_attributes_find("aemakegen:pkg-config:requires");
101     requires = requires.trim();
102     if (!requires.empty())
103         op->fprintf("Requires: %s\n", requires.c_str());
104 
105     nstring conflicts =
106         get_cp()->pconf_attributes_find("aemakegen:pkg-config:conflicts");
107     conflicts = conflicts.trim();
108     if (!conflicts.empty())
109         op->fprintf("Conflicts: %s\n", conflicts.c_str());
110 
111     nstring libs = get_cp()->pconf_attributes_find("aemakegen:pkg-config:libs");
112     nstring libname = get_library_libname();
113     assert(libname.starts_with("lib"));
114     libs = "-l" + libname.substr(3, 999)  + " " + libs;
115     libs = "-L${libdir} " + libs;
116     libs = libs.trim();
117     op->fprintf("Libs: %s\n", libs.c_str());
118 
119     nstring libs_private =
120         get_cp()->pconf_attributes_find("aemakegen:pkg-config:libs.private");
121     libs_private = "@LIBS@ " + libs_private;
122     libs_private = libs_private.trim();
123     op->fprintf("Libs.private: %s\n", libs_private.c_str());
124 
125     nstring cflags =
126         get_cp()->pconf_attributes_find("aemakegen:pkg-config:cflags");
127     if (data.seen_install_include())
128         cflags = "-I${includedir} " + cflags;
129     cflags = cflags.trim();
130     if (!cflags.empty())
131         op->fprintf("Cflags: %s\n", cflags.c_str());
132 }
133 
134 
135 // vim: set ts=8 sw=4 et :
136