summaryrefslogtreecommitdiffstats
path: root/org.rtems.cdt.toolchain/src/org/rtems/cdt/toolchain/RtemsScannerInfoCollector.java
blob: e07454415ac8dcb562de2c6d172d61ff2db7c6d7 (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
/*******************************************************************************
 * Copyright (c) 2004, 2007 RobertF
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 * RobertF - Initial API and implementation
 *******************************************************************************/
package org.rtems.cdt.toolchain;

import java.util.Iterator;
import java.util.List;
import java.util.ArrayList;
import java.util.Map;
import java.util.HashMap;

import org.eclipse.cdt.make.core.scannerconfig.InfoContext;
import org.eclipse.cdt.make.core.scannerconfig.ScannerInfoTypes;

import org.eclipse.core.resources.IProject;
import org.eclipse.core.runtime.Path;
import org.eclipse.cdt.make.core.scannerconfig.IScannerInfoCollector3;
import org.eclipse.cdt.make.internal.core.scannerconfig2.PerProjectSICollector;
import org.eclipse.cdt.make.internal.core.scannerconfig.ScannerConfigUtil;
import org.eclipse.cdt.managedbuilder.scannerconfig.IManagedScannerInfoCollector;
import org.eclipse.cdt.make.internal.core.scannerconfig.util.TraceUtil;

/**
 * Implementation class for gathering the built-in compiler settings for
 * Rtems-based targets.
 *
 * @since 5.0.1
 */
public class RtemsScannerInfoCollector extends PerProjectSICollector 
             implements IScannerInfoCollector3, IManagedScannerInfoCollector {
  // extends DefaultGCCScannerInfoCollector <- has restriction, cannot be used
  public static final String ENV_RTEMS_BSP_DEFINED_SYMBOLS = "RTEMS_BSP_DEFINED_SYMBOLS";

  /* (non-Javadoc)
   * @see org.eclipse.cdt.make.core.scannerconfig.IScannerInfoCollector#contributeToScannerConfig(java.lang.Object, java.util.Map)
   */
  public void contributeToScannerConfig(Object resource, Map scannerInfo) {

    List filteredIncludes = (List) scannerInfo.get(ScannerInfoTypes.INCLUDE_PATHS);

    // This method will be called by the parser each time there is a new value
    Iterator pathIter = filteredIncludes.listIterator();
    while (pathIter.hasNext()) {
        String incPath = (String) pathIter.next();
        // Could find the switch to disable auto discovery, so filtered
        // out MinGW and Cygwin default includes
        if (incPath.contains("MinGW") || incPath.contains("mingw")
            || incPath.contains("Cygwin") || incPath.contains("cygwin")) {
            pathIter.remove();
        }
    }
    //scannerInfo.put(ScannerInfoTypes.INCLUDE_PATHS, filteredIncludes);

    List definedSymbols = (List) scannerInfo.get(ScannerInfoTypes.SYMBOL_DEFINITIONS);
    
    addBspDefinedSymbols(definedSymbols);
    
    //scannerInfo.put(ScannerInfoTypes.SYMBOL_DEFINITIONS, definedSymbols);

    super.contributeToScannerConfig(resource, scannerInfo);
  }
  
  private static void addBspDefinedSymbols(List definedSymbols) { 
    if (definedSymbols==null) return;
    
    String bspSymbols = System.getenv(ENV_RTEMS_BSP_DEFINED_SYMBOLS);
    // e.g., "STDC_HEADERS,HAVE_SYS_TYPES_H,HAVE_SYS_STAT_H,HAVE_STDLIB_H..."
    if (bspSymbols != null) {
      String[] macro = bspSymbols.split(",");
      for (int i=0; i<macro.length; i++) {
        String symbol = macro[i].trim() + "=1";
        if (!definedSymbols.contains(symbol)) definedSymbols.add(symbol);
      }
    }
  }
  
  public static List<String> getBspDefinedSymbols() {
    ArrayList<String> definedSymbols = new ArrayList<String>();
    
    addBspDefinedSymbols(definedSymbols);
    
    return definedSymbols;
  }

  /**
   * Answers a map of collected defines that the the compiler uses by default.
   * The symbols are defined in the map as a (macro, value) pair as follows
   * <p><p><code>-DFOO</code> will be stored as ("FOO","")
   * <p><code>-DFOO=BAR</code> will be stored as ("FOO","BAR")
   * <p><p>Duplicates will not be stored in the map and any whitespaces in
   * the macro or value will be trimmed out.
   *
   * @return a <code>Map</code> of defined symbols and values
   */
  /*
  public Map getDefinedSymbols() {
    HashMap symbolMap = new HashMap();

    String bspSymbols = System.getenv(ENV_RTEMS_BSP_DEFINED_SYMBOLS);
    //String bspSymbols ="STDC_HEADERS,HAVE_SYS_TYPES_H,HAVE_SYS_STAT_H,HAVE_STDLIB_H,HAVE_STRING_H,HAVE_INTTYPES_H,HAVE_STDINT_H,HAVE_UNISTD_H,HAVE_CSTDIO,HAVE_CSTDLIB,HAVE_IOSTREAM";

    if (bspSymbols != null) {
      String[] macro = bspSymbols.split(",");
      for (int i=0; i<macro.length; i++) {
        symbolMap.put(macro[i].trim(), "1");
      }
    }

    return symbolMap;
  }
  */

  public void setProject(IProject project) {
    super.setProject(project);
  }

  public void setInfoContext(InfoContext context) {
    super.setInfoContext(context);
  }
}