Iterating over lists in Makefiles?

后端 未结 6 1525
一整个雨季
一整个雨季 2020-12-31 11:45

I find I\'m writing a lot of Makefiles that could be cleaned up with the use of n-tuple lists. But I can\'t find any way to do this properly (and cleanly). So far I

6条回答
  •  再見小時候
    2020-12-31 12:04

    You can use default rules for a set of files with the same extension as in for compiling each c file to an o. Of course you are not restricted to any special file extensions. For compiling a set of .c files you could do it like this:

    OBJS = foo.o bar.o baz.o
    OUT = myprog
    
    all: $(OBJS)
            $(SILENT) echo "LD $@"
            $(SILENT) $(CPP) -o $(OUT) $^ $(LDFLAGS)
    
    %.o: %.c
            $(SILENT) echo "CC $<"
            $(SILENT) $(CC) $(CCOPTS) -o $@ -c $<
    

提交回复
热议问题