如何编译 Makefile 插件?
How to compile a Makefile plugin?
我正在尝试编译 Makefile 文档中给出的插件示例 (https://www.gnu.org/software/make/manual/make.html):
#include <stdlib.h>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <unistd.h>
#include <errno.h>
#include <gnumake.h>
int plugin_is_GPL_compatible;
char *
gen_tmpfile(const char *nm, int argc, char **argv)
{
int fd;
/* Compute the size of the filename and allocate space for it. */
int len = strlen (argv[0]) + 6 + 1;
char *buf = gmk_alloc (len);
strcpy (buf, argv[0]);
strcat (buf, "XXXXXX");
fd = mkstemp(buf);
if (fd >= 0)
{
/* Don't leak the file descriptor. */
close (fd);
return buf;
}
/* Failure. */
fprintf (stderr, "mkstemp(%s) failed: %s\n", buf, strerror (errno));
gmk_free (buf);
return NULL;
}
int
mk_temp_gmk_setup ()
{
/* Register the function with make name "mk-temp". */
gmk_add_function ("mk-temp", gen_tmpfile, 1, 1, 1);
return 1;
}
但是当运行下面一行:gcc -c mk_temp.c -fPIC,
我收到以下错误消息:
mk_temp.c:8:21: fatal error: gnumake.h: No such file or directory
我在我的电脑上找不到这个文件。我什至下载了 Makefile 3.8.1(与我安装的 Makefile 版本相同)源,但两者都不存在。
有人知道如何获取此文件或我做错了什么吗?
谢谢,
安德烈斯
v3.81 太旧了。 gnumake.h
出现在 GNU make 4.0
我正在尝试编译 Makefile 文档中给出的插件示例 (https://www.gnu.org/software/make/manual/make.html):
#include <stdlib.h>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <unistd.h>
#include <errno.h>
#include <gnumake.h>
int plugin_is_GPL_compatible;
char *
gen_tmpfile(const char *nm, int argc, char **argv)
{
int fd;
/* Compute the size of the filename and allocate space for it. */
int len = strlen (argv[0]) + 6 + 1;
char *buf = gmk_alloc (len);
strcpy (buf, argv[0]);
strcat (buf, "XXXXXX");
fd = mkstemp(buf);
if (fd >= 0)
{
/* Don't leak the file descriptor. */
close (fd);
return buf;
}
/* Failure. */
fprintf (stderr, "mkstemp(%s) failed: %s\n", buf, strerror (errno));
gmk_free (buf);
return NULL;
}
int
mk_temp_gmk_setup ()
{
/* Register the function with make name "mk-temp". */
gmk_add_function ("mk-temp", gen_tmpfile, 1, 1, 1);
return 1;
}
但是当运行下面一行:gcc -c mk_temp.c -fPIC, 我收到以下错误消息:
mk_temp.c:8:21: fatal error: gnumake.h: No such file or directory
我在我的电脑上找不到这个文件。我什至下载了 Makefile 3.8.1(与我安装的 Makefile 版本相同)源,但两者都不存在。
有人知道如何获取此文件或我做错了什么吗?
谢谢, 安德烈斯
v3.81 太旧了。 gnumake.h
出现在 GNU make 4.0