mirror of
https://github.com/aolofsson/oh.git
synced 2025-01-30 02:32:53 +08:00
One line compile script
This commit is contained in:
parent
419d9a67ad
commit
3c8da0f727
104
scripts/c2elf
Executable file
104
scripts/c2elf
Executable file
@ -0,0 +1,104 @@
|
||||
#!/usr/bin/env python3
|
||||
#############################################################################
|
||||
# celf <arch> <inputfile> <outputfile>
|
||||
#
|
||||
# Uses gcc
|
||||
#
|
||||
# Simple utility for compiling c into an elf
|
||||
#
|
||||
# .globl _start
|
||||
# _start:
|
||||
# lui a0,0x1
|
||||
#
|
||||
#############################################################################
|
||||
import subprocess
|
||||
import sys
|
||||
import re
|
||||
import os
|
||||
|
||||
ARCH = sys.argv[1]
|
||||
ASM = sys.argv[2]
|
||||
ELF = sys.argv[3]
|
||||
|
||||
#############################################
|
||||
#SETUP
|
||||
|
||||
LINKERSCRIPT="tmp.ld"
|
||||
|
||||
if(ARCH=="rv32i"):
|
||||
GCC="riscv64-unknown-elf-gcc -march=rv32i -mabi=ilp32"
|
||||
GCCOPT=" -O2 -static -mcmodel=medany -fvisibility=hidden -nostdlib -nostartfiles"
|
||||
OUTPUT="riscv"
|
||||
OBJDUMP="riscv64-unknown-elf-objdump"
|
||||
elif(ARCH=="rv32gc"):
|
||||
GCC="riscv64-unknown-elf-gcc -O2 -march=rv32gc -mabi=ilp32"
|
||||
GCCOPT=" -O2 -static -mcmodel=medany -fvisibility=hidden -nostdlib -nostartfiles"
|
||||
OUTPUT="riscv"
|
||||
OBJDUMP="riscv64-unknown-elf-objdump"
|
||||
elif(ARCH=="rv64gc"):
|
||||
GCC="riscv64-unknown-elf-gcc -O2 -march=rv64gc -mabi=lp64d"
|
||||
GCCOPT=" -O2 -static -mcmodel=medany -fvisibility=hidden -nostdlib -nostartfiles"
|
||||
OUTPUT="riscv"
|
||||
OBJDUMP="riscv64-unknown-elf-objdump"
|
||||
else:
|
||||
GCC="e-gcc"
|
||||
GCCOPT=" -O2 -static -fvisibility=hidden -nostdlib -nostartfiles"
|
||||
OUTPUT="epiphany"
|
||||
OBJDUMP="e-objdump"
|
||||
|
||||
#############################################
|
||||
#PRINT LINKER FILE
|
||||
f=open("tmp.ld",'w')
|
||||
f.write("OUTPUT_ARCH( \"" + OUTPUT + "\" )\n")
|
||||
if(ARCH=="rv32i"):
|
||||
f.write("""ENTRY(_start)
|
||||
SECTIONS
|
||||
{
|
||||
. = 0x80000000;
|
||||
.text.trap : { *(.text.trap) }
|
||||
|
||||
. = 0x00000000;
|
||||
.text.init : { *(.text.init) }
|
||||
|
||||
. = ALIGN(0x1000);
|
||||
.tohost : { *(.tohost) }
|
||||
. = ALIGN(0x1000);
|
||||
.text : { *(.text) }
|
||||
. = ALIGN(0x1000);
|
||||
.data : { *(.data) }
|
||||
.data.string : { *(.data.string)}
|
||||
.bss : { *(.bss) }
|
||||
_end = .;
|
||||
}""")
|
||||
else:
|
||||
f.write("""ENTRY(_start)
|
||||
SECTIONS
|
||||
{
|
||||
. = 0x00000000;
|
||||
.text.init : { *(.text.init) }
|
||||
. = ALIGN(0x1000);
|
||||
.tohost : { *(.tohost) }
|
||||
. = ALIGN(0x1000);
|
||||
.text : { *(.text) }
|
||||
. = ALIGN(0x1000);
|
||||
.data : { *(.data) }
|
||||
.bss : { *(.bss) }
|
||||
_end = .;
|
||||
}""")
|
||||
f.close()
|
||||
|
||||
#############################################
|
||||
#RUN GCC
|
||||
CMD = GCC + GCCOPT + " -T" + LINKERSCRIPT + " -o " + ELF + " " + ASM
|
||||
print(CMD)
|
||||
os.system(CMD)
|
||||
#RUN OBJDUMP
|
||||
CMD = OBJDUMP+ " -d " + ELF + " > " + ELF + ".objdump"
|
||||
print(CMD)
|
||||
os.system(CMD)
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user