我正在学习如何编写Makefile,并想创建一个Makefile,它可以根据给定的参数从多个来源创建多个目标。
这是我到目前为止尝试过的:
# Compiler and others
CC=gcc
# Flags
CFLAGS = -g -c -Wall -DLOGFILE -D_REENTRANT
target1_EXEC = ../build/target1
target2_EXEC = ../build/target2
target1_SRC = ../source/target1
target2_SRC = ../source/target2
target1: TARGET=target1
target1: all
target2: TARGET=target2
target2: all
EXEC=$($(TARGET)_EXEC)
SRC=$($(TARGET)_SRC)
OBJ=$(SRC:.c=.o)
all: $(EXEC)
$(EXEC): $(OBJ)
$(CC) $(INCLUDES) -o $@ $^ $(LDFLAGS) $(LIBS)
%.o: %.c
$(CC) -o $@ -c $< $(CFLAGS)
我想以目标为参数调用生成文件:
makefile target1
但随后似乎找不到子目标:
make: Nothing to be done for 'target1'.
我在做什么错了?