I'm a student in computer engineering and I have yet another C program to implement. Until now I always create a new Makefile from my previous projects and this take time to setup every time. Is there a Makefile canvas I could use that is so powerful that all I would need to provide is the name of the c files containing a main function?
My idea would be that for each new project, I create a folder containing that Makefile
, a bin folder and an src folder. I would then edit some variables to the Makefile (the C files containing a main()
function) and then make
would automatically build everything up, taking dependencies into account.
Do you know if such a Makefile
exists?
[edit via Alexandre C.] : Automake/Autoconf are overkills for these kind of projects which use only standards libraries and run on standard unix os'. For the projects we need to implement, dependencies (for the files to be linked) can always be deduces from the ".h" includes and there is generally very few files involved.
The closest to a magical and perfect Makefile
is to use the de facto standard for portable C programs and libraries: Automake.
As an example lifted from this page, this is the example of what you would add to Makefile.am:
bin_PROGRAMS = zardoz
zardoz_SOURCES = main.c head.c float.c vortex9.c gun.c
zardoz_LDADD = $(LIBOBJS)
The equivalent of a make target which we are adding here is called zardoz
. The sources are specified under zardoz_SOURCES
and any additional libraries which need to be linked are specified under zardoz_LDADD
. You do not need to specify where the main
function lives, because the linker will automatically find this at the linking stage. If it is not present, the link will simply fail.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With