ruby picture

RCR 209: Add find_header to mkmf

Submitted by chemdog (Sun Feb 08 07:02:33 UTC 2004)

Abstract

We should have a function that retrieves a header file in mkmf.

Problem

There is no explicit functionality in Ruby to find the same header file for which have_header (mkmf.rb) returns true.

As a specific example, an OpenGL extension for Ruby has a straightforward mapping from it's C header files to its Ruby-in-C implementation file. The translated header file must be the same header file with which the extension will be compiled. An implementation might find the wrong header file of the right name.

Proposal

Create a find_header function in the file mkmf.rb, preferably located immmediately after the have_header function. The function will return a String or nil like the find_executable (mkmf.rb) function. The paths must be searched in the same order as the compiler searches for includes.

Analysis

This increases the power and flexibility of the mkmf module. This signifigantly eases the creation of translated extensions and prevents some header related errors.

Implementation


    
  1. mkmf.rb after have_header
  2. HEADER_SEARCH_PATH isn't defined here, but it would be an array containing the HSP's in compiler search order
  3. possibly CONFIG["includedir"] + CONFIG["oldincludedir"] + idir

def find_header(header, path = nil)
  checking_for "Path of #{header}" do
    path = (path || HEADER_SEARCH_PATH)
    file = nil
    path.each do |dir|
      return file if FileTest.exists?(file = File.join(dir, header))
    end
    nil
  end
end
ruby picture
Comments Current voting

"find_header" will be merged in the CVS HEAD.

I think this kind of change request should be post to comp.lang.ruby, or ruby-talk mailing list. not to RCR, since this is not the language change.

-- matz.


Specifically for my machine here (WinXP), the HEADER_SEARCH_PATH should be, abbreviated,

[ "C:\DXSDK\Include", "$(VCInstallDir)include", "$(VCInstallDir)atlmfc\include", "$(VCInstallDir)PlatfromSDK\include\prerelease", "$(VCInstallDir)PlatformSDK\include", "$(FrameworkSDKDir)include", "C:\Program Files\Creative Labs\OpenAL 1.0 SDK\Include" ]

p ENV["INCLUDE"] #=> [ "$(VCInstallDir)include", "$(VCInstallDir)atlmfc\include", "$(VCInstallDir)PlatfromSDK\include\prerelease", "$(VCInstallDir)PlatformSDK\include", "$(FrameworkSDKDir)include" ]

Also, the same machine (cygwin), the HEADER_SEARCH_PATH should be, abbreviated,

[ "$(cygwin_root)usr/include", "$(gcc_prefix)include" ]

p ENV["INCLUDE"] #=> [ "$(VCInstallDir)include", "$(FrameworkSDKDir)include" ]

Am I not sure how one would correct these situations. In neither case is the ENV perfectly accurate. In the former, everything in the DXSDK and OpenAL directories would be ignored, which would be devastating to anyone making a DirectX or OpenAL extension for Ruby. The PlatformSDK also contains previous versions of DirectX headers, bearing the same header file name as the DXSDK. Can the interpreter do any snooping to fix this?

-chemdog


Strongly opposed 0
Opposed 0
Neutral 0
In favor 1
Strongly advocate 1
ruby picture
If you have registered at RCRchive, you may now sign in below. If you have not registered, you may sign up for a username and password. Registering enables you to submit new RCRs, and vote and leave comments on existing RCRs.
Your username:
Your password:

ruby picture

Powered by .