【问题标题】:Makefile : Build in a separate directory treeMakefile : 在单独的目录树中构建
【发布时间】:2010-04-14 20:44:17
【问题描述】:

我的项目(一种解释性语言)有一个由多个文件组成的标准库,每个文件都将内置到一个 .so 动态库中,解释器将根据用户请求加载(使用导入指令)。 每个源文件都位于代表其“命名空间”的子目录中,例如:

构建过程必须创建一个“构建”目录,然后在每个文件编译时都必须在“构建”目录中创建其命名空间目录,例如在编译时

std/io/network/tcp.cc

他使用

运行 mkdir 命令
mkdir -p build/std/io/network

Makefile sn-p 是:

STDSRC=stdlib/std/hashing/md5.cc \
       stdlib/std/hashing/crc32.cc \
       stdlib/std/hashing/sha1.cc \
       stdlib/std/hashing/sha2.cc \
       stdlib/std/io/network/http.cc \
       stdlib/std/io/network/tcp.cc \
       stdlib/std/io/network/smtp.cc \
       stdlib/std/io/file.cc \
       stdlib/std/io/console.cc \
       stdlib/std/io/xml.cc \
       stdlib/std/type/reflection.cc \
       stdlib/std/type/string.cc \
       stdlib/std/type/matrix.cc \
       stdlib/std/type/array.cc \
       stdlib/std/type/map.cc \
       stdlib/std/type/type.cc \
       stdlib/std/type/binary.cc \
       stdlib/std/encoding.cc \
       stdlib/std/os/dll.cc \
       stdlib/std/os/time.cc \
       stdlib/std/os/threads.cc \
       stdlib/std/os/process.cc \
       stdlib/std/pcre.cc \
       stdlib/std/math.cc

STDOBJ=$(STDSRC:.cc=.so)

all: stdlib

stdlib: $(STDOBJ)

.cc.so: 
    mkdir -p `dirname $< | sed -e 's/stdlib/stdlib\/build/'`
    $(CXX) $< -o `dirname $< | sed -e 's/stdlib/stdlib\/build/'`/`basename $< .cc`.so $(CFLAGS) $(LDFLAGS)

我有两个问题:

1 - 问题是 make 命令,我真的不知道为什么,不检查文件是否被修改,无论如何都不会在所有文件上启动构建过程,所以如果我只需要构建一个文件,我必须全部构建它们或使用命令:

make path/to/single/file.so

有没有办法解决这个问题?

2 - 有什么方法可以以“更清洁”的方式做到这一点,而不必将所有构建目录与源代码一起分发?

谢谢

【问题讨论】:

    标签: makefile


    【解决方案1】:

    对于 1) 问题是您的规则的目标 (stdlib/something.so) 并不完全是规则所制定的 (build/something.so),因此 Make 始终认为它必须成为目标。这应该可以解决它(我正在使用 GNUMake):

    STDOBJ=$(patsubst stdlib%.cc,build%.so, $(STDSRC))
    
    all: stdlib
    
    stdlib: $(STDOBJ)
    
    build/%.so: stdlib/%.cc
        mkdir -p $(dir $@)
        $(CXX) $< -o $@ $(CFLAGS) $(LDFLAGS)
    

    对于 2) 我不确定你的意思。如果你想要你描述的构建目录结构,这个就可以了。

    【讨论】:

      猜你喜欢
      • 2019-07-14
      • 1970-01-01
      • 2020-08-16
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多