1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-04-23 14:42:11 +02:00

New draft for GNU Makefile

This commit is contained in:
Alain Magloire 2003-09-09 03:52:15 +00:00
parent 084ae250ef
commit 0ec0b04c3e
16 changed files with 829 additions and 0 deletions

View file

@ -0,0 +1,49 @@
/**********************************************************************
* Copyright (c) 2002,2003 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.gnu;
import org.eclipse.cdt.make.internal.core.makefile.MakefileUtil;
import org.eclipse.cdt.make.internal.core.makefile.Statement;
public class Define extends Statement {
String variable;
public Define(String line) {
parse(line);
}
public String toString() {
StringBuffer sb = new StringBuffer("define");
sb.append(' ').append(variable);
return sb.toString();
}
public String getVariable() {
return variable;
}
/**
* Format of the include directive:
* export Variabe ...
*/
protected void parse(String line) {
line = line.trim();
for (int i = 0; i < line.length(); i++) {
if (MakefileUtil.isSpace(line.charAt(i))) {
line = line.substring(i).trim();
break;
}
}
variable = line;
}
}

View file

@ -0,0 +1,25 @@
/**********************************************************************
* Copyright (c) 2002,2003 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.gnu;
import org.eclipse.cdt.make.internal.core.makefile.Statement;
public class Else extends Statement {
public Else() {
}
public String toString() {
return "else";
}
}

View file

@ -0,0 +1,25 @@
/**********************************************************************
* Copyright (c) 2002,2003 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.gnu;
import org.eclipse.cdt.make.internal.core.makefile.Statement;
public class Endef extends Statement {
public Endef() {
}
public String toString() {
return "endef";
}
}

View file

@ -0,0 +1,25 @@
/**********************************************************************
* Copyright (c) 2002,2003 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.gnu;
import org.eclipse.cdt.make.internal.core.makefile.Statement;
public class Endif extends Statement {
public Endif() {
}
public String toString() {
return "endif";
}
}

View file

@ -0,0 +1,55 @@
/**********************************************************************
* Copyright (c) 2002,2003 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.gnu;
import java.util.StringTokenizer;
import org.eclipse.cdt.make.internal.core.makefile.Statement;
public class Export extends Statement {
String variable;
public Export(String line) {
parse(line);
}
public String toString() {
StringBuffer sb = new StringBuffer("export");
sb.append(' ').append(variable);
return sb.toString();
}
public String getVariable() {
return variable;
}
/**
* Format of the include directive:
* export Variabe ...
*/
protected void parse(String line) {
StringTokenizer st = new StringTokenizer(line);
int count = st.countTokens();
if (count > 0) {
for (int i = 0; i < count; i++) {
if (i == 0) {
// ignore the "export" keyword.
continue;
}
variable = st.nextToken();
}
}
if (variable == null) {
variable = new String();
}
}
}

View file

@ -0,0 +1,43 @@
/**********************************************************************
* Copyright (c) 2002,2003 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.gnu;
import java.io.FileReader;
import java.io.IOException;
import java.io.Reader;
import org.eclipse.cdt.make.core.makefile.IStatement;
import org.eclipse.cdt.make.internal.core.makefile.MakefileReader;
import org.eclipse.cdt.make.internal.core.makefile.posix.PosixMakefile;
/**
* GNUMakefile
*/
public class GNUMakefile extends PosixMakefile {
public static String PATH_SEPARATOR = System.getProperty("path.separator", ":");
public GNUMakefile(String name) throws IOException {
this(new FileReader(name));
}
public GNUMakefile(Reader reader) throws IOException {
this(new MakefileReader(reader));
}
public GNUMakefile(MakefileReader reader) throws IOException {
super(reader);
}
protected IStatement processLine(String line, int startLine, int endLine) {
return null;
}
}

View file

@ -0,0 +1,98 @@
/**********************************************************************
* Copyright (c) 2002,2003 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.gnu;
/**
* GNUMakefile
*/
public class GNUMakefileUtil {
public static boolean isIncludeDirective(String line) {
line = line.trim();
boolean isInclude = line.startsWith("include") && line.length() > 7 && Character.isWhitespace(line.charAt(7));
boolean isDashInclude = line.startsWith("-include") && line.length() > 8 && Character.isWhitespace(line.charAt(8));
boolean isSInclude = line.startsWith("sinclude") && line.length() > 8 && Character.isWhitespace(line.charAt(8));
return isInclude || isDashInclude || isSInclude;
}
public static boolean isVPathDirective(String line) {
line = line.trim();
return line.equals("vpath") ||
line.startsWith("vpath") && line.length() > 5 && Character.isWhitespace(line.charAt(5));
}
public static boolean isExport(String line) {
line = line.trim();
return line.equals("export") ||
line.startsWith("export") && line.length() > 6 && Character.isWhitespace(line.charAt(6));
}
public static boolean isUnExport(String line) {
line = line.trim();
return line.equals("unexport") ||
line.startsWith("unexport") && line.length() > 8 && Character.isWhitespace(line.charAt(8));
}
public static boolean isDefine(String line) {
line = line.trim();
return line.equals("define") ||
line.startsWith("define") && line.length() > 6 && Character.isWhitespace(line.charAt(6));
}
public static boolean isEndef(String line) {
line = line.trim();
return line.equals("endef") ||
line.startsWith("endef") && line.length() > 5 && Character.isWhitespace(line.charAt(5));
}
public static boolean isOverride(String line) {
line = line.trim();
return line.equals("override") ||
line.startsWith("override") && line.length() > 8 && Character.isWhitespace(line.charAt(8));
}
public static boolean isIfeq(String line) {
line = line.trim();
return line.equals("ifeq") ||
line.startsWith("ifeq") && line.length() > 4 && Character.isWhitespace(line.charAt(4));
}
public static boolean isIfneq(String line) {
line = line.trim();
return line.equals("ifneq") ||
line.startsWith("ifneq") && line.length() > 5 && Character.isWhitespace(line.charAt(5));
}
public static boolean isIfdef(String line) {
line = line.trim();
return line.equals("ifdef") ||
line.startsWith("ifdef") && line.length() > 5 && Character.isWhitespace(line.charAt(5));
}
public static boolean isIfndef(String line) {
line = line.trim();
return line.equals("ifndef") ||
line.startsWith("ifndef") && line.length() > 5 && Character.isWhitespace(line.charAt(5));
}
public static boolean isElse(String line) {
line = line.trim();
return line.equals("else") ||
line.startsWith("else") && line.length() > 4 && Character.isWhitespace(line.charAt(4));
}
public static boolean isEndif(String line) {
line = line.trim();
return line.equals("endif") ||
line.startsWith("endif") && line.length() > 5 && Character.isWhitespace(line.charAt(5));
}
}

View file

@ -0,0 +1,49 @@
/**********************************************************************
* Copyright (c) 2002,2003 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.gnu;
import org.eclipse.cdt.make.internal.core.makefile.MakefileUtil;
import org.eclipse.cdt.make.internal.core.makefile.Statement;
public class Ifdef extends Statement {
String variable;
public Ifdef(String line) {
parse(line);
}
public String toString() {
StringBuffer sb = new StringBuffer("ifdef");
sb.append(' ').append(variable);
return sb.toString();
}
public String getVariable() {
return variable;
}
/**
* Format of the include directive:
* ifeq condional-directive
*/
protected void parse(String line) {
line = line.trim();
for (int i = 0; i < line.length(); i++) {
if (MakefileUtil.isSpace(line.charAt(i))) {
line = line.substring(i).trim();
break;
}
}
variable = line;
}
}

View file

