[MLton] Support for link options in ML Basis files

Chris Clearwater chris@detriment.org
Mon, 17 Jan 2005 09:03:47 -0800

Matthew Fluet wrote:

>>I wonder then how you guys would feel about using Pkgconfig
>I suppose it is an option.
>>Pkgconfig in
>>combination with mlbs would provide you a fully functional packaging
>>system with minimal effort.  For example, with my SDL bindings I would
>>just install a file such as "mlton-sdl.pc" in /usr/lib/pkgconfig/. An
>>example of what this might look like:
>>Name: MLSDL
>>Description: SDL bindings for the MLton compiler
>>Version: 0.1
>>Libs: -L/usr/lib/mlton/sml/sdl -lSDL -lpthread
>          ^^^^^^^^^^^^^^^^^^^^^^
>I don't think you want /usr/lib/mlton/sml/sdl, as there shouldn't be any
>sdl libraries in that directory, just your SML bindings.
>I think you want a Requires: line to pull in the SDL cflags and libs.
>On the other hand, I can't find a pkgconfig .pc for SDL in any of the
>boxes I have access to.
>And, I think this just demonstrates that there really is no universal
>solution.  A pkgconfig solution might work well for a .mlb that provides
>SML bindings for a C-library that itself uses pkgconfig, but if that C-lib
>doesn't have a pkgconfig, then someone still needs to do some manual
>tweaking to align things correctly.
>MLton mailing list
Pardon me, I am very poor at communicating my thoughts :)

I just had -L/usr/lib/mlton/sml/sdl because I generete a sdl.a library.  
It contains some functions my bindings use for diassembling the event 
structures returned by SDL into SML values. I suppose it would be better 
to give it a name such as libmlton-sdl.a and stick it in the standard  C 
library path ($prefix/lib) and then add -lmlton-sdl to the Libs. SDL 
doesn't use Pkgconfig, it uses old-style $program-config shell scripts 
which Pkgconfig has superceded. For some packages, compile-time 
configuration is unavoidable, using Pkgconfig or not.  I did not mean to 
imply that you could avoid it. If you need that, your package could drop 
to autoconf/automake or whatever you want. The main point of using 
pkgconfig is that it is better than using some common convention for 
gathering compile flags than using Makefiles or something else along 
those lines. Pkgconfig is as standard a way for doing this as exists and 
is already installed on many machines. As an added bonus MLton packages 
which use Pkgconfig'd C libraries can just include a Requires line.

The following convention for using a MLton package would work quite well.

For package users: includein your mlb: $(SML_LIB)/$package/$module.mlb
                                 compile with: -link-opt `pkg-config 
--libs mlton-$package`

For package writers: Create a libmlton-$package.a containing all your .o 
                                    Create a libmlton-$package.pc with 
the appropriate options (including -lmlton-$package)
                                    Install your sml/mlb files, 
libmlton-$package.a and mlton-$package.pc

MLton would create its own mlton.pc which contained a smllib variable 
packages could query with Pkgconfig. They would install their sml/mlb 
files here.

One last question. Awhile ago I started writing a simple program that 
took definitions of C structs and generated a C program which printed 
the offsets of the fields using C's offsetof macro. It then generated a 
program which used functions in the MLton.Pointer structure to unpack a 
MLton.Pointer.t to a SML record equivalent to the C structure.

I see you are working on NLFFI, should I bother finishing it?