I am trying to remove all .o , .i , .asm , .d files stored in variables in this form :
OBJS := $(SRCS:.c=.o)
PP := $(SRCS:.c=.i)
ASM := $(SRCS:.c=.asm)
DEP := $(SRCS:.c=.d)
using this code :
SRCS = text1.c\
text2.c
OBJS :=$(SRCS:.c=.o)
PP := $(SRCS:.c =.i)
ASM := $(SRCS:.c =.asm)
DEP := $(SRCS:.c =.d)
.PHONY : clean
clean :
rm -f $(OBJS) $(PP) $(ASM) $(DEP)
but it only applies the .o to the $(OBJS) like this :
rm -f text1.o text2.o text1.c text2.c text1.c text2.c text1.c text2.c
I don't understand why it didn't replace *.c files with *.i or *.asm and so on .
I used this to solve it :
.PHONY: clean
clean:
rm -f *.o *.i *.asm *.d
but i am still learning "make" so i would like to know why the first is not working .. thank u in advance.
You cannot have spaces in after the equals otherwise it tries to match with the spaces in the name.
Here is a fixed version:
SRCS = text1.c text2.c
OBJS := $(SRCS:.c=.o)
PP := $(SRCS:.c=.i)
ASM := $(SRCS:.c=.asm)
DEP := $(SRCS:.c=.d)
# Note this does not match due to the extra space
PP2 := $(SRCS:.c =.i)
.PHONY : clean
clean :
rm -f $(OBJS) $(PP) $(ASM) $(DEP)