Skip to content

Instantly share code, notes, and snippets.

@balping
Forked from alexdelorenzo/get-cflags.sh
Last active May 19, 2022 19:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save balping/76a7635b685ece5de94ce804098909a0 to your computer and use it in GitHub Desktop.
Save balping/76a7635b685ece5de94ce804098909a0 to your computer and use it in GitHub Desktop.
Get native CFLAGS for your host device. This will list the flags that are enabled on your hardware that are not enabled on the parent arch. https://alexdelorenzo.dev/notes/cflags
#!/usr/bin/env bash
# See: https://alexdelorenzo.dev/notes/cflags
# License: AGPLv3
export detectedArch="$(gcc -march=native -Q --help=target | grep march | awk 'NR==1{print $2}')"
export arch="${1:-$detectedArch}"
get-diff() {
diff \
<(gcc -march=native -mtune=native -Q --help=target) \
<(gcc -march=$arch -Q --help=target)
}
get-flags() {
grep "<" | grep "enabled" | awk '{print $2}' \
| while read flag; do
printf "%s " "$flag"
done
printf '\n'
}
get-diff | get-flags
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment