Reputation: 139
How can I have it so that when I run make
that:
prog.s
is created then prog
is created if prog.s
and prog
does not existprog.s
is created if prog.s
is newer than prog.c
(eg. after manually modifying prog.s
)prog.s
then prog
is created if prog.c
is newer than prog
In other words, have make
create the files it needs to build prog
, if the dependencies have been modified
My current makefile:
CC = gcc
CFLAGS =
TARGET = prog
all: $(TARGET).s $(TARGET).c
$(TARGET).c: $(TARGET).s
$(CC) $(CFLAGS) $(TARGET).s -o $(TARGET)
$(TARGET).s:
$(CC) $(CFLAGS) -S -o $(TARGET).s $(TARGET).c
clean:
$(RM) $(TARGET)
$(RM) $(TARGET).s
It works if I have:
prog.c
prog.s
but does not work if I have manually modified prog.c
(make: Nothing to be done for 'all'.
)
Upvotes: 1
Views: 147
Reputation: 10982
You define your target: source
in the reversed order. For instance, your assembly code depends on your C code, you must write:
$(TARGET).s: $(TARGET).c
however, you have written (wrong order)
$(TARGET).c: $(TARGET).s
Here is the version with the right order for "target: sources" :
CC = gcc
CFLAGS =
TARGET = prog
all: $(TARGET)
$(TARGET): $(TARGET).s
$(CC) $(CFLAGS) $(TARGET).s -o $(TARGET)
$(TARGET).s: $(TARGET).c
$(CC) $(CFLAGS) -S -o $(TARGET).s $(TARGET).c
clean:
$(RM) $(TARGET)
$(RM) $(TARGET).s
Upvotes: 3