Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
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.
#!/usr/bin/env bash
# See:
# Requires `strs` package for Python:
# License: AGPLv3
export detectedArch="$(gcc -march=native -Q --help=target | grep march | str col 2 | str nth 0)"
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" | str col 2 \
| while read flag; do
printf "%s " "$flag"
printf '\n'
get-diff | get-flags
Copy link

balping commented May 19, 2022

I made a fork that doesn't require the strs package, just uses the widely available awk command. Very useful little script though, thanks for sharing!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment