/*
 * Copyright 2013 the original author or authors.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package org.gradle.plugins.cpp.msvcpp.internal;

import org.gradle.api.internal.tasks.compile.ArgCollector;
import org.gradle.api.internal.tasks.compile.ArgWriter;
import org.gradle.api.internal.tasks.compile.CompileSpecToArguments;
import org.gradle.internal.Factory;
import org.gradle.plugins.cpp.compiler.internal.CommandLineCppCompiler;
import org.gradle.plugins.cpp.compiler.internal.CommandLineCppCompilerArgumentsToOptionFile;
import org.gradle.plugins.cpp.internal.LinkerSpec;
import org.gradle.process.internal.ExecAction;

import java.io.File;

class VisualCppStaticLibraryLinker extends CommandLineCppCompiler<LinkerSpec> {

    VisualCppStaticLibraryLinker(File executable, Factory<ExecAction> execActionFactory) {
        super(executable, execActionFactory, new CommandLineCppCompilerArgumentsToOptionFile<LinkerSpec>(
                ArgWriter.windowsStyleFactory(), new VisualCppLinkerSpecArguments()
        ));
    }

    private static class VisualCppLinkerSpecArguments implements CompileSpecToArguments<LinkerSpec> {
        public void collectArguments(LinkerSpec spec, ArgCollector collector) {
            collector.args("/OUT:" + spec.getOutputFile().getAbsolutePath());
            collector.args("/NOLOGO");
            for (File file : spec.getSource()) {
                collector.args(file.getAbsolutePath());
            }
            for (File file : spec.getLibs()) {
                collector.args(file.getAbsolutePath().replaceFirst("\\.dll$", ".lib"));
            }
            // Last arg wins in case of duplicates
            collector.args(spec.getArgs());
        }
    }
}

@@ -1724,24 +1724,68 @@
 ollector) %7B%0A
+            collector.args(spec.getArgs());%0A
             
@@ -1842,32 +1842,32 @@
 bsolutePath());%0A
-
             coll
@@ -1986,32 +1986,32 @@
 bsolutePath());%0A
+
             %7D%0A  
@@ -2012,252 +2012,8 @@
   %7D%0A
-            for (File file : spec.getLibs()) %7B%0A                collector.args(file.getAbsolutePath().replaceFirst(%22%5C%5C.dll$%22, %22.lib%22));%0A            %7D%0A            // Last arg wins in case of duplicates%0A            collector.args(spec.getArgs());%0A
     

Tweak command-line arguments for assembling static library with lib.exe