patsubst on makefile

后端 未结 2 1910
耶瑟儿~
耶瑟儿~ 2020-12-28 22:35

I have to create different *.o files from a same set of *.c using various CFLAGS. I wanted to use patsubst to generate different *.o files from same *.c. I am doing somethin

2条回答
  •  再見小時候
    2020-12-28 23:23

    You can also use wild cards to specify all files in the directory.

    eg:

    #Generic Makefile.
    
    CC := g++
    
    LD := g++
    
    CFLAGS := -c
    
    LDFLAGS := -L -l \
    
               -L -l>libname> \
                ......................
    
    ifeq (${TARGETARCH}, debug)
    
      CFLAGS += -g -O0
    
    elif 
    
      CFLAGS += -O4 -DNDEBUG
    
    SRCFILES := $(wildcard *.cpp)
    
    OBJFILES := $(patsubst %.cpp, %.o, ${SRCFILES})
    
    
    all: main
    
    main: ${OBJFILES}
    
      @echo "[Linking]"$@
    
      ${LD} ${LDFLAGS} ${OBJFILES}
    
    %.o: %.cpp
    
      @echo "[Compiling]"$@
    
      ${CC} ${CFLAGS} $^ -o $@
    

提交回复
热议问题