Page 1 of 1

Working on building ZM for Mac OS X Server 10.6.5 - UPDATE 8

Posted: Sun Nov 28, 2010 1:18 am
by MILxDOT
Previous posts deleted - Here is the updated status:

With this update 8 to the howto ZoneMinder will actually start and go to a running status on the mac mini server but I cannot get either the shared memory or the mapped memory builds to run properly. (see the post below) I can now also build the upcoming 1.24.3 version successfully with only minor modifications. I will need some help with how Mac deals with shared memory or mapped memory before I can get this to work properly. Hopefully we get a response from the Apple developer discussions or MacPorts team concerning the memory issue..then I think we are set.

Mac Mini Server 10.6.5 Zoneminder HOWTO

Note: This Zoneminder build is for IP based cameras only. So far it is NOT designed for capture cards or USB video devices.

1. Install Mac OS X Server but do not install any services, we will add these after we perform all of the updates to snow leopard server. Run Apple Icon Software Update and reboot -- Software Update again until there are no more updates available.

2. SET YOUR MAC TO BOOT THE 64BIT KERNEL
Note: by default apple does not let you boot into the 64 bit kernel using the late 2009 mac mini server 3,1 to work around this I will apply the following modded boot64.efi described here:
http://blog.leanopen.com/2010/04/23/doe ... in-64-bit/
(mid 2010 mac mini can boot 64 bit out of the box so this will be a non issue very soon)

Note: I did try using the stock i386 kernel as well as the stock 32bit build of mysql but the 64bit version of perl mainly DBD::mysql didn't play nicely with the stock mysql. Googling with provide many other discussions about this issue. So we will be using a 64bit version of MySQL.

3. Go to http://developer.apple.com/ register as a developer and login to the developer site.

4. Download and install xcode322_2148_developerdvd.dmg from http://connect.apple.com/cgi-bin/WebObj ... /downloads (Developer Tools on the right menu)

5. For this how to we will be permanently logging in with escalated privileges. This isn't really the preferred method due to security concerns but it will keep the documentation a little less cluttered. Normally you would type sudo before every command that needs escalated privileges.

6. Open terminal and type sudo -i then enter. You are now logged in with escalated privileges.
sudo -i

7. For this how to we will work out of the standard privileged root user's home directory of /var/root. To get to this directory quickly just type cd then enter.
cd /var/root

8. CREATE A BUILD DIRECTORY
mkdir /var/root/builds

9. CHANGE TO THE BUILD DIRECTORY
cd /var/root/builds

10. COMPILE & INSTALL wget
curl -O http://ftp.gnu.org/gnu/wget/wget-1.12.tar.gz
tar -xzvf wget-1.12.tar.gz
cd wget-1.12
./configure
make
make install

CHANGE TO THE BUILD DIRECTORY
cd /var/root/builds

11. INSTALL MYSQL
Download and install mysql-5.1.53-osx10.6-x86_64.dmg (including the package, Pref Pane and Startup Item)
(just double click MySQL.prefPane to install the preferences pane)
Start the service by clicking the button in the preferences pane
mkdir /var/root/mysqloriginals
cd /usr/bin/
mv mysql* /var/root/mysqloriginals
vi /etc/profile and add the following to the bottom of the file:
export PATH=/usr/local/mysql/bin:$PATH

logout of your shell the log back in by doing exit a couple times
log back in and you should now be able to run mysql by simply typing
mysql
it should show "Server version: 5.1.53 MySQL Community Server (GPL)"
exit

cd /usr/local/mysql-5.1.53-osx10.6-x86_64
cp -R include/ /usr/include/mysql/
cp -R lib/ /usr/lib/mysql/

CHANGE TO THE BUILD DIRECTORY
cd /var/root/builds

12. ADD REQUIRED SERVICES
Open the Server Admin (snow leopard server only has this)
In the lower left click on the plus symbol then add service. The following is a list of services that you will want checked:
AFP
DNS
Web

13. Next enable the necessary apache php modules by going into the server admin, web on the left, settings at the top, then modules. Enable the php5_module.
Click on Web then Start

14. mkdir /Library/WebServer/Documents/zm

15. INSTALL REQUIRED PERL MODULES
perl -MCPAN -e 'shell' (just answer yes to any questions it will ask you several times)
install YAML
install DBI
install DBD::mysql
install Date::Manip
install PHP::Serialization
install Sys::Mmap
exit

CHANGE TO THE BUILD DIRECTORY
cd /var/root/builds

16. COMPILE & INSTALL LAME:
GRAB A SNAPSHOT OF LAME SOURCE:
cvs -z3 -d:pserver:anonymous@lame.cvs.sourceforge.net:/cvsroot/lame co -P lame
cd lame
./configure
make
make install

CHANGE BACK TO YOUR BUILD DIRECTORY:
cd /var/root/builds

17. COMPILE & INSTALL FAAD2
wget http://downloads.sourceforge.net/faac/faad2-2.7.tar.gz
tar -xzvf faad2-2.7.tar.gz
cd faad2-2.7
./configure
make
make install

CHANGE BACK TO YOUR BUILD DIRECTORY:
cd /var/root/builds

18. COMPILE & INSTALL FAAC
wget http://downloads.sourceforge.net/faac/faac-1.28.tar.gz
tar -xzvf faac-1.28.tar.gz
cd faac-1.28/
./configure
make
make install

CHANGE BACK TO YOUR BUILD DIRECTORY:
cd /var/root/builds

19. INSTALL git
Use your browser to visit http://git-osx-installer.googlecode.com ... eopard.dmg
Download git-1.7.3.3-i386-leopard.dmg
Install using the dmg
cd /usr/bin/
ln -s /usr/local/git/bin/git git

CHANGE BACK TO YOUR BUILD DIRECTORY:
cd /var/root/builds

20. COMPILE & INSTALL yasm
wget http://www.tortall.net/projects/yasm/re ... 1.0.tar.gz
tar -xzvf yasm-1.1.0.tar.gz
cd yasm-1.1.0
./configure
make
make install

CHANGE BACK TO YOUR BUILD DIRECTORY:
cd /var/root/builds

21. GRAB LIBJPEG SOURCE AND INSTALL
wget http://www.ijg.org/files/jpegsrc.v8b.tar.gz
tar -xzvf jpegsrc.v8b.tar.gz
cd jpeg-8b
./configure
make
make install

CHANGE BACK TO YOUR BUILD DIRECTORY:
cd /var/root/builds

22. COMPILE & INSTALL x264
/usr/local/git/bin/git clone git://git.videolan.org/x264.git
cd x264
CPPFLAGS="-D__STDC_CONSTANT_MACROS" ./configure --enable-shared
In config.mak, I moved -fPIC to the front of the line it is in.
vi config.mak
make
make install

CHANGE BACK TO YOUR BUILD DIRECTORY:
cd /var/root/builds

23. GRAB A SNAPSHOT OF FFMPEG SOURCE:
chmod 755 /usr/bin/pod2man ( or ffmpeg make will fail)
svn checkout svn://svn.ffmpeg.org/ffmpeg/trunk ffmpeg
cd ffmpeg
CPPFLAGS="-D__STDC_CONSTANT_MACROS" ./configure --enable-gpl --enable-libx264 --enable-shared --enable-pthreads
make
make install

CHANGE BACK TO YOUR BUILD DIRECTORY:
cd /var/root/builds

24. WORKAROUND FOR V4L COMPATIBILITY
mkdir /usr/include/linux
wget http://src.gnu-darwin.org/ports/multime ... videodev.h
cp videodev.h /usr/include/linux

CHANGE BACK TO YOUR BUILD DIRECTORY:
cd /var/root/builds

25. SETUP PCRE SOURCE
cd /usr/include/
ln -s /Developer/SDKs/MacOSX10.5.sdk/usr/include/php/ext/pcre/pcrelib/pcre.h pcre.h

CHANGE BACK TO YOUR BUILD DIRECTORY:
cd /var/root/builds

26. DOWNLOAD AND UNPACK FREEBSD 8.0 SUPPLIED PATCH FILES
wget http://white-raven.pisem.net/zoneminder ... 8.0.tar.gz
tar -xzvf zoneminder-1.24.2_2-freebsd-8.0.tar.gz
mv zoneminder bsd-zm-patches

CHANGE BACK TO YOUR BUILD DIRECTORY:
cd /var/root/builds

27. COMPILE AND INSTALL Zoneminder:

