Permalink
Browse files

Great source tree layout reorganization

Reorganized so that running uninstalled lgi is possible without
devsetup.sh hacks (which went missing).  Also waf was replaces by a
few simple makefiles.  rockspec is generated automatically and is
switched to use makefile type build.
  • Loading branch information...
1 parent 747476e commit d51106dd0b0bc4bf178058f294b1278c94cab507 @pavouk committed Nov 27, 2011
View
@@ -2,9 +2,5 @@
*.so
*.dll
*.stackdump
-.cproject
-.project
-.settings
-.waf*
-build
-.lock-wafbuild
+.depcheck
+*.rockspec
View
@@ -0,0 +1,32 @@
+#
+# LGI Dynamic GObject introspection binding.
+#
+# Author: Pavel Holejsovsky <pavel.holejsovsky@gmail.com>
+# License: MIT
+#
+
+VERSION = 0.3
+
+ROCK = lgi-$(VERSION)-1.rockspec
+
+.PHONY : rock all clean install check
+
+all : rock
+ make -C lgi
+
+rock : $(ROCK)
+$(ROCK) : rockspec.in Makefile
+ sed 's/%VERSION%/$(VERSION)/' $< >$@
+
+clean :
+ rm -f *.rockspec
+ make -C lgi clean
+ make -C tests clean
+
+install :
+ make -C lgi install
+
+check :
+ make -C tests check
+
+export VERSION
View
@@ -14,15 +14,14 @@ although preferred version is >= 1.30. The development package is
called `libgirepository1.0-dev` on debian-based systems (like Ubuntu)
and `gobject-introspection-devel` on RedHat-based systems (like Fedora).
-- Using LuaRocks:
+Using LuaRocks:
luarocks install lgi
-- Otherwise, use bundled 'waf' building tool:
+Alternatively, use make-based installation
- ./waf configure --prefix=<prefix>
- ./waf build
- [sudo] ./waf install
+ make
+ [sudo] make install [PREFIX=<prefix>] [DESTDIR=<destdir>]
## Usage:
See examples in samples/ directory. Documentation is available in
View
@@ -1,58 +0,0 @@
-# Sets up environment and links in 'build' waf directory. After sourcing this
-# script into interactive shell, everything should be set up to run uninstalled
-# LGI version incl. testsuite.
-
-test -f ./devsetup.sh || {
- echo 'devsetup.sh must be sourced from LGI top directory, i.e.'
- echo '. ./devsetup.sh'; return; }
-build_dir=`pwd`/build
-ext=.so; pfx=lib
-test x`uname -o` != xCygwin || { ext=.dll; pfx=cyg; }
-test -x $build_dir/src/core${ext} && \
- test -x $build_dir/tests/${pfx}regress${ext} && \
- test -r $build_dir/tests/Regress-1.0.typelib || { \
- echo 'LGI must be built first.'; return; }
-
-# Create links from files to root 'build' dir.
-(cd $build_dir && mkdir -p lgi && \
- (cd lgi && ln -sf ../src/core${ext}) && \
- ln -sf ../src/*.lua . && \
- mkdir -p lgix && (cd lgix && ln -sf ../../src/lgix/* .) && \
- ln -sf tests/${pfx}regress${ext} && \
- ln -sf tests/Regress-1.0.typelib)
-
-# Modify assorted path variables.
-save_ifs=$IFS
-IFS=':;'
-
-unset hasit
-for path in $LD_LIBRARY_PATH; do
- p=`cd "$path" && pwd`; test $p = $build_dir && hasit=yes
-done
-test x$hasit = xyes || LD_LIBRARY_PATH="$build_dir:$LD_LIBRARY_PATH"
-export LD_LIBRARY_PATH
-
-unset hasit
-for path in $GI_TYPELIB_PATH; do
- p=`cd "$path" && pwd`; test $p = $build_dir && hasit=yes
-done
-test x$hasit = xyes || GI_TYPELIB_PATH="$build_dir:$GI_TYPELIB_PATH"
-export GI_TYPELIB_PATH
-
-unset hasit
-lgi_lua_cpath=`lua -e "print(package.cpath)"`
-for path in $lgi_lua_cpath; do
- test "$path" = "$build_dir/?${ext}" && hasit=yes
-done
-test x$hasit = xyes || LUA_CPATH="$build_dir/?${ext};$lgi_lua_cpath"
-export LUA_CPATH
-
-unset hasit
-lgi_lua_path=`lua -e "print(package.path)"`
-for path in $lgi_lua_path; do
- test "$path" = "$build_dir/?.lua" && hasit=yes
-done
-test x$hasit = xyes || LUA_PATH="$build_dir/?.lua;$lgi_lua_path"
-export LUA_PATH
-
-IFS=$save_ifs
View
@@ -40,18 +40,14 @@ plain `luarocks install lgi` does not work yet, although it will be
preferred way to install LGI in the future. Currently, LGI source
must be downloaded, unpacked and installed using `luarocks make`.
-### Installing by 'waf' tool
+### Installing using Makefile
-Another way to install LGI is using bundled `waf` tool. Type
+Another way to install LGI is using makefiles:
- ./waf configure
- ./waf
- sudo ./waf install
+ make
+ sudo make install [PREFIX=prefix-path] [DESTDIR=destir-path]
-to build and install LGI into default location (either /usr/local
-prefix or into Lua modules location specified by Lua's pkg-config .pc
-file, if present). Use `./waf --help` to see other possible options,
-mainly for influencing target installation directories.
+Default `PREFIX` is `/usr/local` and default `DESTDIR` is empty.
## Quick overview
View
19 lgi.lua
@@ -0,0 +1,19 @@
+------------------------------------------------------------------------------
+--
+-- LGI Lua-side core.
+--
+-- Copyright (c) 2011 Pavel Holejsovsky
+-- Licensed under the MIT license:
+-- http://www.opensource.org/licenses/mit-license.php
+--
+------------------------------------------------------------------------------
+
+-- This is simple forwarder to real package 'lgi/init.lua'. Normally,
+-- lgi/init.lua could suffice, but this file is needed for two
+-- reasons:
+-- 1) Running uninstalled, because Lua unfortunately does not contain
+-- './?/init.lua' component in its package.path
+-- 2) Upgrading older installations (<0.2), where lgi.lua was the only
+-- installed file, it would take precedence over 'lgi/init.lua'.
+
+return require 'lgi.init'
View
@@ -0,0 +1,68 @@
+#
+# Makefile for compiling lgi core module in standard-Lua variant
+#
+# Author: Pavel Holejsovsky <pavel.holejsovsky@gmail.com>
+# License: MIT
+#
+
+PREFIX = /usr/local
+LUA_LIBDIR = $(PREFIX)/lib/lua/5.1
+LUA_SHAREDIR = $(PREFIX)/share/lua/5.1
+
+GINAME = gobject-introspection-1.0
+VERSION_FILE = version.lua
+
+ifneq ($(filter $(shell uname -s),Cygwin MSys),)
+CORE = corelgilua51.dll
+LIBS += -llua5.1
+LIBFLAG = -shared
+else
+CORE = corelgilua51.so
+LIBFLAG = -shared
+CCSHARED = -fPIC
+endif
+
+OBJS = buffer.o callable.o core.o gi.o marshal.o object.o record.o
+
+COPTFLAGS = -Wall -O2 -g
+CFLAGS = $(CCSHARED) $(COPTFLAGS) $(LUA_CFLAGS) $(shell pkg-config --cflags $(GINAME))
+LIBS += $(shell pkg-config --libs $(GINAME))
+LDFLAGS = $(LIBFLAG)
+DEPCHECK = .depcheck
+
+# Precondition check
+$(DEPCHECK) : Makefile
+ pkg-config --exists '$(GINAME) >= 0.10.8' --print-errors
+ touch $@
+
+.PHONY : all clean install
+
+all : $(CORE) $(VERSION_FILE)
+clean :
+ rm -f $(CORE) $(OBJS)
+
+$(CORE) : $(OBJS)
+ $(CC) $(LDFLAGS) -o $@ $(OBJS) $(LIBS)
+
+$(VERSION_FILE) : Makefile ../Makefile
+ echo "return '$(VERSION)'" > $@
+
+buffer.o : buffer.c lgi.h $(DEPCHECK)
+callable.o : callable.c lgi.h $(DEPCHECK)
+core.o : core.c lgi.h $(DEPCHECK)
+gi.o : gi.c lgi.h $(DEPCHECK)
+marshal.o : marshal.c lgi.h $(DEPCHECK)
+object.o : object.c lgi.h $(DEPCHECK)
+record.o : record.c lgi.h $(DEPCHECK)
+
+OVERRIDES = $(wildcard override/*.lua)
+
+install : $(CORE) $(VERSION_FILE)
+ mkdir -p $(DESTDIR)$(LUA_LIBDIR)/lgi
+ cp $(CORE) $(DESTDIR)$(LUA_LIBDIR)/lgi
+ mkdir -p $(DESTDIR)$(LUA_SHAREDIR)
+ cp ../lgi.lua $(DESTDIR)$(LUA_SHAREDIR)
+ mkdir -p $(DESTDIR)$(LUA_SHAREDIR)/lgi
+ cp init.lua core.lua $(VERSION_FILE) $(DESTDIR)$(LUA_SHAREDIR)/lgi
+ mkdir -p $(DESTDIR)$(LUA_SHAREDIR)/lgi/override
+ cp $(OVERRIDES) $(DESTDIR)$(LUA_SHAREDIR)/lgi/override
File renamed without changes.
File renamed without changes.
@@ -431,7 +431,7 @@ static const struct luaL_reg lgi_reg[] = {
int lgi_addr_repo;
int
-luaopen_lgi_core (lua_State* L)
+luaopen_lgi_corelgistdlua (lua_State* L)
{
LgiStateMutex *mutex;
View
@@ -0,0 +1,14 @@
+------------------------------------------------------------------------------
+--
+-- LGI Lua-side core module selector
+--
+-- Copyright (c) 2010, 2011 Pavel Holejsovsky
+-- Licensed under the MIT license:
+-- http://www.opensource.org/licenses/mit-license.php
+--
+------------------------------------------------------------------------------
+
+-- This module decides what kind of core routines should be loaded.
+-- Currently only one implementation exists, standard-Lua C-side
+-- implementation, LuaJIT-FFI-based one is planned.
+return require 'lgi.corelgistdlua'
View
File renamed without changes.
@@ -25,7 +25,7 @@ assert(gi.require ('GLib', '2.0'))
assert(gi.require ('GObject', '2.0'))
-- Create lgi table, containing the module.
-local lgi = { _NAME = 'lgi', _VERSION = '0.3' }
+local lgi = { _NAME = 'lgi', _VERSION = require 'lgi.version' }
-- Add simple flag-checking function, avoid compatibility hassle with
-- importing bitlib just because of this simple operation.
@@ -723,7 +723,7 @@ function namespace_mt:__index(symbol)
local package = preconditions[symbol]
if not preconditions[package] then
preconditions[package] = true
- require('lgix.' .. package)
+ require('lgi.override.' .. package)
preconditions[package] = nil
end
preconditions[symbol] = nil
@@ -797,13 +797,17 @@ function lgi.require(name, version)
end
-- Try to load override, if it is present.
- local lgix_name = 'lgix.' .. ns._name
- local ok, msg = pcall(require, lgix_name)
+ local override_name = 'lgi.override.' .. ns._name
+ local ok, msg = pcall(require, override_name)
if not ok then
-- Try parsing message; if it is something different than
- -- "module xxx not found", then rethrow the exception.
- assert(msg:find("module '" .. lgix_name .. "' not found:", 1, true),
- msg)
+ -- "module xxx not found", then attempt to load again and let
+ -- the exception fly out.
+ if not msg:find("module '" .. override_name .. "' not found:",
+ 1, true) then
+ package.loaded[override_name] = nil
+ require(override_name)
+ end
end
end
return ns
View
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
View
@@ -0,0 +1 @@
+return '0.3'
@@ -1,5 +1,5 @@
package = 'LGI'
-version = '0.3-1'
+version = '%VERSION%-1'
description = {
summary = "Lua bindings to GObject libraries",
@@ -12,23 +12,23 @@ description = {
homepage = 'https://gitorious.org/lgi/lgi'
}
-supported_platforms = { "unix" }
+supported_platforms = { 'unix' }
source = {
url = 'git://gitorious.org/lgi/lgi.git',
- tag = '0.3'
+ tag = '%VERSION%'
}
-dependencies = {
- "lua 5.1"
-}
+dependencies = { 'lua 5.1' }
build = {
- type = 'command',
- build_command =
- "LUA_CFLAGS=-I$(LUA_INCDIR) python waf configure " ..
- "--prefix=$(PREFIX) --datadir=$(LUADIR) --libdir=$(LIBDIR); " ..
- "python waf build",
- install_command = "python waf install",
+ type = 'make',
+ variables = {
+ PREFIX = '$(PREFIX)',
+ LUA_LIBDIR = '$(LIBDIR)',
+ LUA_SHAREDIR = '$(LUADIR)',
+ LUA_CFLAGS = '$(CFLAGS) -I$(LUA_INCDIR)',
+ LIBFLAG = '$(LIBFLAG)',
+ },
copy_directories = { 'docs', 'samples' }
}
View
@@ -1,30 +0,0 @@
-#! /usr/bin/env python
-
-from waflib.TaskGen import feature, before, after
-
-@feature('luaext')
-@before('apply_link', 'propagate_uselib')
-def apply_lua_so_name(self):
- pattern = '%s.so'
- if self.env.DEST_OS in ['win32', 'cygwin']:
- pattern = '%s.dll'
- self.env['cshlib_PATTERN'] = self.env['cxxshlib_PATTERN'] = pattern
-
-def build(bld):
- bld(
- features = 'c cshlib luaext',
- source = ['core.c',
- 'gi.c',
- 'buffer.c',
- 'callable.c',
- 'marshal.c',
- 'record.c',
- 'object.c'],
- target = 'core',
- uselib = ['LUA', 'GI'],
- cflags = bld.env.CCFLAGS,
- install_path = '${LUA_INSTALL_CMOD}/lgi',
- )
- bld.install_files('${LUA_INSTALL_LMOD}/', 'lgi.lua')
- bld.install_files('${LUA_INSTALL_LMOD}/lgix/',
- bld.path.ant_glob('lgix/*.lua'))
View
@@ -0,0 +1,2 @@
+*.gir
+*.typelib
Oops, something went wrong.

3 comments on commit d51106d

waf is on my list of build systems to evaluate (mostly for lua bindings to C), but I won't bother if its not a good tool. Can you comment on why you found straight gnu makefiles to be better than waf?

Owner

pavouk replied Jan 2, 2013

waf itself is not bad at all. I only realized that simple Makefiles are better suited to the nature of the project.

  • lgi is simple: cca 5 .c files, single .h file. The advantages of waf (automatic deps generation, parallel compilation) does not buy me anything
  • waf added cca 42kB of 'source' - almost the same amount as the real source of lgi
  • it introduced dependency on python, which I personally don't speak fluently
  • crafting non-standard rules for compiling .gir and .typelib (in testsuite) appeared to be problematic - lack of my skills prevented me from creating rules in waf which I would be satisfied with
  • almost everyone else speaks make, so tweaks from community related to foreign platforms are coming - I guess that waf would be a hurdle here

IMHO waf is good when you have much bigger fish to fry than lgi. With small size of my project, simplicity and well-knowness of make fits it much better.

HTH,
Pavel

Please sign in to comment.