Skip to content

Instantly share code, notes, and snippets.

@vincentisambart
Created October 15, 2009 02:14
Show Gist options
  • Save vincentisambart/210608 to your computer and use it in GitHub Desktop.
Save vincentisambart/210608 to your computer and use it in GitHub Desktop.
#!/usr/bin/env ruby
USR_LOCAL_INCLUDE = '/usr/local/include'
def include_paths(language)
include_paths = []
in_list = false
# LANG=C is forces cpp to output messages in English
cpp_output = `LANG=C cpp -x #{language} -v < /dev/null 2>&1`
cpp_output.each_line do |line|
line.strip!
if in_list
if line == 'End of search list.'
in_list = false
else
line.gsub!(/\s*\(.+\)\z/, '') # remove useless information
include_paths << line
end
elsif line == '#include <...> search starts here:'
in_list = true
end
end
if include_paths.index(USR_LOCAL_INCLUDE)
# move /usr/local/include to the end of the list
include_paths.delete(USR_LOCAL_INCLUDE)
include_paths << USR_LOCAL_INCLUDE
end
include_paths
end
def include_paths_options(language)
include_opts = include_paths(language).map {|path| "-I#{path}"}.join(' ')
"-nostdinc #{include_opts}"
end
p include_paths_options('c')
p include_paths_options('c++')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment