Skip to content

Instantly share code, notes, and snippets.

@zeroxia
Created November 25, 2013 06:11
Show Gist options
  • Save zeroxia/7637039 to your computer and use it in GitHub Desktop.
Save zeroxia/7637039 to your computer and use it in GitHub Desktop.
Show what macros are predefined by your GCC. e.g., for Android, you can rely on -D__ANDROID__
#!/bin/sh
echo "Hello, world"
# PC linux
echo | gcc -dM -E - | less
# For the Android NDK toolchains
echo | /opt/android/android-ndk/toolchains/x86-4.4.3/prebuilt/linux-x86/bin/i686-linux-android-gcc -dM -E -
@zeroxia
Copy link
Author

zeroxia commented Nov 25, 2013

To east the execution of those cross-compilation toolchain commands, you can create a utility script to help you omit the long prefix. e.g., for Android, create an NDK script in your PATH like this:

#!/bin/sh

PREFIX="/opt/android/android-ndk/toolchains/x86-4.4.3/prebuilt/linux-x86/bin/i686-linux-android-"

usage()
{
    echo "USAGE: $0 TOOL ARGS"
}

if [ $# -lt 2 ]; then
    usage
    exit 1
fi

TOOL="$1"
shift

exec "${PREFIX}${TOOL}" "$@"

Remember to chmod +x NDK. Then above command is transformed into:

echo | NDK gcc -dM -E - | less

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