summaryrefslogtreecommitdiff
path: root/build.lua
blob: 3a204bb49d257d1b73a92491338c7a7c2d92a78c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
#!/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(dir .. '/build.lua')
  if build then
    setfenv(build, getfenv(2))
    build(workingDir .. '/' .. dir)
  else
    print("ERROR - " .. err)
  end
end


workingDir = readCommand('pwd')
baseDir = workingDir
if 'number' == type(args) then
  for i = 1, args do
    baseDir = string.gsub(baseDir, '(.*)/.-$', '%1')
  end
end

bin_d    = baseDir
lib_d    = baseDir .. '/lib'
data_d   = baseDir .. '/media'
locale_d = baseDir .. '/locale'

-- 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"')

CFLAGS = '-g -Wall -I ' .. baseDir .. '/src/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 .. ' ' .. CFLAGOPTS

LDFLAGS = '-L ' .. baseDir .. '/lib ' .. pkgConfig('libs-only-L', 'luajit') .. ' -L /usr/lib -L /lib'
libs = pkgConfig('libs', 'elementary') .. ' ' .. pkgConfig('libs', 'luajit') .. ' -lpthread -lm -ldl -Wl,-rpath,' .. baseDir .. '/lib'
LFLAGS = '-L ' .. workingDir .. ' -d'
EDJE_FLAGS = '-id ' .. baseDir .. '/media -fd ' .. baseDir .. '/media'

removeFiles(workingDir, {'evas-3d-elm'})

runCommand('evas-3d-elm',	workingDir, 'gcc ' .. CFLAGS .. ' -o evas-3d-elm evas-3d-elm.c ' .. LDFLAGS .. ' ' .. libs)