HowTo: Compile Janus on Apple M1

162 views
Skip to first unread message

Sebastian Schmid

unread,
Apr 14, 2022, 1:26:14 PM4/14/22
to meetecho-janus
Hi all,

When compiling Janus on Apple M1 today, I realized that some adjustments are required.

Homebrew installs its packages in a different directory on M1. The output of brew --prefix changed from /usr/local to /opt/homebrew 

The tricky thing for me was, that configure.ac needs to be changed too, before running ./configure - otherwise, openssl cannot be found.

Assuming you use homebrew to install the dependecies, you need to run the following commands after checkout:

sh ./autogen.sh
sed -i'.bak' -e 's/\/usr\/local/\/opt\/homebrew/g' configure.ac
./configure --prefix=/usr/local/janus PKG_CONFIG_PATH=$(brew --prefix)/opt/openssl/lib/pkgconfig:$(brew --prefix)/opt/glib/lib/pkgconfig:$(brew --prefix)/opt/libffi/lib/pkgconfig:$(brew --prefix)/libnice/lib/pkgconfig:$(brew --prefix)/libsrtp/lib/pkgconfig:$(brew --prefix)/libwebsockets/lib/pkgconfig:$(brew --prefix)/gzip/lib/pkgconfig
make


Hopefully, this saves some time for you guys 

Happy Easter!

Sebastian

Erwin Dee Junio Villejo

unread,
Apr 15, 2022, 3:21:11 AM4/15/22
to meetecho-janus
Hello!

I thought I'd also share my solution:

First, remove the hard-coded CFLAGS and LDFLAGS on autoconf (configure.ac) and move them to automake (Makefile.am):

```
diff --git a/configure.ac b/configure.ac
index e82b82c1..f6156a3b 100644
--- a/configure.ac
+++ b/configure.ac
@@ -78,10 +78,7 @@ AC_SUBST(JANUS_VERSION_STRING)
 
 case "$host_os" in
 darwin*)
-    CFLAGS="$CFLAGS -I/usr/local/opt/openssl/include -I/usr/local/include"
-    # add rdynamic to LDFLAGS
     LDFLAGS="$LDFLAGS -Wl,-export_dynamic"
-    LDFLAGS="$LDFLAGS -L/usr/local/lib -L/usr/local/opt/openssl/lib -L/opt/local/lib -L/usr/local/libsrtp/lib"
     AM_CONDITIONAL([DARWIN_OS], true)
 ;;
 freebsd*)
diff --git a/src/Makefile.am b/src/Makefile.am
index c8eeb339..75e7587a 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -63,6 +63,14 @@ duktape_DATA = $(NULL)
         s|[@]duktapedir[@]|$(duktapedir)|" \
     $< > $@ || rm $@
 
+##
+# CFLAGS, LDFLAGS
+##
+if DARWIN_OS
+AM_CFLAGS = -I/opt/homebrew/include -I/opt/homebrew/opt/openssl@3/include
+AM_LDFLAGS = -L/opt/homebrew/lib -L/opt/homebrew/opt/openssl@3/lib
+endif
+
 ##
 # Janus
 ##
@@ -476,9 +484,9 @@ endif
 if ENABLE_PLUGIN_VOICEMAIL
 plugin_LTLIBRARIES += plugins/libjanus_voicemail.la
 plugins_libjanus_voicemail_la_SOURCES = plugins/janus_voicemail.c
-plugins_libjanus_voicemail_la_CFLAGS = $(plugins_cflags)
-plugins_libjanus_voicemail_la_LDFLAGS = $(plugins_ldflags) -logg
-plugins_libjanus_voicemail_la_LIBADD = $(plugins_libadd)
+plugins_libjanus_voicemail_la_CFLAGS = $(plugins_cflags) $(OGG_CFLAGS)
+plugins_libjanus_voicemail_la_LDFLAGS = $(plugins_ldflags) $(OGG_LDFLAGS) $(OGG_LIBS)
+plugins_libjanus_voicemail_la_LIBADD = $(plugins_libadd) $(OGG_LIBADD)
 conf_DATA += ../conf/janus.plugin.voicemail.jcfg.sample
 EXTRA_DIST += ../conf/janus.plugin.voicemail.jcfg.sample.in
 CLEANFILES += ../conf/janus.plugin.voicemail.jcfg.sample

```

Then, when invoking the configure script, provide the homebrew paths:

```
./configure --prefix=$HOME/opt/janus \
    PKG_CONFIG_PATH=/opt/homebrew/opt/openssl@3/lib/pkgconfig \
    CFLAGS=-I/opt/homebrew/include \
    LDFLAGS=-L/opt/homebrew/lib
```

Alternatively, one can build and run Janus through a docker container. For Apple M1 specifically, pick a base docker image that provides ARM images (virtually native performance since there is no translation from ARM to x86) and of course, pick a Linux distro (so there is no need to modify Janus build files).

In my case, I used Debian (ARM) as the base image:

```
FROM debian:11 AS buildbase
SHELL ["/bin/bash", "-c"]
RUN apt update
RUN apt install -y gcc dh-autoreconf pkg-config gengetopt cmake npm \
    libglib2.0-dev zlib1g-dev

FROM buildbase AS build
RUN apt install -y lib{jansson,config,nice,ssl,curl4-openssl}-dev \
    lib{srtp2,usrsctp,microhttpd,websockets}-dev \
    lib{opus,ogg}-dev
RUN mkdir -p /home/workspace
WORKDIR /home/workspace
COPY ./ ./
RUN ./autogen.sh
RUN ./configure --prefix=/opt/janus
RUN make -j$(nproc)
RUN make install

FROM debian:11-slim AS deploy
SHELL ["/bin/bash", "-c"]
RUN apt update
RUN apt install -y lib{jansson4,config9,nice10,ssl1.1,curl4} \
    lib{srtp2-1,usrsctp1,microhttpd12,websockets16} \
    lib{opus0,ogg0}
COPY --from=build /opt/janus /opt/janus
EXPOSE 7088 8088 8188
ENTRYPOINT /opt/janus/bin/janus 
```

Hope this helps!

Best regards,
Erwin

Max Trunnikov

unread,
Feb 9, 2023, 8:21:42 AM2/9/23
to meetecho-janus
Hello!
Thanks for you answer, that's great. 
I just wanted to notice that you forgot `make configs` command after `make install` in your Dockerfile.
I could not run it first time because of it.

пятница, 15 апреля 2022 г. в 10:21:11 UTC+3, Erwin Dee Junio Villejo:
Reply all
Reply to author
Forward
0 new messages