rizsotto / Bear

Bear is a tool that generates a compilation database for clang tooling.
GNU General Public License v3.0
4.63k stars 306 forks source link

Question - how to capture built in compiler options #579

Open wonk-andy opened 3 weeks ago

wonk-andy commented 3 weeks ago

I am trying to use Bear 3.1.4 to generate the compile_commands.json file from a Makefile based project which cross compiles for QNX on a Linux host. The compile command line for one of the source files is:

aarch64-unknown-nto-qnx7.0.0-gcc -std=gnu99 -MMD -MP -Iinclude -o build/1.01.00/src/iMX8.o -c src/iMX8.c

The output for this file that is captured says:

  {
    "arguments": [
      "/opt/tools/qnx700/host/linux/x86_64/usr/bin/aarch64-unknown-nto-qnx7.0.0-gcc",
      "-std=gnu99",
      "-Iinclude",
      "-c",
      "-o",
      "build/1.01.00/src/iMX8.o",
      "src/iMX8.c"
    ],
    "directory": "/opt/samba/customers/xxxx/GetMacAddr",
    "file": "/opt/samba/customers/xxxx/GetMacAddr/src/iMX8.c",
    "output": "/opt/samba/customers/xxxx/GetMacAddr/build/1.01.00/src/iMX8.o"
  }

There are other built-in compiler options that it isn't capturing, for example the compiler defines __QNX__ which is used for conditional compilation within the source files. How do I capture this, and any other, built in variable?

-Andy.

rizsotto commented 3 weeks ago

Hey Andy,

The compilation database is capturing the compiler calls only. Compiler internals are not presented in the output.

Compiler specific variables are not easy to mimic with other compilers. OS specific defines can be placed into a common header, but might interfere with the host header files.