Results 1 to 6 of 6

Thread: How do I get QMAKE_CLEAN to delete a directory?

  1. #1
    Join Date
    Jun 2007
    Posts
    19
    Thanks
    1
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default How do I get QMAKE_CLEAN to delete a directory?

    Is there a trick to getting QMAKE_CLEAN, or actually QMAKE_DISTCLEAN, to remove a directory? The generated Makefile has a DEL_DIR command, but everything in QMAKE_CLEAN gets tagged with DEL_FILE.

    I would actually expect qmake to remove directories declared with, for example OBJECTS_DIR, when running "make distclean". But I would settle for a workaround.

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: How do I get QMAKE_CLEAN to delete a directory?

    make distclean should remove any directory that is created by running qmake, including OBJECTS_DIR. At least that's the case on Linux/gcc. Make clean won't do that as it only cleans temporary files.

  3. The following user says thank you to wysota for this useful post:

    fnmblot (28th September 2007)

  4. #3
    Join Date
    Jun 2007
    Posts
    19
    Thanks
    1
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: How do I get QMAKE_CLEAN to delete a directory?

    Oops, forgot to mention this under Windows. I havn't had a chance to check it on Linux yet.

    There are a fair number of generated files that do not get deleted with "make distclean". I've added them to QMAKE_DISTCLEAN, it's just the directories that are left behind now. In Unix, rm will remove directories. In Windows, del will not remove directories. The generated Makefile has

    Qt Code:
    1. DEL_FILE = del
    2. DEL_DIR = rmdir
    To copy to clipboard, switch view to plain text mode 

    But the make clean section only uses DEL_FILE. I've used the line below to take care of emptying the directories without a prompt, but it still leaves the empty directory behind.

    Qt Code:
    1. win32:QMAKE_DEL_FILE = del /q
    To copy to clipboard, switch view to plain text mode 

    I guess I'll go look for rm.exe and put that in there.

  5. #4
    Join Date
    Jun 2007
    Posts
    19
    Thanks
    1
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Talking Re: How do I get QMAKE_CLEAN to delete a directory?

    I got it working, with a small patch to qmake. I've submitted it as a bug, since the option QMAKE_DEL_DIR exists but is never used.

    For windows, it's in the file {QTDIR}\qmake\generators\win32\winmakefile.cpp

    For version 4.3.1 it's at line 490, replace the distclean block with this one :

    Qt Code:
    1. t << "distclean: clean";
    2. {
    3. const char *clean_targets[] = { "QMAKE_DISTCLEAN", 0 };
    4. for(int i = 0; clean_targets[i]; ++i) {
    5. const QStringList &list = project->values(clean_targets[i]);
    6. const QString del_statement("-$(DEL_FILE)");
    7. const QString del_dir_statement("-$(DEL_DIR)");
    8.  
    9. if(project->isActiveConfig("no_delete_multiple_files")) {
    10. for(QStringList::ConstIterator it = list.begin(); it != list.end(); ++it)
    11. t << "\n\t" << del_statement << " " << escapeFilePath((*it));
    12. } else {
    13. QString files, file;
    14.  
    15. const int commandlineLimit = 2047; // NT limit, expanded
    16. for(QStringList::ConstIterator it = list.begin(); it != list.end(); ++it) {
    17. if ( (*it).endsWith("/") )
    18. {
    19. QString s = (*it);
    20. dirs += escapeFilePath(s.remove(s.size()-1, 1));
    21. }
    22. else
    23. {
    24. file = " " + escapeFilePath((*it));
    25. if(del_statement.length() + files.length() +
    26. qMax(fixEnvVariables(file).length(), file.length()) > commandlineLimit) {
    27. t << "\n\t" << del_statement << files;
    28. files.clear();
    29. }
    30. files += file;
    31. }
    32. }
    33. if(!files.isEmpty())
    34. t << "\n\t" << del_statement << files;
    35. if(!dirs.isEmpty())
    36. foreach(QString dir, dirs)
    37. t << "\n\t" << del_dir_statement << " " << dir;
    38. }
    39. }
    40. }
    To copy to clipboard, switch view to plain text mode 

    This allows the following to work in a .pro file (as I expect it to) :

    Qt Code:
    1. QMAKE_DISTCLEAN += object_script.* bin/ build/
    2. win32:QMAKE_DEL_FILE = del /q
    3. win32:QMAKE_DEL_DIR = rmdir /s /q
    To copy to clipboard, switch view to plain text mode 

    Any file listed in QMAKE_DISTCLEAN that ends with a "/" will be get the QMAKE_DEL_DIR command, while anything without a "/" at the end gets the QMAKE_DEL_FILE command as it previously did.

  6. The following user says thank you to Chuk for this useful post:

    elcuco (30th September 2007)

  7. #5
    Join Date
    Jun 2010
    Posts
    10
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: How do I get QMAKE_CLEAN to delete a directory?

    Hi..

    In Qt 4.7 the QMAKE_DEL_DIR can delete my temp created files ?
    Last edited by MaikoID; 31st March 2011 at 18:34.

  8. #6
    Join Date
    Dec 2011
    Posts
    2
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: How do I get QMAKE_CLEAN to delete a directory?

    Got around this problem with a :

    unix:QMAKE_DISTCLEAN += -r dir1 dir2
    win32:QMAKE_DISTCLEAN += /s /f /q dir1 dir2 && rd /s /q dir1 dir2

    Not very pretty, but does the job.

Similar Threads

  1. qt-3.3.8 fail in scratchbox
    By nass in forum Installation and Deployment
    Replies: 0
    Last Post: 25th May 2007, 16:21
  2. error in compiling qtopia.....
    By sar_van81 in forum Qt for Embedded and Mobile
    Replies: 3
    Last Post: 11th January 2007, 10:10
  3. errors while installing Qt4.2 in Linux
    By nimmyj in forum Installation and Deployment
    Replies: 11
    Last Post: 13th December 2006, 12:58
  4. c++, placement delete upon exception
    By stinos in forum General Programming
    Replies: 6
    Last Post: 31st October 2006, 16:38
  5. Am I the only one with "make" error ?
    By probine in forum Installation and Deployment
    Replies: 1
    Last Post: 13th February 2006, 13:54

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.