Skip to content

Commit

Permalink
Merge pull request aweeraman#3 from elleaech/feature/add-polimorph-bu…
Browse files Browse the repository at this point in the history
…ild-busybox-script

Add polimorph build script
  • Loading branch information
lo-han authored Apr 15, 2022
2 parents cff21e2 + b56b9c4 commit bf377c5
Show file tree
Hide file tree
Showing 2 changed files with 99 additions and 3 deletions.
95 changes: 95 additions & 0 deletions build_busybox.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
from subprocess import run
from os import chdir
from abc import ABC
from sys import exit

import argparse


def parse_cli_args() -> argparse.ArgumentParser:
parser = argparse.ArgumentParser()
parser.add_argument(
"arch",
type=str,
help="Busybox's target architecture",
)

args = parser.parse_args()
return args


class BoxBuilder(ABC):
def __init__(self) -> None:
super().__init__()
self.__command = "make"
self.__busybox_dir = "deps/busybox"
self.__basedir = "."

def build(self, procs: int) -> None:
raise NotImplementedError

def _goto_busybox_folder(self) -> None:
chdir(self.__busybox_dir)

def _dump_log(self) -> str:
return f"2>&1 | tee -a {self.__basedir}/log"


class CrossBoxBuilder(BoxBuilder):
def __init__(self, compiler: str) -> None:
super().__init__()
self._cross_compiler = compiler
self._arch = ""


class ARMBoxBuilder(CrossBoxBuilder):
def __init__(self, compiler: str) -> None:
super().__init__(compiler)
self._arch = "arm"

def build(self, procs: int) -> None:
self._goto_busybox_folder()

run(
f"{self._BoxBuilder__command} -j{str(procs)} ARCH={self._arch} CROSS_COMPILE={self._cross_compiler} {self._dump_log()}",
shell=True,
check=True,
)
run(
f"{self._BoxBuilder__command} ARCH={self._arch} CROSS_COMPILE={self._cross_compiler} install {self._dump_log()}",
shell=True,
check=True,
)


class X86_64BoxBuilder(BoxBuilder):
def __init__(self) -> None:
super().__init__()

def build(self, procs: int) -> None:
self._goto_busybox_folder()

run(
f"{self._BoxBuilder__command} -j{str(procs)} {self._dump_log()}",
shell=True,
check=True,
)
run(
f"{self._BoxBuilder__command} CONFIG_PREFIX=initrd install {self._dump_log()}",
shell=True,
check=True,
)


if __name__ == "__main__":
args: argparse.ArgumentParser = parse_cli_args()

if args.arch == "x86_64":
make = X86_64BoxBuilder()
make.build(2)

elif args.arch == "arm":
make = ARMBoxBuilder("arm-linux-gnueabi-")
make.build()

exit(0)
7 changes: 4 additions & 3 deletions mk-initrd
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,10 @@ if [ ! -e ${busyboxdir} ]; then
fi
cp ${confdir}/busybox.config ${busyboxdir}/.config
(
cd ${busyboxdir}
make -j${procs} 2>&1 | tee -a ${basedir}/log
make CONFIG_PREFIX=${initrd} install 2>&1 | tee -a ${basedir}/log
cur_dir=$pwd
cd ..
python3 build_busybox.py $1
cd $cur_dir
)

echo -n "Building initrd... "
Expand Down

0 comments on commit bf377c5

Please sign in to comment.