|
| 1 | +# BeagleG host package. Builds machine-control and its companion tools |
| 2 | +# from the project Makefile. Supports native builds (for tests / dev) and |
| 3 | +# cross-compilation to armv7 for BeagleBone deployment via pkgsCross. |
| 4 | +{ stdenv, lib, pkg-config, gtest, pkgsBuildBuild }: |
| 5 | +stdenv.mkDerivation { |
| 6 | + pname = "beagleg"; |
| 7 | + version = "unstable"; |
| 8 | + |
| 9 | + # Pass the project root directly (not lib.cleanSource) so the |
| 10 | + # am335x_pru_package submodule is included in the build sandbox. |
| 11 | + src = ./..; |
| 12 | + |
| 13 | + # pasm's linuxbuild needs a build-platform C compiler to produce the |
| 14 | + # PRU assembler binary that then runs in this sandbox. |
| 15 | + nativeBuildInputs = [ pkg-config pkgsBuildBuild.gcc ]; |
| 16 | + CC_FOR_BUILD = "${pkgsBuildBuild.gcc}/bin/gcc"; |
| 17 | + buildInputs = [ gtest ]; |
| 18 | + |
| 19 | + # Patches for the vendored am335x_pru_package: |
| 20 | + # - K&R-style ppCleanup() / definition pair rejected by strict GCC. |
| 21 | + # - linuxbuild calls bare `gcc`, which under nix cross-builds is only |
| 22 | + # available with the build-platform prefix; use $CC_FOR_BUILD. |
| 23 | + postPatch = '' |
| 24 | + substituteInPlace am335x_pru_package/pru_sw/utils/pasm_source/pasm.h \ |
| 25 | + --replace-fail 'void ppCleanup();' 'void ppCleanup(int);' |
| 26 | + substituteInPlace am335x_pru_package/pru_sw/utils/pasm_source/pasmpp.c \ |
| 27 | + --replace-fail 'void ppCleanup()' 'void ppCleanup(int Pass)' |
| 28 | + substituteInPlace am335x_pru_package/pru_sw/utils/pasm_source/linuxbuild \ |
| 29 | + --replace-fail 'gcc -Wall' "''${CC_FOR_BUILD:-gcc} -Wall" |
| 30 | + ''; |
| 31 | + |
| 32 | + # The Makefile's ARM_COMPILE_FLAGS default targets cortex-a8/armv7-a, |
| 33 | + # which is what we want for BBB cross builds. Clear it on any host that |
| 34 | + # isn't a 32-bit ARM (nix's stdenv has already set the right CC/CXX). |
| 35 | + ARM_COMPILE_FLAGS = lib.optionalString (!stdenv.hostPlatform.isAarch32) ""; |
| 36 | + |
| 37 | + enableParallelBuilding = true; |
| 38 | + |
| 39 | + # Tests are gtest-based and run on the build machine; skip when cross- |
| 40 | + # compiling because the binaries can't execute on the build host. |
| 41 | + doCheck = stdenv.buildPlatform.canExecute stdenv.hostPlatform; |
| 42 | + checkTarget = "test"; |
| 43 | + |
| 44 | + installPhase = '' |
| 45 | + runHook preInstall |
| 46 | + mkdir -p $out/bin |
| 47 | + install -m 755 machine-control gcode-print-stats $out/bin/ |
| 48 | + install -m 755 src/gcode2ps $out/bin/ |
| 49 | + runHook postInstall |
| 50 | + ''; |
| 51 | + |
| 52 | + meta = with lib; { |
| 53 | + description = "Step-motor controller for CNC-like devices using the BeagleBone PRU"; |
| 54 | + homepage = "https://github.com/hzeller/beagleg"; |
| 55 | + license = licenses.gpl3Plus; |
| 56 | + platforms = platforms.linux; |
| 57 | + mainProgram = "machine-control"; |
| 58 | + }; |
| 59 | +} |
0 commit comments