lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


On Tue, Oct 08, 2002 at 07:24:06PM -0300, Luiz Henrique de Figueiredo wrote:
> >Maybe it would be cool if the lua distribution was modified to provide
> >a lua-config script, like some other projects do. It should be
> >triviual to get make install to write that file out based on where
> >it's doing the installations. Though I'm not entirely convinced such
> >is actually neccesary. 
> What would such a lua-config script look like?

Please find attached my hot-off-the-keys initial stab at one which once
tidied will make its way into Debian...

I imagine something similar would be suitable for release in Lua.

I've written it in lua, partly to prove a point, and partly to prevent
dependency on any particular other scripting language.

D.

-- 
Daniel Silverstone                               http://www.digital-scurf.org/
Hostmaster, Webmaster, and Chief Code Wibbler          Digital-Scurf Unlimited
GPG Public key available from keyring.debian.org               KeyId: 20687895
Q:	How was Thomas J. Watson buried?
A:	9 edge down.
#!/usr/bin/lua40 -f
-- -*- Lua -*-

-- Process the arg table
function usage()
   write( _STDERR, [[Usage: lua-config <options>

  Valid options are:

  --include      Outputs the -I switches needed to find <lua.h> etc.

  --static       Outputs the full path to the static libraries

  --libs         Outputs the -L and -l switches needed to find the library
  --libs-only-L  Outputs only the -L switches
  --libs-only-l  Outputs only the -l switches

  Note that --static is mututally exclusive with the --libs* options

  Also, you can specify the following

  --vmonly       Outputs only the switches for finding the VM libraries
  --libonly      Outputs only the switches for finding the standard libraries
  --both         Outputs the switches for both [The default]

  Example:

  gcc `lua-config --include` my_prog.c -o my_prog `lua-config --libs`

]] );
   exit(1);
end


if( getn(arg) == 0 ) then
   usage()
end

output_vm      = 1
output_lib     = 1

output_static  = 0
output_libs_l  = 0
output_libs_L  = 0
output_include = 0

foreachi( arg, 
	 function(n,param)
	    if( param == '--include' ) then
	       output_include = 1;
	       return
	    end
	    if( param == '--libs' ) then
	       output_libs_l = 1;
	       output_libs_L = 1;
	       return
	    end
	    if( param == '--libs-only-L' ) then
	       output_libs_L = 1;
	       return
	    end
	    if( param == '--libs-only-l' ) then
	       output_libs_l = 1;
	       return
	    end
	    if( param == '--static' ) then
	       output_static = 1;
	       return
	    end
	    if( param == '--vmonly' ) then
	       output_vm = 1;
	       output_lib = 0;
	       return
	    end
	    if( param == '--libonly' ) then
	       output_lib = 1;
	       output_vm = 0;
	       return
	    end
	    if( param == '--both' ) then
	       output_lib = 1;
	       output_vm = 1;
	       return
	    end
	    write( _STDERR, "Unknown argument ", param );
	    usage();
	 end );

if( (output_libs_l + output_libs_L + output_include + output_static) == 0 ) then
   usage()
end

if( (output_static + (output_libs_l or output_libs_L)) > 1 ) then
   usage();
end

outargs = {}

if( output_include == 1 ) then
   tinsert( outargs, "-I/usr/include/lua40" );
end

if( output_libs_L == 1 ) then
   tinsert( outargs, "-L/usr/include" );
end

if( output_libs_l == 1 ) then
   if( output_lib == 1 ) then
      tinsert( outargs, "-llualib40" );
   end
   if( output_vm == 1 ) then
      tinsert( outargs, "-llua40" );
   end
end

if( output_static == 1 ) then
   if( output_lib == 1 ) then
      tinsert( outargs, "/usr/lib/liblualib40.a" );
   end
   if( output_vm == 1 ) then
      tinsert( outargs, "/usr/lib/liblua40.a" );
   end
end

write( outargs[1] );

for i=2,getn(outargs) do
   write( " ", outargs[i] );
end

write( "\n" );