Revisions

gist: 210608 Download_button fork
public
Public Clone URL: git://gist.github.com/210608.git
Embed All Files: show embed
Ruby #
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
#!/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++')