bug-gnu-utils
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

How to Create Pattern Rule in GNUmake for Source from Multiple Places?


From: Hon-Chi Ng
Subject: How to Create Pattern Rule in GNUmake for Source from Multiple Places?
Date: 24 Oct 2001 22:16:13 -0700

Hi

I'm using GNUmake 3.79.1.

My C source files are scattered in multiple locations, and I want to
compile them in a single location.

How can I create pattern rule in GNUmake to ensure correct rule for
source-object dependency without explicitly write each rule?

E.g. in my GNUmakefile,

  SRC_FILES := /aaa/bbb/ccc/abc.c /ddd/eee/fff/def.c /ggg/hhh/iii/ghi.c

  OBJ_FILES := $(addsuffix .o,$(addprefix /tmp/,$(basename $(notdir 
$(SRC_FILES)))))

However, for the problem I need to solve, SRC_FILES may contain more
than 50 files, which I keep them in a file and cat them to SRC_FILES,
e.g.

  SRC_FILES := $(shell cat ./src_files)

So, the ugly and inefficient way is to explicitly write all the rules
one by one, e.g.

  /tmp/abc.o: /aaa/bbb/ccc/abc.c
         $(CC) -c $(CFLAGS) $< -o $@

  /tmp/def.o: /ddd/eee/fff/def.c
         $(CC) -c $(CFLAGS) $< -o $@

  /tmp/ghi.o: /ggg/hhh/iii/ghi.c
         $(CC) -c $(CFLAGS) $< -o $@

However, it becomes an impossible task when SRC_FILES contains more than
50 files.

Is there anyway to write a pattern rule for all the required rules
without explicitly writing them one by one?

I tried something like this, but it didn't work:

  /tmp/%.o: $(filter %.c,$(SRC_FILES))
         $(CC) -c $(CFLAGS) $< -o $@

I believe it is because the % in the RHS is treated as pattern for
filter to search SRC_FILES, not the stem for pattern matched.

Can I escape % for filter, so that the stem of pattern rule is used?

Your help is appreciated.

Thanks.

Hon-Chi



reply via email to

[Prev in Thread] Current Thread [Next in Thread]