Last active
December 14, 2021 06:58
-
-
Save khronii/3315baaff613f3525570314456a20ee3 to your computer and use it in GitHub Desktop.
Kludge to build Busybox using llvm-mingw, for armv7-w64-mingw32
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# artynet/cross-compile-zlib-windows.sh | |
SRC=https://www.zlib.net/zlib-1.2.11.tar.gz | |
PREFIXDIR=$HOME/mingw64/armv7-w64-mingw32 | |
if [ ! -d "zlib-1.2.11" ]; then | |
wget $SRC | |
tar xf zlib-1.2.11.tar.gz | |
fi | |
cd zlib-1.2.11 | |
make -f win32/Makefile.gcc BINARY_PATH=$PREFIXDIR/bin INCLUDE_PATH=$PREFIXDIR/include LIBRARY_PATH=$PREFIXDIR/lib SHARED_MODE=1 PREFIX=armv7-w64-mingw32- install |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#install nori and nori-sanargs in $PATH | |
git clone https://github.com/khronii/busybox-w32.git | |
cd busybox-w32 | |
make CROSS_COMPILE="armv7-w64-mingw32-" mingw32_defconfig | |
make CROSS_COMPILE="armv7-w64-mingw32-" LD="nori armv7-w64-mingw32-ld" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/mingw64/bin/python | |
import os | |
import sys | |
import shutil | |
import subprocess | |
def split_args (args): | |
out = "a.o" | |
get_nextarg = False | |
relocatable = False | |
libs = list() | |
misc_args = list() | |
objects = list() | |
for arg in args: | |
if get_nextarg: | |
out = arg | |
get_nextarg = False | |
elif arg.startswith("-r"): | |
relocatable = True | |
elif arg.startswith("--relocateable"): | |
relocatable = True | |
elif arg.startswith("-i"): | |
relocatable = True | |
elif arg.startswith("-l"): | |
libs.append(arg) | |
elif arg.startswith("--output"): | |
out = arg[9:] | |
elif arg.startswith("-o"): | |
get_nextarg = True | |
elif arg.endswith(".o"): | |
objects.append(arg) | |
else: | |
misc_args.append(arg) | |
return (relocatable, libs, misc_args, objects, out) | |
def unpack_objs (obj): | |
libs = list() | |
misc_args = list() | |
objects = list() | |
out = obj | |
lines = False | |
with open (os.path.join(os.path.abspath(obj), "objs.txt"), 'r') as file: | |
lines = file.readlines() | |
lines = [line.rstrip() for line in lines] | |
libs = lines[1].split(" ") | |
misc_args = lines[0].split(" ") | |
objects = lines[2:] | |
return (libs, misc_args, objects, out) | |
def pack_objs (libs, misc_args, objects, out): | |
objdir = os.path.abspath(out) | |
if not os.path.exists(objdir): | |
os.mkdir(objdir) | |
text = [] | |
text.append(misc_args) | |
text.append(libs) | |
for obj in objects: | |
obj_name = os.path.basename(obj) | |
if os.path.isdir(obj): | |
(libs_2, misc_args_2, objects_2, out_2) = unpack_objs(obj) | |
text[1] = text[1] + libs_2 | |
for obj_2 in objects_2: | |
text.append (os.path.join(objdir, os.path.basename(obj_2))) | |
shutil.copy (obj_2, objdir) | |
if (" ".join(misc_args)) != (" ".join(misc_args_2)): | |
print (" ".join(misc_args)) | |
print (" ".join(misc_args_2)) | |
elif os.path.isfile(obj): | |
text.append(os.path.abspath(obj)) | |
shutil.copy(obj, os.path.join(objdir, obj_name)) | |
text[0] = " ".join(text[0]) | |
text[1] = " ".join(text[1]) | |
with open (os.path.join(objdir, "objs.txt"), 'w') as file: | |
file.write("\n".join(text)) | |
if __name__ == "__main__": | |
wokrdir = os.getcwd() | |
(rel, libs, misc_args, objects, out) = split_args (sys.argv[2:]) | |
if rel: | |
pack_objs(libs, misc_args, objects, out) | |
else: | |
full_args = [sys.argv[1], "-o", out] + misc_args + libs | |
for obj in objects: | |
if os.path.isdir(obj): | |
(libs_2, _, objects_2, _) = unpack_objs(obj) | |
full_args = full_args + libs_2 + objects_2 | |
print(full_args) | |
print(sys.argv) | |
subprocess.run(full_args) | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/mingw64/bin/python | |
import os | |
import sys | |
import shutil | |
import subprocess | |
def unpack_objs (obj): | |
libs = list() | |
misc_args = list() | |
objects = list() | |
out = obj | |
lines = False | |
with open (os.path.join(os.path.abspath(obj), "objs.txt"), 'r') as file: | |
lines = file.readlines() | |
lines = [line.rstrip() for line in lines] | |
libs = lines[1].split(" ") | |
misc_args = lines[0].split(" ") | |
objects = lines[2:] | |
return (libs, misc_args, objects, out) | |
if __name__ == "__main__": | |
sanargs = list() | |
for arg in sys.argv[1:]: | |
if arg.startswith("-Wl,--warn"): | |
continue | |
if arg.endswith(".o") and os.path.isdir(arg): | |
(libs, _, objects, _) = unpack_objs(arg) | |
sanargs = sanargs + libs + objects | |
else: | |
sanargs.append(arg) | |
print(sanargs) | |
subprocess.run(sanargs) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#install nori and nori-sanargs in $PATH | |
sed -e "s/try $CC/try nori-sanargs $CC/g" scripts/trylink | |
set -e "s/const ptr_to_globals;/BB_GLOBAL_CONST ptr_to_globals;/g" include/libbb.h #ptr_to_globals causes SEGFAULT w/o this | |
## remove L152-L185 from scripts/trylink | |
## https://github.com/rmyorston/busybox-w32/blob/c29dc205d2dc590f6d66df5a4f26efa7ada9632d/scripts/trylink#L152 | |
## Lazy to create a patch RN | |
make CROSS_COMPILE="armv7-w64-mingw32-" mingw32_defconfig | |
make CROSS_COMPILE="armv7-w64-mingw32-" LD="nori ld" EXTRA_CFLAGS="-DBB_GLOBAL_CONST=''" #I would definitely go to legacy hell if I die | |
sed -e "s/ ffs(/ __builtin_ffs(/g" archival/gzip.c #Fixes the last symbol error and causes re-compilation I guess | |
make CROSS_COMPILE="armv7-w64-mingw32-" LD="nori armv7-w64-mingw32-ld" EXTRA_CFLAGS="-DBB_GLOBAL_CONST=''" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment