Syncboot/compile.py

45 lines
2.4 KiB
Python
Raw Normal View History

2019-07-25 21:07:36 +00:00
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/as.exe', '-64', '-I/inc/', '-g', '-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()
subprocess.run([f'{GCC_FOLDER}/bin/ld.exe', f'-T{LinkScript}', "-nostdlib", "--warn-common", "--no-undefined", "-shared", "--subsystem", '10', "-Bsymbolic", "--gc-sections", "-Map=output.map" , "-o Syncboot.efi", "@objects.list"])
subprocess.run(['objcopy', '-j .text', '-j .sdata', '-j .data', '-j .dynamic', '-j .dynsym', '-j .rel', '-j .rela', '-j .rel.*', '-j .rel*', '-j .reloc', '--target=efi-app-x86_64', 'Syncboot.efi', 'image/efi/boot/BOOTX64.efi'])
subprocess.run(['objcopy', '--only-keep-debug', 'image/efi/boot/BOOTX64.efi', 'BOOTX64.debug'])
subprocess.run(['--add-gnu-debuglink=BOOTX64.debug', 'image/efi/boot/BOOTX64.efi'])