Ejemplo n.º 1
0
 public final String getName(final NarProperties properties, final String prefix)
     throws MojoFailureException, MojoExecutionException {
   if (this.name == null && properties != null && prefix != null) {
     this.name = properties.getProperty(prefix + "linker");
   }
   if (this.name == null) {
     throw new MojoExecutionException(
         "NAR: One of two things may be wrong here:\n\n"
             + "1. <Name> tag is missing inside the <Linker> tag of your NAR configuration\n\n"
             + "2. no linker is defined in the aol.properties file for '"
             + prefix
             + "linker'\n");
   }
   return this.name;
 }
Ejemplo n.º 2
0
  public final LinkerDef getLinker(
      final AbstractCompileMojo mojo,
      final CCTask task,
      final String os,
      final String prefix,
      final String type)
      throws MojoFailureException, MojoExecutionException {
    Project antProject = task.getProject();
    if (this.name == null) {
      throw new MojoFailureException("NAR: Please specify a <Name> as part of <Linker>");
    }

    final LinkerDef linker = new LinkerDef();
    linker.setProject(antProject);
    final LinkerEnum linkerEnum = new LinkerEnum();
    linkerEnum.setValue(this.name);
    linker.setName(linkerEnum);

    // tool path
    if (this.toolPath != null) {
      linker.setToolPath(this.toolPath);
    } else if ("msvc".equalsIgnoreCase(name)) {
      linker.setToolPath(mojo.getMsvc().getToolPath());
    }

    // incremental, map
    linker.setIncremental(this.incremental);
    linker.setMap(this.map);

    // Add definitions (Window only)
    if (os.equals(OS.WINDOWS)
        && getName(null, null).equals("msvc")
        && (type.equals(Library.SHARED) || type.equals(Library.JNI))) {
      final Set defs = new HashSet();
      try {
        if (mojo.getC() != null) {
          final List cSrcDirs = mojo.getC().getSourceDirectories();
          for (final Iterator i = cSrcDirs.iterator(); i.hasNext(); ) {
            final File dir = (File) i.next();
            if (dir.exists()) {
              defs.addAll(FileUtils.getFiles(dir, "**/*.def", null));
            }
          }
        }
      } catch (final IOException e) {
      }
      try {
        if (mojo.getCpp() != null) {
          final List cppSrcDirs = mojo.getCpp().getSourceDirectories();
          for (final Iterator i = cppSrcDirs.iterator(); i.hasNext(); ) {
            final File dir = (File) i.next();
            if (dir.exists()) {
              defs.addAll(FileUtils.getFiles(dir, "**/*.def", null));
            }
          }
        }
      } catch (final IOException e) {
      }
      try {
        if (mojo.getFortran() != null) {
          final List fortranSrcDirs = mojo.getFortran().getSourceDirectories();
          for (final Iterator i = fortranSrcDirs.iterator(); i.hasNext(); ) {
            final File dir = (File) i.next();
            if (dir.exists()) {
              defs.addAll(FileUtils.getFiles(dir, "**/*.def", null));
            }
          }
        }
      } catch (final IOException e) {
      }

      for (final Iterator i = defs.iterator(); i.hasNext(); ) {
        final LinkerArgument arg = new LinkerArgument();
        arg.setValue("/def:" + i.next());
        linker.addConfiguredLinkerArg(arg);
      }
    }

    // FIXME, this should be done in CPPTasks at some point, and may not be
    // necessary, but was for VS 2010 beta 2
    if (os.equals(OS.WINDOWS)
        && getName(null, null).equals("msvc")
        && !getVersion(mojo).startsWith("6.")
        && (type.equals(Library.SHARED)
            || type.equals(Library.JNI)
            || type.equals(Library.EXECUTABLE))) {
      final LinkerArgument arg = new LinkerArgument();
      if (isGenerateManifest()) arg.setValue("/MANIFEST");
      else arg.setValue("/MANIFEST:NO");
      linker.addConfiguredLinkerArg(arg);

      if (isGenerateManifest()) {
        final LinkerArgument arg2 = new LinkerArgument();
        arg2.setValue("/MANIFESTFILE:" + task.getOutfile() + ".manifest");
        linker.addConfiguredLinkerArg(arg2);
      }
    }

    // Add options to linker
    if (this.options != null) {
      for (final Iterator i = this.options.iterator(); i.hasNext(); ) {
        final LinkerArgument arg = new LinkerArgument();
        arg.setValue((String) i.next());
        linker.addConfiguredLinkerArg(arg);
      }
    }

    if (this.optionSet != null) {

      final String[] opts = this.optionSet.split("\\s");

      for (final String opt : opts) {

        final LinkerArgument arg = new LinkerArgument();

        arg.setValue(opt);
        linker.addConfiguredLinkerArg(arg);
      }
    }

    if (!this.clearDefaultOptions) {
      final String option =
          NarProperties.getInstance(mojo.getMavenProject()).getProperty(prefix + "options");
      if (option != null) {
        final String[] opt = option.split(" ");
        for (final String element : opt) {
          final LinkerArgument arg = new LinkerArgument();
          arg.setValue(element);
          linker.addConfiguredLinkerArg(arg);
        }
      }
    }

    // record the preference for nar dependency library link order
    if (this.narDependencyLibOrder != null) {

      final List libOrder = new LinkedList();

      final String[] lib = this.narDependencyLibOrder.split(",");

      for (final String element : lib) {
        libOrder.add(element.trim());
      }

      mojo.setDependencyLibOrder(libOrder);
    }

    // Add Libraries to linker
    if (this.libs != null || this.libSet != null) {

      if (this.libs != null) {

        for (final Iterator i = this.libs.iterator(); i.hasNext(); ) {

          final Lib lib = (Lib) i.next();
          lib.addLibSet(mojo, linker, antProject);
        }
      }

      if (this.libSet != null) {
        addLibraries(this.libSet, linker, antProject, false);
      }
    } else {

      final String libsList =
          NarProperties.getInstance(mojo.getMavenProject()).getProperty(prefix + "libs");

      addLibraries(libsList, linker, antProject, false);
    }

    // Add System Libraries to linker
    if (this.sysLibs != null || this.sysLibSet != null) {

      if (this.sysLibs != null) {

        for (final Iterator i = this.sysLibs.iterator(); i.hasNext(); ) {

          final SysLib sysLib = (SysLib) i.next();
          linker.addSyslibset(sysLib.getSysLibSet(antProject));
        }
      }

      if (this.sysLibSet != null) {
        addLibraries(this.sysLibSet, linker, antProject, true);
      }
    } else {

      final String sysLibsList =
          NarProperties.getInstance(mojo.getMavenProject()).getProperty(prefix + "sysLibs");

      addLibraries(sysLibsList, linker, antProject, true);
    }

    mojo.getMsvc().configureLinker(linker);

    return linker;
  }