我想制作一个带有 PATH 参数的模块化 makefile,但我不知道如何。
这是我之前的:
CC=
CFLAGS=-c -stack-protect
LDFLAGS=
SOURCES=
SSOURCES=
OBJECTS=$(SOURCES:.cpp=.o)
SOBJECTS=$(SSOURCES:.s=.o)
DEBUGFLAGS=-g -DDEBUG
EXECUTABLE=
all: CC += -DNDEBUG
all: $(SOURCES) $(SSOURCES) $(EXECUTABLE)
$(EXECUTABLE): $(OBJECTS) $(SOBJECTS)
$(CC) $(LDFLAGS) $(OBJECTS) $(SOBJECTS) -o $@
.cpp.o:
$(CC) $(CFLAGS) $< -o $@
.s.o:
$(CC) $(CFLAGS) $< -o $@
debug: CFLAGS += $(DEBUGFLAGS)
debug: $(SOURCES) $(SSOURCES) $(LDFLAGS) $(EXECUTABLE)
$(CC) $(LDFLAGS) $(OBJECTS) $(SOBJECTS) -o $(EXECUTABLE)
clean:
rm -rf *o $(OBJECTS) $(SOBJECTS)
这就是我或多或少想做的事情:
PATH=
CC=
CFLAGS=-c -stack-protect
LDFLAGS=
SOURCES=./src1 ./src1
SSOURCES=./src1 ./src2
FSOURCES=$(SOURCES:./=$(PATH))
FSSOURCES=$(SSOURCES:./=$(PATH))
OBJECTS=$(SOURCES:.cpp=.o)
SOBJECTS=$(SSOURCES:.s=.o)
DEBUGFLAGS=-g -DDEBUG
EXECUTABLE=
all: CC += -DNDEBUG
all: $(FSOURCES) $(FSSOURCES) $(EXECUTABLE)
$(EXECUTABLE): $(OBJECTS) $(SOBJECTS)
$(CC) $(LDFLAGS) $(OBJECTS) $(SOBJECTS) -o $@
.cpp.o:
$(CC) $(CFLAGS) $< -o $@
.s.o:
$(CC) $(CFLAGS) $< -o $@
debug: CFLAGS += $(DEBUGFLAGS)
debug: $(FSOURCES) $(FSSOURCES) $(LDFLAGS) $(EXECUTABLE)
$(CC) $(LDFLAGS) $(OBJECTS) $(SOBJECTS) -o $(EXECUTABLE)
clean:
rm -rf *o $(OBJECTS) $(SOBJECTS)
我怎样才能使这项工作?