diff --git a/Makefile b/Makefile index 3346bfc..ed23aa9 100644 --- a/Makefile +++ b/Makefile @@ -1,4 +1,10 @@ -all: mtxrpicam +ifeq ($(shell gcc -dumpmachine),aarch64-linux-gnu) + EXECUTABLE_NAME = mtxrpicam_64 +else + EXECUTABLE_NAME = mtxrpicam_32 +endif + +all: $(EXECUTABLE_NAME) ################################################# # text font @@ -64,5 +70,5 @@ DEPENDENCIES = \ %.o: %.cpp $(DEPENDENCIES) $(CXX) $(CXXFLAGS) -c $< -o $@ -mtxrpicam: $(OBJS) +$(EXECUTABLE_NAME): $(OBJS) $(CXX) $^ $(LDFLAGS) -o $@ diff --git a/README.md b/README.md index bca349a..2ffe581 100644 --- a/README.md +++ b/README.md @@ -29,7 +29,7 @@ This is embedded into all MediaMTX releases and shouldn't normally be downloaded make -j$(nproc) ``` -4. The resulting executable will be available in `mtxrpicam` + This will produce `mtxrpicam_32` or `mtxrpicam_64` (depending on the architecture). ## Cross-compile @@ -43,7 +43,7 @@ This is embedded into all MediaMTX releases and shouldn't normally be downloaded make -f utils.mk build ``` -4. The resulting executables will be available in `mtxrpicam_32` and `mtxrpicam_64` + This will produce `mtxrpicam_32` and `mtxrpicam_64`. ## Installation @@ -51,7 +51,7 @@ This is embedded into all MediaMTX releases and shouldn't normally be downloaded 2. Run `go generate ./...` -3. Copy `mtxrpicam` inside `internal/staticsources/rpicamera/mtxrpicam_64` (if the Raspberry Pi OS is 64-bit) or inside `internal/staticsources/rpicamera/mtxrpicam_32` (if the Raspberry Pi OS is 32-bit) +3. Copy `mtxrpicam_32` and/or `mtxrpicam_64` inside `internal/staticsources/rpicamera/` 4. Compile MediaMTX diff --git a/utils.mk b/utils.mk index 4eaf7a5..ceecbce 100644 --- a/utils.mk +++ b/utils.mk @@ -1,4 +1,3 @@ -ALPINE_IMAGE = alpine:3.20 RPI32_IMAGE = balenalib/raspberry-pi:bullseye-run-20240508 RPI64_IMAGE = balenalib/raspberrypi3-64:bullseye-run-20240429 @@ -16,9 +15,13 @@ help: build: build32 build64 +enable_multiarch: + docker run --rm --privileged multiarch/qemu-user-static:register --reset --credential yes + define DOCKERFILE_BUILD32 +FROM multiarch/qemu-user-static:x86_64-arm AS qemu FROM $(RPI32_IMAGE) AS build -RUN ["cross-build-start"] +COPY --from=qemu /usr/bin/qemu-arm-static /usr/bin/qemu-arm-static RUN apt update && apt install -y --no-install-recommends \ g++ \ pkg-config \ @@ -30,18 +33,17 @@ RUN apt update && apt install -y --no-install-recommends \ WORKDIR /s COPY . . RUN make -j$$(nproc) -FROM $(ALPINE_IMAGE) -COPY --from=build /s/mtxrpicam /s/mtxrpicam endef export DOCKERFILE_BUILD32 -build32: +build32: enable_multiarch echo "$$DOCKERFILE_BUILD32" | docker build . -f - -t build32 - docker run --rm -v $(PWD):/o build32 sh -c "mv /s/mtxrpicam /o/mtxrpicam_32" + docker run --rm -v $(PWD):/o build32 sh -c "mv /s/mtxrpicam_32 /o/" define DOCKERFILE_BUILD64 +FROM multiarch/qemu-user-static:x86_64-aarch64 AS qemu FROM $(RPI64_IMAGE) AS build -RUN ["cross-build-start"] +COPY --from=qemu /usr/bin/qemu-aarch64-static /usr/bin/qemu-aarch64-static RUN apt update && apt install -y --no-install-recommends \ g++ \ pkg-config \ @@ -53,14 +55,12 @@ RUN apt update && apt install -y --no-install-recommends \ WORKDIR /s COPY . . RUN make -j$$(nproc) -FROM $(ALPINE_IMAGE) -COPY --from=build /s/mtxrpicam /s/mtxrpicam endef export DOCKERFILE_BUILD64 -build64: +build64: enable_multiarch echo "$$DOCKERFILE_BUILD64" | docker build . -f - -t build64 - docker run --rm -v $(PWD):/o build64 sh -c "mv /s/mtxrpicam /o/mtxrpicam_64" + docker run --rm -v $(PWD):/o build64 sh -c "mv /s/mtxrpicam_64 /o/" define DOCKERFILE_TEST32 FROM multiarch/qemu-user-static:x86_64-arm AS qemu @@ -70,8 +70,7 @@ RUN apt update && apt install -y --no-install-recommends libcamera0 libfreetype6 endef export DOCKERFILE_TEST32 -test32: - docker run --rm --privileged multiarch/qemu-user-static:register --reset --credential yes +test32: enable_multiarch echo "$$DOCKERFILE_TEST32" | docker build . -f - -t test32 docker run --rm --platform=linux/arm/v6 -v $(PWD):/s -w /s test32 bash -c "TEST=1 ./mtxrpicam_32" @@ -83,7 +82,6 @@ RUN apt update && apt install -y --no-install-recommends libcamera0 libfreetype6 endef export DOCKERFILE_TEST64 -test64: - docker run --rm --privileged multiarch/qemu-user-static:register --reset --credential yes +test64: enable_multiarch echo "$$DOCKERFILE_TEST64" | docker build . -f - -t test64 docker run --rm --platform=linux/arm64/v8 -v $(PWD):/s -w /s test64 bash -c "TEST=1 ./mtxrpicam_64"