]> ruderich.org/simon Gitweb - blhc/blhc.git/commitdiff
Handle dependency generation flags (-M/-MM/-MD/-MMD).
authorSimon Ruderich <simon@ruderich.org>
Sun, 8 Apr 2012 14:11:54 +0000 (16:11 +0200)
committerSimon Ruderich <simon@ruderich.org>
Sun, 8 Apr 2012 14:11:54 +0000 (16:11 +0200)
bin/blhc
t/logs/bad
t/logs/good
t/tests.t

index 5adfca6c13ea2d28d7e3c43c3a61d43c8530e443..91a5f4943c29076d61bde0904dffc7aa8d38a74a 100755 (executable)
--- a/bin/blhc
+++ b/bin/blhc
@@ -731,6 +731,7 @@ FILE: foreach my $file (@ARGV) {
         # Skip unnecessary tests when only preprocessing.
         my $flag_preprocess = 0;
 
         # Skip unnecessary tests when only preprocessing.
         my $flag_preprocess = 0;
 
+        my $dependency = 0;
         my $preprocess = 0;
         my $compile    = 0;
         my $link       = 0;
         my $preprocess = 0;
         my $compile    = 0;
         my $link       = 0;
@@ -740,11 +741,25 @@ FILE: foreach my $file (@ARGV) {
             $preprocess      = 1;
             $flag_preprocess = 1 if $1 eq '-E';
             $compile         = 1 if $1 eq '-S' or $1 eq '-c';
             $preprocess      = 1;
             $flag_preprocess = 1 if $1 eq '-E';
             $compile         = 1 if $1 eq '-S' or $1 eq '-c';
+        # Dependency generation for Makefiles. The other flags (-MF -MG -MP
+        # -MT -MQ) are always used with -M/-MM.
+        } elsif ($line =~ /\s(?:-M|-MM)\b/) {
+            $dependency = 1;
         # Otherwise assume we are linking.
         } else {
             $link = 1;
         }
 
         # Otherwise assume we are linking.
         } else {
             $link = 1;
         }
 
+        # -MD/-MMD also cause dependency generation, but they don't imply -E!
+        if ($line =~ /\s(?:-MD|-MMD)\b/) {
+            $dependency      = 0;
+            $flag_preprocess = 0;
+        }
+
+        # Dependency generation for Makefiles, no preprocessing or other flags
+        # needed.
+        next if $dependency;
+
         # Get all file extensions on this line.
         my @extensions = $line =~ /$file_extension_regex/go;
         # Ignore all unknown extensions to speedup the search below.
         # Get all file extensions on this line.
         my @extensions = $line =~ /$file_extension_regex/go;
         # Ignore all unknown extensions to speedup the search below.
index f77809bc3ec6730bd7c9faab8416603a4fd0aa2f..bac71a1afb0b3125c8564b68dc0acfcdac9aad5f 100644 (file)
@@ -32,3 +32,8 @@ gcc -E test.c
 gcc test.c
 
 gcc -Wl,-z,relro -o test test-.cpp test-b.cpp.o
 gcc test.c
 
 gcc -Wl,-z,relro -o test test-.cpp test-b.cpp.o
+
+gcc -MD -c test.c
+gcc -MT -MD -MF test.d -c test.c
+gcc -MMD -c test.c
+gcc -MT -MMD -MF test.d -c test.c
index 180a64d81ec5dbe23ca1e7e6ed1543073d01676d..e863207e421282b44d68124ecd64a4fe04ca5974 100644 (file)
@@ -33,3 +33,6 @@ gcc -E -D_FORTIFY_SOURCE=2 test.c
 gcc -Wl,-z,relro -o test test.cpp.o
 
 command --cc test
 gcc -Wl,-z,relro -o test test.cpp.o
 
 command --cc test