@ -0,0 +1,50 @@
/**********************************************************************
* Copyright (c) 2002,2003 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.gnu;
import org.eclipse.cdt.make.internal.core.makefile.MakefileUtil;
import org.eclipse.cdt.make.internal.core.makefile.Statement;
public class Ifeq extends Statement {
String conditional;
public Ifeq(String line) {
parse(line);
}
public String toString() {
StringBuffer sb = new StringBuffer("ifeq");
sb.append(' ').append(conditional);
return sb.toString();
}
public String getConditional() {
return conditional;
}
/**
* Format of the include directive:
* ifeq condional-directive
*/
protected void parse(String line) {
line = line.trim();
for (int i = 0; i < line.length(); i++) {
if (MakefileUtil.isSpace(line.charAt(i))) {
line = line.substring(i).trim();
break;
}
}
conditional = line;
}
}

View file

@ -0,0 +1,49 @@
/**********************************************************************
* Copyright (c) 2002,2003 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.gnu;
import org.eclipse.cdt.make.internal.core.makefile.MakefileUtil;
import org.eclipse.cdt.make.internal.core.makefile.Statement;
public class Ifndef extends Statement {
String variable;
public Ifndef(String line) {
parse(line);
}
public String toString() {
StringBuffer sb = new StringBuffer("ifndef");
sb.append(' ').append(variable);
return sb.toString();
}
public String getVariable() {
return variable;
}
/**
* Format of the include directive:
* ifeq condional-directive
*/
protected void parse(String line) {
line = line.trim();
for (int i = 0; i < line.length(); i++) {
if (MakefileUtil.isSpace(line.charAt(i))) {
line = line.substring(i).trim();
break;
}
}
variable = line;
}
}

View file

@ -0,0 +1,49 @@
/**********************************************************************
* Copyright (c) 2002,2003 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.gnu;
import org.eclipse.cdt.make.internal.core.makefile.MakefileUtil;
import org.eclipse.cdt.make.internal.core.makefile.Statement;
public class Ifneq extends Statement {
String conditional;
public Ifneq(String line) {
parse(line);
}
public String toString() {
StringBuffer sb = new StringBuffer("ifneq");
sb.append(' ').append(conditional);
return sb.toString();
}
public String getConditional() {
return conditional;
}
/**
* Format of the include directive:
* ifeq condional-directive
*/
protected void parse(String line) {
line = line.trim();
for (int i = 0; i < line.length(); i++) {
if (MakefileUtil.isSpace(line.charAt(i))) {
line = line.substring(i).trim();
break;
}
}
conditional = line;
}
}

View file

@ -0,0 +1,57 @@
/**********************************************************************
* Copyright (c) 2002,2003 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.gnu;
import java.util.StringTokenizer;
import org.eclipse.cdt.make.internal.core.makefile.Statement;
public class Include extends Statement {
String[] filenames;
public Include(String line) {
parse(line);
}
public String toString() {
StringBuffer sb = new StringBuffer("include");
for (int i = 0; i < filenames.length; i++) {
sb.append(' ').append(filenames[i]);
}
return sb.toString();
}
public String[] getFilenames() {
return filenames;
}
/**
* Format of the include directive:
* include filename1 filename2 ...
*/
protected void parse(String line) {
StringTokenizer st = new StringTokenizer(line);
int count = st.countTokens();
if (count > 0) {
filenames = new String[count - 1];
for (int i = 0; i < count; i++) {
if (i == 0) {
// ignore the "include" keyword.
continue;
}
filenames[i] = st.nextToken();
}
} else {
filenames = new String[0];
}
}
}

View file

@ -0,0 +1,54 @@
/**********************************************************************
* Copyright (c) 2002,2003 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.gnu;
import org.eclipse.cdt.make.internal.core.makefile.MakefileUtil;
import org.eclipse.cdt.make.internal.core.makefile.Statement;
public class Override extends Statement {
String variable;
public Override(String line) {
parse(line);
}
public String toString() {
StringBuffer sb = new StringBuffer("override");
sb.append(' ').append(variable);
return sb.toString();
}
public String getVariable() {
return variable;
}
/**
* Format:
* override VARIABLE := VALUE
*/
protected void parse(String line) {
int i = 0;
line = line.trim();
for (; i < line.length(); i++) {
if (MakefileUtil.isSpace(line.charAt(i))) {
break;
}
}
if (i < line.length()) {
variable = line.substring(i).trim();
} else {
variable = new String();
}
}
}

