Syncboot/compile.py
Curle 3b3e94a644 Improve buildscript.
Hopefully it should now be able to automagically build the bootloader for Jenkins automation.
2019-07-26 01:15:10 +01:00

49 lines
2.9 KiB
Python

import os
import subprocess
CurrentPath = os.getcwd()
print(CurrentPath)
# Here goes the absolute path to your x86_64-mingw-w64 folder.
# There should be a \bin\gcc.exe relative to that folder.
GCC_FOLDER = "C:\\Users\Gem\Desktop\comp\mingw64"
if os.path.exists('objects.list'):
os.remove("objects.list")
HeaderFiles="-Iinc/ -Ignu-efi/inc -Ignu-efi/inc/x86_64 -Ignu-efi/inc/protocol -Ignu-efi/lib"
LinkScript = "gnu-efi/gnuefi/elf_x86_64_efi.lds"
OBJECTS = ""
with open('c_files.txt') as file:
line = file.readline().strip()
while line:
line = line[:-2]
print(f'{HeaderFiles}')
if line == "gnu-efi/lib/x86_64/setjmp" or line == "gnu-efi/lib/x86_64/efi_stub":
print(f'Assembling file {line}.s')
subprocess.run([f'{GCC_FOLDER}/bin/gcc.exe', '-ffreestanding', '-fpic', '-fshort-wchar', '-fno-stack-protector', '-fno-stack-check', '-fno-strict-aliasing', '-fno-merge-all-constants', '-m64', '-mno-red-zone', '-DGNU_EFI_USE_MS_ABI', '-maccumulate-outgoing-args', '--std=c11', '-Iinc/', '-Ignu-efi/inc', '-Ignu-efi/inc/x86_64', '-Ignu-efi/inc/protocol', '-Ignu-efi/lib', '-Og', '-g3', '-Wall', '-Wextra', '-Wdouble-promotion', '-Wpedantic', '-fmessage-length=0', '-c', '-MMD', '-MP', f'-Wa,-adghlmns={line}.out', f'-MT{line}.o', '-o', f'{line}.o', f'{line}.S'], shell=True)
else:
print(f'Compiling file {line}.c')
subprocess.run([f'{GCC_FOLDER}/bin/gcc.exe', '-ffreestanding', '-fpic', '-fshort-wchar', '-fno-stack-protector', '-fno-stack-check', '-fno-strict-aliasing', '-fno-merge-all-constants', '-m64', '-mno-red-zone', '-DGNU_EFI_USE_MS_ABI', '-maccumulate-outgoing-args', '--std=c11', '-Iinc/', '-Ignu-efi/inc', '-Ignu-efi/inc/x86_64', '-Ignu-efi/inc/protocol', '-Ignu-efi/lib', '-Og', '-g3', '-Wall', '-Wextra', '-Wdouble-promotion', '-Wpedantic', '-fmessage-length=0', '-c', '-MMD', '-MP', f'-Wa,-adghlmns={line}.out', f'-MT{line}.o', '-o', f'{line}.o', f'{line}.c'], shell=True)
OBJECTS = line + ".o "
os.path.normpath(OBJECTS)
with open('objects.list', 'a') as objectsfile:
ofile = OBJECTS.replace('\\', '/')
objectsfile.write(ofile + "\n")
line = file.readline().strip()
print("Linking EFI.")
subprocess.run([f'{GCC_FOLDER}/bin/gcc.exe', "-nostdlib", "-Wl,--warn-common", "-Wl,--no-undefined", "-Wl,-dll", "-shared", "-Wl,--subsystem,10", "-e", "efi_main", "-Wl,-Map=output.map", "-o", "Syncboot.efi", "@objects.list"])
print("Generating binary and debug symbols.")
subprocess.run([f'{GCC_FOLDER}/bin/objcopy.exe', '--only-keep-debug', 'Syncboot.efi', 'BOOTX64.debug'])
subprocess.run([f'{GCC_FOLDER}/bin/objcopy.exe', '--strip-debug', 'Syncboot.efi'])
subprocess.run([f'{GCC_FOLDER}/bin/objcopy.exe', '--add-gnu-debuglink=BOOTX64.debug', 'Syncboot.efi'])
print("Copying file to virtual hard disk")
os.system('copy Syncboot.efi image/efi/boot/BOOTX64.EFI')