+
+gcc -MM test.c > test.d
+gcc -MM -MT test.d test.c
index 3108c19c925f3bbaf0a42e11494e9e981ab6bb06..7fc4f9e534a11f8ab724623fd1577808de1ce9ed 100644 (file)
--- a/t/tests.t
+++ b/t/tests.t
@@ -111,6 +111,14 @@ CPPFLAGS missing (-D_FORTIFY_SOURCE=2): gcc test.c
 LDFLAGS missing (-Wl,-z,relro): gcc test.c
 CXXFLAGS missing (-g -O2 -fstack-protector --param=ssp-buffer-size=4 -Wformat -Wformat-security -Werror=format-security): gcc -Wl,-z,relro -o test test-.cpp test-b.cpp.o
 CPPFLAGS missing (-D_FORTIFY_SOURCE=2): gcc -Wl,-z,relro -o test test-.cpp test-b.cpp.o
 LDFLAGS missing (-Wl,-z,relro): gcc test.c
 CXXFLAGS missing (-g -O2 -fstack-protector --param=ssp-buffer-size=4 -Wformat -Wformat-security -Werror=format-security): gcc -Wl,-z,relro -o test test-.cpp test-b.cpp.o
 CPPFLAGS missing (-D_FORTIFY_SOURCE=2): gcc -Wl,-z,relro -o test test-.cpp test-b.cpp.o
+CFLAGS missing (-g -O2 -fstack-protector --param=ssp-buffer-size=4 -Wformat -Wformat-security -Werror=format-security): gcc -MD -c test.c
+CPPFLAGS missing (-D_FORTIFY_SOURCE=2): gcc -MD -c test.c
+CFLAGS missing (-g -O2 -fstack-protector --param=ssp-buffer-size=4 -Wformat -Wformat-security -Werror=format-security): gcc -MT -MD -MF test.d -c test.c
+CPPFLAGS missing (-D_FORTIFY_SOURCE=2): gcc -MT -MD -MF test.d -c test.c
+CFLAGS missing (-g -O2 -fstack-protector --param=ssp-buffer-size=4 -Wformat -Wformat-security -Werror=format-security): gcc -MMD -c test.c
+CPPFLAGS missing (-D_FORTIFY_SOURCE=2): gcc -MMD -c test.c
+CFLAGS missing (-g -O2 -fstack-protector --param=ssp-buffer-size=4 -Wformat -Wformat-security -Werror=format-security): gcc -MT -MMD -MF test.d -c test.c
+CPPFLAGS missing (-D_FORTIFY_SOURCE=2): gcc -MT -MMD -MF test.d -c test.c
 ';
 is_blhc 'bad', '--pie', 8,
         'CFLAGS missing (-fPIE -fstack-protector --param=ssp-buffer-size=4 -Wformat -Wformat-security -Werror=format-security): gcc -g -O2 -c test-a.c
 ';
 is_blhc 'bad', '--pie', 8,
         'CFLAGS missing (-fPIE -fstack-protector --param=ssp-buffer-size=4 -Wformat -Wformat-security -Werror=format-security): gcc -g -O2 -c test-a.c
@@ -141,6 +149,14 @@ LDFLAGS missing (-fPIE -pie -Wl,-z,relro): gcc test.c
 CXXFLAGS missing (-g -O2 -fPIE -fstack-protector --param=ssp-buffer-size=4 -Wformat -Wformat-security -Werror=format-security): gcc -Wl,-z,relro -o test test-.cpp test-b.cpp.o
 CPPFLAGS missing (-D_FORTIFY_SOURCE=2): gcc -Wl,-z,relro -o test test-.cpp test-b.cpp.o
 LDFLAGS missing (-fPIE -pie): gcc -Wl,-z,relro -o test test-.cpp test-b.cpp.o
 CXXFLAGS missing (-g -O2 -fPIE -fstack-protector --param=ssp-buffer-size=4 -Wformat -Wformat-security -Werror=format-security): gcc -Wl,-z,relro -o test test-.cpp test-b.cpp.o
 CPPFLAGS missing (-D_FORTIFY_SOURCE=2): gcc -Wl,-z,relro -o test test-.cpp test-b.cpp.o
 LDFLAGS missing (-fPIE -pie): gcc -Wl,-z,relro -o test test-.cpp test-b.cpp.o
+CFLAGS missing (-g -O2 -fPIE -fstack-protector --param=ssp-buffer-size=4 -Wformat -Wformat-security -Werror=format-security): gcc -MD -c test.c
+CPPFLAGS missing (-D_FORTIFY_SOURCE=2): gcc -MD -c test.c
+CFLAGS missing (-g -O2 -fPIE -fstack-protector --param=ssp-buffer-size=4 -Wformat -Wformat-security -Werror=format-security): gcc -MT -MD -MF test.d -c test.c
+CPPFLAGS missing (-D_FORTIFY_SOURCE=2): gcc -MT -MD -MF test.d -c test.c
+CFLAGS missing (-g -O2 -fPIE -fstack-protector --param=ssp-buffer-size=4 -Wformat -Wformat-security -Werror=format-security): gcc -MMD -c test.c
+CPPFLAGS missing (-D_FORTIFY_SOURCE=2): gcc -MMD -c test.c
+CFLAGS missing (-g -O2 -fPIE -fstack-protector --param=ssp-buffer-size=4 -Wformat -Wformat-security -Werror=format-security): gcc -MT -MMD -MF test.d -c test.c
+CPPFLAGS missing (-D_FORTIFY_SOURCE=2): gcc -MT -MMD -MF test.d -c test.c
 ';
 is_blhc 'bad', '--bindnow', 8,
         'CFLAGS missing (-fstack-protector --param=ssp-buffer-size=4 -Wformat -Wformat-security -Werror=format-security): gcc -g -O2 -c test-a.c
 ';
 is_blhc 'bad', '--bindnow', 8,
         'CFLAGS missing (-fstack-protector --param=ssp-buffer-size=4 -Wformat -Wformat-security -Werror=format-security): gcc -g -O2 -c test-a.c
@@ -170,6 +186,14 @@ LDFLAGS missing (-Wl,-z,relro -Wl,-z,now): gcc test.c
 CXXFLAGS missing (-g -O2 -fstack-protector --param=ssp-buffer-size=4 -Wformat -Wformat-security -Werror=format-security): gcc -Wl,-z,relro -o test test-.cpp test-b.cpp.o
 CPPFLAGS missing (-D_FORTIFY_SOURCE=2): gcc -Wl,-z,relro -o test test-.cpp test-b.cpp.o
 LDFLAGS missing (-Wl,-z,now): gcc -Wl,-z,relro -o test test-.cpp test-b.cpp.o
 CXXFLAGS missing (-g -O2 -fstack-protector --param=ssp-buffer-size=4 -Wformat -Wformat-security -Werror=format-security): gcc -Wl,-z,relro -o test test-.cpp test-b.cpp.o
 CPPFLAGS missing (-D_FORTIFY_SOURCE=2): gcc -Wl,-z,relro -o test test-.cpp test-b.cpp.o
 LDFLAGS missing (-Wl,-z,now): gcc -Wl,-z,relro -o test test-.cpp test-b.cpp.o
