当宏更改时强制 erl -make 重新编译文件

发布于 2024-09-26 15:20:20 字数 1698 浏览 1 评论 0原文

我尝试做类似的事情 如何将 Makefile 中的两个不同源目录输出到一个 bin 目录?,所以我有这些文件(相对于我的项目根目录):

Emakefile:
% EMakefile
% -*- mode: erlang -*-
{["src/*", "src/*/*", "src/*/*/*"],
 [{i, "include"}, {outdir, "ebin"}, debug_info]}.

test/Emakefile:
% EMakefile
% -*- mode: erlang -*-
{["../src/*", "../src/*/*", "../src/*/*/*"],
 [{i, "../include"}, {outdir, "../ebin"}, debug_info, {d, 'TEST'}]}.

Makefile:
EPATH=-pa ebin

all: before_compile
    erl -make

all_test: before_compile
    cd test
    erl -make
    cd ..

before_compile: mk_ebin copy_sqlite create_db copy_config copy_dot_app

test: all_test
    erl -noshell $(EPATH) \
        -s tests run \
        -s init stop
    rm -f ct.db

clean:
    rm -fv ebin/*

... dependencies of before_compile

问题是运行 make test 不会重新编译任何已使用 make 编译的模块。似乎 erl -make 并不关心它们是在没有定义 TEST 的情况下编译的,它只是检查模块本身是否比梁文件旧。如何强制它重新编译(并在不需要时避免重新编译)?

更新:奇怪的是,在make clean之后立即运行make all_test时,似乎使用了./Emakefile test/Emakefile:我得到了

Recompile: src/tests
Recompile: src/server_protocol_client

等等,并且没有测试,而是

Recompile: ../src/tests
Recompile: ../src/server_protocol_client

通过执行 cd test; 得到了测试; erl -make 手动。知道为什么吗?无论如何,我通过删除 test/Emakefile 并替换 Makefile 中的 all_test 解决了这个问题:

all_test: before_compile
    erl -noshell -eval "make:all([{d, 'TEST'}])." -s init stop

I tried to do something similar to How to make two different source directories in a Makefile output to one bin directory?, so I have these files (relative to my project root):

Emakefile:
% EMakefile
% -*- mode: erlang -*-
{["src/*", "src/*/*", "src/*/*/*"],
 [{i, "include"}, {outdir, "ebin"}, debug_info]}.

test/Emakefile:
% EMakefile
% -*- mode: erlang -*-
{["../src/*", "../src/*/*", "../src/*/*/*"],
 [{i, "../include"}, {outdir, "../ebin"}, debug_info, {d, 'TEST'}]}.

Makefile:
EPATH=-pa ebin

all: before_compile
    erl -make

all_test: before_compile
    cd test
    erl -make
    cd ..

before_compile: mk_ebin copy_sqlite create_db copy_config copy_dot_app

test: all_test
    erl -noshell $(EPATH) \
        -s tests run \
        -s init stop
    rm -f ct.db

clean:
    rm -fv ebin/*

... dependencies of before_compile

The problem is that running make test doesn't recompile any modules which are already compiled with make. It seems erl -make doesn't care that they were compiled without TEST defined, it just checks that the modules themselves are older than beam-files. How do I force it to recompile (and avoid recompilation when it isn't needed)?

UPDATE: Strangely, when running make all_test immediately after make clean, it appears that ./Emakefile is used instead of test/Emakefile: I am getting

Recompile: src/tests
Recompile: src/server_protocol_client

etc. and no tests instead of

Recompile: ../src/tests
Recompile: ../src/server_protocol_client

which I get by doing cd test; erl -make manually. Any idea why? Anyway, I've fixed this problem by removing test/Emakefile and replacing all_test in Makefile:

all_test: before_compile
    erl -noshell -eval "make:all([{d, 'TEST'}])." -s init stop

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

青春有你 2024-10-03 15:20:20
all_test: before_compile
    cd test
    erl -make
    cd ..

这是不正确的。每条生产线都有自己的生产流程。这样做:

all_test: before_compile
    cd test; \
    erl -make
all_test: before_compile
    cd test
    erl -make
    cd ..

This is incorrect. Each line produces its own process. Do such:

all_test: before_compile
    cd test; \
    erl -make
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文