Is Samba's compile_commands.json useful?

Martin Schwenke martin at meltin.net
Thu Sep 9 02:25:17 UTC 2021


I'm getting into the 21st century and attempting to use Emacs with LSP,
in particular with clangd.

If I use Samba's automatically generated (via
./configure [...] && make -j) compile_commands.json then clangd
generates way too many errors, apparently because it can't find any
include files. compile_commands.json contains very few details. For
example, here's what it has for replace.c:

  {
    "arguments": [
      "/usr/bin/gcc",
      "-D_SAMBA_BUILD_=4",
      "-DHAVE_CONFIG_H=1",
      "-MMD",
      "-D_GNU_SOURCE=1",
      "-D_XOPEN_SOURCE_EXTENDED=1",
      "-DHAVE_CONFIG_H=1",
      "../../lib/replace/replace.c",
      "-c",
      "-o/home/martins/samba/samba/bin/default/lib/replace/replace.c.2.o"
    ],
    "directory": "/home/martins/samba/samba/bin/default",
    "file": "../../lib/replace/replace.c"
  },

If I generate my own compile_commands.json via something like:

  ./configure [...] && bear -- make -j

then this file contains all of the options for compiling each file,
including -D, -I and -W options, which is what I expect.  This works
well with clangd.

Here's the snippet for replace.c:

  {
    "arguments": [
      "/usr/bin/x86_64-linux-gnu-gcc-10",
      "-D_SAMBA_BUILD_=4",
      "-DHAVE_CONFIG_H=1",
      "-D_GNU_SOURCE=1",
      "-D_XOPEN_SOURCE_EXTENDED=1",
      "-DHAVE_CONFIG_H=1",
      "-D_SAMBA_HOSTCC_",
      "-DDEVELOPER",
      "-DDEBUG_PASSWORD",
      "-fPIC",
      "-D__STDC_WANT_LIB_EXT1__=1",
      "-D_REENTRANT",
      "-DDEVELOPER",
      "-DDEBUG_PASSWORD",
      "-DCTDB_HELPER_BINDIR=\"/usr/local/samba/libexec/ctdb\"",
      "-DLOGDIR=\"/usr/local/samba/var/log\"",
      "-DCTDB_DATADIR=\"/usr/local/samba/share/ctdb\"",
      "-DCTDB_ETCDIR=\"/usr/local/samba/etc/ctdb\"",
      "-DCTDB_VARDIR=\"/usr/local/samba/var/lib/ctdb\"",
      "-DCTDB_RUNDIR=\"/usr/local/samba/var/run/ctdb\"",
      "-fstack-protector-strong",
      "-fstack-clash-protection",
      "-g",
      "-Wall",
      "-Wshadow",
      "-Wmissing-prototypes",
      "-Wmissing-field-initializers",
      "-Wformat-overflow=2",
      "-Wcast-align",
      "-Wcast-qual",
      "-fno-common",
      "-Werror=address",
      "-Werror=strict-prototypes",
      "-Wstrict-prototypes",
      "-Werror=write-strings",
      "-Wwrite-strings",
      "-Werror-implicit-function-declaration",
      "-Werror=pointer-arith",
      "-Wpointer-arith",
      "-Werror=declaration-after-statement",
      "-Wdeclaration-after-statement",
      "-Werror=return-type",
      "-Wreturn-type",
      "-Werror=uninitialized",
      "-Wuninitialized",
      "-Wimplicit-fallthrough",
      "-Werror=strict-overflow",
      "-Wstrict-overflow=2",
      "-Wformat=2",
      "-Wno-format-y2k",
      "-Wno-format-zero-length",
      "-Werror=format-security",
      "-Wformat-security",
      "-Werror=format",
      "-Werror",
      "-Wno-error=deprecated-declarations",
      "-Wno-error=tautological-compare",
      "-Wno-error=cast-align",
      "-Wno-error=discarded-qualifiers",
      "-Wno-error=cast-qual",
      "-Wno-error=missing-field-initializers",
      "-Wno-error=shadow",
      "-Wno-error=implicit-fallthrough",
      "-Wno-error=enum-compare",
      "-Wno-error=unused-but-set-variable",
      "-Wno-error=unused-const-variable",
      "-Wno-error=unused-variable",
      "-Wno-error=unused-result",
      "-DSTATIC_ROKEN_HOSTCC_MODULES=NULL",
      "-DSTATIC_ROKEN_HOSTCC_MODULES_PROTO=extern void __ROKEN_HOSTCC_dummy_module_proto(void)",
      "-Isource4/heimdal_build",
      "-I../../source4/heimdal_build",
      "-Isource4/heimdal/lib/roken",
      "-I../../source4/heimdal/lib/roken",
      "-Isource4/heimdal/include",
      "-I../../source4/heimdal/include",
      "-Isource4/heimdal_build/include",
      "-I../../source4/heimdal_build/include",
      "-Iinclude/public",
      "-I../../include/public",
      "-Isource4",
      "-I../../source4",
      "-Ilib",
      "-I../../lib",
      "-Isource4/lib",
      "-I../../source4/lib",
      "-Isource4/include",
      "-I../../source4/include",
      "-Iinclude",
      "-I../../include",
      "-Ilib/replace",
      "-I../../lib/replace",
      "-Ictdb/include",
      "-I../../ctdb/include",
      "-Ictdb",
      "-I../../ctdb",
      "-I.",
      "-I../..",
      "../../source4/heimdal_build/replace.c",
      "-c",
      "-o/home/martins/samba/samba/bin/default/source4/heimdal_build/replace.c.3.o"
    ],
    "directory": "/home/martins/samba/samba/bin/default",
    "file": "/home/martins/samba/samba/bin/default/../../source4/heimdal_build/replace.c",
    "output": "/home/martins/samba/samba/bin/default/../../source4/heimdal_build/replace.o"
  },


I'm trying to understand how the automatically generated
compile_commands.json can be useful without all of these options.

What am I missing?

Thanks...

peace & happiness,
martin



More information about the samba-technical mailing list