wget http://www2.zoneminder.com/downloads/Zo ... 4.2.tar.gz
tar -xzvf ZoneMinder-1.24.2.tar.gz
cd ZoneMinder-1.24.2
patch -p0 < ../bsd-zm-patches/files/patch-Makefile.am
patch -p0 < ../bsd-zm-patches/files/patch-Memory.pm
patch -p0 < ../bsd-zm-patches/files/patch-Memory.pm.in
patch -p0 < ../bsd-zm-patches/files/patch-configure.ac
patch -p0 < ../bsd-zm-patches/files/patch-functions.php
patch -p0 < ../bsd-zm-patches/files/patch-zm_create.sql.in
patch -p0 < ../bsd-zm-patches/files/patch-zm_debug.c
patch -p0 < ../bsd-zm-patches/files/patch-zm_event.cpp
patch -p0 < ../bsd-zm-patches/files/patch-zm_ffmpeg_camera.cpp
patch -p0 < ../bsd-zm-patches/files/patch-zm_image.cpp
patch -p0 < ../bsd-zm-patches/files/patch-zm_image.h
patch -p0 < ../bsd-zm-patches/files/patch-zm_jpeg.c
patch -p0 < ../bsd-zm-patches/files/patch-zm_jpeg.h
patch -p0 < ../bsd-zm-patches/files/patch-zm_local_camera.h
patch -p0 < ../bsd-zm-patches/files/patch-zm_monitor.cpp
patch -p0 < ../bsd-zm-patches/files/patch-zm_mpeg.cpp
patch -p0 < ../bsd-zm-patches/files/patch-zm_remote_camera.h
patch -p0 < ../bsd-zm-patches/files/patch-zm_remote_camera_http.cpp
patch -p0 < ../bsd-zm-patches/files/patch-zm_rtp_source.cpp
patch -p0 < ../bsd-zm-patches/files/patch-zm_signal.h
patch -p0 < ../bsd-zm-patches/files/patch-zm_stream.cpp
patch -p0 < ../bsd-zm-patches/files/patch-zm_time.h
patch -p0 < ../bsd-zm-patches/files/patch-zmaudit.pl
patch -p0 < ../bsd-zm-patches/files/patch-zmc.cpp
patch -p0 < ../bsd-zm-patches/files/patch-zmcomms.cpp
patch -p0 < ../bsd-zm-patches/files/patch-zmcomms.h
patch -p0 < ../bsd-zm-patches/files/patch-zmcontrol.pl
patch -p0 < ../bsd-zm-patches/files/patch-zmdc.pl
patch -p0 < ../bsd-zm-patches/files/patch-zmfilter.pl
patch -p0 < ../bsd-zm-patches/files/patch-zmpkg.pl
patch -p0 < ../bsd-zm-patches/files/patch-zmpkg.pl.in
patch -p0 < ../bsd-zm-patches/files/patch-zmtrack.pl
patch -p0 < ../bsd-zm-patches/files/patch-zmtrigger.pl
patch -p0 < ../bsd-zm-patches/files/patch-zmu.cpp
patch -p0 < ../bsd-zm-patches/files/patch-zmu2.cpp
patch -p0 < ../bsd-zm-patches/files/patch-zmwatch.pl
patch -p0 < ../bsd-zm-patches/files/patch-zmx10.pl

cp -i ../bsd-zm-patches/files/videodev.h src/
cp -i ../bsd-zm-patches/files/zm.sh.in src/
cp -i ../bsd-zm-patches/files/zm_fbsd_camera.cpp src/
cp -i ../bsd-zm-patches/files/zm_fbsd_camera.h src/

CPPFLAGS="-D__STDC_CONSTANT_MACROS" ./configure --with-webdir=/Library/WebServer/Documents/zm --with-cgidir=/Library/WebServer/CGI-Executables ZM_DB_HOST=localhost ZM_DB_NAME=zm ZM_DB_USER=zmuser ZM_DB_PASS=zmpass --enable-debug=yes --with-webgroup=_www --with-webuser=_www --with-mysql=/usr ZM_SSL_LIB=openssl --enable-shared --disable-crashtrace

vi src/zm_signal.h (change ucontext.h to sys/ucontext.h)
vi src/zm_signal.cpp (change ucontext.h to sys/ucontext.h)

vi src/zm_thread.cpp
(comment out the following if tests):
void Mutex::lock( int secs )
{
struct timespec timeout = getTimeout( secs );
// if ( pthread_mutex_timedlock( &mMutex, &timeout ) < 0 )
// throw ThreadException( stringtf( "Unable to timedlock pthread mutex: %s", strerror(errno) ) );
}

void Mutex::lock( double secs )
{
struct timespec timeout = getTimeout( secs );
// if ( pthread_mutex_timedlock( &mMutex, &timeout ) < 0 )
// throw ThreadException( stringtf( "Unable to timedlock pthread mutex: %s", strerror(errno) ) );
}

save and exit

make
make install

mysql
create database zm;
grant all on zm.* to 'zmuser'@localhost identified by 'zmpass';
exit

mysql zm < db/zm_create.sql

28. SET FINAL PHP MYSQL OPTIONS
vi /private/etc/php.ini
change pdo_mysql.default_socket=/var/mysql/mysql.sock
to
pdo_mysql.default_socket=/tmp/mysql.sock
change mysql.default_socket = /var/mysql/mysql.sock
to
mysql.default_socket = /tmp/mysql.sock
change mysqli.default_socket = /var/mysql/mysql.sock
to
mysqli.default_socket = /tmp/mysql.sock

change short_open_tag = Off
to
short_open_tag = On

save and exit

Go into your server manager and restart the Web service.

Now you should be able to access ZoneMinder via http://127.0.0.1/zm (on the mac mini server of course)

Posted: Mon Nov 29, 2010 4:34 am
by MILxDOT
Post resolved.

