Makefile: Avoid explicit list of directories in clean target
PATCH 1/1 Makefile: Avoid explicit list of directories in clean target
Avoid having an explicit list of directories in the 'clean' target by using 'find' to remove all .o and .d files instead.
---
I figured that (unlike Makefile.target) we should probably take the xargs route here since otherwise the rm command line is huge...
There's also an argument that there's not much point having a clean target in Makefile.target when this one blows away most of it anyway.
Makefile | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-)
Makefile +2 -5
@@ -212,13 +212,10 @@ clean: # avoid old build problems by removing potentially incorrect old files rm -f config.mak op-i386.h opc-i386.h gen-op-i386.h op-arm.h opc-arm.h gen-op-arm.h rm -f qemu-options.def - rm -f *.o *.d *.a *.lo $(TOOLS) $(HELPERS-y) qemu-ga TAGS cscope.* *.pod *~ */*~ + find . -name '*.[od]' | xargs rm -f + rm -f *.a *.lo $(TOOLS) $(HELPERS-y) qemu-ga TAGS cscope.* *.pod *~ */*~ rm -Rf .libs - rm -f slirp/*.o slirp/*.d audio/*.o audio/*.d block/*.o block/*.d net/*.o net/*.d fsdev/*.o fsdev/*.d ui/*.o ui/*.d qapi/*.o qapi/*.d qga/*.o qga/*.d - rm -f qom/*.o qom/*.d - rm -f usb/*.o usb/*.d hw/*.o hw/*.d rm -f qemu-img-cmds.h - rm -f trace/*.o trace/*.d rm -f trace-dtrace.dtrace trace-dtrace.dtrace-timestamp @# May not be present in GENERATED_HEADERS rm -f trace-dtrace.h trace-dtrace.h-timestamp
Signature · 1 line
1.7.9.5
Quoted 8 lines · Peter Maydell
Avoid having an explicit list of directories in the 'clean' target by using 'find' to remove all .o and .d files instead.
Signed-off-by Peter Maydell <[email protected]>---
I figured that (unlike Makefile.target) we should probably take the xargs route here since otherwise the rm command line is huge...
Quoted 5 lines
There's also an argument that there's not much point having a clean target in Makefile.target when this one blows away most of it anyway.
Makefile | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-)
Looks fine but waiting for others to review in case there is a subtlety that affects some build environments.
Stefan
Quoted 19 lines · Peter Maydell
Avoid having an explicit list of directories in the 'clean' target by using 'find' to remove all .o and .d files instead.
Signed-off-by Peter Maydell <[email protected]>---
I figured that (unlike Makefile.target) we should probably take the xargs route here since otherwise the rm command line is huge...There's also an argument that there's not much point having a clean target in Makefile.target when this one blows away most of it anyway.
Makefile | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-)Makefile +0
-0
Makefile clean: · line 216
Quoted 6 lines
Makefile +2
-1@@ -212,13 +212,10 @@ clean: # avoid old build problems by removing potentially incorrect old files rm -f config.mak op-i386.h opc-i386.h gen-op-i386.h op-arm.h opc-arm.h gen-op-arm.h rm -f qemu-options.def - rm -f *.o *.d *.a *.lo $(TOOLS) $(HELPERS-y) qemu-ga TAGS cscope.* *.pod *~ */*~ + find . -name '*.[od]' | xargs rm -f + rm -f *.a *.lo $(TOOLS) $(HELPERS-y) qemu-ga TAGS cscope.* *.pod *~ */*~
Shit happens if you somehow manage to create a "mean" file name in the build tree. Sure you don't want to -print0 | xargs -0?
Quoted 9 lines
Makefile +0
-4rm -Rf .libs - rm -f slirp/*.o slirp/*.d audio/*.o audio/*.d block/*.o block/*.d net/*.o net/*.d fsdev/*.o fsdev/*.d ui/*.o ui/*.d qapi/*.o qapi/*.d qga/*.o qga/*.d - rm -f qom/*.o qom/*.d - rm -f usb/*.o usb/*.d hw/*.o hw/*.d rm -f qemu-img-cmds.h - rm -f trace/*.o trace/*.d rm -f trace-dtrace.dtrace trace-dtrace.dtrace-timestamp @# May not be present in GENERATED_HEADERS rm -f trace-dtrace.h trace-dtrace.h-timestamp
Quoted 6 lines · Markus Armbruster
Makefile clean: · line 216
Quoted 2 lines · Peter Maydell
Makefile +2
-0+ find . -name '*.[od]' | xargs rm -f + rm -f *.a *.lo $(TOOLS) $(HELPERS-y) qemu-ga TAGS cscope.* *.pod *~ */*~Shit happens if you somehow manage to create a "mean" file name in the build tree. Sure you don't want to -print0 | xargs -0?
-print0 isn't POSIX, so I wasn't sure it would be present on all our platforms. (It's probably fairly safe, though...)
-- PMM
Quoted 11 lines · Peter Maydell
Quoted 7 lines · Markus Armbruster
Quoted 3 lines · Peter Maydell
+ find . -name '*.[od]' | xargs rm -f
+ rm -f *.a *.lo $(TOOLS) $(HELPERS-y) qemu-ga TAGS cscope.* *.pod *~ */*~Shit happens if you somehow manage to create a "mean" file name in the build tree. Sure you don't want to -print0 | xargs -0?
-print0 isn't POSIX, so I wasn't sure it would be present on all our platforms. (It's probably fairly safe, though...)
Another option is "-exec rm {} +".
Quoted 8 lines · Markus Armbruster
Quoted 6 lines · Peter Maydell
Quoted 5 lines · Markus Armbruster
Quoted 3 lines · Peter Maydell
+ find . -name '*.[od]' | xargs rm -f
+ rm -f *.a *.lo $(TOOLS) $(HELPERS-y) qemu-ga TAGS cscope.* *.pod *~ */*~
Quoted 7 lines
Quoted 5 lines
Quoted 2 lines
Shit happens if you somehow manage to create a "mean" file name in the build tree. Sure you don't want to -print0 | xargs -0?
-print0 isn't POSIX, so I wasn't sure it would be present on all our platforms. (It's probably fairly safe, though...)
Another option is "-exec rm {} +".
Isn't using 'find' somewhat overkill here really. QEMU only creates .o and .d files in 2 levels of directory, so sure we can just avoid find entirely
rm -f *.[od] */*.[od]
Daniel
Signature · 4 lines
|: http://berrange.com -o- http://www.flickr.com/photos/dberrange/ :| |: http://libvirt.org -o- http://virt-manager.org :| |: http://autobuild.org -o- http://search.cpan.org/~danberr/ :| |: http://entangle-photo.org -o- http://live.gnome.org/gtk-vnc :|
Quoted 5 lines · Daniel P. Berrange
Isn't using 'find' somewhat overkill here really. QEMU only creates .o and .d files in 2 levels of directory, so sure we can just avoid find entirely
rm -f *.[od] */*.[od]
That's exactly the bug this change is addressing (in a more general way than a couple of the proposed point fixes). There are subdirectories of hw/, so for instance we have a hw/usb/bus.o which your rm would not delete.
-- PMM
Am 31.07.2012 17:00, schrieb Peter Maydell:
Quoted 5 lines · Daniel P. Berrange
Quoted 4 lines
Isn't using 'find' somewhat overkill here really. QEMU only creates .o and .d files in 2 levels of directory, so sure we can just avoid find entirely
Quoted 8 lines
Quoted 1 line
rm -f *.[od] */*.[od]That's exactly the bug this change is addressing (in a more general way than a couple of the proposed point fixes). There are subdirectories of hw/, so for instance we have a
hw/usb/bus.owhich your rm would not delete.-- PMM
Yes, QEMU creates files in 3 levels. We could use
rm -f *.[od] */*.[od] */*/*.[od]
I suggest using the wrapper $(call quiet-command,...) to suppress printing of all removed file names.
For me, your patch using find would also be sufficient.
Only developers use "make clean", and they should know how to name files. Even if there are files with blanks in their name, in most cases nothing bad will happen (as long as they are not named "-rf .. .o" which would be the worst scenario I can imagine).
Regards,
Stefan W.
Quoted 6 lines · Stefan Weil
Yes, QEMU creates files in 3 levels. We could use
rm -f *.[od] */*.[od] */*/*.[od]I suggest using the wrapper $(call quiet-command,...) to suppress printing of all removed file names.
My worry was not so much what we print as that we might be exceeding the total command line length limits on some systems (whether you did it this way or via "rm -f $(find ...)").
-- PMM
Am 31.07.2012 17:51, schrieb Peter Maydell:
Quoted 8 lines · Stefan Weil
Quoted 6 lines
Yes, QEMU creates files in 3 levels. We could use
rm -f *.[od] */*.[od] */*/*.[od]I suggest using the wrapper $(call quiet-command,...) to suppress printing of all removed file names.
Quoted 6 lines
My worry was not so much what we print as that we might be exceeding the total command line length limits on some systems (whether you did it this way or via "rm -f $(find ...)").
-- PMM
That's quite possible:
$ find -name "*.[od]"|wc 4862 4862 151329 $ ls *.[od] */*.[od] */*/*.[od] */*/*/*.[od] */*/*/*/*.[od]|wc 4862 4862 141605
(I was somewhat surprised to see that we use 5 levels of directories).
The command line would be more than 140000 characters which is indeed very long.
Separating .o and .d files and the levels reduces that number:
$ ls *.o|wc
80 80 952
$ ls */*.o|wc
819 819 20048
$ ls */*/*.o|wc
1406 1406 45573
$ ls */*/*/*.o|wc
87 87 2579
$ ls */*/*/*/*.o|wc
16 16 796The 2nd and the 3rd level are potentially critical, but they could be split up further if needed.
What about removing support for in-tree builds? For out-of-tree builds 'make distclean' is nearly trivial.
-- Stefan W.
Quoted 45 lines · Stefan Weil
Am 31.07.2012 17:51, schrieb Peter Maydell:
Quoted 11 lines · Stefan Weil
Quoted 7 lines
Yes, QEMU creates files in 3 levels. We could use
rm -f *.[od] */*.[od] */*/*.[od]I suggest using the wrapper $(call quiet-command,...) to suppress printing of all removed file names.
Quoted 6 lines
My worry was not so much what we print as that we might be exceeding the total command line length limits on some systems (whether you did it this way or via "rm -f $(find ...)").
-- PMM
That's quite possible:
$ find -name "*.[od]"|wc 4862 4862 151329 $ ls *.[od] */*.[od] */*/*.[od] */*/*/*.[od] */*/*/*/*.[od]|wc 4862 4862 141605(I was somewhat surprised to see that we use 5 levels of directories).
The command line would be more than 140000 characters which is indeed very long.
Separating .o and .d files and the levels reduces that number:
$ ls *.o|wc 80 80 952 $ ls */*.o|wc 819 819 20048 $ ls */*/*.o|wc 1406 1406 45573 $ ls */*/*/*.o|wc 87 87 2579 $ ls */*/*/*/*.o|wc 16 16 796
Quoted 5 lines
The 2nd and the 3rd level are potentially critical, but they could be split up further if needed.
What about removing support for in-tree builds? For out-of-tree builds 'make distclean' is nearly trivial.
We could also recommend out of tree build for those hosts which have command line restrictions (can they be detected?). Even better, always warn if in tree build is detected.
Quoted 4 lines
-- Stefan W.
Quoted 6 lines · Markus Armbruster
Quoted 3 lines · Peter Maydell
Avoid having an explicit list of directories in the 'clean' target by using 'find' to remove all .o and .d files instead.
Quoted 7 lines
Makefile clean: · line 216
Quoted 4 lines
Makefile +2
-1rm -f qemu-options.def - rm -f *.o *.d *.a *.lo $(TOOLS) $(HELPERS-y) qemu-ga TAGS cscope.* *.pod *~ */*~ + find . -name '*.[od]' | xargs rm -f + rm -f *.a *.lo $(TOOLS) $(HELPERS-y) qemu-ga TAGS cscope.* *.pod *~ */*~Shit happens if you somehow manage to create a "mean" file name in the build tree. Sure you don't want to -print0 | xargs -0?
Except that 'find -print0' and 'xargs -0' are both GNU extensions, not available everywhere. We may be requiring gmake and gcc, but are we also requiring GNU find?
The POSIX way to write this, without relying on extensions, is:
find . -name '*.[od]' -exec rm -f {} +
(although then you get into the arguments of whether 'find -exec {} +' is portable yet, even though it has now been required by POSIX for more than 4 years.)
Signature · 2 lines
Eric Blake [email protected] +1-919-301-3266 Libvirt virtualization library http://libvirt.org
Quoted 19 lines · Eric Blake
Quoted 6 lines · Markus Armbruster
Quoted 3 lines · Peter Maydell
Avoid having an explicit list of directories in the 'clean' target by using 'find' to remove all .o and .d files instead.
Quoted 7 lines
Makefile clean: · line 216
Quoted 4 lines
Makefile +2
-1rm -f qemu-options.def - rm -f *.o *.d *.a *.lo $(TOOLS) $(HELPERS-y) qemu-ga TAGS cscope.* *.pod *~ */*~ + find . -name '*.[od]' | xargs rm -f + rm -f *.a *.lo $(TOOLS) $(HELPERS-y) qemu-ga TAGS cscope.* *.pod *~ */*~Shit happens if you somehow manage to create a "mean" file name in the build tree. Sure you don't want to -print0 | xargs -0?
Except that 'find -print0' and 'xargs -0' are both GNU extensions, not available everywhere. We may be requiring gmake and gcc, but are we also requiring GNU find?
Quoted 7 lines
The POSIX way to write this, without relying on extensions, is:
find . -name '*.[od]' -exec rm -f {} +
(although then you get into the arguments of whether 'find -exec {} +' is portable yet, even though it has now been required by POSIX for more than 4 years.)
This portable approach seems reasonable. I have checked the find(1) man page on: FreeBSD, OpenBSD, Solaris 11, Mac OS X.
Let's give find -exec + a shot. If it breaks something then the folks who care can provide a buildslave to ensure their host platform continues to be supported in the future.
Stefan