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.
|
2019-07-26 15:17:28 +00:00
|
|
|
GCC_FOLDER = "C:\\Users\ruby\Desktop\comp\mingw64"
|
2019-07-25 21:07:36 +00:00
|
|
|
|
|
|
|
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]
|
2019-07-26 15:17:28 +00:00
|
|
|
print(HeaderFiles)
|
2019-07-25 21:07:36 +00:00
|
|
|
|
|
|
|
if line == "gnu-efi/lib/x86_64/setjmp" or line == "gnu-efi/lib/x86_64/efi_stub":
|
|
|
|
print(f'Assembling file {line}.s')
|
2019-07-26 00:15:10 +00:00
|
|
|
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)
|
2019-07-25 21:07:36 +00:00
|
|
|
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)
|
|
|
|
|
|
|
|
|
2019-07-26 15:17:28 +00:00
|
|
|
with open('objects.list', 'w') as objectsfile:
|
2019-07-25 21:07:36 +00:00
|
|
|
ofile = OBJECTS.replace('\\', '/')
|
|
|
|
objectsfile.write(ofile + "\n")
|
|
|
|
line = file.readline().strip()
|
|
|
|
|
2019-07-26 00:15:10 +00:00
|
|
|
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')
|