diff mbox series

[FFmpeg-devel,GASPP,2/2] Use cl for preprocessing when using armasm

Message ID 20200923063917.19016-2-martin@martin.st
State New
Headers show
Series [FFmpeg-devel,GASPP,1/2] Handle line continuations within gas-preprocessor
Related show

Checks

Context Check Description
andriy/default pending
andriy/configure warning Failed to apply patch

Commit Message

Martin Storsjö Sept. 23, 2020, 6:39 a.m. UTC
When invoking gas-preprocessor to preprocess only to get the dependency
list, we still need to use cpp, as cl doesn't support the -M options.

This allows using gas-preprocessor in an environment with only MSVC
available, no GCC/Clang providing a cpp.exe, allowing building e.g.
dav1d with MSVC targeting ARM, without any mingw/msys tools involved.
---
 gas-preprocessor.pl | 30 ++++++++++++++++++------------
 1 file changed, 18 insertions(+), 12 deletions(-)

Comments

Martin Storsjö Sept. 25, 2020, 9:51 a.m. UTC | #1
On Wed, 23 Sep 2020, Martin Storsjö wrote:

> When invoking gas-preprocessor to preprocess only to get the dependency
> list, we still need to use cpp, as cl doesn't support the -M options.
>
> This allows using gas-preprocessor in an environment with only MSVC
> available, no GCC/Clang providing a cpp.exe, allowing building e.g.
> dav1d with MSVC targeting ARM, without any mingw/msys tools involved.
> ---
> gas-preprocessor.pl | 30 ++++++++++++++++++------------
> 1 file changed, 18 insertions(+), 12 deletions(-)

I'll go ahead and push these (this series of two patches, and the other, 
separate, gas-preprocessor patch) tonight if there's no objections; they 
should be pretty uncontroversial, and I've had them in use locally for a 
long time, so they should be pretty safe.

// Martin
diff mbox series

Patch

diff --git a/gas-preprocessor.pl b/gas-preprocessor.pl
index e9baeba..69f6f6d 100755
--- a/gas-preprocessor.pl
+++ b/gas-preprocessor.pl
@@ -103,14 +103,7 @@  if (grep /\.c$/, @gcc_cmd) {
 if ($as_type eq "armasm") {
 
     $preprocess_c_cmd[0] = "cpp";
-    push(@preprocess_c_cmd, "-undef");
-    # Normally a preprocessor for windows would predefine _WIN32,
-    # but we're using any generic system-agnostic preprocessor "cpp"
-    # with -undef (to avoid getting predefined variables from the host
-    # system in cross compilation cases), so manually define it here.
-    push(@preprocess_c_cmd, "-D_WIN32");
-
-    @preprocess_c_cmd = grep ! /^-nologo$/, @preprocess_c_cmd;
+
     # Remove -ignore XX parameter pairs from preprocess_c_cmd
     my $index = 1;
     while ($index < $#preprocess_c_cmd) {
@@ -121,10 +114,23 @@  if ($as_type eq "armasm") {
         $index++;
     }
     if (grep /^-MM$/, @preprocess_c_cmd) {
+        push(@preprocess_c_cmd, "-D_WIN32");
+        # Normally a preprocessor for windows would predefine _WIN32,
+        # but we're using any generic system-agnostic preprocessor "cpp"
+        # with -undef (to avoid getting predefined variables from the host
+        # system in cross compilation cases), so manually define it here.
+        # We only use this generic preprocessor for generating dependencies,
+        # if the build system runs preprocessing with -M/-MM without -MF.
+        push(@preprocess_c_cmd, "-undef");
+        @preprocess_c_cmd = grep ! /^-nologo$/, @preprocess_c_cmd;
         print STDERR join(" ", @preprocess_c_cmd)."\n" if $verbose;
         system(@preprocess_c_cmd) == 0 or die "Error running preprocessor";
         exit 0;
     }
+
+    # If not preprocessing for getting a dependency list, use cl.exe
+    # instead.
+    $preprocess_c_cmd[0] = "cl";
 }
 
 # if compiling, avoid creating an output file named '-.o'
@@ -139,13 +145,12 @@  if ((grep /^-c$/, @gcc_cmd) && !(grep /^-o/, @gcc_cmd)) {
         }
     }
 }
-# replace only the '-o' argument with '-', avoids rewriting the make dependency
-# target specified with -MT to '-'
+# Remove the -o argument; if omitted, we by default preprocess to stdout.
 my $index = 1;
 while ($index < $#preprocess_c_cmd) {
     if ($preprocess_c_cmd[$index] eq "-o") {
-        $index++;
-        $preprocess_c_cmd[$index] = "-";
+        splice(@preprocess_c_cmd, $index, 2);
+        last;
     }
     $index++;
 }
@@ -166,6 +171,7 @@  if ($as_type ne "armasm") {
     @preprocess_c_cmd = grep ! /^-oldit/, @preprocess_c_cmd;
     @preprocess_c_cmd = grep ! /^-FS/, @preprocess_c_cmd;
     @preprocess_c_cmd = grep ! /^-w/, @preprocess_c_cmd;
+    @preprocess_c_cmd = grep ! /^-M/, @preprocess_c_cmd;
 
     @gcc_cmd = grep ! /^-G/, @gcc_cmd;
     @gcc_cmd = grep ! /^-W/, @gcc_cmd;