I have 4 files: definitions.h devices.h devices.cpp and main.cpp
can anyone help me write a makefile for these files? thanks
how do I create a makefile
Page 1 of 11 Replies - 95 Views - Last Post: 07 February 2012 - 05:34 AM
Topic Sponsor:
Replies To: how do I create a makefile
#2
Re: how do I create a makefile
Posted 07 February 2012 - 05:34 AM
A quick manual makefile to compile this looks something like this:
The basic principle is, you declare for every rule what it depends on. This can either be a file or another rule in the makefile to create what it depends on. Now whenever a file changes everything that depends on that file directly or indirectly will be recompiled but nothing more. i.e.: When devices.cpp changes it will be recompiled, but main.cpp won't be.
It does get hard to track these changes manually, so people use a lot of tricks/macros to make this easier. When that became hard to track, people started using scripts to write it for them, these are today further developed and known as autotools. When people realized that these scripts were becoming a mess and they could do better, they started writing alternatives like cmake/qmake/scons/... . I don't think any of those has much improved things, just laying down your options if you ever need something for a bigger project.
program: main.o devices.o g++ -oprogram main.o devices.o main.o: main.cpp definitions.h g++ -c -omain.o main.cpp devices.o: devices.cpp devices.h definitions.h g++ -c -odevices.o devices.cpp clean: rm -rf program main.o devices.o
The basic principle is, you declare for every rule what it depends on. This can either be a file or another rule in the makefile to create what it depends on. Now whenever a file changes everything that depends on that file directly or indirectly will be recompiled but nothing more. i.e.: When devices.cpp changes it will be recompiled, but main.cpp won't be.
It does get hard to track these changes manually, so people use a lot of tricks/macros to make this easier. When that became hard to track, people started using scripts to write it for them, these are today further developed and known as autotools. When people realized that these scripts were becoming a mess and they could do better, they started writing alternatives like cmake/qmake/scons/... . I don't think any of those has much improved things, just laying down your options if you ever need something for a bigger project.
This post has been edited by Karel-Lodewijk: 07 February 2012 - 05:35 AM
Page 1 of 1
|
|

New Topic/Question
Reply



MultiQuote



|