|
| 1 | +ARG VERSION="" |
| 2 | + |
| 3 | +# Assume this is run from capstone/debian directory |
| 4 | +# Run in the root of the repo |
| 5 | +# docker build -f ./debian/Dockerfile -t packager . |
| 6 | +FROM debian:bookworm-slim |
| 7 | + |
| 8 | +# Install necessary tools for packaging |
| 9 | +RUN apt-get -qq update && \ |
| 10 | + DEBIAN_FRONTEND=noninteractive apt-get -qq install -y \ |
| 11 | + fakeroot dpkg-dev dos2unix cmake |
| 12 | + |
| 13 | +# Copy your project files into the container |
| 14 | +RUN mkdir /capstone |
| 15 | +COPY . /capstone |
| 16 | +WORKDIR /capstone/ |
| 17 | + |
| 18 | +# Using cmake, see BUILDING.md file |
| 19 | +# For debug build change "Release" to "Debug" |
| 20 | +RUN cmake -B build -DCMAKE_BUILD_TYPE=Release -DBUILD_SHARED_LIBS=1 |
| 21 | +RUN cmake --build build |
| 22 | + |
| 23 | +# List files before cmake install |
| 24 | +# RUN find / -type f > /before-install.txt |
| 25 | + |
| 26 | +# Run cmake install, by default everything goes into /usr/local |
| 27 | +RUN cmake --install build |
| 28 | + |
| 29 | +# List files after cmake install |
| 30 | +# RUN find / -type f > /after-install.txt |
| 31 | + |
| 32 | +# Make directories as needed |
| 33 | +RUN mkdir -p /package-root/usr/local/include/capstone/ |
| 34 | +RUN mkdir -p /package-root/usr/local/lib/pkgconfig/ |
| 35 | +RUN mkdir -p /package-root/usr/local/bin/ |
| 36 | + |
| 37 | +# Copy /usr/local/include/capstone/ to /package-root/usr/local/include/capstone/ and all other cases |
| 38 | +RUN cp -r /usr/local/include/capstone/* /package-root/usr/local/include/capstone/ |
| 39 | +RUN cp -r /usr/local/lib/libcapstone* /package-root/usr/local/lib/ |
| 40 | +RUN cp -r /usr/local/lib/pkgconfig/capstone* /package-root/usr/local/lib/pkgconfig/ |
| 41 | +RUN cp -r /usr/local/bin/cstool /package-root/usr/local/bin/ |
| 42 | + |
| 43 | +# Create DEBIAN directory and control file |
| 44 | +COPY ./debian/control /package-root/DEBIAN/control |
| 45 | + |
| 46 | +# Update capstone.pc file with the correct version and remove archs field |
| 47 | +# Update control file with the correct version |
| 48 | +ARG VERSION |
| 49 | +RUN sed -i "s/^Version:.*/Version: ${VERSION}/" /package-root/DEBIAN/control |
| 50 | +RUN sed -i "s/^Version:.*/Version: ${VERSION}/" /package-root/usr/local/lib/pkgconfig/capstone.pc |
| 51 | +RUN sed -i "/^archs=/d" /package-root/usr/local/lib/pkgconfig/capstone.pc |
| 52 | + |
| 53 | +# Add postinst script to run ldconfig after installation |
| 54 | +COPY ./debian/postinst /package-root/DEBIAN/postinst |
| 55 | +RUN chmod 755 /package-root/DEBIAN/postinst |
| 56 | + |
| 57 | +# Build the package |
| 58 | +RUN fakeroot dpkg-deb --build /package-root /libcapstone-dev.deb |
| 59 | + |
| 60 | +# The user can now extract the .deb file from the container with something like |
| 61 | +# docker run --rm -v $(pwd):/out packager bash -c "cp /libcapstone-dev.deb /out" |
0 commit comments