# Makefile for the VideoLAN mini-server
# Regis Duchesne, VIA, ECP, France <regis@via.ecp.fr>, 20/01/97
#
# Note : You need a make clean each time you modify this Makefile.

############ Beginning of the configuration section ############

# System specific
SYS=LINUX
#SYS=SOLARIS
#SYS=DARWIN
#SYS=BSD

# Debug
#CFLAGS += -g

# Profile with gprof. Don't strip the executable file !
#CFLAGS += -g -pg

VLMS_VERSION=0.2.2

prefix=/usr/local

############ End of the configuration section ############

INSTALL=/usr/bin/install -c

OBJ = \
   vlms.o \
   netutils.o \
   error.o \
   ts.o \
   ps.o

CFLAGS += -D$(SYS)

# Use threads
CFLAGS += -D_REENTRANT

ifeq ($(SYS),SOLARIS)
OBJ += getopt.o getopt1.o
LIB += -lsocket -lxnet
endif

ifeq ($(SYS),BSD)
OBJ += getopt.o getopt1.o
LIB += -pthread
else
LIB += -lpthread
endif

ifeq ($(SYS),DARWIN)
OBJ += getopt.o getopt1.o
CFLAGS += -no-cpp-precomp
else
CC = gcc
endif

# GNU gcc parameters style
#CFLAGS += -O6 -Wall
CFLAGS += -g

# Generate the dependencies
CFLAGS += -MMD

# CLIENT or SERVER
CFLAGS += -DSERVER

# Include the dependancies
ifeq (depend,$(wildcard depend))
all: vlms vlf
include depend
else
all: clean vlms vlf
endif

vlms: $(OBJ)
	cat *.d > depend
	rm -f *.d
	$(CC) -o $@ $(OBJ) $(LIB) $(LDFLAGS) $(LOADLIBES) $(CFLAGS)
	chmod 755 $@

vlf: vlf.c
	$(CC) -o $@ $< $(CFLAGS) $(LIB)

clean:
	for i in $(OBJ); \
	do rm -f $$i; \
	done; \
	rm -f *.d depend
	rm -f vlms vlf

distclean: clean

install:
	$(INSTALL) vlms $(prefix)/bin
	#$(INSTALL) vlf $(prefix)/bin

snapshot-common:
	# Check that tmp isn't in the way
	@if test -e tmp; then \
		echo "Error: please remove ./tmp, it is in the way"; false; \
	else \
		echo "OK."; mkdir tmp; \
	fi
	# Copy directory structure in tmp
	find -type d | grep -v '\(\.dep\|snapshot\|CVS\)' | while read i ; \
		do mkdir -p tmp/vlms/$$i ; \
	done
	rm -Rf tmp/vlms/tmp
	find debian -mindepth 1 -maxdepth 1 -type d | \
		while read i ; do rm -Rf tmp/vlms/$$i ; done
	# Copy .c .h files
	cp *.c *.h tmp/vlms/
	# Copy misc files
	cp vlms.spec AUTHORS COPYING ChangeLog README INSTALL NEWS Makefile \
		tmp/vlms/
	# Copy Debian control files
	for file in debian/*dirs debian/*docs \
		debian/*copyright ; do cp $$file tmp/vlms/debian ; done
	for file in control changelog rules ; do \
		cp debian/$$file tmp/vlms/debian/ ; done

snapshot: snapshot-common
	# Build archives
	F=vlms-${VLMS_VERSION}; \
	mv tmp/vlms tmp/$$F; (cd tmp ; tar cf $$F.tar $$F); \
	bzip2 -f -9 < tmp/$$F.tar > $$F.tar.bz2; \
	gzip -f -9 tmp/$$F.tar ; mv tmp/$$F.tar.gz .
	# Clean up
	rm -Rf tmp

