PageRenderTime 364ms CodeModel.GetById 242ms app.highlight 4ms RepoModel.GetById 116ms app.codeStats 0ms

/src/org/ooc/frontend/pkgconfig/PkgInfo.java

http://github.com/nddrylliog/ooc
Java | 65 lines | 33 code | 18 blank | 14 comment | 1 complexity | c6579ef7b89dff99c93f79aa38e7afca MD5 | raw file
 1package org.ooc.frontend.pkgconfig;
 2
 3import java.util.ArrayList;
 4import java.util.List;
 5import java.util.StringTokenizer;
 6
 7/**
 8 * Information about a package managed by pkg-config
 9 * 
10 * @author Amos Wenger
11 */
12public class PkgInfo {
13
14	/** The name of the package, e.g. gtk+-2.0, or imlib2 */
15	public final String name;
16	
17	/** The output of `pkg-config --libs name` */
18	public final String libsString;
19	
20	/** The output of `pkg-config --cflags name` */
21	public final String cflagsString;
22	
23	/** The C flags (include the include paths) */
24	public final List<String> cflags;
25	
26	/** A list of all libraries needed */
27	public final List<String> libraries;
28	
29	/** A list of all include paths */
30	public final List<String> includePaths;
31	
32	/**
33	 * Create a new Package info
34	 */
35	public PkgInfo(String name, String libsString, String cflagsString) {
36		
37		this.name = name;
38		this.libsString = libsString;
39		this.cflagsString = cflagsString;
40
41		cflags = new ArrayList<String>();
42		libraries = new ArrayList<String>();
43		includePaths = new ArrayList<String>();
44		
45		extractTokens("-l", libsString, libraries);
46		extractTokens("-I", cflagsString, includePaths);
47		extractTokens("", cflagsString, cflags);
48		
49	}
50
51	protected void extractTokens(String prefix, String string, List<String> list) {
52		
53		int prefixLength = prefix.length();
54		
55		StringTokenizer st = new StringTokenizer(string);
56		while(st.hasMoreTokens()) {
57			String token = st.nextToken();
58			if(token.startsWith(prefix)) {
59				list.add(token.substring(prefixLength).trim());
60			}
61		}
62		
63	}
64	
65}