Skip to content

Commit

Permalink
Great source tree layout reorganization
Browse files Browse the repository at this point in the history
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
pavouk committed Nov 27, 2011
1 parent 747476e commit d51106d
Show file tree
Hide file tree
Showing 36 changed files with 235 additions and 243 deletions.
8 changes: 2 additions & 6 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,5 @@
*.so
*.dll
*.stackdump
.cproject
.project
.settings
.waf*
build
.lock-wafbuild
.depcheck
*.rockspec
32 changes: 32 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
#
# LGI Dynamic GObject introspection binding.
#
# Author: Pavel Holejsovsky <[email protected]>
# 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
9 changes: 4 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
58 changes: 0 additions & 58 deletions devsetup.sh

This file was deleted.

14 changes: 5 additions & 9 deletions docs/overview.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
19 changes: 19 additions & 0 deletions lgi.lua
Original file line number Diff line number Diff line change
@@ -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'
68 changes: 68 additions & 0 deletions lgi/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
#
# Makefile for compiling lgi core module in standard-Lua variant
#
# Author: Pavel Holejsovsky <[email protected]>
# 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.
2 changes: 1 addition & 1 deletion src/core.c → lgi/core.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
14 changes: 14 additions & 0 deletions lgi/core.lua
Original file line number Diff line number Diff line change
@@ -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'
File renamed without changes.
18 changes: 11 additions & 7 deletions src/lgi.lua → lgi/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
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.
1 change: 1 addition & 0 deletions lgi/version.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
return '0.3'
24 changes: 12 additions & 12 deletions lgi.rockspec → rockspec.in
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
package = 'LGI'
version = '0.3-1'
version = '%VERSION%-1'

description = {
summary = "Lua bindings to GObject libraries",
Expand All @@ -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' }
}
30 changes: 0 additions & 30 deletions src/wscript

This file was deleted.

2 changes: 2 additions & 0 deletions tests/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
*.gir
*.typelib
Loading

3 comments on commit d51106d

@sam-github
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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?

@pavouk
Copy link
Collaborator Author

@pavouk pavouk commented on d51106d Jan 2, 2013

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

@sam-github
Copy link

@sam-github sam-github commented on d51106d Jan 21, 2013 via email

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.