makefile - 从源列表生成文件自动生成目标

标签 makefile

我有这个目录结构。

app/
   src
   include
   lib/
       src
   maincode/
           main.cc
           Makefile

我想从 makefile 中的源列表生成自动目标。所以我不必为每个文件编写规则。

例子
source=\
        ../src/a.cpp
        ../src/ab.cpp
        ../lib/src/b.cpp

我想写规则
%.o:%.cpp

这样我就不必为每个文件重复规则。
我怎么能做到这一点?

最佳答案

编辑: find 命令应该在 shell 变量内

如果您使用的是 Linux,我认为您可以使用:

SOURCES=$(shell find . -name *.cpp)
OBJECTS=$(SOURCES:%.cpp=%.o)

%.o: %.cpp
    <command to compile>

关于makefile - 从源列表生成文件自动生成目标,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5193648/

相关文章:

安卓NDK : build after added a new library module directly under jni/folder

java - 如何在项目的 makefile 中指定任何类的路径?

c - 系统的 Makefile

c - Libbson 和 MongoDB-C 驱动编译

C++ - 生成文件问题

Linux 中的 C 程序生成文件

Makefile(不区分大小写的目标)

linux - 制作 glib : . ./libtool: line 6003: cd: (libdir): No such file or directory

linux - 无法为 BeagleBone Debian 编译内核模块

command-line - 在makefile中定义默认值