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

automatically add _32 and _64 prefix to executable #3

Merged
merged 1 commit into from
Aug 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -64,5 +70,5 @@ DEPENDENCIES = \
%.o: %.cpp $(DEPENDENCIES)
$(CXX) $(CXXFLAGS) -c $< -o $@

mtxrpicam: $(OBJS)
$(EXECUTABLE_NAME): $(OBJS)
$(CXX) $^ $(LDFLAGS) -o $@
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -43,15 +43,15 @@ 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

1. Download MediaMTX source code and open a terminal in it

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

Expand Down
28 changes: 13 additions & 15 deletions utils.mk
Original file line number Diff line number Diff line change
@@ -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

Expand All @@ -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 \
Expand All @@ -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 \
Expand All @@ -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
Expand All @@ -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"

Expand All @@ -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"