#
# Makefile
#
# Make file for ptlib library
#
# Portable Windows Library
#
# Copyright (c) 1993-1998 Equivalence Pty. Ltd.
#
# The contents of this file are subject to the Mozilla Public License
# Version 1.0 (the "License"); you may not use this file except in
# compliance with the License. You may obtain a copy of the License at
# http://www.mozilla.org/MPL/
#
# Software distributed under the License is distributed on an "AS IS"
# basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
# the License for the specific language governing rights and limitations
# under the License.
#
# The Original Code is Portable Windows Library.
#
# The Initial Developer of the Original Code is Equivalence Pty. Ltd.
#
# Portions are Copyright (C) 1993 Free Software Foundation, Inc.
# All Rights Reserved.
# 
# Contributor(s): ______________________________________.
#
# $Log: Makefile,v $
# Revision 1.81  2001/08/11 15:38:43  rogerh
# Add Mac OS Carbon changes from John Woods <jfw@jfwhome.funhouse.com>
#
# Revision 1.80  2001/07/20 07:36:59  rogerh
# Move ESD detection.
#
# Revision 1.79  2001/07/19 09:53:29  rogerh
# Add the PWAVFile class to read and write .wav files
#
# Revision 1.78  2001/07/19 09:27:12  rogerh
# Add support for EsounD and esd (the Enlightenment Sound Daemon).
# This allows OhPhone to run on platforms where EsounD and esd have been
# ported which includes Mac OS X.
# Code written by Shawn Pai-Hsiang Hsiao <shawn@eecs.harvard.edu>.
#
# Revision 1.77  2001/07/10 03:45:14  robertj
# Added queue channel and delay channel classes to ptclib.
#
# Revision 1.76  2001/07/09 06:16:15  yurik
# Jac Goudsmit's BeOS changes of July,6th. Cleaning up media subsystem etc.
#
# Revision 1.75  2001/06/27 17:25:46  rogerh
# Compile the dummyvideo.cxx file on platforms with no video capture hardware
#
# Revision 1.74  2001/06/26 15:49:15  rogerh
# Define HAS_VIDEOCAPTURE on platforms with video capture code
#
# Revision 1.73  2001/06/26 14:20:36  rogerh
# Compile the generic video files on all platforms
#
# Revision 1.72  2001/05/29 03:34:39  craigs
# Changed to use new HAS_OPENSSL define
#
# Revision 1.71  2001/02/27 01:05:24  robertj
# Updated regular expression parser to latest version from Henry Spencer.
#
# Revision 1.70  2001/02/23 08:42:17  rogerh
# Add dummyaudio as the default SOUND_SOURCE
#
# Revision 1.69  2001/02/15 04:58:51  robertj
# Added class to do secure HTTP based service process.
#
# Revision 1.68  2001/01/24 02:51:15  robertj
# Changed definition of list of files for make clean to more correct position
#   as expected by common.mak
#
# Revision 1.67  2001/01/04 18:13:32  rogerh
# Tidy up the Makefile when building video4bsd.cxx
#
# Revision 1.66  2001/01/04 18:02:16  rogerh
# remove some old parts refering to linux
#
# Revision 1.65  2001/01/03 23:10:09  craigs
# Fixed Makefile problem when video not available
#
# Revision 1.64  2001/01/03 16:48:13  rogerh
# Rename V4L_SOURCE to VIDEO_SOURCE (to be less platform specific).
# Specify which files to use for VIDEO_SOURCE on non-linux systems eg BSD.
#
# Revision 1.63  2000/12/19 22:20:26  dereks
# Add video channel classes to connect to the PwLib PVideoInputDevice class.
# Add PFakeVideoInput class to generate test images for video.
#
# Revision 1.62  2000/12/16 13:00:46  rogerh
# BeOS changes, submitted by Yuri Kiryanov <openh323@kiryanov.com>
#
# Revision 1.61  2000/07/26 02:40:30  robertj
# Added video I/O devices.
#
# Revision 1.60  2000/06/21 01:01:22  robertj
# AIX port, thanks Wolfgang Platzer (wolfgang.platzer@infonova.at).
#
# Revision 1.59  2000/04/26 00:40:48  robertj
# Redesigned version number system to have single file to change on releases.
#
# Revision 1.58  2000/04/19 00:13:52  robertj
# BeOS port changes.
#
# Revision 1.57  2000/04/09 18:19:23  rogerh
# Add my changes for NetBSD support.
#
# Revision 1.56  2000/03/08 18:22:03  rogerh
# Select oss.cxx sound support for OpenBSD
#
# Revision 1.55  2000/03/03 00:30:31  robertj
# Removed ptclilb/proto directory.
#
# Revision 1.54  2000/02/24 11:03:27  craigs
# Fixed problem with making PW programs
#
# Revision 1.53  2000/02/17 12:09:19  robertj
# Added better random number generator after finding major flaws in MSVCRT version.
#
# Revision 1.52  2000/02/15 23:11:34  robertj
# Audio support for FreeBSD, thanks Roger Hardiman.
#
# Revision 1.51  2000/01/31 01:56:48  robertj
# Fixed BeOS compatibility problem.
#
# Revision 1.50  2000/01/22 00:52:06  craigs
# Added ability to use in any directory, and to create shared libraries
#
# Revision 1.49  2000/01/10 02:22:41  craigs
# Updated for new OpenSSL functionality
#
# Revision 1.48  1999/09/27 01:04:42  robertj
# BeOS support changes.
#
# Revision 1.47  1999/07/03 04:31:53  robertj
# Fixed problems with not including oss.cxx in library if OSTYPE not "linux"
#
# Revision 1.46  1999/06/28 09:28:02  robertj
# Portability issues, especially n BeOS (thanks Yuri!)
#
# Revision 1.45  1999/06/21 00:57:10  robertj
# Fixed inclusion of getdate.tab.c to clean files.
#
# Revision 1.44  1999/06/09 15:41:18  robertj
# Added better UI to make files.
#
# Revision 1.43  1999/04/18 09:36:31  robertj
# Get date grammar build.
#
# Revision 1.42  1999/04/16 14:37:41  craigs
# Added build for getdate.y
#
# Revision 1.41  1999/03/02 05:41:59  robertj
# More BeOS changes
#
# Revision 1.40  1999/02/25 03:44:58  robertj
# Sound driver implementation changes for various unix platforms.
#
# Revision 1.39  1999/02/22 13:24:47  robertj
# Added first cut sound implmentation.
#
# Revision 1.38  1999/02/19 11:33:51  robertj
# Added IP access control lists file.
#
# Revision 1.37  1999/01/22 00:30:46  robertj
# Yet more build environment changes.
#
# Revision 1.36  1999/01/21 08:27:18  robertj
# Added tarfiles target
#
# Revision 1.35  1999/01/16 09:54:04  robertj
# Changed some macros to more informative names.
#
# Revision 1.34  1998/12/04 12:53:14  craigs
# Fixed problem with regex in wrong directory
#
# Revision 1.33  1998/12/02 02:10:19  robertj
# New directory structure
#
# Revision 1.32  1998/11/22 10:44:10  craigs
# New GUI build system - for sure!
#
# Revision 1.31  1998/11/22 08:11:28  craigs
# Changed for new GUI build mechanism
#
# Revision 1.29  1998/10/15 07:03:46  robertj
# Moved object.cxx to last place so memory leak destructor is called at the right time.
#
# Revision 1.28  1998/09/24 07:40:34  robertj
# Moved structured file to common.
# Removed small files only containing pragma implementations
#
# Revision 1.27  1998/09/24 04:20:50  robertj
# Added open software license.
#
# Revision 1.26  1998/08/21 05:32:14  robertj
# Allowed for multiple "all" target, so can build lib from app makefile.
#
# Revision 1.25  1998/02/12 04:17:55  robertj
# Made DEBUG variable optional
#
# Revision 1.24  1998/01/26 07:25:21  robertj
# Removed tiny files, as now have pragma in the common files.
#
# Revision 1.22  1998/01/04 09:41:20  robertj
# Changed perasn.cxx to asner.cxx
#
# Revision 1.21  1998/01/04 08:29:37  craigs
# Changed for Linux
#
# Revision 1.20  1997/04/22 11:00:01  craigs
# Added SSL and DLL functions
#
# Revision 1.19  1996/11/17 08:35:50  craigs
# Fixed distsrc target
#
# Revision 1.18  1996/11/17 02:35:12  craigs
# Removed SSL from list of build targets
#
# Revision 1.16  1996/10/31 10:30:03  craigs
# Lots of changes
#
# Revision 1.15  1996/09/21 05:41:41  craigs
# Added new common files
#
# Revision 1.14  1996/08/03 12:05:10  craigs
# *** empty log message ***
#
# Revision 1.13  1996/07/03 06:32:18  craigs
# Removed spurious lines causing warnings during library make
#
# Revision 1.12  1996/06/29 11:37:28  craigs
# Added unix system type to object directories
# Added support for Linux shared libraries
#
# Revision 1.11  1996/06/19 01:56:26  craigs
# Added uhttpsvc to the list
#
# Revision 1.10  1996/06/14 09:30:43  craigs
# Included buildinc stuff
#
# Revision 1.9  1996/05/10 11:03:22  craigs
# Fixed distsrc rule to only include ptlib stuff
#
# Revision 1.8  1996/05/03 13:48:58  craigs
# Sun4 fixes
#
# Revision 1.7  1996/05/02  10:53:24  craigs
# Fixed problem with SUN4 target
#
# Revision 1.6  1996/04/17 11:12:20  craigs
# Latest version pre mibmaster release 1.0
#
# Revision 1.5  1996/04/15 10:50:13  craigs
# Last revision prior to release of MibMaster
#
# Revision 1.4  1996/01/26 11:09:04  craigs
# *** empty log message ***
#
# Revision 1.3  1995/12/08 13:18:13  craigs
# Lots of changes
#
# Revision 1.2  1995/07/09 00:35:42  craigs
# Latest and greatest omnibus change
#
# Revision 1.1  1995/01/16 20:50:44  craigs
# Initial revision
#
# Revision 1.1  1993/07/12  21:22:16  craigs
# Initial revision
#
#

ifndef PWLIBDIR
PWLIBDIR := $(HOME)/pwlib
endif

include $(PWLIBDIR)/make/unix.mak

OBJDIR	= $(PT_OBJDIR)
LIBDIR  = $(PW_LIBDIR)
TARGET  = $(LIBDIR)/$(PTLIB_FILE)
VERSION_FILE = $(PWLIBDIR)/version.h

##########################################

COMPONENT_SRC_DIR	= ../../ptclib
COMMON_SRC_DIR		= ../common
VPATH_CXX		:= $(COMMON_SRC_DIR) $(COMPONENT_SRC_DIR)

# try and keep the order of modules in reverse order of usage so any
# global statics will be constructed/destructed in the correct order


ifdef HAS_OPENSSL
SSL_SOURCE := $(COMPONENT_SRC_DIR)/pssl.cxx \
              $(COMPONENT_SRC_DIR)/shttpsvc.cxx
endif

# Video Capture. Set Video Capture Source to a dummy file, (which does not
# actually do anything, and then override it with platform specific files

VIDEO_CAPTURE_SOURCE = dummyvideo.cxx

ifneq (,$(wildcard /usr/include/linux/videodev.h))
VIDEO_CAPTURE_SOURCE = video4linux.cxx
STDCCFLAGS += -DHAS_VIDEOCAPTURE
endif

ifeq ($(OSTYPE),FreeBSD)
VIDEO_CAPTURE_SOURCE = video4bsd.cxx
STDCCFLAGS += -DHAS_VIDEOCAPTURE
endif

ifeq ($(OSTYPE),OpenBSD)
VIDEO_CAPTURE_SOURCE = video4bsd.cxx
STDCCFLAGS += -DHAS_VIDEOCAPTURE
endif

VIDEO_SOURCE := $(COMMON_SRC_DIR)/vfakeio.cxx \
                $(COMMON_SRC_DIR)/videoio.cxx \
		$(VIDEO_CAPTURE_SOURCE) \
	        $(COMMON_SRC_DIR)/vconvert.cxx


#Set SOUND_SOURCE to dummyaudio, a file which links but does not
#actually play or record audio.
#This will then be overridden by platform specific audio files.

SOUND_SOURCE = dummyaudio.cxx

ifeq ($(OSTYPE),linux)
SOUND_SOURCE = oss.cxx
endif

ifeq ($(OSTYPE),solaris)
SOUND_SOURCE = sunaudio.cxx
endif

ifeq ($(OSTYPE),FreeBSD)
SOUND_SOURCE = oss.cxx
endif

ifeq ($(OSTYPE),OpenBSD)
SOUND_SOURCE = oss.cxx
endif

ifeq ($(OSTYPE),NetBSD)
SOUND_SOURCE = oss.cxx
endif

ifeq ($(OSTYPE),AIX)
SOUND_SOURCE = ossaix.cxx
endif

ifeq ($(OSTYPE),beos)

ifdef MEDIA_KIT_UPDATE
SOUND_SOURCE = beaudio.cxx
else
BEAUDIO_SRC_DIR	= ./beaudio
VPATH_CXX += $(BEAUDIO_SRC_DIR)

SOUND_SOURCE = beaudio.cxx \
	$(BEAUDIO_SRC_DIR)/MediaRecorder.cxx \
	$(BEAUDIO_SRC_DIR)/MediaRecorderNode.cxx
endif

VIDEO_SOURCE = $(COMMON_SRC_DIR)/vfakeio.cxx \
               $(COMMON_SRC_DIR)/videoio.cxx \
	       	   video4beos.cxx \
	       	   $(COMMON_SRC_DIR)/vconvert.cxx
endif

ifeq ($(OSTYPE),Carbon)
MACAUDIO_SRC_DIR	= ./macosaudio
VPATH_CXX += $(MACAUDIO_SRC_DIR)

SOUND_SOURCE = macosaudio.cxx \
	$(MACAUDIO_SRC_DIR)/ringbuffer.cxx \
	$(MACAUDIO_SRC_DIR)/MacMain.cxx \
	$(MACAUDIO_SRC_DIR)/SequenceGrabber.cxx \
	$(MACAUDIO_SRC_DIR)/SoundMangler.cxx
endif

ifdef HAS_ESD
SOUND_SOURCE = esdaudio.cxx
endif

GETDATE_SOURCE = $(COMMON_SRC_DIR)/getdate.tab.c

SOURCES	= \
	$(COMPONENT_SRC_DIR)/asner.cxx \
	$(COMPONENT_SRC_DIR)/ipacl.cxx \
	$(COMPONENT_SRC_DIR)/modem.cxx \
	$(COMPONENT_SRC_DIR)/qchannel.cxx \
	$(COMPONENT_SRC_DIR)/delaychan.cxx \
	$(COMPONENT_SRC_DIR)/cypher.cxx \
	$(COMPONENT_SRC_DIR)/random.cxx \
	$(COMPONENT_SRC_DIR)/socks.cxx \
	$(COMPONENT_SRC_DIR)/httpsvc.cxx \
	$(COMPONENT_SRC_DIR)/snmpclnt.cxx \
	$(COMPONENT_SRC_DIR)/snmpserv.cxx \
	$(COMPONENT_SRC_DIR)/psnmp.cxx \
	$(COMPONENT_SRC_DIR)/pasn.cxx \
	$(COMPONENT_SRC_DIR)/httpform.cxx \
	$(COMPONENT_SRC_DIR)/httpclnt.cxx \
	$(COMPONENT_SRC_DIR)/httpsrvr.cxx \
	$(COMPONENT_SRC_DIR)/http.cxx \
	$(COMPONENT_SRC_DIR)/html.cxx \
	$(COMPONENT_SRC_DIR)/ftpclnt.cxx \
	$(COMPONENT_SRC_DIR)/ftpsrvr.cxx \
	$(COMPONENT_SRC_DIR)/ftp.cxx \
	$(COMPONENT_SRC_DIR)/inetmail.cxx \
	$(COMPONENT_SRC_DIR)/inetprot.cxx \
	$(COMPONENT_SRC_DIR)/telnet.cxx \
	$(SSL_SOURCE) \
	$(VIDEO_SOURCE) \
	$(SOUND_SOURCE) \
	$(GETDATE_SOURCE) \
	uicmp.cxx \
	$(COMMON_SRC_DIR)/sockets.cxx \
	$(COMMON_SRC_DIR)/pvidchan.cxx \
	socket.cxx \
	svcproc.cxx \
	remconn.cxx \
	config.cxx \
	udll.cxx \
	$(COMMON_SRC_DIR)/ptime.cxx \
	pipechan.cxx \
	serchan.cxx \
	$(COMMON_SRC_DIR)/sfile.cxx \
	$(COMMON_SRC_DIR)/pwavfile.cxx \
	channel.cxx \
	osutil.cxx \
	$(COMMON_SRC_DIR)/osutils.cxx \
	tlib.cxx \
	switch.cxx \
	assert.cxx \
	$(COMMON_SRC_DIR)/collect.cxx \
	$(COMMON_SRC_DIR)/contain.cxx \
	$(COMMON_SRC_DIR)/object.cxx   # must be last module

