Autotools Makefile 找不到源

Autotools Makefile cannot find sources

我正在尝试在我的 Yocto 项目中使用 autotools。与另一个用户合作,我能够让 bitbake 识别我的 autogen.shconfigure.acMakefile.am。我现在收到错误

make: *** No rule to make target 'main.c', needed by 'main.o'.  Stop.

我的树如下:

.
├── files
│   ├── MAIN_Application
│   │   ├── autogen.sh
│   │   ├── configure.ac
│   │   ├── include
│   │   │   ├── main.h
│   │   │   ├── scheduler.h
│   │   │   └── utilities
│   │   │       └── time_conversions.h
│   │   ├── Makefile.am
│   │   ├── project.yml
│   │   └── src
│   │       ├── main.c
│   │       ├── Makefile.am
│   │       ├── scheduler.c
│   │       └── utilities
|   |           ├── Makefile.am
│   │           └── time_conversions.c
│   └── services
│       └── mainapplication.service
└── mainapplication_0.0.bb

我的makefile.am如下:

AUTOMAKE_OPTIONS = foreign

CFLAGS = -Wall -pedantic -O2
include_HEADERS = main.h

bin_PROGRAMS = MAIN_Application
MAIN_Application_SOURCES = main.c

我认为我需要添加其他源文件。我不确定该怎么做。我是用 MAIN_Application_SOURCES 添加它们还是需要在每个子目录中添加 Makefile.am

编辑:将 添加到上一个问题。 编辑 2:我在每个目录中添加了一个 makefile.am。在 MAIN_Application 我有:

AUTOMAKE_OPTIONS = foreign
SUBDIRS = src
    

在 src 中我有:

AUTOMAKE_OPTIONS = foreign
bin_PROGRAMS = MAIN_Application
EVCC_Application_SOURCES = main.c scheduler.c time_conversions.c

这给出了一个新的错误:

| Making all in src
| /bin/bash: line 20: cd: src: No such file or directory
| make: *** [Makefile:332: all-recursive] Error 1
| ERROR: oe_runmake failed
            

编辑 3:如果我删除 src 和 include 文件夹,将所有内容放入一个文件夹(顶级),一切正常。这太丑了,我讨厌它。

.
├── files
│   ├── MAIN_Application
│   │   ├── autogen.sh
│   │   ├── configure.ac
│   │   ├── main.c
│   │   ├── main.h
│   │   ├── Makefile.am
│   │   ├── project.yml
│   │   ├── scheduler.c
│   │   ├── scheduler.h
│   │   ├── time_conversions.c
│   │   └── time_conversions.h
│   └── services
│       └── mainapplication.service
└── mainapplication_0.0.bb

必须有办法解决这个问题。

编辑 4:我试图将我的所有代码移动到 src 目录并在我的 makefile.am

中使用 SUBDIR
.
├── files
│   ├── MAIN_Application
│   │   ├── autogen.sh
│   │   ├── configure.ac
│   │   ├── include
│   │   ├── Makefile.am
│   │   ├── project.yml
│   │   ├── src
│   │   │   ├── main.c
│   │   │   ├── main.h
│   │   │   ├── Makefile.am
│   │   │   ├── scheduler.c
│   │   │   ├── scheduler.h
│   │   │   ├── time_conversions.c
│   │   │   └── time_conversions.h
│   │   └── test
│   │       ├── test_scheduler.c
│   │       └── test_time_conversions.c
│   └── services
│       └── mainapplication.service
└── mainapplication_0.0.bb

这会导致与 src no such file or directory 相同的错误。

configure.ac 有问题! 这是我的新文件夹结构

.
├── files
│   ├── MAIN_Application
│   │   ├── autogen.sh
│   │   ├── configure.ac
│   │   ├── include
│   │   │   ├── main.h
│   │   │   ├── scheduler.h
│   │   │   └── utilities
│   │   │       └── time_conversions.h
│   │   ├── Makefile.am
│   │   ├── project.yml
│   │   ├── src
│   │   │   ├── main.c
│   │   │   ├── Makefile.am
│   │   │   ├── scheduler.c
│   │   │   └── utilities
│   │   │       └── time_conversions.c
│   │   └── test
│   │       ├── test_scheduler.c
│   │       └── test_time_conversions.c
│   └── services
│       └── mainapplication.service
└── mainapplication_0.0.bb

我的顶级 Makefile.am 包含:

AUTOMAKE_OPTIONS = foreign
SUBDIRS =  src

我的 Makefile.am 在 src 包含

AUTOMAKE_OPTIONS = foreign
bin_PROGRAMS = MAIN_Application
MAIN_Application_SOURCES = main.c scheduler.c time_conversions.c

显然这些与我上面的问题并没有改变。在我的 configure.ac 中,我向 AC_CONFIG_FILES 添加了一项。此行更改自

AC_CONFIG_FILES([Makefile])

AC_CONFIG_FILES([Makefile src/Makefile])

任何时候你使用这样的子目录你都需要告诉自动工具。我通过在 GitHub 上搜索类似项目解决了这个问题,我找到了 this.

在这个项目中,他们有一个顶级生成文件,以及包含源文件的每个子目录中的一个生成文件。在他们的 configure.ac 中,他们还给出了每个 makefile 的路径!

I believe I need to add my other source files. What I am not sure is how to do so.

有不止一种方法可以做到这一点,但是无论如何,是的,您确实需要告诉 Automake 所有涉及的来源。根据您的操作方式,您可能需要的不仅仅是指定来源。

Do I add them with MAIN_Application_SOURCES or do I need to add a Makefile.am in each subdirectory?

对于问题中描述的项目,您可以并且可能应该将它们添加到 top-level Makefile.am 中的 MAIN_Application_SOURCES。在这种情况下,您可能不需要任何其他 Makefile.am 文件。您应该提供相对于包含 Makefile.am 的目录的路径,例如:

MAIN_Application_SOURCES = \
  src/main.c \
  src/scheduler.c \
  src/utilities/time_conversions.c

(没有必要使用上面的 one-per-line 格式,但我发现这比将多个文件名放在一行上更容易阅读和维护。)在这种情况下,您可能还想添加subdir-objects 到您的 AUTOMAKE_OPTIONS:

AUTOMAKE_OPTIONS = foreign subdir-objects

仅当您想要生成更多 Makefile 时才需要更多 Makefile.am 文件,这通常与递归 make.

相关联

此外,一个Makefile.am必须定义至少一个要构建的目标,而且我在整个项目中只看到一个自然目标(MAIN_Application)。您可以引入 so-called“便利库”作为子目录 make 的目标,但我不赞成这种方法,就此而言,大多数递归 make 的使用也不赞成。


另外,这个...

include_HEADERS = main.h

... 并不代表您可能认为的意思。它说文件 main.h(在当前目录中,或在当前目录中生成)应该由 make install 安装到 $(includedir)。它没有说明 main.h 与其他目标的关系。仍然在单个 top-level Makefile.am 的假设下工作,我认为你在这里想要的是完全不同的:

AM_CPPFLAGS = -I$(srcdir)/include

这将导致向编译器提供看似合适的 -I 选项。

假设您不需要 make dist 支持,并且您实际上不想将头文件安装为 make install 的一部分,则无需明确指定单独的头文件来汽车制造商。