Search code examples
cdockerfilepreprocessor

c preprocessor for templating - suppress extra artefacts


Command :

% cat <<EOF | cpp -DVERBOSE=3
#if VERBOSE >= 2
  printf("trace message");
#endif
EOF

Output :

# 1 "<stdin>"
# 1 "<built-in>" 1
# 1 "<built-in>" 3
# 362 "<built-in>" 3
# 1 "<command line>" 1
# 1 "<built-in>" 2
# 1 "<stdin>" 2

  printf("trace message");

Anyone know how to suppress those lines such as # 1 "<stding>" 2, I need to include some instructions like # dockerfile syntax=experiemental in the input Dockerfile.


Solution

  • how to suppress those lines such as # 1 "" 2

    From gcc manual:

    -P

    Inhibit generation of linemarkers in the output from the preprocessor. This might be useful when running the preprocessor on something that is not C code, and will be sent to a program which might be confused by the linemarkers.

    cpp -P ...