Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Configure Builds with Lua #114

Draft
wants to merge 72 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
72 commits
Select commit Hold shift + click to select a range
5fad0c1
Initial Lua build config
Lethja Apr 6, 2024
b5eff3f
Added help and compiler skip flags
Lethja Apr 7, 2024
e4cc5e2
Added tests to check bit size of int and long
Lethja Apr 7, 2024
fbfc65c
Added clang target support so far, improved cc support
Lethja Apr 7, 2024
1dc8afa
Use consistent formatting across Lua code
Lethja Apr 7, 2024
65e8e17
Added linker checks for gcc and watcom
Lethja Apr 8, 2024
b6c3da0
Removed ld entry point warning by setting it to address zero (actual …
Lethja Apr 10, 2024
f3ee4ab
Check if gcc can target a x86 architecture
Lethja Apr 13, 2024
7074def
Added skip for linker check
Lethja Apr 13, 2024
f849d6b
Inital makefile generation
Lethja Apr 13, 2024
285b4af
Check for `RD /S /Q` before `DELTREE /Y` on DOS-like systems
Lethja Apr 13, 2024
a7b3598
Added and use GetMakefileOutputName() function
Lethja Apr 14, 2024
d3070c7
Added optional 'src' parameter to 'CreateCTestFile()' to allow C code…
Lethja Apr 14, 2024
f3fe981
Remove family parameter from SanitizePath(), use System.family from g…
Lethja Apr 14, 2024
39a4c69
Removed unneeded pramaters from several functions (use global table d…
Lethja Apr 14, 2024
ef743bf
WIP Generate mockup of wmake for large model build when running 'lua …
Lethja Apr 14, 2024
979b957
Added assembly executable checks
Lethja Apr 15, 2024
18d720e
Free memory after every program execution to keep memory available on…
Lethja Apr 15, 2024
6403418
Added MASM and GAS Assembler tests
Lethja Apr 17, 2024
a0cd774
Added StringToHexArray
Lethja Apr 17, 2024
5307f3f
Added cross compile flag
Lethja Apr 17, 2024
a2e04e2
Added check if build system can run binary produced by C compiler
Lethja Apr 17, 2024
308384e
Added `pp` (pre-processor) entry to the `Compiler` table
Lethja Apr 17, 2024
e1720c9
Simplified CheckSystemFamily()
Lethja Jun 30, 2024
66a035b
Improved system checks
Lethja Jul 20, 2024
a40f9b2
Improved configur.lua options
Lethja Jul 21, 2024
9421427
Move tests only specific to the GCC or Watcom compiler to their own f…
Lethja Jul 21, 2024
d1b2093
Check that all Lua files are present before doing build tests
Lethja Jul 22, 2024
fdee5dc
Add directory check to FileExists()
Lethja Jul 23, 2024
1072f55
Added mkdir() utility function
Lethja Jul 23, 2024
1863289
WIP: lazy-load makefile generators as their own modules
Lethja Jul 23, 2024
c8fde27
Clean up build artifacts in CheckCompilerNative() test
Lethja Jul 24, 2024
183c9ee
Gave sub-modules more accurate names
Lethja Jul 24, 2024
c29a437
Implemented CheckLuaPath
Lethja Jul 25, 2024
6b154cf
Remove check message from mkdir()
Lethja Jul 25, 2024
a884b21
Added check for archiver
Lethja Jul 25, 2024
d5b286c
Removed redundant implementation of CheckLinker()
Lethja Jul 25, 2024
c1aa597
Initial implementation of watcom makefile generation
Lethja Jul 25, 2024
fc0dc6b
Corrected watcom_*.mak description and object paths
Lethja Jul 27, 2024
213d873
Merge branch 'gvanem:master' into lua-conf
Lethja Jul 27, 2024
b337f38
Added description and flag documentation to generated Watcom makefiles
Lethja Jul 27, 2024
ffe9506
Remove variables from makefile that don't need them
Lethja Jul 27, 2024
36d77f1
Added comment and spacing for each section of a generated makefile
Lethja Jul 27, 2024
b1180a7
Corrected OBJPATH variable path relative to where the makefile
Lethja Jul 27, 2024
8134add
Reimplement bin2c as a Lua script
Lethja Jul 28, 2024
eaaa709
Initial implementation of GenerateMakefileRules() for wmake.lua
Lethja Jul 28, 2024
ce715c8
Implmented syserr.c & watcom.err generation from Lua
Lethja Jul 29, 2024
b20d8f1
Added footer and fixed several bugs
Lethja Jul 29, 2024
adda857
Added more descriptive footer after Watcom makefile generation
Lethja Jul 29, 2024
6273ad8
Implemented check for nasm compiler
Lethja Jul 30, 2024
3d0b4c8
Added resfile.lua
Lethja Aug 1, 2024
f810b20
Added check for GCC version
Lethja Aug 2, 2024
82617c3
Initial DJGPP makefile generation
Lethja Aug 2, 2024
0596b27
Added string pattern argument to resfile.lua
Lethja Aug 4, 2024
f6b2df1
Changed the paths GeneratePaths() generates based on makefiles prefer…
Lethja Aug 4, 2024
e7e527e
Use resfile.lua to write cflags.h when generating a GNU makefile
Lethja Aug 4, 2024
ace830b
Added arguments, sources & footer helper to djgpp makefile generation
Lethja Aug 4, 2024
a494396
Improved CheckCompilerNative() check
Lethja Aug 4, 2024
ce200bf
Fixed potenical nil access error in gcc.lua
Lethja Aug 4, 2024
489ee4f
Initial implementation of make.lua version of GenerateErrorFile()
Lethja Aug 4, 2024
c6d22b8
Initial implementation of dosemu check and execution
Lethja Aug 4, 2024
bfb129d
Added emu.lua
Lethja Aug 4, 2024
36e597c
Added cpu_emu = full to temporary dosemu configuration (required to r…
Lethja Aug 5, 2024
2ea6eed
Implemented generating 'inc/sys/djgpp.err' and 'src/build/djgpp/syser…
Lethja Aug 6, 2024
d53c487
Added '-c' to cflags for Djgpp
Lethja Aug 6, 2024
4bd5ab5
Don't include uio.h on DJGPP v2.3
Lethja Aug 6, 2024
87f8558
Added varfill.lua
Lethja Aug 7, 2024
bb4f584
Successfully built DJGPP
Lethja Aug 8, 2024
3566d90
Revert "Added varfill.lua"
Lethja Aug 8, 2024
88ed226
Fixed error in Watcom makefile generation
Lethja Aug 8, 2024
5debd9c
Only add asmpkt to OBJS on 16-bit makefiles
Lethja Aug 8, 2024
f130067
Merge branch 'master' into lua-conf
Lethja Aug 27, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
88 changes: 88 additions & 0 deletions configur.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
require("lua.boot")

-- Determine operating system family
System = CheckSystemFamily()

-- Check 'lua' contains required files
CheckDirContains("lua", {
"asm.lua",
"checks.lua",
"compiler.lua",
"compiler/custom.lua",
"compiler/gcc.lua",
"compiler/watcom.lua",
"makefile.lua",
"makefile/make.lua",
"makefile/wmake.lua",
"util.lua",
}
)

-- Required files are found and can now be loaded
require("lua.checks")
require("lua.makefile")
require("lua.util")

Target = {}
GetOpt()

-- Check parameters and which makefile to generate
Target.makefile = CheckMakefileRequestValid()

-- Create a unique name for testing file and folder
TmpFolder = UniqueName()

-- Check creating/deleting files and folders works
CheckCreateDirCmd(TmpFolder)
CheckRemoveFileCmd(TmpFolder)
CheckRemoveDirCmd(TmpFolder)

-- Check 'util' contains required source code files
CheckDirContains("util", {
"errnos.c",
}
)

-- Check 'inc' contains required files (for application to include)
CheckDirContains("inc", {
"arpa/inet.h",
"netdb.h",
"netinet/in.h",
"sys/socket.h",
"tcp.h",
}
)

-- Check 'src' contains required files
CheckDirContains("src", MakefileCoreSource())

-- Create a basic C file to test the compiler
Compiler = {}
CheckAssembler()
CheckCompiler()

-- Check size of standard types an actual 32-bit typedef can be defined
CheckCompilerNative() -- Check that these tests can be done (or skipped)
CheckCompilerIntSize()
CheckCompilerLongSize()

-- Check archiver and linker works
CheckArchiver()
CheckLinker()

-- Free memory (nessasary for real mode DOS systems)
package.loaded["lua.boot"] = nil
package.loaded["lua.checks"] = nil
package.loaded["lua.compiler"] = nil
package.loaded["lua.compiler.custom"] = nil
package.loaded["lua.compiler.gcc"] = nil
package.loaded["lua.compiler.watcom"] = nil
collectgarbage("collect", 9001)

-- Generate makefile
GenerateMakefile()

-- Print helpful commands to run next
PrintFooterHelper()

os.exit()
245 changes: 245 additions & 0 deletions lua/asm.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,245 @@
--[[
asm.lua contains functions for testing assemblers.
]]

function CreateNasmTestFile(name, src)
if not src then
src =
[[
org 100h ; Origin point for .COM files

; Print string
mov ah, 09h ; Function to print string
mov dx, helloMsg ; Load address of the message directly into dx
int 21h ; Call DOS interrupt to print the string

; Terminate program
mov ah, 4Ch ; DOS function to terminate program
int 21h ; Call DOS interrupt

helloMsg db 'Hello, NASM!', '$'
]]
end

local file = io.open(name, "w")
if file then
file:write(src)
file:close()
src = nil
return true
end

return false
end

function CreateMasmTestFile(name, src)
if not src then
src =
[[
.model small
.stack 100h

.data
helloMsg db 'Hello, MASM!', '$'

.code
main:
mov ax, @data
mov ds, ax

mov ah, 09h ; Function to print string
lea dx, helloMsg ; Load address of the message
int 21h ; Call DOS interrupt to print the string

mov ah, 4Ch ; DOS function to terminate program
int 21h ; Call DOS interrupt

end main
]]
end

local file = io.open(name, "w")
if file then
file:write(src)
file:close()
src = nil
return true
end

return false
end

function CreateGasTestFile(name, src)
if not src then
src =
[[
.section .data
hello_msg:
.ascii "Hello, GAS!\0"
.section .text
.global _start
_start:
mov $0x2, %ax
mov %ax, %ds

mov $0x09, %ah # Function to print string
mov $hello_msg, %dx # Load address of the message
int $0x21 # Call DOS interrupt to print the string

mov $0x4c, %ah # DOS function to terminate program
int $0x21 # Call DOS interrupt
]]
end

local file = io.open(name, "w")
if file then
file:write(src)
file:close()
src = nil
return true
end

return false
end

function CheckCustomAssembler(as, tmpName)
Check("Checking '" .. as .. "' compiler understands MASM format")

if Target.skip then
Pass("Skipped")
return
end

if not CreateMasmTestFile(tmpName .. ".asm") then Error() end
RunCommand(as .. " " .. tmpName .. ".asm")
os.remove(tmpName .. ".asm")

local exists = CheckAndRemoveCommonArtifacts(tmpName)
if exists > 0 then
Pass("Yes")
Compiler.as = as
Compiler.aext = ".asm"
else
Pass("No")
Check("Checking '" .. as .. "' compiler understands GAS format")

if not CreateGasTestFile(tmpName .. ".s") then Error() end
RunCommand(as .. " " .. tmpName .. ".s")
os.remove(tmpName .. ".s")
exists = CheckAndRemoveCommonArtifacts(tmpName)
if exists > 0 then
Pass("Yes")
Compiler.as = as
Compiler.aext = ".s"
Pass("Yes")
end
end

local name

if Compiler.aext == "masm" then
if not CreateMasmTestFile(tmpName .. ".asm") then Error() else
name = tmpName .. ".asm"
end
else
if not CreateGasTestFile(tmpName .. ".s") then Error() else
name = tmpName .. ".s"
end
end

local aflags = CheckEnvVar("AFLAGS")
if aflags then
Check("Checking if C compiler works with CFLAGS")
local r = RunCommand (as .. " " .. aflags .. " " .. name)

local exists = CheckAndRemoveCommonArtifacts(tmpName)
if exists > 0 then Pass("Yes")
else
os.remove(name)
Fail("No")
end

Compiler.aflags = aflags
end

os.remove(name)
end

function CheckGccAssembler(as, tmpName)
local gcc = as or "as"

Check("Checking '" .. gcc .. "' is available")

if Target.skip then
Pass("Skipped")
Compiler.as = gcc
Compiler.aext = ".s"
return
end

if not CreateGasTestFile(tmpName .. ".s") then Error() end

RunCommand (gcc .. " " .. tmpName .. ".s ")

local exist = CheckAndRemoveCommonArtifacts(tmpName)
if exist > 0 then Pass("Yes")
else
os.remove(tmpName .. ".s")
Fail("No")
end

os.remove(tmpName .. ".s")
Compiler.as = gcc
Compiler.aext = ".s"
end

function CheckNasmAssembler(tmpName)
local nasm = CheckEnvVar("NASM") or "nasm"

Check("Checking " .. nasm .. " is available")

if not CreateNasmTestFile(tmpName .. ".nas") then Error() end

RunCommand (nasm .. " -f bin -o " ..
tmpName .. ".com " ..
tmpName .. ".nas"
)

os.remove(tmpName .. ".nas")

local exist = CheckAndRemoveCommonArtifacts(tmpName)
if exist > 0 then
Pass("Yes")
Compiler.nasm = nasm
else
Pass("No")
end
end

function CheckWasmAssembler(as, tmpName)
local wasm = as or "wasm"

Check("Checking " .. wasm .. " is available")

if Target.skip then
Compiler.as = "wasm"
Compiler.aext = ".asm"
Pass("Skipped")
return
end

if not CreateMasmTestFile(tmpName .. ".asm") then Error() end

RunCommand (
wasm .. " -bt=dos " ..
tmpName .. ".asm"
)

os.remove(tmpName .. ".asm")

local exist = CheckAndRemoveCommonArtifacts(tmpName)
if exist > 0 then Pass("Yes") else Fail("No") end

Compiler.as = wasm
Compiler.aext = ".asm"
end
43 changes: 43 additions & 0 deletions lua/bin2c.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
--[[
This lua script converts an ASCII characters into to a
C hex array for generating cflagsbf.h and asmpkt.bin

Usage: lua bin2c.lua [file] (> [output file])
]]

-- Silent exit with error if no readable file can be found
if #arg < 1 then os.exit(1) end
local file = io.open(arg[1], "rb")
if not file then os.exit(1) end

local column = {}
local row = {}
local count = 0

-- Parse the file
while true do
local byte = file:read(1)

if not byte then break end -- EOF

-- Insert the processed byte into the table
table.insert(column, string.format("0x%02X", string.byte(byte)))

-- Newline after every 12th element
count = count + 1
if count % 12 == 0 then
table.insert(row, table.concat(column, ", ") .. ",")
column = {}
end
end
file:close()

-- Append last row
table.insert(row, table.concat(column, ", ") .. ",")

-- Write C hex array to stdout
local result = "/* bin2c.lua output begin */\n\t" ..
table.concat(row, '\n\t') ..
"\n/* bin2c.lua output end */"
print(result)
os.exit(0)
Loading