在 Makefile.am 中调用 SED 获取源

发布于 2024-08-03 01:12:28 字数 2195 浏览 3 评论 0原文

我有 C++ 代码,需要在编译之前对其进行 sed 处理。如何将其放入 Makefile.am 中?

我尝试了典型的 makefile 设置,目标似乎不存在:

gentest.cc:

<块引用>

$(SED) -i "s|查找|替换|" gentest.cc

如果您对我为什么要这样做感兴趣,那是因为我用 python 编写了我的程序 (slider3.py),而我的伙伴用 C++ 编写了他的程序 (slider3.py) >gentest.cc)并且他需要打电话给我。我通过编辑 argv 然后使用 execv() 来完成此操作。

<代码>...{

char **argv2 = new char*[argc];

memset(argv2,0,sizeof(argv2));

argv2[0] = "__PREFIX__/bin/slider3.py";

memcpy(argv2 + 1, argv + 2, sizeof(char *) * (argc - 2));

int Oranges = execv(argv2[0], argv2);

printf("%s\n", strerror(oranges));

返回橙子;

<代码>} ...

我已经处理了将 #! 添加到 slider3.pychmod +x< /code> 使用不适用于 gentest.cc 的方法。我还处理了将 slider3.py 添加到安装的文件列表中。

EXTRA_DIST=testite.sh slider3_base.py

bin_SCRIPTS = slider3.py

CLEANFILES = $(bin_SCRIPTS)

slider3.py: slider3_base.py

<块引用>

rm -f slider3.py

echo "#! " $(PYTHON) > slider3.py

cat slider3_base.py >>> slider3.py

chmod +x slider3.py

gentestMakefile.am 中定义如下:

bin_PROGRAMS = gentest

gentest_SOURCES = gentest.cc

gentest_LDADD = libgen.a #../libsbsat.la $(LIBM)

这失败了在 make 期间运行(请注意 @ 模式已在 Makefile 中成功扩展):

gentest.cc:

<块引用>

<代码>$(SED) -i "s|__PREFIX__|@prefix@|" gentest.cc

对于如何在编译 gentest.cc 之前运行 sed 有什么想法吗?

I've got c++ code that needs a sed done to it prior to compilation. How do I place this into Makefile.am?

I tried the typical makefile setup and the target appears to not exist:

gentest.cc:

$(SED) -i "s|FIND|REPLACE|" gentest.cc

If you are interested as to why I want to do this, it's because I wrote my program (slider3.py) in python and my partner wrote his in c++ (gentest.cc) and his needs to call mine. I'm accomplishing this by editing the argv and then using execv().

... {

char **argv2 = new char*[argc];

memset(argv2,0,sizeof(argv2));

argv2[0] = "__PREFIX__/bin/slider3.py";

memcpy(argv2 + 1, argv + 2, sizeof(char *) * (argc - 2));

int oranges = execv(argv2[0], argv2);

printf("%s\n", strerror(oranges));

return oranges;

} ...

I've already handled getting the #! added to slider3.py and chmod +x by using the method that was not working for gentest.cc. I've also handled adding slider3.py to the list of files that get installed.

EXTRA_DIST=testite.sh slider3_base.py

bin_SCRIPTS = slider3.py

CLEANFILES = $(bin_SCRIPTS)

slider3.py: slider3_base.py

rm -f slider3.py

echo "#! " $(PYTHON) > slider3.py

cat slider3_base.py >> slider3.py

chmod +x slider3.py

gentest is defined this way in Makefile.am:

bin_PROGRAMS = gentest

gentest_SOURCES = gentest.cc

gentest_LDADD = libgen.a #../libsbsat.la $(LIBM)

And this fails to be run during make (note the @ pattern is successfully expanded in Makefile):

gentest.cc:

$(SED) -i "s|__PREFIX__|@prefix@|" gentest.cc

Any ideas on how to get sed to run before compiling gentest.cc?

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

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

发布评论

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

评论(3

羞稚 2024-08-10 01:12:28

不要使用就地 sed。

反而:

gentest_SOURCES = gentest-seded.cc

gentest-seded.cc : gentest.cc
    $(SED) "s|__PREFIX__|@prefix@|" 
lt; >$@

Don't use in-place sed.

Instead:

gentest_SOURCES = gentest-seded.cc

gentest-seded.cc : gentest.cc
    $(SED) "s|__PREFIX__|@prefix@|" 
lt; >$@
养猫人 2024-08-10 01:12:28

您是否曾经考虑过在 config.h 中使用 #define-ing 它(您正在使用 autotools,对吧?)或使用 -D 传递它编译时? sed 的情况实际上并非如此。

来自 Andrew Y 的回答的详细信息:

在您的 C++ 源代码中,指定:

argv2[0] = SCRIPTPREFIX "/bin/slider3.py";

然后使用

-DSCRIPTPREFIX='"/your/script/prefix"'

Have you ever considered #define-ing it in config.h (you're using autotools, right?) or passing it using -D when compiling? This is really not the case for sed.

The details from Andrew Y's answer:

in your C++ source, specify:

argv2[0] = SCRIPTPREFIX "/bin/slider3.py";

then compile with

-DSCRIPTPREFIX='"/your/script/prefix"'
疏忽 2024-08-10 01:12:28

您是否考虑过直接从 C++ 调用 Python 代码?这是一个关于使用boost调用python的教程来自 C++ 的函数。您在这里描述的方法似乎非常脆弱。

Have you considered calling the Python code directly from the C++? Here is a tutorial on using boost to call python functions from C++. The method you are describing here seems very brittle.

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