SHELL=/bin/sh
CC = gcc
C_FLAGS = -Wall -g -O2 -m486 -fno-strength-reduce
GTK_CFLAGS = `gtk-config --cflags`
GTK_LIBS = `gtk-config --libs` 
LFLAGS = $(GTK_LIBS) -lresolv -lXmu -lXt -lSM -lICE
PROGNAME = IglooFTP
PROGNAME-STATIC = IglooFTP-static
VERSION = 0.6.1
VERSION_DATE = 1999
DESTDIR = /usr/local
BIN_PATH = $(DESTDIR)/bin
MAN_PATH = $(DESTDIR)/man
SHARE_PATH = $(DESTDIR)/share/$(PROGNAME)
RPM_RELEASE = 1
RPM_BUILDPATH = /usr/src/redhat
CODE_LINES = `cat *.c *.h | grep -ch -e "[[:alpha:]|[:punct:]]"` 

$(PROGNAME): main.o GTKmisc.o menu.o toolbar.o connectbar.o statusbar.o\
	dirlist.o ftplist.o queue.o log.o console.o dialog.o chmod.o\
	version.o custom.o string.o pixmaps.o color.o cursor.o\
	FTP.o FTPmisc.o IGLOOftp.o dir_tree.o site_manager.o text.o\
	docs.o netscape_remote.o execute.o path_functions.o RDC.o \
	messages.o dir.o layout.o IglooEdit.o list_share.o list_filter.o\
	text_ext.o session.o
	$(CC) $(C_FLAGS) -v *.o -o $(PROGNAME) $(GTK_CFLAGS) $(LFLAGS)
	@echo ---
	@echo $(CODE_LINES) Lines of code ...
	@echo

install : 
	@if ! test -e $(SHARE_PATH); then \
	echo "Making $(SHARE_PATH) directory ..."; mkdir -m 0755 $(SHARE_PATH); \
	else :; fi;	
	@if ! test -e $(SHARE_PATH)/docs; then \
	echo "Making $(SHARE_PATH)/docs directory ..."; mkdir -m 0755 $(SHARE_PATH)/docs; \
	else :; fi;
	@if ! test -e $(SHARE_PATH)/html; then \
	echo "Making $(SHARE_PATH)/html directory ..."; mkdir -m 0755 $(SHARE_PATH)/html; \
	else :; fi;
	@if ! test -e $(SHARE_PATH)/html/images; then \
	echo "Making $(SHARE_PATH)/html/images directory ..."; mkdir -m 0755 $(SHARE_PATH)/html/images; \
	else :; fi;
	@if ! test -e $(SHARE_PATH)/xpm; then \
	echo "Making $(SHARE_PATH)/xpm directory ..."; mkdir -m 0755 $(SHARE_PATH)/xpm; \
	else :; fi;
	@if ! test -e $(SHARE_PATH)/bookmarks; then \
	echo "Making $(SHARE_PATH)/bookmarks directory ..."; mkdir -m 0755 $(SHARE_PATH)/bookmarks; \
	else :; fi;
	@if ! test -e $(SHARE_PATH)/app_ass; then \
	echo "Making $(SHARE_PATH)/app_ass directory ..."; mkdir -m 0755 $(SHARE_PATH)/app_ass; \
	else :; fi;
	/usr/bin/install -s -m 755 $(PROGNAME) $(BIN_PATH)
	/usr/bin/install -m 644 ../share/docs/* $(SHARE_PATH)/docs/
	/usr/bin/install -m 644 ../share/html/*.* $(SHARE_PATH)/html/
	/usr/bin/install -m 644 ../share/html/images/*.* $(SHARE_PATH)/html/images/
	/usr/bin/install -m 644 ../share/xpm/* $(SHARE_PATH)/xpm/
	/usr/bin/install -m 644 ../share/bookmarks/* $(SHARE_PATH)/bookmarks/
	/usr/bin/install -m 644 ../share/app_ass/* $(SHARE_PATH)/app_ass/
	/usr/bin/install -m 644 ../share/gtkrc $(SHARE_PATH)/gtkrc	




uninstall : 
	rm -f $(BIN_PATH)/$(PROGNAME)
	rm -Rf $(SHARE_PATH)



FTP.o: FTP.c FTP.h 
	$(CC) -c $(C_FLAGS) $< $(GTK_CFLAGS)

FTPmisc.o: FTPmisc.c FTP.h 
	$(CC) -c $(C_FLAGS) $< $(GTK_CFLAGS)

netscape_remote.o : ../lib/netscape_remote.c
	$(CC) -c $(C_FLAGS) $< $(GTK_CFLAGS)

dirlist.o : dirlist.h local_sort.h

ftplist.o : ftplist.h remote_sort.h ftp_tree.h

site_manager.o : site_manager.h site_manager.c site_notebook.h

custom.o : custom.h custom_io.h custom_profiles.h files_assoc.h

FTP.o : FTP.h FTPcommands.h

text_ext.o : text_ext.h

queue.o : queue.h queue_log.h queue_dnd.h

.c.o:  
	$(CC) -c $(C_FLAGS) -DSHARE_PATH=\"$(SHARE_PATH)\" $< $(GTK_CFLAGS)




version.o : version.h


version.h : FORCE	
	@echo "/* this header is automatically generated */" > version.h
	@echo "/* and recreated for each new compilation */" >> version.h
	@echo "#define PROG_NAME \"$(PROGNAME)\"" >> version.h
	@echo "#define PROG_AUTHOR \"`cat ../AUTHORS`\"">>version.h
	@echo "#define PROG_VERSION \"$(VERSION)\"" >> version.h
	@echo "#define VERSION_DATE \"$(VERSION_DATE)\"">> version.h
	@echo "#define COMPILE_DATE \"`date +%D`\"" >> version.h
	@echo "#define COMPILE_TIME \"`date +%T`\"" >> version.h
	@echo "#define COMPILE_BY \"`whoami`\"" >> version.h
	@echo "#define COMPILE_HOST \"`hostname`\"" >> version.h
	@echo "#define GTK_VERSION \"GTK+ `gtk-config --version`\"" >> version.h
	@echo "#define CC_VERSION \"`$(CC) -v 2>&1 | tail -1`\"">>version.h
	@echo "#define CODE_LINES \"`cat *.c *.h | grep -ch -e \"[[:alpha:]|[:punct:]]\"`\"">>version.h


