what is the difference between 'make after make clean' and just 'make'?

there are C files in a directory and I have a makefile. I usually use makefile to compile. I have been wandering the role of the 'make clean' 'make clean' is just to remove files. Though I didn't use 'make clean', t he error and warning was shown up when there were something wrong. I cannot realize why I need to use 'make clean' whenever I change the source file.

2

2 Answers

make is a utility is to determine automatically which pieces of a large program need to be recompiled, and issue the commands to recompile them.

To prepare to use make, you must write a file called the makefile that describes the relationships among files in your program, and the states the commands for updating each file.

Once a suitable makefile exists, each time you change some source files, this simple shell command:

make 

suffices to perform all necessary recompilations. The make program uses the makefile data base and the last-modification times of the files to decide which of the files need to be updated.

We generally use make clean as a generic way to tell clean up the code.ie; remove all the compiled object files from the source code. You can name it as anything you like.

It's convention only. The convention is that clean will return you to a state where all you have is the "source" files. In other words, it gets rid of everything that can be built from something else (objects, executables, listings and so on).

So make clean ; make is expected to build everything from scratch. And, in fact, you'll often find a rule like:

rebuild: clean all

which will do both steps for you.

You should never have to do a clean unless you're wanting to (for example) copy just the source files somewhere. If you have to do so after editing a file, then your Makefile is not set up correctly.

And, if you make and get an error, you should get exactly the same error if you subsequently make without fixing said error.

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

You Might Also Like