Skip to content

Lua gd compilation

David Mansolino edited this page Feb 4, 2019 · 3 revisions

This page explains how to recompile the lua gd dependency on every platforms. Lua gd is used internally by Webots to generate procedural textures to be used in procedural PROTO nodes.

Linux:

Install libgd-dev:

sudo apt-get install libgd-dev

Get lua-gd from:

cd ~/software
git clone https://github.com/ittner/lua-gd.git

You will need to edit the Makefile:

# Lua-GD version. This one must be set.
VERSION=2.0.33r3

# Command used to run Lua code
LUABIN=$(HOME)/software/lua-5.2.3/src/lua

# Optimization for the brave of heart ;)
OMITFP=-fomit-frame-pointer

# ---------------------------------------------------------------------------
# Manual configuration for systems without pkgconfig.

OUTFILE=gd.so
CFLAGS=-O3 -Wall -fPIC $(OMITFP)
CFLAGS+=-I $(HOME)/software/lua-5.2.3/src
CFLAGS+=-DVERSION=\"$(VERSION)\"
GDFEATURES=-DGD_XPM -DGD_JPEG -DGD_FONTCONFIG -DGD_FREETYPE -DGD_PNG -DGD_GIF
LFLAGS=-shared -lgd

# ---------------------------------------------------------------------------


all: test

$(OUTFILE): gd.lo
	$(CC) -o $(OUTFILE) gd.lo $(LFLAGS)

test: $(OUTFILE)
	$(LUABIN) test_features.lua

gd.lo: luagd.c
	$(CC) -o gd.lo -c $(GDFEATURES) $(CFLAGS) luagd.c

install: $(OUTFILE)
	install -D -s $(OUTFILE) $(DESTDIR)/$(INSTALL_PATH)/$(OUTFILE)


# Rules for making a distribution tarball