FORCE:	


clean: dist_clean
	rm -f $(PROGNAME) $(PROGNAME-STATIC) *.o  mkhelp

dist_clean:
	rm -f *~ ../*~ *_doc.* version.h core build/* 




$(PROGNAME-STATIC): $(PROGNAME)	     
	$(CC) $(CFLAGS) -v *.o -o $(PROGNAME-STATIC) $(GTK_CFLAGS) $(LFLAGS) -static
	strip $(PROGNAME-STATIC)	

dist:   $(PROGNAME) $(PROGNAME-STATIC) dist_clean
	mkdir $(PROGNAME)-$(VERSION)
	mkdir $(PROGNAME)-$(VERSION)/pixmaps
	mkdir $(PROGNAME)-$(VERSION)/lib
	mkdir $(PROGNAME)-$(VERSION)/src
	mkdir $(PROGNAME)-$(VERSION)/share	
	mkdir $(PROGNAME)-$(VERSION)/share/docs
	mkdir $(PROGNAME)-$(VERSION)/share/html
	mkdir $(PROGNAME)-$(VERSION)/share/html/images
	mkdir $(PROGNAME)-$(VERSION)/share/xpm
	mkdir $(PROGNAME)-$(VERSION)/share/bookmarks
	mkdir $(PROGNAME)-$(VERSION)/share/app_ass
	cp ../share/gtkrc $(PROGNAME)-$(VERSION)/share/gtkrc	
	cp ../share/docs/* $(PROGNAME)-$(VERSION)/share/docs
	cp ../share/html/*.* $(PROGNAME)-$(VERSION)/share/html
	cp ../share/html/images/*.* $(PROGNAME)-$(VERSION)/share/html/images/	
	cp ../share/xpm/*.* $(PROGNAME)-$(VERSION)/share/xpm
	cp ../share/bookmarks/*.* $(PROGNAME)-$(VERSION)/share/bookmarks
	cp ../share/app_ass/*.* $(PROGNAME)-$(VERSION)/share/app_ass
	cp ../pixmaps/*.* $(PROGNAME)-$(VERSION)/pixmaps
	cp ../lib/*.* $(PROGNAME)-$(VERSION)/lib			
	cp *.c *.h Makefile  $(PROGNAME)-$(VERSION)/src
	cp ../AUTHORS ../COPYRIGHT ../THANKS ../BUGS ../INSTALL ../NEWS ../TODO ../*.lsm $(PROGNAME)-$(VERSION)
	ln -fs ../pixmaps  $(PROGNAME)-$(VERSION)/src/pixmaps
	ln -fs share/docs/ChangeLog  $(PROGNAME)-$(VERSION)/ChangeLog
	ln -fs share/docs/LICENSE  $(PROGNAME)-$(VERSION)/LICENSE
	ln -fs share/docs/README  $(PROGNAME)-$(VERSION)/README		
	cp ../scripts/Make ../scripts/Install ../scripts/Uninstall  $(PROGNAME)-$(VERSION)/ 
	tar cvf $(PROGNAME)-$(VERSION).src.tar $(PROGNAME)-$(VERSION)
	#bzip2 -k $(PROGNAME)-$(VERSION).src.tar 
	#mv $(PROGNAME)-$(VERSION).src.tar.bz2 build/
	gzip $(PROGNAME)-$(VERSION).src.tar 
	mv $(PROGNAME)-$(VERSION).src.tar.gz build/
	mv $(PROGNAME)-$(VERSION)  $(PROGNAME-STATIC)-$(VERSION)
	tar cvf $(PROGNAME-STATIC)-$(VERSION).src.tar $(PROGNAME-STATIC)-$(VERSION)
	gzip $(PROGNAME-STATIC)-$(VERSION).src.tar
	mv $(PROGNAME-STATIC)-$(VERSION).src.tar.gz build/
	mv $(PROGNAME-STATIC)-$(VERSION)  $(PROGNAME)-$(VERSION)	
	#
	# STATIC
	#
	rm -Rf $(PROGNAME)-$(VERSION)/src  $(PROGNAME)-$(VERSION)/pixmaps
	mkdir $(PROGNAME)-$(VERSION)/bin
	cp Makefile $(PROGNAME)-$(VERSION)/bin
	cp $(PROGNAME-STATIC) $(PROGNAME)-$(VERSION)/bin/$(PROGNAME) 
	rm $(PROGNAME)-$(VERSION)/Make
	tar cvf $(PROGNAME)-$(VERSION)-static.bin.tar $(PROGNAME)-$(VERSION)
	#bzip2 -k $(PROGNAME)-$(VERSION).bin.tar
	#mv $(PROGNAME)-$(VERSION).bin.tar.bz2 build/
	gzip -9 $(PROGNAME)-$(VERSION)-static.bin.tar
	mv $(PROGNAME)-$(VERSION)-static.bin.tar.gz build/
	#
	# DYNAMIC
	#
	cp -f $(PROGNAME) $(PROGNAME)-$(VERSION)/bin/$(PROGNAME) 
	strip  $(PROGNAME)-$(VERSION)/bin/$(PROGNAME) 
	tar cvf $(PROGNAME)-$(VERSION).bin.tar $(PROGNAME)-$(VERSION)
	#bzip2 -k $(PROGNAME)-$(VERSION).bin.tar
	#mv $(PROGNAME)-$(VERSION).bin.tar.bz2 build/
	gzip -9 $(PROGNAME)-$(VERSION).bin.tar
	mv $(PROGNAME)-$(VERSION).bin.tar.gz build/
	cp ../*.lsm build/
	rm -Rf $(PROGNAME)-$(VERSION)
	du -k build/*.*


rpm: 
	sed -e s,THIS_VERSION,$(VERSION), \
	    -e s,THIS_RPM_RELEASE,$(RPM_RELEASE), \
	    ../distrib/$(PROGNAME).spec > $(RPM_BUILDPATH)/SPECS/$(PROGNAME)-$(VERSION).spec
	cp -f build/$(PROGNAME)-$(VERSION).src.tar.gz $(RPM_BUILDPATH)/SOURCES
	rpm -ba --clean $(RPM_BUILDPATH)/SPECS/$(PROGNAME)-$(VERSION).spec
	mv $(RPM_BUILDPATH)/RPMS/i386/$(PROGNAME)-$(VERSION)-$(RPM_RELEASE)* build/
	mv $(RPM_BUILDPATH)/SRPMS/$(PROGNAME)-$(VERSION)-$(RPM_RELEASE)* build/ 

rpm-static: 
	sed -e s,THIS_VERSION,$(VERSION), \
	    -e s,THIS_RPM_RELEASE,$(RPM_RELEASE), \
	    ../distrib/$(PROGNAME-STATIC).spec > $(RPM_BUILDPATH)/SPECS/$(PROGNAME-STATIC)-$(VERSION).spec
	cp -f build/$(PROGNAME-STATIC)-$(VERSION).src.tar.gz $(RPM_BUILDPATH)/SOURCES
	rpm -ba --clean $(RPM_BUILDPATH)/SPECS/$(PROGNAME-STATIC)-$(VERSION).spec
	mv $(RPM_BUILDPATH)/RPMS/i386/$(PROGNAME-STATIC)-$(VERSION)-$(RPM_RELEASE)* build/
	mv $(RPM_BUILDPATH)/SRPMS/$(PROGNAME-STATIC)-$(VERSION)-$(RPM_RELEASE)* build/ 
	rm -f build/$(PROGNAME-STATIC)-$(VERSION).src.tar.gz

rpms : rpm rpm-static

all-dist : dist rpms
