[Haskell] Workaround for building profiling libs and apps with Cabal

Satnam Singh satnams at microsoft.com
Tue May 17 20:14:27 EDT 2005


I recently tried to build a version of an application with Cabal to use
with profiling by simply adding:

	ghc-options:	 -prof -auto-all

to my Cabal file but this did not work because the generated .hi
interface files ended in .hi and not .p_hi as expected and the .o and .a
files also did not have the expected names.

As a work-around I wrote a small script "fixhi" to create symbolic links
for the expected filenames. The script can be adjusted to perform a
rename by substituting the "ln -s" with "mv". The script is at the end
of the message. It is designed to be run in the install directory of the
package for a specific version e.g.

lagavulin> pwd
/c/Program Files/lava/lava-0.1
lagavulin> fixhi
Symbolically linking ./Lava/Below.hi to ./Lava/Below.p_hi
Symbolically linking ./Lava/Beside.hi to ./Lava/Beside.p_hi
Symbolically linking ./Lava/Bit.hi to ./Lava/Bit.p_hi
Symbolically linking ./Lava/Classes.hi to ./Lava/Classes.p_hi
Symbolically linking ./Lava/Col.hi to ./Lava/Col.p_hi
<...lots of lines deleted...>
Symbolically linking ./Xilinx/Adder.hi to ./Xilinx/Adder.p_hi
Symbolically linking ./Xilinx/Comparator.hi to ./Xilinx/Comparator.p_hi
Symbolically linking ./Xilinx/Components.hi to ./Xilinx/Components.p_hi
Symbolically linking ./Xilinx/OneBitAdder.hi to
./Xilinx/OneBitAdder.p_hi
Symbolically linking ./Xilinx/OneBitSubtractor.hi to
./Xilinx/OneBitSubtractor.p_hi
Symbolically linking ./Xilinx/Subtractor.hi to ./Xilinx/Subtractor.p_hi
Symbolically linking ./Xilinx.hi to ./Xilinx.p_hi
Symbolically linking ./HSlava-0.1.o to ./HSlava-0.1_p.o
Symbolically linking ./libHSlava-0.1.a to ./libHSlava-0.1_p.a
lagavulin>

Application of the script should be idempotent. A simple change could
allow the script to take a path to the installation so it can be run
from elsewhere (e.g. a Makefile).

I also expected when I used ghc --make to compile my programs that use
this library to also be automatically compiled with "-prof -auto-all"
but I guess that must be another option to Cabal and I had to add this
to the ghc compilation command for the clients of this library.

Hopefully the next version of Cabal will make it easier to build
profiled and non-profiled versions of libraries and applications. Until
then maybe the script below might provide some utility to others. I've
only tested it under Microsoft Windows with msys (other OS-es are kind
of hard to come by where I work).

Cheers,

Satnam Singh
Microsoft
One Microsoft Way
Redmond
Washington 98052-6399
USA


#!/bin/sh
# Workaround script for producing profiling interface files and libs
# with the expected extension for use with Cabal. 

# Find and symbolically link to the interface files.
for intfFile in `find . -name "*.hi" -print`
do
	echo Symbolically linking $intfFile to ${intfFile%*.*}.p_hi
	ln -f -s $intfFile ${intfFile%*.*}.p_hi
done

# Find all the libraries and objects and link to them too.
# First delete old profiling library files.
rm -rf *_p.a *_p.o
for objFile in `find . -name "*.o" -print`
do
	echo Symbolically linking $objFile to ${objFile%*.*}_p.o
	ln -f -s $objFile ${objFile%*.*}_p.o
done
for libFile in `find . -name "*.a" -print`
do
	echo Symbolically linking $libFile to ${libFile%*.*}_p.a
	ln -f -s $libFile ${libFile%*.*}_p.a
done






More information about the Haskell mailing list