Skip to content

Instantly share code, notes, and snippets.

@Pixailz
Created November 1, 2023 13:37
Show Gist options
  • Save Pixailz/8f0c8044868c40aca89b354248bb7af8 to your computer and use it in GitHub Desktop.
Save Pixailz/8f0c8044868c40aca89b354248bb7af8 to your computer and use it in GitHub Desktop.
Get gcc / clang, in C or C++, information
#!/usr/bin/env bash
declare -a includes
function get_includes()
{
local compiler="${1:-gcc}"
local language="${2:-c}"
local data beg_inc end_inc
data="$(echo | "${compiler}" -x${language} -v -E - 2>&1)"
beg_inc="$(<<< ${data} grep -n '<...> search starts here:' | cut -f1 -d':')"
end_inc="$(<<< ${data} grep -n 'End of search list.' | cut -f1 -d':')"
includes+=($(<<< ${data} sed -n "$((beg_inc + 1)),$((end_inc - 1))p"))
}
get_includes "gcc"
get_includes "clang"
get_includes "cc"
includes=($(tr ' ' '\n' <<<${includes[@]} | sort -u ))
echo Includes :
printf -- "- %s\n" ${includes[@]}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment