Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

meson build system does not install any files for distro packaging #93

Closed
anthraxx opened this issue Aug 20, 2022 · 9 comments
Closed

Comments

@anthraxx
Copy link
Contributor

anthraxx commented Aug 20, 2022

It seems that the meson build system is lacking some instructions. Its not installing a single file:

Expected files:

  • all the /usr/lib/radare2/$version/r2ghidra_sleigh sleigh as well as the .so
==> Starting package()...
ninja: Entering directory `build'
[0/1] /usr/bin/meson install --no-rebuild
Nothing to install.

its called like this:

meson setup   --prefix        /usr \
  --libexecdir    lib \
  --sbindir       bin \
  --buildtype     plain \
  --auto-features enabled \
  --wrap-mode     nodownload \
  -D              b_lto=true \
  -D              b_pie=true \
  build
ninja -C build --verbose
DESTDIR="${pkgdir}" ninja --verbose -C build install

Expected installed files:

${pkgdir}/usr/
${pkgdir}/usr/lib/
${pkgdir}/usr/lib/radare2/
${pkgdir}/usr/lib/radare2/5.6.6/
${pkgdir}/usr/lib/radare2/5.6.6/anal_ghidra.so
${pkgdir}/usr/lib/radare2/5.6.6/asm_ghidra.so
${pkgdir}/usr/lib/radare2/5.6.6/core_ghidra.so
${pkgdir}/usr/lib/radare2/5.6.6/r2ghidra_sleigh/
${pkgdir}/usr/lib/radare2/5.6.6/r2ghidra_sleigh/6502.cspec
${pkgdir}/usr/lib/radare2/5.6.6/r2ghidra_sleigh/6502.ldefs
${pkgdir}/usr/lib/radare2/5.6.6/r2ghidra_sleigh/6502.pspec
${pkgdir}/usr/lib/radare2/5.6.6/r2ghidra_sleigh/6502.sla
${pkgdir}/usr/lib/radare2/5.6.6/r2ghidra_sleigh/...
@trufae
Copy link
Contributor

trufae commented Aug 22, 2022

Fixed in b827e93

@trufae trufae closed this as completed Aug 22, 2022
@trufae
Copy link
Contributor

trufae commented Aug 22, 2022

the sleigh files are shipped in a separate zip in the release page. you can build them, but only with make for now

@anthraxx
Copy link
Contributor Author

anthraxx commented Aug 23, 2022

@trufae great thanks. Do you have any pointer how one could build/distribute sleigh files themselves? Its important for us to be able to build them ourselves.

I think right now I figured it like this:

make -C ghidra sleigh-build
export R2_LIBR_PLUGINS=$(r2 -H R2_LIBR_PLUGINS)
DESTDIR="${pkgdir}" make -C ghidra install

@trufae
Copy link
Contributor

trufae commented Aug 23, 2022

yep. thats how you build it if you think it's worth to have the instructions in the readme they can be added. it will be good to be able to build it with meson too, but i dont see it as a prioriy right now

@anthraxx
Copy link
Contributor Author

@trufae Sounds good enough for now, thank you! Compared the results to the provided zip and they seem to match. Good enough for now. If its ever moved over to meson please make us somehow aware :D

@trufae
Copy link
Contributor

trufae commented Aug 23, 2022

Yeah the sleigh files are portable. You can generate them once and use them on different systems. The zip in the release page is generated by the ci.

i'll open a ticket to make that part meson friendly when i get bored :)

btw i have a patch installing the sleighc compiler, not sure if you want to package this bonary too. Or maybe in a separate package because that may allow users to build their own custom processors

@anthraxx
Copy link
Contributor Author

@trufae nice, good to hear. I've done some first meson adjustments for iaito but wanted to check in on some translations related topics. Can i reach you somewhere or should we discuss that on a bug ticket at iaito?

@trufae
Copy link
Contributor

trufae commented Aug 23, 2022

Sure, use mail, telegram or discord

@milahu
Copy link
Contributor

milahu commented Jan 29, 2023

workaround for meson in NixOS/nixpkgs#213388
using xargs to run sleighc in parallel
(using a sparse checkout of ghidra, 6 of 240 MB)

{
  # workround for https://github.com/radareorg/r2ghidra/issues/93
  # https://github.com/radareorg/r2ghidra/blob/master/ghidra/Makefile
  postBuild = ''
    GHIDRA_SLEIGH_HOME=../ghidra/src/Processors
    cp -v ../ghidra-processors.txt.default ../ghidra-processors.txt
    echo "Compiling processor files"
    ./sleighc -a $GHIDRA_SLEIGH_HOME/DATA
    cat ../ghidra-processors.txt | sed "s|^|$GHIDRA_SLEIGH_HOME/|" | xargs -n1 -P$NIX_BUILD_CORES ./sleighc -a 2>/dev/null
  '';

  # TODO use radare2.abiVersion https://github.com/radareorg/radare2/pull/20545
  postInstall = ''
    echo "Installing processor files to $out/lib/radare2/${radare2.version}/r2ghidra_sleigh"
    mkdir $out/lib/radare2/${radare2.version}/r2ghidra_sleigh
    for a in DATA $(cat ../ghidra-processors.txt); do
      for b in $GHIDRA_SLEIGH_HOME/$a/*/*/*.{cspec,ldefs,pspec,sla}; do
        cp $b $out/lib/radare2/${radare2.version}/r2ghidra_sleigh
      done
    done
  '';

for reference ...

https://mesonbuild.com/Custom-build-targets.html

all: sleigh-build
clean:
rm -rf ../ghidra-native ghidra/Ghidra
-include ../config.mk
include deps.mk
DD=$(DESTDIR)/$(R2_LIBR_PLUGINS)/r2ghidra_sleigh
DH=$(DESTDIR)/$(R2_USER_PLUGINS)/r2ghidra_sleigh
D?=$(DH)
install:
$(MAKE) sleigh-install D="$(DD)"

r2ghidra/ghidra/deps.mk

Lines 111 to 131 in a1495c5

GHIDRA_SLEIGH_HOME=$(GHIDRA_HOME)/src/Processors
GHIDRA_SLEIGH_SLASPECS=$(GHIDRA_SLEIGH_HOME)/*.slaspec
GHIDRA_SLEIGH_FILES=$(GHIDRA_SLEIGH_HOME)/*.cspec
GHIDRA_SLEIGH_FILES+=$(GHIDRA_SLEIGH_HOME)/*.ldefs
GHIDRA_SLEIGH_FILES+=$(GHIDRA_SLEIGH_HOME)/*.pspec
../ghidra-processors.txt:
cp -f ../ghidra-processors.txt.default ../ghidra-processors.txt
sleigh-build: sleighc ../ghidra-processors.txt
for a in DATA $(shell cat ../ghidra-processors.txt) ; do ./sleighc -a $(GHIDRA_SLEIGH_HOME)/$$a ; done
GHIDRA_PROCS=$(GHIDRA_SLEIGH_HOME)/*/*/*
sleigh-install:
mkdir -p "$(D)"
for a in DATA $(shell cat ../ghidra-processors.txt) ; do \
for b in cspec ldefs pspec sla ; do \
cp -f $(GHIDRA_SLEIGH_HOME)/$$a/*/*/*.$$b "$(D)"; \
done ;\
done

r2ghidra/Makefile

Lines 22 to 23 in 0799403

ghidra-processors.txt:
cp -f ghidra-processors.txt.default ghidra-processors.txt

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants