在 Makefile.am 中调用 SED 获取源
我有 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.py
和 chmod +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
gentest
在 Makefile.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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
不要使用就地 sed。
反而:
Don't use in-place sed.
Instead:
您是否曾经考虑过在 config.h 中使用
#define
-ing 它(您正在使用autotools
,对吧?)或使用-D
传递它编译时?sed
的情况实际上并非如此。来自 Andrew Y 的回答的详细信息:
在您的 C++ 源代码中,指定:
然后使用
Have you ever considered
#define
-ing it in config.h (you're usingautotools
, right?) or passing it using-D
when compiling? This is really not the case forsed
.The details from Andrew Y's answer:
in your C++ source, specify:
then compile with
您是否考虑过直接从 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.