Search code examples
c++makefilegnu

MakeFile for C++ project


I wrote my own makefile -Which will be used to compile my C++ project-

But I had some issues with it:

  1. I need to delete all temporary files; objects, executables and those for UNIX

    I did the first two like this; but how may I implement the latter?

    clean:

     rm -f $(OBJS) $(EXEC)
    
  2. I need to zip all files in a test.zip folder using tar command in the folder where makefile is -including it-), how may I do that?

    tar:


Solution

  • You want to delete all "temporary files", but a temporary file is a file that people don't intend to keep very long. There is no way for a tool like Make to know people's intentions without being told.

    To create a zipped archive of Makefile and test.zip/ from the command line, you can use a command like:

    tar -czvf archive.tgz Makefile test.zip
    

    You can put that in a rule in the makefile like this:

    archive.tgz:
        tar -czvf archive.tgz Makefile test.zip
    

    Further refinements are possible, once you have this much working correctly.