define の部分で、ファイルの存在確認と、ファイルがない場合の取得処理を
マクロ化することにより、ちょっとだけすっきりさせることができる。
Makefile まだまだ知らないこと多いなぁ。
PROG = prog
CC = /usr/bin/gcc
CFLAGS = -g -DDEBUG -Wall -Wmissing-prototypes -Wmissing-declarations
OBJS = main.o source1.o source2.o source3.o
SRCS = $(OBJS:.o=.c)
FGET = scp -q
ORIGIN = source-host.example.com:/path/to/sources/
.SUFFIXES: .c .o
.PHONY: all clean
define get-file
if test ! -f $1; then \
$(FGET) $(ORIGIN)$1 .; \
else :; fi
endef
all: $(PROG)
$(PROG): $(OBJS)
$(CC) $(LDFLAGS) -o $@ $(OBJS)
$(SRCS):
.c.o:
@$(call get-file,$<)
@headers=`$(CC) -MG -MM $< | sed 's/$*.o: $<//g'`; \
for h in $$headers; do \
$(call get-file,$$h) \
done
$(CC) $(CFLAGS) $(CPPFLAGS) -c $< -o $@;
clean:
-rm -f $(PROG) *.o *.c *.h *core *~
0 件のコメント:
コメントを投稿