+CFLAGS missing (-g -O2 -fstack-protector --param=ssp-buffer-size=4 -Wformat -Wformat-security -Werror=format-security): gcc -MD -c test.c
+CPPFLAGS missing (-D_FORTIFY_SOURCE=2): gcc -MD -c test.c
+CFLAGS missing (-g -O2 -fstack-protector --param=ssp-buffer-size=4 -Wformat -Wformat-security -Werror=format-security): gcc -MT -MD -MF test.d -c test.c
+CPPFLAGS missing (-D_FORTIFY_SOURCE=2): gcc -MT -MD -MF test.d -c test.c
+CFLAGS missing (-g -O2 -fstack-protector --param=ssp-buffer-size=4 -Wformat -Wformat-security -Werror=format-security): gcc -MMD -c test.c
+CPPFLAGS missing (-D_FORTIFY_SOURCE=2): gcc -MMD -c test.c
+CFLAGS missing (-g -O2 -fstack-protector --param=ssp-buffer-size=4 -Wformat -Wformat-security -Werror=format-security): gcc -MT -MMD -MF test.d -c test.c
+CPPFLAGS missing (-D_FORTIFY_SOURCE=2): gcc -MT -MMD -MF test.d -c test.c
 ';
 my $bad_pie_bindnow =
         'CFLAGS missing (-fPIE -fstack-protector --param=ssp-buffer-size=4 -Wformat -Wformat-security -Werror=format-security): gcc -g -O2 -c test-a.c
 ';
 my $bad_pie_bindnow =
         'CFLAGS missing (-fPIE -fstack-protector --param=ssp-buffer-size=4 -Wformat -Wformat-security -Werror=format-security): gcc -g -O2 -c test-a.c
@@ -200,6 +224,14 @@ LDFLAGS missing (-fPIE -pie -Wl,-z,relro -Wl,-z,now): gcc test.c
 CXXFLAGS missing (-g -O2 -fPIE -fstack-protector --param=ssp-buffer-size=4 -Wformat -Wformat-security -Werror=format-security): gcc -Wl,-z,relro -o test test-.cpp test-b.cpp.o
 CPPFLAGS missing (-D_FORTIFY_SOURCE=2): gcc -Wl,-z,relro -o test test-.cpp test-b.cpp.o
 LDFLAGS missing (-fPIE -pie -Wl,-z,now): gcc -Wl,-z,relro -o test test-.cpp test-b.cpp.o
 CXXFLAGS missing (-g -O2 -fPIE -fstack-protector --param=ssp-buffer-size=4 -Wformat -Wformat-security -Werror=format-security): gcc -Wl,-z,relro -o test test-.cpp test-b.cpp.o
 CPPFLAGS missing (-D_FORTIFY_SOURCE=2): gcc -Wl,-z,relro -o test test-.cpp test-b.cpp.o
 LDFLAGS missing (-fPIE -pie -Wl,-z,now): gcc -Wl,-z,relro -o test test-.cpp test-b.cpp.o
+CFLAGS missing (-g -O2 -fPIE -fstack-protector --param=ssp-buffer-size=4 -Wformat -Wformat-security -Werror=format-security): gcc -MD -c test.c
+CPPFLAGS missing (-D_FORTIFY_SOURCE=2): gcc -MD -c test.c
+CFLAGS missing (-g -O2 -fPIE -fstack-protector --param=ssp-buffer-size=4 -Wformat -Wformat-security -Werror=format-security): gcc -MT -MD -MF test.d -c test.c
+CPPFLAGS missing (-D_FORTIFY_SOURCE=2): gcc -MT -MD -MF test.d -c test.c
+CFLAGS missing (-g -O2 -fPIE -fstack-protector --param=ssp-buffer-size=4 -Wformat -Wformat-security -Werror=format-security): gcc -MMD -c test.c
+CPPFLAGS missing (-D_FORTIFY_SOURCE=2): gcc -MMD -c test.c
+CFLAGS missing (-g -O2 -fPIE -fstack-protector --param=ssp-buffer-size=4 -Wformat -Wformat-security -Werror=format-security): gcc -MT -MMD -MF test.d -c test.c
+CPPFLAGS missing (-D_FORTIFY_SOURCE=2): gcc -MT -MMD -MF test.d -c test.c
 ';
 is_blhc 'bad', '--pie --bindnow', 8,
         $bad_pie_bindnow;
 ';
 is_blhc 'bad', '--pie --bindnow', 8,
         $bad_pie_bindnow;