1

我试图制作一个简单的 makefile,它将构建多个以 src 目录的子目录命名的工件。这是我的目录结构:

>find .
.
./makefile
./src
./src/binA
./src/binA/main.java
./src/binB
./src/binB/main.cpp
./src/binC
./src/binC/main.scala

这是我要使用的makefile。由于某种原因,当我在同一规则中同时使用模式和通配符时,二进制目标拒绝扩展其依赖关系

>cat makefile
dirs    :=      $(shell find src -mindepth 1 -type d)
all:    $(dirs:src/%=bin/%.exe)
        @echo $(dirs)
bin/%.exe:      src/%/*
        @echo "$@ <-- $^"

我知道 dirs 设置正确

src/binA src/binB src/binC

这是我得到的错误

>make
make: *** No rule to make target `bin/binA.exe', needed by `all'.  Stop.

我如何制定一个通用规则,将其依赖项正确扩展为基于其名称的子目录的内容

4

1 回答 1

0

我能够通过将规则匹配器更改为并在此之前bin/%.exe: $(wildcard src/%/*)添加一个来使其工作。.SECONDARYEXPANSION:

于 2013-09-14T03:45:28.860 回答