6

I was building a C automake project. Running "aclocal" is showing the following error.

 $ aclocal
 ' is already registered with AC_CONFIG_FILES./usr/src/ports/autoconf2.5/autoconf2.5-2.69-3.noarch/src/autoconf-2.69/lib/autoconf/status.m4:288: AC_CONFIG_FILES is 
 expanded from...
 configure.ac:890: the top level
 autom4te-2.69: /usr/bin/m4 failed with exit status: 1
 aclocal-1.15: error: echo failed with exit status: 1

I am using Cygwin on windows 10.

The configure.ac has the following from the line 886 to the end.

# ----------------------------------------------------------------------
# Create output files
#
echo $SLIM_VERSION > VERSION
AC_OUTPUT(Makefile \
      src/Makefile \
      src/genconfig \
      src/verifier/Makefile \
      src/utility/Makefile \
      src/test/Makefile \
      lib/Makefile \
      ext/Makefile \
      test/Makefile \
      test/system_check/Makefile \
      third_party/Makefile \
      third_party/zdelta-2.1/Makefile \
      third_party/google-perftools-1.8.3/Makefile \
      third_party/google-perftools-1.8.3/src/google/tcmalloc.h \
      third_party/google-perftools-1.8.3/src/windows/google/tcmalloc.h \
      doc/Makefile \
      doc/slim.1)

As suggested, I used "dos2unix" on every "*.am" files and "configure.ac", but running "make" is showing the following error.

configure.ac:596: the top level
cd ../.. && /bin/sh ./config.status third_party/zdelta-2.1/Makefile depfiles
config.status: creating third_party/zdelta-2.1/Makefile
config.status: executing depfiles commands
source='deflate.c' object='deflate.o' libtool=no \
DEPDIR=.deps depmode=none /bin/sh ../../depcomp \
gcc -DHAVE_CONFIG_H -I. -I../../src     -Wall -export-dynamic -O3  -fopenmp -c -o deflate.o deflate.c
../../depcomp:行2: $'\r': 未找到命令
../../depcomp:行5: $'\r': 未找到命令
../../depcomp:行10: $'\r': 未找到命令
../../depcomp:行15: $'\r': 未找到命令
../../depcomp:行20: $'\r': 未找到命令
../../depcomp:行25: $'\r': 未找到命令
../../depcomp:行27: $'\r': 未找到命令
../../depcomp:行64: 未预期的符号 `$'in\r'' 附近有语法错误
'./../depcomp:行64: `case "$depmode" in
make[2]: *** [Makefile:419:deflate.o] 错误 2
make[2]: 离开目录“/cygdrive/c/LaViT2_8_9/lmntal/slim-lightweight- 
hlground/third_party/zdelta-2.1”
make[1]: *** [Makefile:386:all-recursive] 错误 1
make[1]: 离开目录“/cygdrive/c/LaViT2_8_9/lmntal/slim-lightweight- 
hlground/third_party”
make: *** [Makefile:425:all-recursive] 错误 1

Here,

行2: $'\r': 未找到命令

means line 2: $'\r': cannot find the command

Could anyone help me fix this issue?

Charles Duffy
  • 280,126
  • 43
  • 390
  • 441
arslan
  • 2,034
  • 7
  • 34
  • 61
  • You have something wrong on or near line 890 of configure.ac. Please copy and paste lines 880 through 900, or so, of that file into the question. – zwol May 09 '18 at 15:28
  • If you have `grep`, the output of `grep AC_CONFIG_FILES configure.ac` would also be helpful. If you don't have `grep`, please try to get us that information (i.e. all of the lines in `configure.ac` on which the string `AC_CONFIG_FILES` appears) some other way. – zwol May 09 '18 at 15:29
  • @zwol I added the part of the configure.ac file. could you take a look at it. – arslan May 09 '18 at 15:34
  • Blech. I need to see more context. Can you provide a link to the source code of this program, which it sounds like you didn't write yourself? – zwol May 09 '18 at 15:34
  • @zwol the code is here: https://gitlab.com/alimjanyasin/slim-lightweight-hlground Yes, I did not write all of that but I extended the project, however never had to touch the configure before. – arslan May 09 '18 at 15:34
  • Looks likely that the files have CRLF newlines -- ie. that they're DOS text files, not UNIX files. Did you maybe use a Windows version of git to do the checkout? – Charles Duffy May 09 '18 at 15:35
  • 1
    If you open the file up in vim, run `:set fileformat=unix` and save it, does that fix things? – Charles Duffy May 09 '18 at 15:36
  • I'm looking at it. Meanwhile, here are some things for you to try: (1) If you are building from a tarball release, you should not need to run `aclocal` at all. Skip to the point in the build instructions where you run `./configure` and go from there. (2) If you are building from a VCS checkout, instead of running `aclocal` (and then `automake` and `autoconf` and `autoheader` and ...) yourself, run `autoreconf -iv`. – zwol May 09 '18 at 15:36
  • @zwol, ...unfortunately, which newlines git uses on checkout of text files is runtime-configurable, so looking at the repository doesn't provide a way to get a definitive answer re: what the OP has on disk. – Charles Duffy May 09 '18 at 15:37
  • 1
    @CharlesDuffy I was thinking of an entirely different set of potential problems than it seems you are. Your hypothesis explains the mangled error message and mine doesn't, though. – zwol May 09 '18 at 15:38
  • 1
    @arslan see also [Dealing with EOL characters in Cygwin Git and Git for Windows accessing the same repository](https://stackoverflow.com/questions/26407408/dealing-with-eol-characters-in-cygwin-git-and-git-for-windows-accessing-the-same); the lowest-effort workaround may to be use cygwin's own git to check out working trees you're going to be building and compiling with Cygwin tools, rather than using Git for Windows. – Charles Duffy May 09 '18 at 15:43
  • `$'\r'` is a CR character -- so this is still a DOS-newline issue. Fix remains the same. (That said, while in this case the answer *wasn't* invalidated -- editing questions in a way that invalidates prior correct answers is frowned on here; this is what tends to be called a "chameleon question"; see https://meta.stackoverflow.com/questions/332820/what-to-do-when-someone-answers-dont-be-a-chameleon-dont-be-a-vandal). – Charles Duffy May 09 '18 at 16:21

1 Answers1

16

It's effectively certain that your issue is caused by DOS newlines.

The giveaway is this error:

' is already registered with AC_CONFIG_FILES./usr/src/ports/autoconf2.5/autoconf2.5-2.69-3.noarch/src/autoconf-2.69/lib/autoconf/status.m4:288: AC_CONFIG_FILES is

The line beginning with ' is already registered with implies that the cursor was sent back to the beginning of the line partway through writing the line to the console -- the exact behavior of printing a string read from a DOS-format text file while it expecting it to be in UNIX format.


Configuring git to check out text files in UNIX format

git config --global core.autocrlf false
git config --global core.eol lf
Charles Duffy
  • 280,126
  • 43
  • 390
  • 441
  • 1
    Further evidence for this hypothesis: I don't see any duplicate AC_OUTPUT/AC_CONFIG_FILES entries in the full configure.ac, but the DOS newlines could also be preventing M4 from interpreting \-newline as intended, in which case the AC_OUTPUT construct shown in the question would be taken as containing many repetitions of a file named "\". – zwol May 09 '18 at 15:41
  • I am trying to install vim on cygwin, and try your suggestion. :) – arslan May 09 '18 at 15:43
  • If you don't already have vim, do you have `dos2unix`? It's also possible to use `tr` or other tools for the same purpose; see https://stackoverflow.com/questions/2613800/how-to-convert-dos-windows-newline-crlf-to-unix-newline-lf-in-a-bash-script for a whole bunch of possible tools. – Charles Duffy May 09 '18 at 15:44
  • 1
    @arslan You may need to convert all of the files in the `m4` directory, and all of the `Makefile.am` files throughout the project, as well as `configure.ac` itself. The command-line tool `dos2unix` may be easier to install than vim. – zwol May 09 '18 at 15:45
  • 2
    ...or use a Cygwin-native git to avoid having DOS newlines on your files in the first place. – Charles Duffy May 09 '18 at 15:46
  • used cygwin git to clone the project, and did not work. maybe dos2unix is the option I should try. – arslan May 09 '18 at 15:55
  • @CharlesDuffy dos2unix worked, hope "./configure" and "make" work as well. :) – arslan May 09 '18 at 15:59
  • re: cygwin clone not fixing the issue -- try setting `core.autocrlf` to `false` and `core.eol` to `lf` in your git configuration (as with `git config --global`). – Charles Duffy May 09 '18 at 16:20
  • @CharlesDuffy how can I set "core.autocrlf" to "false" and "core.elf" to "If". I am not very familiar with these. I also updated the question regarding to using "dos2unix". – arslan May 09 '18 at 16:21
  • `git config --global core.autocrlf false; git config --global core.eol lf` – Charles Duffy May 09 '18 at 16:23
  • @CharlesDuffy by doing these git settings, it worked. Thank you so much :) you saved the day. – arslan May 09 '18 at 17:17