ifneq ($(OSTYPE),Carbon)
OBJS	= $(OBJDIR)/regcomp.o $(OBJDIR)/regexec.o $(OBJDIR)/regerror.o $(OBJDIR)/regfree.o
endif

CLEAN_FILES = $(GETDATE_SOURCE)


#######################################################

include ../../../make/common.mak

#######################################################

alllibs:
	$(MAKE) both
	$(MAKE) bothshared


$(OBJDIR)/regcomp.o: $(COMMON_SRC_DIR)/regex/regcomp.c
	$(CC) $(CFLAGS) $(DEBUG_FLAG) $(OPTCCFLAGS) -c -DPOSIX_MISTAKE -I$(COMMON_SRC_DIR)/regex -o $@ -c $<

$(OBJDIR)/regexec.o: $(COMMON_SRC_DIR)/regex/regexec.c
	$(CC) $(CFLAGS) $(DEBUG_FLAG) $(OPTCCFLAGS) -c -DPOSIX_MISTAKE -I$(COMMON_SRC_DIR)/regex -o $@ -c $<

$(OBJDIR)/regerror.o: $(COMMON_SRC_DIR)/regex/regerror.c
	$(CC) $(CFLAGS) $(DEBUG_FLAG) $(OPTCCFLAGS) -c -DPOSIX_MISTAKE -I$(COMMON_SRC_DIR)/regex -o $@ -c $<

$(OBJDIR)/regfree.o: $(COMMON_SRC_DIR)/regex/regfree.c
	$(CC) $(CFLAGS) $(DEBUG_FLAG) $(OPTCCFLAGS) -c -DPOSIX_MISTAKE -I$(COMMON_SRC_DIR)/regex -o $@ -c $<


ifdef REQUIRES_SEPARATE_SWITCH 
$(OBJDIR)/switch.o: ./switch.cxx
	@if [ ! -d $(OBJDIR) ] ; then mkdir -p $(OBJDIR) ; fi
	$(CPLUS) $(CFLAGS) $(STDCCFLAGS) -c $< -o $@
endif

$(OBJDIR)/getdate.tab.o: $(GETDATE_SOURCE)
	$(CC) $(CFLAGS) $(STDCCFLAGS) -c $< -o $@

$(DEPDIR)/getdate.tab.dep: $(GETDATE_SOURCE)
	$(CC) $(STDCCFLAGS) -M $< >> $@

$(GETDATE_SOURCE): $(COMMON_SRC_DIR)/getdate.y
	bison $(COMMON_SRC_DIR)/getdate.y

#######################################################

LIB_BASENAME = $(PTLIB_FILE)

include $(PWLIBDIR)/make/lib.mak

#######################################################

# End of Makefile