Posted: Mon Nov 29, 2010 5:06 am
by MILxDOT
Post resolved.

Posted: Sun Dec 05, 2010 7:11 am
by MILxDOT
I made a post in the macports.org mailing list and had some email conversations with Jeremy "snc" who suggested that I look into simply using the macports system instead of trying to patch all of these files manually and manually insure that I have all of the dependencies. I learned that macports is much like the emerge process in gentoo which is really cool. Jeremy wrote a base Portfile for us and I am doing my best to tweak it using much of the info that the BSD zoneminder port maintainers have donated.

I think we can get this built for mac and have a really easy installation system for Mac much like apt in Ubuntu or emerge in gentoo.

I told Jeremy that I will donate to his paypal account or get him something from his wishlist for his much appreciated help on this.

I will post more info as it develops.

Posted: Thu Dec 09, 2010 2:37 pm
by multiplex
very interested in your work here! i'll wait a bit and see how you make out with macports

Posted: Thu Dec 09, 2010 6:47 pm
by MILxDOT
Using the MacPorts method we still hit the same brick wall that I encountered just building from source not using MacPorts:

zm_thread.cpp: In member function ‘void Mutex::lock(int)’:
zm_thread.cpp:78: error: ‘pthread_mutex_timedlock’ was not declared in this scope
zm_thread.cpp: In member function ‘void Mutex::lock(double)’:
zm_thread.cpp:85: error: ‘pthread_mutex_timedlock’ was not declared in this scope
make[2]: *** [zm_thread.o] Error 1
make[1]: *** [all-recursive] Error 1
make: *** [all] Error 2

Looks like we will need to patch zm_thread.cpp because mac doesn't have pthread_mutex_timedlock() in pthreads.h on the mac.

Here is what we will attempt to do, but it is a little over my head:
http://lists.apple.com/archives/xcode-u ... 00331.html

I will try to work with the MacPorts people to create a patch.

If anyone has any suggestions/patches they would like me to try I am all ears. I should be able to work on this over the weekend.

Posted: Sat Dec 11, 2010 9:13 pm
by joako
This is very interesting... Just the other day I was thinking "Hmm we could switch to Mac OS X Server... but ZM won't work"

But also if you have Mac OS X client I don't see why you can't install Apache from macports and go from there as well....

Posted: Mon Dec 13, 2010 8:51 am
by MILxDOT
Went back to just doing source builds and finally got a successful make, make install...although ZM isn't running properly yet.

I am going to pause trying to use the MacPorts method until I can get it to build properly using manual patch files and source builds.

Once we get it to build and run properly, I will work with the guys at MacPorts to make it so that we can install using "port install ZoneMinder"

Will try to provide another update soon.

Posted: Tue Dec 14, 2010 8:06 am
by MILxDOT
With this update 7 to the howto ZoneMinder will actually start and go to a running status on the mac mini server but the logs show that I have to do some work on the shared memory. I'm out of time for the evening but this is one step closer.

Posted: Wed Dec 15, 2010 5:18 am
by MILxDOT
I posted the following in the Apple developer discussion forums and also the MacPorts mailing list. Until I can get a little help with the shared memory or mapped memory issues I am probably going to have to put this project on hold. Zoneminder starts and goes to a running status...but when you add cameras you start getting errors whether you use shared memory or mapped memory.

Successful Build of Zoneminder -now issues w shared memory & or mmap

So I am finally able to build Zoneminder 1.24.2 using BSD patches or just making a few mods to the svn 1.24.3 version (I can build either of them without a problem now). You can build Zoneminder with either shared memory or mapped memory functionality. I cannot get either method to work properly.

SHARED MEMORY METHOD PROBLEMS
If I use shared memory I get:
[Can't get shared memory id '7a6d0001', 1: No such file or directory]
Question: what would be a good shared memory ID for Mac OS X here? Do I need to point the shared memory to a specific path in Mac?

MAPPED MEMORY METHOD PROBLEMS
If I build for mmap it isn't ever creating the zm.mmap.1 by itself
[Can't open memory map file '/mmap/zm.mmap.1': No such file or directory]
I just created a /mmap directory and gave it wide open permissions for testing purposes but it doesn't ever create a zm.mmap.1 but if I do touch /mmap/zm.mmap.1 while zm is running then stop zm...it removes it automatically.

Here is a link to my prerequisite setup and build HOWTO:
http://www.zoneminder.com/forums/viewtopic.php?t=16801

The svn version which will be 1.24.3 is pretty easy to modify to get it to compile properly. I actually think modding the 1.24.3 version is easier. I have the 1.24.2 step by step with BSD patches listed in the HOWTO. Both versions are acting the same way about either shared memory or mapped memory.

I would really like to get Zoneminder working on Mac and at this point I am probably willing to pay someone to help me finish porting this over.