Как включить макрос в распространенные макросы Autoconf? - PullRequest
0 голосов
/ 04 февраля 2019

Фон

Мне удается собрать прошивку и библиотеки для примерно полдюжины разных плат, которые используют один и тот же встроенный процессор.Поскольку все платы используют один и тот же процессор, существует значительная общая конфигурация (CC, CXX, CPPFLAGS, CFLAGS, CXXFLAGS, LDFLAGS и т. Д.) И рецепты.Для прошивки я использую пользовательские make-файлы, которые включают в себя общий файл конфигурации, который определяет все общие конфигурации и рецепты.Чтобы упростить установку библиотек и заголовков на компьютерах разработчиков, я использую инструменты GNU Autotools для библиотек.Однако между пользовательскими make-файлами и файлами Autotools GNU существует значительная дублирующая конфигурация, поэтому я переношу прошивку на GNU Autotools.

Objective

Я хочу иметь как можно меньше шаблонов,configure.ac для доски может выглядеть следующим образом:

AC_INIT([mppt], [0.1.0])
AM_INIT_AUTOMAKE([foreign subdir-objects -Wall -Werror])
: ${CC='arm-none-eabi-gcc -specs=nosys.specs'}
AC_PROG_CC
AM_PROG_CC_C_O
AC_CONFIG_FILES([Makefile])
AC_OUTPUT

A configure.ac для библиотеки может выглядеть следующим образом:

AC_INIT([gcc-arm-none-eabi-samples], [4.7+])
AM_INIT_AUTOMAKE([foreign subdir-objects -Wall -Werror])
: ${CXX='arm-none-eabi-g++ -specs=nosys.specs'}
AC_PROG_CXX
: ${CC='arm-none-eabi-gcc -specs=nosys.specs'}
AM_PROG_AS
m4_ifdef([AM_PROG_AR], [AM_PROG_AR])
AC_PROG_RANLIB
AC_PROG_CXX_C_O
AC_CONFIG_FILES([Makefile])
AC_OUTPUT

Существует много общегоКонфигурация между этими файлами.Я хотел бы иметь один файл в локальной директории include, который определяет макрос с общими макросами Autoconf:

AC_DEFUN([TIVASDK],
[AM_INIT_AUTOMAKE([foreign subdir-objects -Wall -Werror])
: ${CC='arm-none-eabi-gcc -specs=nosys.specs'}
AC_PROG_CC
: ${CXX='arm-none-eabi-g++ -specs=nosys.specs'}
AC_PROG_CXX
AM_PROG_AS
m4_ifdef([AM_PROG_AR], [AM_PROG_AR])
AC_PROG_RANLIB
AM_PROG_CC_C_O
AC_PROG_CXX_C_O
AC_CONFIG_FILES([Makefile])])

Затем я бы хотел упростить первый пример до следующего:

AC_INIT([mppt], [0.1.0])
TIVASDK
AC_OUTPUT

Это имеет ряд преимуществ помимо простоты.Если, например, разработчики MPPT внедрили C ++ в прошивку, в настоящее время полностью написанную на C, то им или мне не пришлось бы обновлять свои configure.ac.Если бы я внес изменения в набор инструментов, мне нужно было бы отправить обновление только в один репозиторий, а не почти на десять.

Проблема

Autoconf не понимает макрос так, как я быожидать.Существует несколько различных механизмов отказа.

expanded before it was required

См. этот ответ .

У меня есть скелетный проект, который я использую для тестирования,Его очень просто Makefile.am определяет ACLOCAL_AMFLAGS:

ACLOCAL_AMFLAGS = -I "$TIVASDK_HOME"/include

noinst_PROGRAMS = skel.axf

skel_axf_SOURCES = \
    src/main.cpp \
    src/abort.cpp

TIVASDK_HOME определено в ~/.profile.

См. этот вопрос .Его configure.ac использует макрос:

AC_INIT([skel], [0.1.0])
m4_define([TIVASDK_HOME], [esyscmd([printf "$TIVASDK_HOME"])])
AC_CONFIG_MACRO_DIR(TIVASDK_HOME[/include])
TIVASDK
AC_OUTPUT

Его autogen.sh строится вне дерева в build:

#!/bin/sh

autoreconf -vfi .. && \
  ../configure --prefix="$TIVASDK_HOME" --host=arm-none-eabi

Запуск autogen.sh дает следующее:

$ ./autogen.sh 
autoreconf: Entering directory `..'
autoreconf: configure.ac: not using Gettext
autoreconf: running: aclocal --force -I /home/matthew/github.gatech.edu/GTSR/tiva-sdk/include
configure.ac:4: warning: AC_REQUIRE: `AC_PROG_CC' was expanded before it was required
configure.ac:4: http://www.gnu.org/software/autoconf/manual/autoconf.html#Expanded-Before-Required
/home/matthew/github.gatech.edu/GTSR/tiva-sdk/include/tivasdk.m4:1: TIVASDK is expanded from...
configure.ac:4: the top level
configure.ac:4: warning: AC_REQUIRE: `AC_PROG_CC' was expanded before it was required
configure.ac:4: http://www.gnu.org/software/autoconf/manual/autoconf.html#Expanded-Before-Required
/home/matthew/github.gatech.edu/GTSR/tiva-sdk/include/tivasdk.m4:1: TIVASDK is expanded from...
configure.ac:4: the top level
autoreconf: configure.ac: tracing
configure.ac:4: warning: AC_REQUIRE: `AC_PROG_CC' was expanded before it was required
configure.ac:4: http://www.gnu.org/software/autoconf/manual/autoconf.html#Expanded-Before-Required
aclocal.m4:1173: TIVASDK is expanded from...
configure.ac:4: the top level
autoreconf: configure.ac: not using Libtool
autoreconf: running: /usr/bin/autoconf --force
configure.ac:4: warning: AC_REQUIRE: `AC_PROG_CC' was expanded before it was required
configure.ac:4: http://www.gnu.org/software/autoconf/manual/autoconf.html#Expanded-Before-Required
aclocal.m4:1173: TIVASDK is expanded from...
configure.ac:4: the top level
autoreconf: configure.ac: not using Autoheader
autoreconf: running: automake --add-missing --copy --force-missing
configure.ac:4: warning: AC_REQUIRE: `AC_PROG_CC' was expanded before it was required
configure.ac:4: http://www.gnu.org/software/autoconf/manual/autoconf.html#Expanded-Before-Required
aclocal.m4:1173: TIVASDK is expanded from...
configure.ac:4: the top level
configure.ac:4: installing './compile'
configure.ac:4: installing './install-sh'
configure.ac:4: installing './missing'
Makefile.am: installing './depcomp'
autoreconf: Leaving directory `..'
checking for a BSD-compatible install... /usr/bin/install -c
checking whether build environment is sane... yes
checking for arm-none-eabi-strip... arm-none-eabi-strip
checking for a thread-safe mkdir -p... /bin/mkdir -p
checking for gawk... gawk
checking whether make sets $(MAKE)... yes
checking whether make supports nested variables... yes
checking for style of include used by make... GNU
checking for arm-none-eabi-gcc... arm-none-eabi-gcc
checking whether we are using the GNU C compiler... no
checking whether arm-none-eabi-gcc accepts -g... no
checking for arm-none-eabi-gcc option to accept ISO C89... unsupported
checking whether arm-none-eabi-gcc understands -c and -o together... yes
checking dependency style of arm-none-eabi-gcc... gcc3
checking for arm-none-eabi-gcc... (cached) arm-none-eabi-gcc
checking whether the C compiler works... no
configure: error: in `/home/matthew/gatech.edu/sp2019/vip4602/tmp/skel/build':
configure: error: C compiler cannot create executables
See `config.log' for more details

command not found

Я догадывался, что AC_DEFUN по некоторым причинам расширяет некоторые макросы Autoconf.Я заменил AC_DEFUN на m4_define:

m4_define([TIVASDK],
[AM_INIT_AUTOMAKE([foreign subdir-objects -Wall -Werror])
: ${CC='arm-none-eabi-gcc -specs=nosys.specs'}
AC_PROG_CC
: ${CXX='arm-none-eabi-g++ -specs=nosys.specs'}
AC_PROG_CXX
AM_PROG_AS
AM_PROG_CC_C_O
AC_PROG_CXX_C_O
AC_CONFIG_FILES([Makefile])])

Запуск autogen.sh дает следующее:

$ ./autogen.sh 
autoreconf: Entering directory `..'
autoreconf: configure.ac: not using Gettext
autoreconf: running: aclocal --force -I /home/matthew/github.gatech.edu/GTSR/tiva-sdk/include
autoreconf: configure.ac: tracing
autoreconf: configure.ac: not using Libtool
autoreconf: running: /usr/bin/autoconf --force
autoreconf: configure.ac: not using Autoheader
autoreconf: configure.ac: not using Automake
autoreconf: Leaving directory `..'
../configure: line 1678: TIVASDK: command not found
configure: creating ./config.status

Кажется, что TIVASDK вообще не расширяется.Я попытался заменить m4_define на define безрезультатно.

Минимальный рабочий пример

Простое размещение определения макроса в configure.ac решает проблему:

m4_define([TIVASDK],
[AM_INIT_AUTOMAKE([foreign subdir-objects -Wall -Werror])
: ${CC='arm-none-eabi-gcc -specs=nosys.specs'}
AC_PROG_CC
: ${CXX='arm-none-eabi-g++ -specs=nosys.specs'}
AC_PROG_CXX
AM_PROG_AS
AM_PROG_CC_C_O
AC_PROG_CXX_C_O
AC_CONFIG_FILES([Makefile])])
AC_INIT([skel], [0.1.0])
TIVASDK
AC_OUTPUT

Запуск autogen.sh дает следующее:

$ ./autogen.sh 
autoreconf: Entering directory `..'
autoreconf: configure.ac: not using Gettext
autoreconf: running: aclocal --force -I /home/matthew/github.gatech.edu/GTSR/tiva-sdk/include
autoreconf: configure.ac: tracing
autoreconf: configure.ac: not using Libtool
autoreconf: running: /usr/bin/autoconf --force
autoreconf: configure.ac: not using Autoheader
autoreconf: running: automake --add-missing --copy --force-missing
configure.ac:12: installing './compile'
configure.ac:12: installing './install-sh'
configure.ac:12: installing './missing'
Makefile.am: installing './depcomp'
autoreconf: Leaving directory `..'
checking for a BSD-compatible install... /usr/bin/install -c
checking whether build environment is sane... yes
checking for arm-none-eabi-strip... arm-none-eabi-strip
checking for a thread-safe mkdir -p... /bin/mkdir -p
checking for gawk... gawk
checking whether make sets $(MAKE)... yes
checking whether make supports nested variables... yes
checking for arm-none-eabi-gcc... arm-none-eabi-gcc -specs=nosys.specs
checking whether the C compiler works... yes
checking for C compiler default output file name... a.out
checking for suffix of executables... 
checking whether we are cross compiling... yes
checking for suffix of object files... o
checking whether we are using the GNU C compiler... yes
checking whether arm-none-eabi-gcc -specs=nosys.specs accepts -g... yes
checking for arm-none-eabi-gcc -specs=nosys.specs option to accept ISO C89... none needed
checking whether arm-none-eabi-gcc -specs=nosys.specs understands -c and -o together... yes
checking for style of include used by make... GNU
checking dependency style of arm-none-eabi-gcc -specs=nosys.specs... gcc3
checking whether we are using the GNU C++ compiler... yes
checking whether arm-none-eabi-g++ -specs=nosys.specs accepts -g... yes
checking dependency style of arm-none-eabi-g++ -specs=nosys.specs... gcc3
checking dependency style of arm-none-eabi-gcc -specs=nosys.specs... gcc3
checking whether arm-none-eabi-g++ -specs=nosys.specs understands -c and -o together... yes
checking that generated files are newer than configure... done
configure: creating ./config.status
config.status: creating Makefile
config.status: executing depfiles commands

TL; DR

  • Почему AC_DEFUN пытается расширить AC_PROG_CC?
  • Почемумакрос, определенный в m4_define, кажется, не расширяется?
  • Почему макрос, определенный в configure.ac, ведет себя иначе, чем макрос, определенный в другом файле и включенный?

1 Ответ

0 голосов
/ 09 февраля 2019
  • Почему AC_DEFUN пытается расширить AC_PROG_CC?

Я не могу объяснить причину вашей ошибки.Я повторил это с вашим кодом, но не с аналогичным кодом, который я изначально пробовал.Похоже, здесь задействовано несколько факторов, в том числе наличие как AC_PROG_CC, так и AC_PROG_CXX вместе.

Однако, начиная с вашей первоначальной попытки, представленной в вопросе над заголовком «Проблема»,и на основе информации со страницы руководства Autoconf, на которую ссылается сообщение об ошибке, я смог решить проблему, просто позвонив AC_PROG_CC через AC_REQUIRE, а не напрямую:

AC_DEFUN([TIVASDK], [
AM_INIT_AUTOMAKE([foreign subdir-objects -Wall -Werror])
: ${CC='arm-none-eabi-gcc -specs=nosys.specs'}

# HERE:
AC_REQUIRE([AC_PROG_CC])

: ${CXX='arm-none-eabi-g++ -specs=nosys.specs'}
AC_PROG_CXX
# ...

Я нахожуКстати, по крайней мере в скелетном проекте нет причин определять или использовать макрос TIVASDK_HOME.ACLOCAL_AMFLAGS, определенный в Makefile.in, очевидно, достаточно.

Я не очень восхищен идеей использования переменной окружения для определения местоположения нужного макроса include-каталога, и пример не делает егоМне понятно, почему это полезно, но если вы продолжите с этим, тогда я призываю вас

  • использовать AC_ARG_VAR, чтобы задокументировать эту переменную и сделать ее драгоценной, И
  • действительно удалитьмакрос с тем же именем.
  • Почему макрос, определенный в m4_define, кажется, не расширяется?

Я предполагаю, что этобыло бы потому, что внешние макрофайлы не используются напрямую, а обрабатываются aclocal для генерации файла aclocal.m4, что и включается.Я думаю, вы обнаружите, что прямое m4_define, появляющееся за рамками любого определения макроса Autoconf, не было скопировано.

  • Почему макрос определен в configure.acведут себя иначе, чем макрос, определенный в другом файле и включенный?

Не думаю, что это так.Но макрос M4, определенный в configure.ac, безусловно, ведет себя не так, как определено в другом месте, и не включен.

...