Add flags to generate .hex files

This commit is contained in:
Savanni D'Gerinel 2022-08-05 14:50:03 -04:00
parent 301496cf0e
commit 7e16faefae
1 changed files with 12 additions and 6 deletions

View File

@ -43,8 +43,10 @@
'';
};
mkProgram = { pkgs, gcc, cflags, pname, psrc, pbuildInputs ? [] }:
pkgs.stdenv.mkDerivation rec {
mkProgram = { pkgs, gcc, cflags, pname, psrc, pbuildInputs ? [], avr ? false }:
let
AVR = if avr == true then "1" else "";
in pkgs.stdenv.mkDerivation rec {
name = pname;
src = psrc;
@ -63,12 +65,15 @@
fi
done
${gcc} -o ${name} ${cflags} ${object_files} *.o
${gcc} -o ${name}.elf ${cflags} ${object_files} *.o
if $AVR; then
$OBJCOPY -O ihex ${name}.elf ${name}.hex
fi
'';
installPhase = ''
mkdir -p $out/bin
cp ${name} $out/bin
cp ${name}.elf ${name}.hex $out/bin
'';
};
@ -83,7 +88,7 @@
paths = [
(packages."x86_64-linux"."prime-tx" { gcc = "${avr.gcc}/bin/avr-gcc"; cflags = mcu_cflags atmega32u4; })
(packages."x86_64-linux"."radio-rx" { gcc = "${avr.gcc}/bin/avr-gcc"; cflags = mcu_cflags atmega32u4; })
(packages."x86_64-linux"."lantern" { gcc = "${avr.gcc}/bin/avr-gcc"; cflags = mcu_cflags atmega32u4; })
(packages."x86_64-linux"."lantern" { gcc = "${avr.gcc}/bin/avr-gcc"; cflags = mcu_cflags atmega32u4; avr = true; })
];
};
@ -232,7 +237,7 @@
avr = pkgs.pkgsCross.avr.buildPackages;
in packages."x86_64-linux"."lantern" { gcc = "${avr.gcc}/bin/avr-gcc"; cflags = mcu_cflags atmega32u4; };
packages."x86_64-linux"."lantern" =
{ gcc, cflags }:
{ gcc, cflags, avr }:
let
pkgs = import nixpkgs { system = "x86_64-linux"; };
in mkProgram {
@ -241,6 +246,7 @@
cflags = cflags;
pname = "lantern";
psrc = ./lantern;
inherit avr;
pbuildInputs = [
(packages."x86_64-linux"."animation" { inherit gcc cflags; })