Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: 58f7cb7cfce21e7bbb2603a1a91f290118c0dd89 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
/*******************************************************************************
 * Copyright (c) 2000, 2004 QNX Software Systems and others.
 * All rights reserved. This program and the accompanying materials 
 * are made available under the terms of the Common Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/cpl-v10.html
 * 
 * Contributors:
 *     QNX Software Systems - Initial API and implementation
 *******************************************************************************/
package org.eclipse.cdt.make.internal.core.makefile.posix;

import java.util.ArrayList;
import java.util.List;

import org.eclipse.cdt.make.internal.core.makefile.MakeFileConstants;
import org.eclipse.cdt.make.internal.core.makefile.Util;

/**
 */
public class PosixMakefileUtil {

	public static String[] findPrerequisites(String line) {
		return findTargets(line);
	}

	public static String[] findTargets(String line) {
		List aList = new ArrayList();
		int space;
		// Trim away trailing and prepending spaces.
		line = line.trim();
		while ((space = Util.indexOf(line, " \t")) != -1) { //$NON-NLS-1$
			aList.add(line.substring(0, space).trim());
			line = line.substring(space + 1).trim();
		}
		// The last target.
		if (line.length() > 0) {
			aList.add(line);
		}
		return (String[]) aList.toArray(new String[0]);
	}

	public static boolean isMacroDefinition(String line) {
		return Util.indexOf(line, '=') != -1;
	}

	public static boolean isTargetRule(String line) {
		return Util.indexOf(line, ':') != -1;
	}

	public static boolean isCommand(String line) {
		return line.length() > 1 && line.charAt(0) == '\t';
	}

	public static boolean isEmptyLine(String line) {
		return line.trim().length() == 0;
	}

	public static boolean isInferenceRule(String line) {
		line = line.trim();
		if (line.startsWith(".")) { //$NON-NLS-1$
			int index = Util.indexOf(line, ':');
			if (index > 1) {
				line = line.substring(index + 1).trim();
				if (line.length() == 0 || line.equals(";")) { //$NON-NLS-1$
					return true;
				}
			}
		}
		return false;
	}

	public static boolean isDefaultRule(String line) {
		line = line.trim();
		int colon = Util.indexOf(line, ':');
		if (colon > 0) {
			line = line.substring(0, colon).trim();
			return line.equals(MakeFileConstants.RULE_DEFAULT);
		}
		return false;
	}

	public static boolean isIgnoreRule(String line) {
		line = line.trim();
		int colon = Util.indexOf(line, ':');
		if (colon > 0) {
			line = line.substring(0, colon).trim();
			return line.equals(MakeFileConstants.RULE_IGNORE);
		}
		return false;
	}

	public static boolean isPosixRule(String line) {
		line = line.trim();
		int colon = Util.indexOf(line, ':');
		if (colon > 0) {
			line = line.substring(0, colon).trim();
			return line.equals(MakeFileConstants.RULE_POSIX);
		}
		return false;
	}

	public static boolean isPreciousRule(String line) {
		line = line.trim();
		int colon = Util.indexOf(line, ':');
		if (colon > 0) {
			line = line.substring(0, colon).trim();
			return line.equals(MakeFileConstants.RULE_PRECIOUS);
		}
		return false;
	}

	public static boolean isSccsGetRule(String line) {
		line = line.trim();
		int colon = Util.indexOf(line, ':');
		if (colon > 0) {
			line = line.substring(0, colon).trim();
			return line.equals(MakeFileConstants.RULE_SCCS_GET);
		}
		return false;
	}

	public static boolean isSilentRule(String line) {
		line = line.trim();
		int colon = Util.indexOf(line, ':');
		if (colon > 0) {
			line = line.substring(0, colon).trim();
			return line.equals(MakeFileConstants.RULE_SILENT);
		}
		return false;
	}

	public static boolean isSuffixesRule(String line) {
		line = line.trim();
		int colon = Util.indexOf(line, ':');
		if (colon > 0) {
			line = line.substring(0, colon).trim();
			return line.equals(MakeFileConstants.RULE_SUFFIXES);
		}
		return false;
	}

	public static boolean isLibraryTarget(String line) {
		char prev = 0;
		int paren = 0;

		for (int i = 0; i < line.length(); i++) {
			char ch = line.charAt(i);
			if (ch == '(' && prev != '$' && prev != '\\') {
				paren++;
			} else if (ch == ')' && prev != '\\') {
				if (paren > 0) {
					return true;
				}
			}
			prev = ch;
		}
		return false;
	}

}

Back to the top