From c501a8c75e6fce2e91d52f60a5454de5aa3ef8f1 Mon Sep 17 00:00:00 2001 From: David Walter Seikel Date: Sun, 20 Apr 2014 15:24:46 +1000 Subject: Convert build shell scripts to Lua, with common infrastructure. --- ClientHamr/GuiLua/build.lua | 23 ++++++++++++ ClientHamr/GuiLua/build.sh | 26 -------------- ClientHamr/extantz/build.lua | 26 ++++++++++++++ ClientHamr/extantz/build.sh | 29 --------------- LuaSL/build.lua | 25 +++++++++++++ LuaSL/build.sh | 69 ----------------------------------- build.lua | 86 ++++++++++++++++++++++++++++++++++++++++++++ build.sh | 40 --------------------- 8 files changed, 160 insertions(+), 164 deletions(-) create mode 100755 ClientHamr/GuiLua/build.lua delete mode 100755 ClientHamr/GuiLua/build.sh create mode 100755 ClientHamr/extantz/build.lua delete mode 100755 ClientHamr/extantz/build.sh create mode 100755 LuaSL/build.lua delete mode 100755 LuaSL/build.sh create mode 100755 build.lua delete mode 100755 build.sh diff --git a/ClientHamr/GuiLua/build.lua b/ClientHamr/GuiLua/build.lua new file mode 100755 index 0000000..3fcfffb --- /dev/null +++ b/ClientHamr/GuiLua/build.lua @@ -0,0 +1,23 @@ +#!/usr/bin/env lua + +local dir = ... + +if 'nil' == type(dir) then + local build, err = loadfile('../../build.lua') + if build then + setfenv(build, getfenv(2)) + build('') + else + print("ERROR - " .. err) + end + dir = readCommand('pwd') +end + +LDFLAGS = '-L ' .. dir .. ' ' .. LDFLAGS + +removeFiles(dir, {'test_c.so', 'GuiLua.o', 'libGuiLua.so', 'skang'}) + +runCommand('C modules', dir, 'gcc ' .. CFLAGS .. ' -fPIC -shared -o test_c.so test_c.c') +runCommand(nil, dir, 'gcc ' .. CFLAGS .. ' -fPIC -c GuiLua.c') +runCommand('C libraries', dir, 'gcc ' .. CFLAGS .. ' -shared -Wl,-soname,libGuiLua.so -o libGuiLua.so GuiLua.o') +runCommand('C apps', dir, 'gcc ' .. CFLAGS .. ' -Wl,-export-dynamic -o skang skang.c ' .. LDFLAGS .. ' -lGuiLua ' .. libs) diff --git a/ClientHamr/GuiLua/build.sh b/ClientHamr/GuiLua/build.sh deleted file mode 100755 index c405bb2..0000000 --- a/ClientHamr/GuiLua/build.sh +++ /dev/null @@ -1,26 +0,0 @@ -#! /bin/bash - -export LOCALDIR=`pwd` - -# No need for a make file, or dependencies, the entire thing takes only a few seconds to build. - -CFLAGS="-g -Wall -I include -I $LOCALDIR" -CFLAGS="$CFLAGS -I ../../libraries" -CFLAGS="$CFLAGS $(pkg-config --cflags luajit)" -CFLAGS="$CFLAGS $(pkg-config --cflags elementary)" -CFLAGS="$CFLAGS -DPACKAGE_BIN_DIR=\"$LOCALDIR\"" -CFLAGS="$CFLAGS -DPACKAGE_LIB_DIR=\"$LOCALDIR\"" -CFLAGS="$CFLAGS -DPACKAGE_DATA_DIR=\"$LOCALDIR\" $CFLAGOPTS" - -LDFLAGS="-L $LOCALDIR $(pkg-config --libs-only-L luajit) -L lib -L /usr/lib -L /lib" -libs="$(pkg-config --cflags --libs elementary) $(pkg-config --libs luajit) -lpthread -lm -ldl" - -echo "clean" -rm -f test_c.so GuiLua.o libGuiLua.so skang -echo "C modules" -gcc $CFLAGS -fPIC -shared -o test_c.so test_c.c -gcc $CFLAGS -fPIC -c GuiLua.c -echo "C libraries" -gcc $CFLAGS -shared -Wl,-soname,libGuiLua.so -o libGuiLua.so GuiLua.o -echo "C apps" -gcc $CFLAGS -Wl,-export-dynamic -o skang skang.c $LDFLAGS -lGuiLua $libs diff --git a/ClientHamr/extantz/build.lua b/ClientHamr/extantz/build.lua new file mode 100755 index 0000000..d53449e --- /dev/null +++ b/ClientHamr/extantz/build.lua @@ -0,0 +1,26 @@ +#!/usr/bin/env lua + +local dir = ... + +if 'nil' == type(dir) then + local build, err = loadfile('../../build.lua') + if build then + setfenv(build, getfenv(2)) + build('') + else + print("ERROR - " .. err) + end + dir = readCommand('pwd') +end + +CFLAGS = CFLAGS .. ' -I../../libraries/irrlicht-1.8.1/include -I/usr/X11R6/include' +LDFLAGS = LDFLAGS .. ' -L../../libraries/irrlicht-1.8.1/lib/Linux' +libs = libs .. ' -lIrrlicht -lGL -lbz2' + +removeFiles(dir, {'extantz', 'crappisspuke.o', 'CDemo.o', 'extantzCamera.o', 'extantz.edj'}) + +runCommand('edje_cc', dir, 'edje_cc ' .. EDJE_FLAGS .. ' extantz.edc extantz.edj') +runCommand('Irrlicht files', dir, 'g++ ' .. CFLAGS .. ' -O3 -ffast-math -c crappisspuke.cpp -o crappisspuke.o ' .. LDFLAGS) +runCommand(nil, dir, 'g++ ' .. CFLAGS .. ' -O3 -ffast-math -c CDemo.cpp -o CDemo.o ' .. LDFLAGS) +runCommand('extantz', dir, 'g++ ' .. CFLAGS .. ' -O3 -ffast-math -c extantzCamera.cpp -o extantzCamera.o ' .. LDFLAGS) +runCommand(nil, dir, 'gcc ' .. CFLAGS .. ' extantz.c crappisspuke.o CDemo.o extantzCamera.o -o extantz ' .. LDFLAGS .. ' ' .. libs .. ' && strip extantz') diff --git a/ClientHamr/extantz/build.sh b/ClientHamr/extantz/build.sh deleted file mode 100755 index d3ad3b0..0000000 --- a/ClientHamr/extantz/build.sh +++ /dev/null @@ -1,29 +0,0 @@ -#! /bin/bash - -export LOCALDIR=`pwd` - -# No need for a make file, or dependencies, the entire thing takes only a few seconds to build. - -CFLAGS="-g -Wall -I include -I $LOCALDIR" -CFLAGS="$CFLAGS -I ../../libraries -I../../libraries/irrlicht-1.8.1/include -I/usr/X11R6/include" -CFLAGS="$CFLAGS $(pkg-config --cflags luajit)" -CFLAGS="$CFLAGS $(pkg-config --cflags elementary)" -CFLAGS="$CFLAGS $(pkg-config --cflags ephysics)" -CFLAGS="$CFLAGS -DPACKAGE_BIN_DIR=\"$LOCALDIR\"" -CFLAGS="$CFLAGS -DPACKAGE_LIB_DIR=\"$LOCALDIR\"" -CFLAGS="$CFLAGS -DPACKAGE_DATA_DIR=\"$LOCALDIR\" $CFLAGOPTS" - -LDFLAGS="-L $LOCALDIR $(pkg-config --libs-only-L luajit) -L lib -L /usr/lib -L /lib -L../../libraries/irrlicht-1.8.1/lib/Linux " -libs="$(pkg-config --cflags --libs elementary) $(pkg-config --libs luajit) -lpthread -lm -ldl -lIrrlicht -lGL -lbz2" - -echo "clean" -rm -f extantz crappisspuke.o CDemo.o extantzCamera.o extantz.edj -echo "edje" -edje_cc -id images extantz.edc extantz.edj -echo "Irrlicht" -#g++ -O3 -ffast-math crappisspuke.cpp -o crappisspuke -I../../libraries/irrlicht-1.8/include -I/usr/X11R6/include -L../../libraries/irrlicht-1.8/lib/Linux -lIrrlicht -lGL -lXxf86vm -lXext -lX11 -lXcursor && ./crappisspuke -g++ $CFLAGS -O3 -ffast-math -c crappisspuke.cpp -o crappisspuke.o $LDFLAGS -g++ $CFLAGS -O3 -ffast-math -c CDemo.cpp -o CDemo.o $LDFLAGS -echo "extantz" -g++ $CFLAGS -O3 -ffast-math -c extantzCamera.cpp -o extantzCamera.o $LDFLAGS -gcc $CFLAGS extantz.c crappisspuke.o CDemo.o extantzCamera.o -o extantz $LDFLAGS $libs && strip extantz diff --git a/LuaSL/build.lua b/LuaSL/build.lua new file mode 100755 index 0000000..ea2151d --- /dev/null +++ b/LuaSL/build.lua @@ -0,0 +1,25 @@ +#!/usr/bin/env lua + +local dir = ... + +if 'nil' == type(dir) then + local build, err = loadfile('../build.lua') + if build then + setfenv(build, getfenv(2)) + build('') + else + print("ERROR - " .. err) + end + dir = readCommand('pwd') +end + +dir = dir .. '/src' + +removeFiles(dir, {'../LuaSL', '*.o', '*.output', '*.backup', '../*.edj', 'LuaSL_lexer.h', 'LuaSL_lexer.c', 'LuaSL_lemon_yaccer.h', 'LuaSL_lemon_yaccer.c', 'LuaSL_lemon_yaccer.out'}) + +-- Run lemon first, flex depends on it to define the symbol values. +runCommand('lemon', dir, '../../libraries/lemon/lemon -s -T../../libraries/lemon/lempar.c LuaSL_lemon_yaccer.y') +runCommand('flex', dir, 'flex -C --outfile=LuaSL_lexer.c --header-file=LuaSL_lexer.h LuaSL_lexer.l') +runCommand('edje_cc', dir, 'edje_cc ' .. EDJE_FLAGS .. ' LuaSL.edc ../LuaSL.edj') +compileFiles('../LuaSL', dir, {'LuaSL_main', 'LuaSL_compile', 'LuaSL_threads', 'LuaSL_utilities', 'LuaSL_lexer', 'LuaSL_lemon_yaccer'}) +compileFiles('../LuaSL_test', dir, {'LuaSL_test', 'LuaSL_utilities'}) diff --git a/LuaSL/build.sh b/LuaSL/build.sh deleted file mode 100755 index 8d776d6..0000000 --- a/LuaSL/build.sh +++ /dev/null @@ -1,69 +0,0 @@ -#! /bin/bash - -export LOCALDIR=`pwd` - -# No need for a make file, or dependencies, the entire thing takes only a few seconds to build. - -CFLAGS="-g -Wall -Wunreachable-code -I include -I $LOCALDIR" -CFLAGS="$CFLAGS -I ../../libraries" -CFLAGS="$CFLAGS $(pkg-config --cflags luajit)" -CFLAGS="$CFLAGS $(pkg-config --cflags eo)" -CFLAGS="$CFLAGS $(pkg-config --cflags eet)" -CFLAGS="$CFLAGS $(pkg-config --cflags ecore-con)" -CFLAGS="$CFLAGS $(pkg-config --cflags ecore-evas)" -CFLAGS="$CFLAGS $(pkg-config --cflags ecore-file)" -CFLAGS="$CFLAGS $(pkg-config --cflags edje)" -CFLAGS="$CFLAGS -DPACKAGE_BIN_DIR=\"$LOCALDIR\"" -CFLAGS="$CFLAGS -DPACKAGE_LIB_DIR=\"$LOCALDIR\"" -CFLAGS="$CFLAGS -DPACKAGE_DATA_DIR=\"$LOCALDIR\" $CFLAGOPTS" - -LDFLAGS="$(pkg-config --libs-only-L luajit) -L lib -L /usr/lib -L /lib" -libs="$(pkg-config --libs edje) $libs $(pkg-config --libs luajit)" - -LFLAGS="-d" -EDJE_FLAGS="-id images -fd fonts" -# Dunno why I needed this, not gonna work with a packaged LuaJIT anyway. -#LD_RUN_PATH="../../libraries/LuaJIT-2.0.2/src:" - -cd src -echo "clean" -rm -f ../LuaSL *.o *.output *.backup ../luac.out ../*.edj LuaSL_lexer.h LuaSL_lexer.c LuaSL_lemon_yaccer.h LuaSL_lemon_yaccer.c LuaSL_lemon_yaccer.out - -# Run lemon first, flex depends on it to define the symbol values. -command="../../libraries/lemon/lemon -s -T../../libraries/lemon/lempar.c LuaSL_lemon_yaccer.y" -echo "lemon" -$command - -command="flex -C --outfile=LuaSL_lexer.c --header-file=LuaSL_lexer.h LuaSL_lexer.l" -echo "flex" -$command - -command="edje_cc $EDJE_FLAGS LuaSL.edc ../LuaSL.edj" -echo "edje_cc" -$command - -names="LuaSL_main LuaSL_compile LuaSL_threads LuaSL_utilities LuaSL_lexer LuaSL_lemon_yaccer" -objects="" -for i in $names -do - command="gcc $CFLAGS -c -o $i.o $i.c" - echo $i - $command - objects="$objects $i.o" -done -command="gcc $CFLAGS -o ../LuaSL $objects $LDFLAGS $libs" -echo "LuaSL" -$command - -names="LuaSL_test LuaSL_utilities" -objects="" -for i in $names -do - command="gcc $CFLAGS -c -o $i.o $i.c" - echo $i - $command - objects="$objects $i.o" -done -command="gcc $CFLAGS -o ../LuaSL_test $objects $LDFLAGS $libs" -echo "LuaSL_test" -$command diff --git a/build.lua b/build.lua new file mode 100755 index 0000000..de337de --- /dev/null +++ b/build.lua @@ -0,0 +1,86 @@ +#!/usr/bin/env lua + +local args = ... +local tmpFile = os.tmpname() + +readCommand = function (command) + os.execute(command .. ' >' .. tmpFile) + local tf = io.open(tmpFile, 'r') + local result = tf:read() + tf:close() + return result +end + +pkgConfig = function (what, name) + return readCommand('pkg-config --' .. what .. ' ' .. name) +end + +removeFiles = function (dir, files) + print('clean') + for i, v in ipairs(files) do + os.execute('rm -f ' .. dir .. '/' .. v) + end +end + +runCommand = function (name, dir, command) + if name then print('\n' .. name) end + os.execute('cd ' .. dir .. '; ' .. command) +end + +compileFiles = function (name, dir, files) + local objects = '' + print('\n' .. name) + for i, v in ipairs(files) do + print(' ' .. v) + os.execute('cd ' .. dir .. '; gcc ' .. CFLAGS .. ' -c -o ' .. v .. '.o ' .. v .. '.c') + objects = objects .. ' ' .. v .. '.o' + end + os.execute('cd ' .. dir .. '; gcc ' .. CFLAGS .. ' -o ' .. name .. ' ' .. objects .. ' ' .. LDFLAGS .. ' ' .. libs) +end + +local buildSub = function (name, dir) + print('_______________ BUILDING ' .. name .. ' _______________') + local build, err = loadfile(LOCALDIR .. '/' .. dir .. '/build.lua') + if build then + setfenv(build, getfenv(2)) + build(LOCALDIR .. '/' .. dir) + else + print("ERROR - " .. err) + end +end + +-- Likely this will fail, coz Lua likes to strip out environmont variables. +-- On the other hand, there's a more direct way to get to environment variables, it would fail to. +CFLAGOPTS = readCommand('echo "$CFLAGOPTS"') + +LOCALDIR = readCommand('pwd')readCommand('pwd') +CFLAGS = '-g -Wall -I include -I ' .. LOCALDIR .. ' -I ../../libraries' +CFLAGS = CFLAGS .. ' ' .. pkgConfig('cflags', 'luajit') +CFLAGS = CFLAGS .. ' ' .. pkgConfig('cflags', 'eo') +CFLAGS = CFLAGS .. ' ' .. pkgConfig('cflags', 'eet') +CFLAGS = CFLAGS .. ' ' .. pkgConfig('cflags', 'ecore-con') +CFLAGS = CFLAGS .. ' ' .. pkgConfig('cflags', 'ecore-evas') +CFLAGS = CFLAGS .. ' ' .. pkgConfig('cflags', 'ecore-file') +CFLAGS = CFLAGS .. ' ' .. pkgConfig('cflags', 'edje') +CFLAGS = CFLAGS .. ' ' .. pkgConfig('cflags', 'elementary') +CFLAGS = CFLAGS .. ' -DPACKAGE_BIN_DIR=\\"' .. LOCALDIR .. '\\"' +CFLAGS = CFLAGS .. ' -DPACKAGE_LIB_DIR=\\"' .. LOCALDIR .. '\\"' +CFLAGS = CFLAGS .. ' -DPACKAGE_DATA_DIR=\\"' .. LOCALDIR .. '\\"' +CFLAGS = CFLAGS .. ' ' .. CFLAGOPTS + +LDFLAGS = '-L ' .. LOCALDIR .. ' ' .. pkgConfig('libs-only-L', 'luajit') .. ' -L lib -L /usr/lib -L /lib' +libs = pkgConfig('libs', 'elementary') .. ' ' .. pkgConfig('libs', 'luajit') .. ' -lpthread -lm' +LFLAGS = '-d' +EDJE_FLAGS = '-id images -fd fonts' + + +if 'nil' == type(args) then + print('_______________ BUILDING lemon _______________') + removeFiles(LOCALDIR .. '/libraries/lemon', {'*.o', 'lemon'}) + compileFiles('lemon', LOCALDIR .. '/libraries/lemon', {'lemon'}) + print('_______________ BUILDING Irrlicht _______________') + runCommand('Irrlicht', 'libraries/irrlicht-1.8.1/source/Irrlicht', 'make') + buildSub('LuaSL', 'LuaSL') + buildSub('GuiLua', 'ClientHamr/GuiLua') + buildSub('extantz', 'ClientHamr/extantz') +end diff --git a/build.sh b/build.sh deleted file mode 100755 index 28c03f7..0000000 --- a/build.sh +++ /dev/null @@ -1,40 +0,0 @@ -#! /bin/bash - -wd=$(pwd) - -echo "_______________ BUILDING lemon _______________" -cd $wd/libraries/lemon -rm -f *.o lemon - -CFLAGS="-g -Wall -I include $CFLAGOPTS" -LDFLAGS="-L lib -L /usr/lib -L /lib" -LFLAGS="-d" - -names="lemon" -objects="" -for i in $names -do - command="gcc $CFLAGS -c -o $i.o $i.c" - echo $command - $command - objects="$objects $i.o" -done -command="gcc $CFLAGS -o lemon $objects $LDFLAGS $libs" -echo $command -$command - -echo "_______________ BUILDING Irrlicht _______________" -cd $wd/libraries/irrlicht-1.8.1/source/Irrlicht -make - -echo "_______________ BUILDING LuaSL _______________" -cd $wd/LuaSL -./build.sh - -echo "_______________ BUILDING GuiLua _______________" -cd $wd/ClientHamr/GuiLua -./build.sh - -echo "_______________ BUILDING extantz _______________" -cd $wd/ClientHamr/extantz -./build.sh -- cgit v1.1