aboutsummaryrefslogtreecommitdiff
path: root/bam.lua
blob: be75fe5236ad83a810f2559abdb8302825a7d7bc (plain) (blame)
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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
--
-- Redefine output function to put everything in build/
--

function BuildOutput(settings, fname)
	if fname:sub(1, 4) == "src/" then
		fname = fname:sub(5)
	end
	local out = PathJoin("build", PathBase(fname) .. settings.config_ext)
	return out
end

--
-- Define custom settings
--

host_settings = NewSettings()
common_settings = NewSettings()

if os.getenv('CC') and string.match(os.getenv('CC'), '.*analyzer$') then
	print("Detected clang-analyzer")
	SetDriversGCC(host_settings)
	host_settings.cc.exe_c = 'CCC_CC=gcc ' .. os.getenv('CC')
	host_settings.cc.exe_cxx = 'CCC_CXX=g++ ' .. os.getenv('CXX')

	SetDriversGCC(common_settings)
	common_settings.cc.flags:Add('-U__linux__')
	common_settings.cc.exe_c = 'CCC_CC=i586-elf-gcc ' .. os.getenv('CC')
	common_settings.cc.exe_cxx = 'CCC_CXX=i586-elf-g++ ' .. os.getenv('CXX')
	common_settings.link.exe = 'CCC_CC=i586-elf-gcc ' .. os.getenv('CC')
else
	common_settings.cc.exe_c = "i586-elf-gcc"
	common_settings.cc.exe_cxx = "i586-elf-g++"
	common_settings.link.exe = "i586-elf-gcc"
end


host_settings.cc.Output = BuildOutput
host_settings.cc.extension = ".host.o"
host_settings.cc.includes:Add("src/lib/include/proto",
							  "src/common/include")
host_settings.link.extension = ".bin"


common_settings.compile.mappings['s'] = function(settings, input)
	local output = BuildOutput(settings, input) .. settings.cc.extension
	AddJob(output, "nasm " .. input,
		   "nasm -felf -g -o " .. output .. " " .. input)
	AddDependency(output, input)
	return output
end

common_settings.cc.Output = BuildOutput
common_settings.cc.includes:Add("src/common/include", ".")
common_settings.cc.flags:Add("-m32",
							 "-ffreestanding",
							 "-std=gnu99",
							 "-Wall", "-Wextra", "-Werror",
							 "-Wno-unused-parameter",
							 "-Wno-unused-function",
							 "-g", "-O0")

common_settings.link.extension = ".bin"
common_settings.link.flags:Add("-ffreestanding",
							   "-nostdlib",
							   "-O0")
common_settings.link.libs:Add("gcc")
common_settings.link.Output = BuildOutput


user_settings = TableDeepCopy(common_settings)
user_settings.cc.includes:Add('src/lib/include')

--
-- Require build scripts for all components
--

require 'src/common/libkogata/bam'
require 'src/common/libc/bam'
require 'src/common/libalgo/bam'

require 'src/kernel/bam'

require 'src/lib/libkogata/bam'

require 'src/sysbin/bam'

require 'res/fonts/bam'
require 'res/keymaps/bam'

--
-- Build script for CDROM.iso
--

cdrom = "build/cdrom.iso"

AddJob(cdrom, "building ISO", "./make_cdrom.sh")
AddDependency(cdrom, kernel, sysbin, fonts, keymaps)

DefaultTarget(cdrom)

--
-- Script for running tests
--

tests = {}

require 'src/tests/slab_test/bam'
require 'src/tests/ktests/bam'
require 'src/tests/utests/bam'

PseudoTarget("test", tests)