Reputation: 1684
I've no experience at all with makefiles, but I managed to get mine working. However, when I modify a file and want the new version to get compiled again, I've just noticed that I need to delete de .o file generated previously to make the new compilation (otherwhise, I am told that nothing can be done).
Is there any option that can be added to a makefile to make it replace an old .o (only if it is an older version) with the new one? Or, at least, that's what I think my solution could be.
Thanks in advance,
Eduardo
PD: Here you have my Makefile, in case you need it.
todo: Sensor Control Lista
#Ficheros de los que depende
Sensor: Sensor.o semaforo.o memocomp.o colamsg.o
#Cómo crea esos ficheros
g++ Sensor.o semaforo.o memocomp.o colamsg.o -o Sensor -lrt -lpthread
Control: Control.o semaforo.o memocomp.o colamsg.o
g++ Control.o semaforo.o memocomp.o colamsg.o -o Control -lrt -lpthread
Lista: Lista.o semaforo.o memocomp.o colamsg.o
g++ Lista.o semaforo.o memocomp.o colamsg.o -o Lista -lrt -lpthread
#Compilación de cada uno de esos ficheros
Sensor.o: Sensor.cpp semaforo.hpp memocomp.hpp colamsg.hpp
g++ -c Sensor.cpp
Control.o: Control.cpp semaforo.hpp memocomp.hpp colamsg.hpp
g++ -c Control.cpp
Lista.o: Lista.cpp semaforo.hpp memocomp.hpp colamsg.hpp
g++ -c Lista.cpp
semaforo.o: semaforo.cpp semaforo.hpp
g++ -c semaforo.cpp
memocomp.o: memocomp.cpp memocomp.hpp
g++ -c memocomp.cpp
colamsg.o: colamsg.cpp colamsg.hpp
g++ -c colamsg.cpp
#Elimina los ficheros creados previamente por el usuario ****
clean:
rm /dev/shm/sem.1207*
rm /dev/shm/1207*
rm /dev/mqueue/1207*
Upvotes: 2
Views: 262
Reputation: 69884
Usage: make [options] [target] ...
Options:
-b, -m Ignored for compatibility.
-B, --always-make Unconditionally make all targets.
...etc
Upvotes: 1
Reputation: 96258
colamsg.o: colamsg.cpp colamsg.hpp
^target ^dependencies
As long as all the dependencies are listed for each target, you don't have to do anything.
Make will notice that the object file is out of date.
Upvotes: 0