If you do not know ohcount, you should; the guys at ohloh.net have GPL’d one of their core components, namely the one that allows you to perform source code line counts in your own projects. Neat and useful!
However, the current ohcount distribution (which you can download from this link) does not build out-of-the-box in Leopard. Here’s how I made it work in my own Leopard G4 PowerBook (PPC) computer.
- Download pcre-7.6.tar.gz from SourceForge
- Extract the file into the “pcre-7.6″ folder
- cd into the pcre-7.6 folder and
./configure make sudo make install
- Download ohcount-1.0.0.tar.gz from Ohloh
- Extract the file into the “ohcount-1.0.0″ folder
- cd into the ohcount-1.0.0 folder and open “Rakefile” with your favorite editor; modify line 73 as follows:
file "#{EXT_DIR}/Makefile" => "#{EXT_DIR}/extconf.rb" do
cd EXT_DIR do
if ENV['DEBUG']
ruby 'extconf.rb', 'debug'
else
ENV['ARCHFLAGS'] = "-arch ppc"
\# or "-arch i386" if you use an Intel Mac
ruby 'extconf.rb'
end
end
end
- Now cd into the ohcount-1.0.0 folder and
rake
the project. You should see a series of tests running, with the final message saying “92 tests, 321 assertions, 0 failures, 0 errors”. - Now you can use the bin/ohcount binary to get statistics from your source code!
The root of the problem is that Leopard’s Ruby installation is a “Universal Binary”, while the pcre library is built as a native binary only; hence, it does not link for the i386 binary, hence, it does not work. Another solution, I think, would be to compile pcre as a Universal Binary, but I leave this as an exercise to the reader :)
I found the fix thanks to this conversation in Ohloh’s forum, which took me to this thread on ruby-talk and finally this wiki page in MacOS Forge.
Hope this helps!