# Path settings for 'make install'
# cod-file will be searched in DATADIR  /* $(HOME) and current directory */
# ini-file will be searched in DATADIR  /* $(HOME), current directory    */
BINDIR = /usr/local/bin
DATADIR = /usr/local/share/psk31
MANDIR = /usr/local/man/man1
CC = g++ 
LD = g++
###CXXFLAGS = -O2 -g
CXXFLAGS = -O2 -g -Wall 
LDFLAGS = -v -H

#############################################################################
## If you change these lines, you have to do a "make clean"!!!
##
## Uncomment these two lines for recommended mode with pthread library
LIBS = -lncurses -lm -lpthread
CXXFLAGS += -DUSE_PTHREAD
##
## Uncomment this line for operation without phreads
## This will only work for "make twpsk"
## making "psk31lx" will currently fail!
## (Well, it compiles, but the executable does not work...)
##LIBS = -lncurses -lm
#############################################################################
export CXXFLAGS

OBJS = psk31-coder.o psk31-receiver.o psk31-transmitter.o psk31-main.o window.o
# OBJS += hansis-fft.o
FILES = README Changes Makefile *.C *.h psk31.ini psk31.cod psk31.1

TWPSKLIBDIRS = -L/usr/X11R6/lib
TWPSKLIBS = -lXm -lXt -lX11 -lXp -lXext -lXpm -lm

all:	 twpsk psk31lx 

psk31lx:	modes_d server_d user_d 
		$(LD) $(LDFLAGS) $(LIBS) modes/*.o user/*.o\
		server/server-main.o -o psk31lx

twpsk:	modes_d server_d twpsk_d inst_files
	$(LD)  $(LDFLAGS) $(LIBS) $(TWPSKLIBDIRS) $(TWPSKLIBS) \
	modes/*.o server/server-main.o user-twpsk/*.o -o twpsk

inst_files:
	if test -d $(HOME)/twpskDir ; \
	then \
	   echo $(HOME)/twpskDir exists - preserving your files. ; \
	else \
	   echo Copying some files to $(HOME)/twpskDir; \
	   install -d  $(HOME)/twpskDir ; \
	   install user-twpsk/twpskDir/* $(HOME)/twpskDir ; \
	fi

modes_d:
	(cd modes; $(MAKE))

twpsk_d:
	(cd user-twpsk; $(MAKE))

user_d:
	(cd user; $(MAKE) direct)

server_d:
	(cd server; $(MAKE) direct)

arch:	$(FILES)
	tar -cvzf psk31lx.tgz $(FILES)

rpm:	
	tar -cvzf /usr/src/packages/SOURCES/twpsk-V1.1.tar.gz $(FILES)
	rpm -ba /usr/src/packages/SPECS/twpsk-1.1-1.spec

install:
	install -d $(BINDIR)
	install -d $(DATADIR)
	install -d $(MANDIR)
	install psk31lx $(BINDIR)
	install psk31.ini psk31.cod $(DATADIR)
	install psk31.1 $(MANDIR)

install_twpsk:
	install -d $(BINDIR)
	install -d $(DATADIR)
	install  psk31.ini psk31.cod user-twpsk/twpskHelp $(DATADIR)
	install  twpsk $(BINDIR)
	install  user-twpsk/Twpsk /usr/X11R6/lib/X11/app-defaults

clean:
	/bin/rm -f */*.o psk31lx twpsk core
