I wanted to share a makefile that I have been using for multifile C projects that produce a single binary program. I included a simple hello world example so that it’s easy to test this out.
The way it works is you list all your .c files in
SOURCES=main.c greet.c and it makes targets that compile them into .o object files. It also has a target called
main which links all the objects together to make the final program.
If you change one of the .c files it will recompile just that one object file before linking them all together to rebuild the binary. This helps a good fast workflow.
Hope it’s useful! I have been using this as a base for most of my projects. It can be used for other languages than C too if you edit it a little.