Skip to content

Commit

Permalink
Initial pass of getting newlib to compile
Browse files Browse the repository at this point in the history
  • Loading branch information
ammrat13 committed Aug 6, 2023
1 parent b7c39d9 commit 951ab80
Show file tree
Hide file tree
Showing 5 changed files with 228 additions and 1 deletion.
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -46,3 +46,8 @@ core
!core/

lost+found

Makefile
build/

.vscode
3 changes: 2 additions & 1 deletion config.sub
Original file line number Diff line number Diff line change
Expand Up @@ -1255,7 +1255,8 @@ case $cpu-$vendor in
| x86 | x86_64 | xc16x | xgate | xps100 \
| xstormy16 | xtensa* \
| ymp \
| z8k | z80)
| z8k | z80 \
| lc_3.2)
;;

*)
Expand Down
130 changes: 130 additions & 0 deletions flake.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

89 changes: 89 additions & 0 deletions flake.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
{
description = "Newlib for LC-3.2 Development and Build Environment";

inputs = {
nixpkgs-23-05.url = "github:NixOS/nixpkgs/release-23.05";
flake-utils.url = "github:numtide/flake-utils";

# We have to use SSH here since the repository is private
llvm-lc-3-2.url = "git+ssh://git@github.com/lc-3-2/llvm.git";
};

outputs = { self, nixpkgs-23-05, flake-utils, llvm-lc-3-2 }@inputs :
flake-utils.lib.eachSystem ["x86_64-linux"] (system:
let
name = "newlib-lc-3.2-dev";
pkgs = nixpkgs-23-05.legacyPackages.${system};
inherit (pkgs) stdenv;

nativeBuildInputs = [
pkgs.texinfo

# Usually, we would add custom packages with an overlay, but that adds a
# lot of complexity. Thus, we fetch the package manually.
llvm-lc-3-2.packages.${system}.lc-3-2
];

in {

packages = rec {
default = newlib-lc-3-2;

newlib-lc-3-2 = stdenv.mkDerivation {
inherit name nativeBuildInputs;

src = self;

configurePhase = ''
mkdir ./build/
pushd ./build/
CC_FOR_TARGET="clang" \
CXX_FOR_TARGET="clang++" \
AS_FOR_TARGET="llvm-mc" \
LD_FOR_TARGET="ld.lld" \
AR_FOR_TARGET="llvm-ar" \
RANLIB_FOR_TARGET="llvm-ranlib" \
STRIP_FOR_TARGET="llvm-strip" \
OBJCOPY_FOR_TARGET="llvm-objcopy" \
OBJDUMP_FOR_TARGET="llvm-objdump" \
READELF_FOR_TARGET="llvm-readelf" \
NM_FOR_TARGET="llvm-nm" \
DLLTOOL_FOR_TARGET="llvm-dlltool" \
LIPO_FOR_TARGET="llvm-lipo" \
WINDRES_FOR_TARGET="llvm-windres" \
CFLAGS_FOR_TARGET="-nostdlib -D__IEEE_LITTLE_ENDIAN -v" \
../configure \
--host=x86_64-pc-linux-gnu --target=lc_3.2 \
--prefix=$out \
--disable-multilib
popd
'';

buildPhase = "make -C ./build/";
installPhase = "make -C ./build/ install";
};
};

devShells = rec {
default = newlib-lc-3-2;

newlib-lc-3-2 = pkgs.mkShell {
inherit name nativeBuildInputs;

# Add autotools in case we need to modify and regenerate. We don't
# mark this as a nativeBuildInput for the package since this is only
# done when we push changes.
buildInputs = [
pkgs.autoconf269
pkgs.automake115x
];

shellHook = ''
export PS1="(${name}) [\u@\h \W]\$ "
'';
};
};
});
}
2 changes: 2 additions & 0 deletions newlib/configure.host
Original file line number Diff line number Diff line change
Expand Up @@ -377,6 +377,8 @@ case "${host_cpu}" in
newlib_cflags="${newlib_cflags} -DMISSING_SYSCALL_NAMES"
newlib_cflags="${newlib_cflags} -ffunction-sections -fdata-sections "
;;
lc_3.2)
;;
*)
echo '***' "Newlib does not support CPU ${host_cpu}" 1>&2
exit 1
Expand Down

0 comments on commit 951ab80

Please sign in to comment.