Statically linking asterisk addons


#1

I have two servers, one running mysql 5.0, and the other running 3.23. I must run asterisk realtime on the server with 3.23, while actually using databases from the one with 5.0. My solution has been to statically compile the asterisk addons on a box with the 5.0, but I cannot seem to do it.

I’ve tried running make after LDFLAGS="-static", but no luck.

Any advice? Thanks.

—Mike


#2

Found an answer, here’s my Makefile for whoever else needs this solution:

Asterisk – A telephony toolkit for Linux.

Makefile for CDR backends (dynamically loaded)

Copyright © 1999, Mark Spencer

Mark Spencer markster@linux-support.net

This program is free software, distributed under the terms of

the GNU General Public License

.EXPORT_ALL_VARIABLES:

MODS=format_mp3/format_mp3.so app_saycountpl.so

CFLAGS+=-fPIC
CFLAGS+=-I…/asterisk
CFLAGS+=-D_GNU_SOURCE

INSTALL=install
INSTALL_PREFIX=
ASTLIBDIR=$(INSTALL_PREFIX)/usr/lib/asterisk
MODULES_DIR=$(ASTLIBDIR)/modules

MySQL stuff… Autoconf anyone??

MODS+=$(shell if [ -d /usr/local/mysql/include ] || [ -d /usr/include/mysql ] || [ -d /usr/local/include/mysql ] || [ -d /opt/mysql/include ]; then echo “cdr_addon_mysql.so app_addon_sql_mysql.so res_config_mysql.so”; fi)
CFLAGS+=$(shell if [ -d /usr/local/mysql/include ]; then echo “-I/usr/local/mysql/include”; fi)
CFLAGS+=$(shell if [ -d /usr/include/mysql ]; then echo “-I/usr/include/mysql”; fi)
CFLAGS+=$(shell if [ -d /usr/local/include/mysql ]; then echo “-I/usr/local/include/mysql”; fi)
CFLAGS+=$(shell if [ -d /opt/mysql/include/mysql ]; then echo “-I/opt/mysql/include/mysql”; fi)
MLFLAGS=
MLFLAGS+=$(shell if [ -d /usr/lib/mysql ]; then echo “-L/usr/lib/mysql”; fi)
MLFLAGS+=$(shell if [ -d /usr/lib64/mysql ]; then echo “-L/usr/lib64/mysql”; fi)
MLFLAGS+=$(shell if [ -d /usr/local/mysql/lib ]; then echo “-L/usr/local/mysql/lib”; fi)
MLFLAGS+=$(shell if [ -d /usr/local/lib/mysql ]; then echo “-L/usr/local/lib/mysql”; fi)
MLFLAGS+=$(shell if [ -d /opt/mysql/lib/mysql ]; then echo “-L/opt/mysql/lib/mysql”; fi)

OSARCH=$(shell uname -s)

ifeq (${OSARCH},Darwin)
SOLINK=-dynamic -bundle -undefined suppress -force_flat_namespace
else
SOLINK=-shared -Xlinker -x
endif
ifeq (${OSARCH},SunOS)
SOLINK=-shared -fpic -L$(CROSS_COMPILE_TARGET)/usr/local/ssl/lib
endif

all: depend $(MODS)

format_mp3/format_mp3.so:
$(MAKE) -C format_mp3 all

install: all
for x in $(MODS); do $(INSTALL) -m 755 $$x $(DESTDIR)$(MODULES_DIR) ; done

clean:
rm -f *.so *.o .depend
$(MAKE) -C format_mp3 clean

%.so : %.o
$(CC) $(SOLINK) -o $@ $<

ifneq ($(wildcard .depend),)
include .depend
endif

cdr_addon_mysql.so: cdr_addon_mysql.o
$(CC) $(SOLINK) -o $@ $< -Wl,-Bstatic -lmysqlclient -lz $(MLFLAGS) -Wl,-Bdynamic

res_config_mysql.so: res_config_mysql.o
$(CC) $(SOLINK) -o $@ $< -Wl,-Bstatic -lmysqlclient -lz $(MLFLAGS) -Wl,-Bdynamic

app_addon_sql_mysql.so: app_addon_sql_mysql.o
$(CC) $(SOLINK) -o $@ $< -Wl,-Bstatic -lmysqlclient -lz $(MLFLAGS) -Wl,-Bdynamic

depend: .depend

.depend:
./mkdep $(CFLAGS) ls *.c

update:
@if [ -d CVS ]; then
echo “Updating from CVS…” ;
cvs -q -z3 update -Pd;
else
echo “Not CVS”;
fi