View file

@ -0,0 +1,60 @@
/**********************************************************************
* Copyright (c) 2002,2003 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.gnu;
import org.eclipse.cdt.make.internal.core.makefile.MakefileUtil;
import org.eclipse.cdt.make.internal.core.makefile.Statement;
public class OverrideDefine extends Statement {
String variable;
public OverrideDefine(String line) {
parse(line);
}
public String toString() {
StringBuffer sb = new StringBuffer("override define");
sb.append(' ').append(variable);
return sb.toString();
}
public String getVariable() {
return variable;
}
/**
* Format:
* override define VARIABLE
*/
protected void parse(String line) {
line = line.trim();
// Pass over "override"
for (int i = 0; i < line.length(); i++) {
if (MakefileUtil.isSpace(line.charAt(i))) {
line = line.substring(i).trim();
break;
}
}
// Pass over "define"
for (int i = 0; i < line.length(); i++) {
if (MakefileUtil.isSpace(line.charAt(i))) {
line = line.substring(i).trim();
break;
}
}
variable = line;
}
}

View file

@ -0,0 +1,55 @@
/**********************************************************************
* Copyright (c) 2002,2003 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.gnu;
import java.util.StringTokenizer;
import org.eclipse.cdt.make.internal.core.makefile.Statement;
public class UnExport extends Statement {
String variable;
public UnExport(String line) {
parse(line);
}
public String toString() {
StringBuffer sb = new StringBuffer("unexport");
sb.append(' ').append(variable);
return sb.toString();
}
public String getVariable() {
return variable;
}
/**
* Format of the include directive:
* export Variabe ...
*/
protected void parse(String line) {
StringTokenizer st = new StringTokenizer(line);
int count = st.countTokens();
if (count > 0) {
for (int i = 0; i < count; i++) {
if (i == 0) {
// ignore the "unexport" keyword.
continue;
}
variable = st.nextToken();
}
}
if (variable == null) {
variable = new String();
}
}
}

View file

@ -0,0 +1,86 @@
/**********************************************************************
* Copyright (c) 2002,2003 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.gnu;
import java.util.ArrayList;
import java.util.List;
import java.util.StringTokenizer;
import org.eclipse.cdt.make.internal.core.makefile.Statement;
public class VPath extends Statement {
String pattern;
String[] directories;
public VPath(String line) {
parse(line);
}
public String toString() {
StringBuffer sb = new StringBuffer("vpath");
if (pattern != null && pattern.length() > 0) {
sb.append(' ').append(pattern);
}
for (int i = 0; i < directories.length; i++) {
sb.append(' ').append(directories[i]);
}
return sb.toString();
}
public String[] getDirectories() {
return directories;
}
public String getPattern() {
return pattern;
}
/**
* There are three forms of the "vpath" directive:
* "vpath PATTERN DIRECTORIES"
* Specify the search path DIRECTORIES for file names that match PATTERN.
*
* The search path, DIRECTORIES, is a list of directories to be
* searched, separated by colons (semi-colons on MS-DOS and
* MS-Windows) or blanks, just like the search path used in the `VPATH' variable.
*
* "vpath PATTERN"
* Clear out the search path associated with PATTERN.
*
* "vpath"
* Clear all search paths previously specified with `vpath' directives.
*/
protected void parse(String line) {
StringTokenizer st = new StringTokenizer(line);
int count = st.countTokens();
List dirs = new ArrayList(count);
if (count > 0) {
for (int i = 0; i < count; i++) {
if (count == 0) {
// ignore the "vpath" directive
st.nextToken();
} else if (count == 1) {
pattern = st.nextToken();
} else if (count == 3) {
String delim = " \t\n\r\f" + GNUMakefile.PATH_SEPARATOR;
dirs.add(st.nextToken(delim));
} else {
dirs.add(st.nextToken());
}
}
}
directories = (String[]) dirs.toArray(new String[0]);
if (pattern == null) {
pattern = new String();
}
}
}