53 lines
1.1 KiB
Python
53 lines
1.1 KiB
Python
|
|
import os
|
|
import sys
|
|
import time
|
|
import shutil
|
|
|
|
|
|
|
|
|
|
CC="riscv64-unknown-elf-gcc"
|
|
OBJCPY="riscv64-unknown-elf-objcopy"
|
|
OBJDUMP="riscv64-unknown-elf-objdump"
|
|
|
|
CFLAG=[
|
|
"-march=rv32i",
|
|
"-mabi=ilp32",
|
|
"-ffunction-sections",
|
|
"-fdata-sections",
|
|
"-ffast-math",
|
|
"-fno-common",
|
|
"-fno-builtin-printf",
|
|
"-Wall",
|
|
"-Werror",
|
|
"-g",
|
|
"-O0",
|
|
"-fno-omit-frame-pointer",
|
|
"-msave-restore"
|
|
]
|
|
|
|
SRC=[
|
|
"riscv/main.c",
|
|
"riscv/test.c",
|
|
"riscv/start.S"
|
|
]
|
|
|
|
LD_FILE="riscv.ld"
|
|
|
|
TARGET="riscv"
|
|
|
|
OUTPUT="output"
|
|
|
|
if __name__ == "__main__":
|
|
if not os.path.exists(OUTPUT):
|
|
os.mkdir(OUTPUT)
|
|
os.system(f"{CC} {' '.join(CFLAG)} {' '.join(SRC)} -T{LD_FILE} -Wall -Wextra -nostartfiles -Wl,-Map,\"{TARGET}.map\" -o {TARGET}.elf")
|
|
os.system(f"{OBJCPY} -O binary {TARGET}.elf {TARGET}.bin")
|
|
os.system(f"{OBJCPY} -O ihex {TARGET}.elf {TARGET}.hex")
|
|
os.system(f"{OBJDUMP} -d {TARGET}.elf > {TARGET}.lst")
|
|
tagets_list=[f"{TARGET}.bin",f"{TARGET}.hex",f"{TARGET}.lst",f"{TARGET}.map",f"{TARGET}.elf"]
|
|
for item in tagets_list:
|
|
if os.path.exists(item):
|
|
shutil.move(item,f"{OUTPUT}/{item}")
|