Skip to content

Instantly share code, notes, and snippets.

Created January 31, 2015 02:34
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
What would you like to do?
Get Macros from your compiler
#!/usr/bin/env python
# imports you need or a kitty will die
# if you don't use them :(
import os
import shlex
import subprocess
import sys
# remplace with the compiler you want to see
# compiler macros.
# ex. 'G++', 'g++'
# 'CC', 'cc'
# Want to check cross compilers (android toolchains)?
# be sure you set the compiler in PATH var CC
c = os.environ.get('CC')
def init():
# I know this could be more simple with grep
# but i want to do it on python. I am a bad guy
# and bad guys uses python for all simple things.
print '''C compiler found!'''
compiler = subprocess.Popen(shlex.split(c) + ['-dM', '-E', '-'], stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
print compiler
except OSError:
# Sorry, good luck next time.
print '''No acceptable C compiler found!\n'''
print '''\nCompiler macros list\n'''
c_out = compiler.communicate()[0]
# I save it on a file because so compilers have
# really long macros list and check them on a
# terminal screen is not the best thing in the
# world.
print '''Macros saved on compiler-macros file'''
print c_out
c_out = str(c_out).split('\n')
# Print compiler macros as Array. Don0t know if you
# will use this but I want to print something. So,
# you got it.
print c_out
# just run it man!
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment