Writing a generic Makefile with GCC options
In the previous recipe, we learned that Make compiles a program using the
cc prog.c -o prog command. In this recipe, we will learn how to change that default command. To control the default command, we write a Makefile and place that file in the same directory as the source file.
Writing a generic Makefile for all your projects is an excellent idea since you can then enable
-pedantic for all files you compile. With these three options enabled, GCC will warn you about many more errors and irregularities in your code, making your programs better. That is what we will do in this recipe.
In this recipe, we will use the
circumference.c source code file that we wrote in the previous recipe. If you don't already have the file on your computer, you can download it from https://github.com/PacktPublishing/Linux-System-Programming-Techniques/blob/master/ch3/circumference.c.
How to do it…