TDIR=lua-gd-$(VERSION)
DFILES=COPYING README luagd.c lua-gd.spec Makefile test_features.lua
dist: $(DISTFILES)
	rm -f $(TDIR).tar.gz
	mkdir $(TDIR)
	mkdir -p $(TDIR)/doc $(TDIR)/demos $(TDIR)/debian
	cp $(DFILES) $(TDIR)
	cp demos/* $(TDIR)/demos/
	cp doc/* $(TDIR)/doc/
	cp debian/* $(TDIR)/debian/
	tar czf $(TDIR).tar.gz $(TDIR)
	rm -rf $(TDIR)

clean:
	rm -f $(OUTFILE) gd.lo
	rm -rf $(TDIR) $(TDIR).tar.gz
	rm -f demos/out.png demos/out.gif demos/counter.txt

.PHONY: all test install clean dist

Create the package by adding gd.so to the archive.


Mac:

Build libgd

cd ~/software
git clone https://github.com/libgd/libgd.git
cd libgd
git checkout gd-2.2.3
mkdir build
cd build
cmake -DENABLE_PNG=1 -DPNG_LIBRARY=~/software/libpng-1.0.12/libpng.a -DPNG_PNG_INCLUDE_DIR=~/software/libpng-1.0.12/ -DENABLE_JPEG=1 -DJPEG_LIBRARY=~/software/jpeg-9b/libjpeg.a -DENABLE_FREETYPE=1 -DFREETYPE_LIBRARY=~/software/ogre/Dependencies/lib/Release/libfreetype.a  -DFREETYPE_INCLUDE_DIRS=~/software/ogre/Dependencies/include  -DCMAKE_OSX_SYSROOT=/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.12.sdk -DCMAKE_OSX_DEPLOYMENT_TARGET=10.7 ..
make -j4

Install lua-gd

Get lua-gd from:

cd ~/software
git clone https://github.com/ittner/lua-gd.git

To be able to run the test, add the following line to test_features.lua:

package.cpath = package.cpath .. ";?.dylib"

And add liblua to the path:

export DYLD_LIBRARY_PATH=$DYLD_LIBRARY_PATH:$HOME/software/lua-5.2.3/src

You will need to edit the Makefile:

# Lua-GD version. This one must be set.
VERSION=2.0.33r3

# Command used to run Lua code
LUABIN=$(HOME)/software/lua-5.2.3/src/lua

# Path to the utility 'gdlib-config'. This may be changed to compile the
# module with development versions of libgd.
GDLIBCONFIG=gdlib-config

# Optimization for the brave of heart ;)
OMITFP=-fomit-frame-pointer

# ---------------------------------------------------------------------------
# Manual configuration for Windows and systems without sed, pkgconfig, etc.
# Uncomment, change and good luck :)


OUTFILE=gd.dylib
CFLAGS=-O3 -Wall $(OMITFP)
CFLAGS+=-I $(HOME)/software/lua-5.2.3/src -I /opt/local/include
CFLAGS+=-DVERSION=\"$(VERSION)\" -mmacosx-version-min=10.7
GDFEATURES=-DGD_XPM -DGD_JPEG -DGD_FONTCONFIG -DGD_FREETYPE -DGD_PNG -DGD_GIF
LFLAGS=-dynamiclib -compatibility_version 1.0 -current_version 1.0.0 -L /opt/local/lib -L $(HOME)/software/lua-5.2.3/src -llua -lgd -lm $(OMITFP) -mmacosx-version-min=10.7
# ---------------------------------------------------------------------------


all: test

$(OUTFILE): gd.lo
	$(CC) -o $(OUTFILE) gd.lo $(LFLAGS)

test: $(OUTFILE)
	$(LUABIN) test_features.lua

gd.lo: luagd.c
	$(CC) -o gd.lo -c $(GDFEATURES) $(CFLAGS) luagd.c

install: $(OUTFILE)
	install -D -s $(OUTFILE) $(DESTDIR)/$(INSTALL_PATH)/$(OUTFILE)


# Rules for making a distribution tarball

TDIR=lua-gd-$(VERSION)
DFILES=COPYING README luagd.c lua-gd.spec Makefile test_features.lua
dist: $(DISTFILES)
	rm -f $(TDIR).tar.gz
	mkdir $(TDIR)
	mkdir -p $(TDIR)/doc $(TDIR)/demos $(TDIR)/debian
	cp $(DFILES) $(TDIR)
	cp demos/* $(TDIR)/demos/
	cp doc/* $(TDIR)/doc/
	cp debian/* $(TDIR)/debian/
	tar czf $(TDIR).tar.gz $(TDIR)
	rm -rf $(TDIR)

clean:
	rm -f $(OUTFILE) gd.lo
	rm -rf $(TDIR) $(TDIR).tar.gz
	rm -f demos/out.png demos/out.gif demos/counter.txt

.PHONY: all test install clean dist

Create the package by adding gd.dylib to the archive.

Package creation

cd ~/software
cp libgd/build/Bin/libgd.dylib ~/webots/lib/libgd.3.dylib
cp lua-gd/gd.dylib ~/webots/resources/lua/modules/gd/gd.dylib
cd ~/webots
install_name_tool -id @rpath/lib/libgd.3.dylib lib/libgd.3.dylib
install_name_tool -id @rpath/resources/lua/modules/gd/gd.dylib resources/lua/modules/gd/gd.dylib
install_name_tool -change liblua.dylib @rpath/lib/liblua.dylib resources/lua/modules/gd/gd.dylib
install_name_tool -change libgd.3.dylib @rpath/lib/libgd.3.dylib resources/lua/modules/gd/gd.dylib
tar -cvjf gd.tar.bz2 lib/libgd.3.dylib resources/lua/modules/gd/gd.dylib

Windows:

Get lua-gd from:

cd ~/software
git clone https://github.com/ittner/lua-gd.git

Add the following line to test_features.lua:

package.cpath = package.cpath .. ";?.dll"

You will need to edit the Makefile:

# Lua-GD version. This one must be set.
VERSION=2.0.33r3

# Command used to run Lua code
LUABIN=$(HOME)/software/lua-5.2.3/src/lua.exe

# Path to the utility 'gdlib-config'. This may be changed to compile the
# module with development versions of libgd.
GDLIBCONFIG=gdlib-config

# Optimization for the brave of heart ;)
OMITFP=-fomit-frame-pointer

# ---------------------------------------------------------------------------
# Manual configuration for Windows and systems without sed, pkgconfig, etc.
# Uncomment, change and good luck :)

OUTFILE=gd.dll
CFLAGS=-O3 -Wall $(OMITFP)
CFLAGS+=-I$(HOME)/software/lua-5.2.3/src -I/mingw64/include/libgd-2.2
CFLAGS+=-DVERSION=\"$(VERSION)\"
GDFEATURES=-DGD_XPM -DGD_JPEG -DGD_FONTCONFIG -DGD_FREETYPE -DGD_PNG -DGD_GIF
LFLAGS=-shared -L "$(HOME)/webots/msys64/mingw64/bin" -lgd -llua52 -lm $(OMITFP)
# ---------------------------------------------------------------------------


all: test

$(OUTFILE): gd.lo
	$(CC) -o $(OUTFILE) gd.lo $(LFLAGS)

test: $(OUTFILE)
	$(LUABIN) test_features.lua

gd.lo: luagd.c
	$(CC) -o gd.lo -c $(GDFEATURES) $(CFLAGS) luagd.c

install: $(OUTFILE)
	install -D -s $(OUTFILE) $(DESTDIR)/$(INSTALL_PATH)/$(OUTFILE)


# Rules for making a distribution tarball

TDIR=lua-gd-$(VERSION)
DFILES=COPYING README luagd.c lua-gd.spec Makefile test_features.lua
dist: $(DISTFILES)
	rm -f $(TDIR).tar.gz
	mkdir $(TDIR)
	mkdir -p $(TDIR)/doc $(TDIR)/demos $(TDIR)/debian
	cp $(DFILES) $(TDIR)
	cp demos/* $(TDIR)/demos/
	cp doc/* $(TDIR)/doc/
	cp debian/* $(TDIR)/debian/
	tar czf $(TDIR).tar.gz $(TDIR)
	rm -rf $(TDIR)

clean:
	rm -f $(OUTFILE) gd.lo
	rm -rf $(TDIR) $(TDIR).tar.gz
	rm -f demos/out.png demos/out.gif demos/counter.txt

.PHONY: all test install clean dist

Create the package by adding gd.dll to the archive.

Clone this wiki locally