Autoconf: dnl vs. #
Asked Answered
N

3

49

The Autoconfig manual states that comment lines can start with either dnl or #.

Is there any difference between them, any reason to use one rather than the other in any circumstance? Or is it purely a matter of taste?

Namedropper answered 30/7, 2010 at 12:7 Comment(0)
T
63

In configure.ac, lines commented with '#' that occur after AC_INIT will appear in the resulting configure script. dnl comments will not. One purpose of dnl is to discard unwanted newlines in an effort to make the configure script readable. Also, it is appropriate to use dnl comments to document an m4 macro; those comments make no sense in the configure script, since the m4 macro does not appear there, only its expansion.

Comments in Makefile.am are treated differently. Makefile.am is not processed by m4, but by automake, where the convention is to discard lines which begin with ## preceded only by whitespace. (Although ### comments carry through to the Makefile.in) Since Makefile.am is not processed by m4, 'dnl' does not introduce a comment.

Terzetto answered 31/7, 2010 at 10:29 Comment(5)
dnl stands for “Discard to Next Line” in case you're like me and must knowBewail
@JeffCharter: We, the Acronym Challenged, salute you!Psychologize
@Bewail I Googled, found this question, and upvote your comment because this is what I want to know!Beneficial
Manual gnu.org/software/m4/manual/m4-1.4.18/html_node/Dnl.htmlDramatic
^^ gnu.org/software/m4/manual/html_node/Dnl.html (upated as previous link is broken, documentaton now currently version independent) ^^Titbit
W
16

dnl is an m4 macro that discards all input that follows it on the same line (including the newline). # doesn't mean anything in m4, so it ends up in the target (Makefile?), in which it acts as a comment.

So the key difference is that dnl is a comment in the original source, whereas # becomes a comment in the generated file.

Wampler answered 30/7, 2010 at 12:12 Comment(2)
Erm... not quite, it seems to me after some tests. 1) I was referring to configure.in (and its target configure). 2) '#' comments in configure.in do not appear in configure. 3) '#' comments in Makefile.am do appear in the Makefile. 4) 'dnl' lines in Makefile.am do appear in the Makefile. 5) '##' comments in Makefile.am, on the other hand, do not appear in the Makefile.Namedropper
This is a good example of why the name 'configure.in' was deprecated in favor of 'configure.ac'. autoconf treats configure.ac differently that typical *.in input files. configure.ac is parsed by m4, but Makefile.am is not, nor are the input files used by configure to generate targets. So dnl is only a comment in configure.ac or in m4 macros defined in aclocal.m4, acinclude.m4, or elsewhere.Terzetto
C
0

As noted by others: use dnl for everything in configure.ac that is a "comment" for the configure.ac file and # for everything that you intend to go into the resulting configure script. One important thing here: dnl prevents all parsing (with the sole exception of dnl(, which can be seen in the following example:

# CHECKME: possibly drop AM_PROG_AR + build_aux/ar-lib
AM_PROG_AR
LT_INIT([dlopen win32-dll])

processed by autoconf leads to

possibly undefined macro: AM_PROG_AR If this token and others are legitimate, please use m4_pattern_allow. See the Autoconf documentation.

While

dnl CHECKME: possibly drop AM_PROG_AR + build_aux/ar-lib
AM_PROG_AR
LT_INIT([dlopen win32-dll])

works fine...
Lesson learned: never use a macro after # (wouldn't make sense to the user of the final configure script in any case) and in most cases use dnl in configure.ac. Also see Comments in m4 input.

Clasping answered 2/11, 2021 at 9:16 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.