Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: 2dda288c899ee932638a824fdd77a596bc47e458 (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
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
/*******************************************************************************
 * Copyright (c) 2000, 2010 QNX Software Systems and others.
 *
 * This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License 2.0
 * which accompanies this distribution, and is available at
 * https://www.eclipse.org/legal/epl-2.0/
 *
 * SPDX-License-Identifier: EPL-2.0
 *
 * Contributors:
 *     QNX Software Systems - Initial API and implementation
 *******************************************************************************/
package org.eclipse.cdt.make.internal.core.makefile.gnu;

import org.eclipse.cdt.make.internal.core.makefile.Util;
import org.eclipse.cdt.make.internal.core.makefile.posix.PosixMakefileUtil;

/**
 * GNUMakefile
 */
public class GNUMakefileUtil extends PosixMakefileUtil {

	public static boolean isInclude(String line) {
		line = line.trim();
		boolean isInclude = line.startsWith(GNUMakefileConstants.DIRECTIVE_INCLUDE) && line.length() > 7 && Character.isWhitespace(line.charAt(7));
		boolean isDashInclude = line.startsWith("-" + GNUMakefileConstants.DIRECTIVE_INCLUDE) && line.length() > 8 && Character.isWhitespace(line.charAt(8)); //$NON-NLS-1$
		boolean isSInclude = line.startsWith("s" + GNUMakefileConstants.DIRECTIVE_INCLUDE) && line.length() > 8 && Character.isWhitespace(line.charAt(8)); //$NON-NLS-1$
		return isInclude || isDashInclude || isSInclude;
	}

	public static boolean isVPath(String line) {
		line = line.trim();
		return line.equals(GNUMakefileConstants.DIRECTIVE_VPATH) || line.startsWith(GNUMakefileConstants.DIRECTIVE_VPATH) && line.length() > 5 && Character.isWhitespace(line.charAt(5));
	}

	public static boolean isExport(String line) {
		line = line.trim();
		return line.equals(GNUMakefileConstants.VARIABLE_EXPORT) || line.startsWith(GNUMakefileConstants.VARIABLE_EXPORT) && line.length() > 6 && Character.isWhitespace(line.charAt(6));
	}

	public static boolean isUnExport(String line) {
		line = line.trim();
		return line.startsWith(GNUMakefileConstants.DIRECTIVE_UNEXPORT) && line.length() > 8 && Character.isWhitespace(line.charAt(8));
	}

	public static boolean isDefine(String line) {
		line = line.trim();
		return line.startsWith(GNUMakefileConstants.VARIABLE_DEFINE) && line.length() > 6 && Character.isWhitespace(line.charAt(6));
	}

	public static boolean isEndef(String line) {
		return line.trim().equals(GNUMakefileConstants.TERMINAL_ENDEF);
	}

	public static boolean isOverride(String line) {
		line = line.trim();
		return line.startsWith(GNUMakefileConstants.VARIABLE_OVERRIDE) && line.length() > 8 && Character.isWhitespace(line.charAt(8));
	}

	public static boolean isIfeq(String line) {
		line = line.trim();
		return line.startsWith(GNUMakefileConstants.CONDITIONAL_IFEQ) && line.length() > 4 && Character.isWhitespace(line.charAt(4));
	}

	public static boolean isIfneq(String line) {
		line = line.trim();
		return line.startsWith(GNUMakefileConstants.CONDITIONAL_IFNEQ) && line.length() > 5 && Character.isWhitespace(line.charAt(5));
	}

	public static boolean isIfdef(String line) {
		line = line.trim();
		return line.startsWith(GNUMakefileConstants.CONDITIONAL_IFDEF) && line.length() > 5 && Character.isWhitespace(line.charAt(5));
	}

	public static boolean isIfndef(String line) {
		line = line.trim();
		return line.startsWith(GNUMakefileConstants.CONDITIONAL_IFNDEF) && line.length() > 6 && Character.isWhitespace(line.charAt(6));
	}

	public static boolean isElse(String line) {
		return line.trim().equals(GNUMakefileConstants.CONDITIONAL_ELSE);
	}

	public static boolean isEndif(String line) {
		return line.trim().equals(GNUMakefileConstants.TERMINAL_ENDIF);
	}

	public static boolean isOverrideDefine(String line) {
		line = line.trim();
		if (line.startsWith(GNUMakefileConstants.VARIABLE_OVERRIDE)) {
			int i = 8;
			while(i < line.length() && Character.isWhitespace(line.charAt(i))) {
				i++;
			}
			if (line.startsWith(GNUMakefileConstants.VARIABLE_DEFINE, i)) {
				return true;
			}
		}
		return false;
	}

	public static boolean isTargetVariable(String line) {
		line = line.trim();
		int index = Util.indexOf(line, ':');
		if (index > 1) {
			line = line.substring(index + 1).trim();
			int equal = Util.indexOf(line, '=');
			if (equal > 1) {
				return true;
			}
		}
		return false;
	}

	public static boolean isVariableDefinition(String line) {
		return isOverrideDefine(line)
			|| isTargetVariable(line)
			|| isDefine(line)
			|| isOverride(line)
			|| isExport(line)
			|| isMacroDefinition(line);
	}

	public static boolean isStaticTargetRule(String line) {
		line = line.trim();
		int colon1 = Util.indexOf(line, ':');
		if (colon1 > 0) {
			// move pass colon1
			line = line.substring(colon1 + 1);
			int colon2 =  Util.indexOf(line, ':');
			// Catch operator "::" not a static pattern rule
			return (colon2 > 0);
		}
		return false;
	}

	public static boolean isGNUTargetRule(String line) {
		line = line.trim();
		int colon = Util.indexOf(line, ':');
		if (colon > 0) {
			colon++;
			// Catch VariableDefiniton with operator ":="
			if (colon < line.length()) {
				return line.charAt(colon) != '=';
			}
			return true;
		}
		return false;
	}

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

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

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

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

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

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

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

}

Back to the top