#                        Copyright (c) 1987 Bellcore
#                            All Rights Reserved
#       Permission is granted to copy or use this program, EXCEPT that it
#       may not be sold for profit, the copyright notice must be reproduced
#       on copies, and credit should be given to Bellcore where it is due.
#       BELLCORE MAKES NO WARRANTY AND ACCEPTS NO LIABILITY FOR THIS PROGRAM.

#	$Header: Makefile,v 1.1 89/09/27 09:28:25 sau Exp $
#	$Source: /m1/mgr.new/src/RCS/Makefile,v $

#
#	compile flags:
#	  WHO:		muck utmp file so "who" works
#	  VI		code for vi mouse hack
#	  DEBUG		turns on lots of debugging code (for -d option)
#	  FASTMOUSE	xor mouse track
#	  BUCKEY	for keyboard operated "mouse" commands
#	  PRIORITY	for priority window scheduling instead of 
#			round-robin; the active window gets higher priority
#	  CUT		for cut/paste (don't use)
#	  ALIGN		forces window alignment for fast scrolling
#			use with 68010/68020 version only
#	  ALIGN32	Obsolete (expunged)
#	  WEIRD		does weird thing on window reshapes
#	  KILL		kills windows upon tty i/o errors
#
#	  MALLOC	for malloc debugging code - you supply the malloc
#
#	  SHRINK	use only some of the screen (define [XYWH]0 too)
#
#	  NOSTACK	don't permit event stacking 
#
#	  BELL		really ring the bell (works on at least sun 3's)
#			You need to do a "mknod /dev/bell c 12 2"
#
#	  KBD		read mgr input from the sun kbd, instead of stdin
#			This permits redirection of console msgs to a window
#
#	  FRACCHAR	fractional character movement stuff (experimental)
#
#	  XMENU		extended menu stuff (experimental)
#

#	bitblit libraries
#	   blit - template based 68020 asm code (fastest)
#					uses 32 bit alignment
#	 	oblit - crufty sun-2 specific code (obsolete, use port instead)
#					uses 16 bit alignment
#     port - template based portable "C" code  (monochrome only for now)
#					uses 32 bit alignment (or 16 or 8)
#	   pixrect - SUN's pixrect library: Useful for color
#					uses 16 bit alignment (mostly)
#		stub_lib - Stub libraries for use as a basis for porting
#    atari - atari st bilt support
CROSSDIR = /net/acae127/home/bammi/atari/cross-gcc
CROSSBIN = $(CROSSDIR)/bin
CC=$(CROSSBIN)/cgcc
AR=$(CROSSBIN)/car
HOSTCC = cc
HOSTCCFLAGS = -O  -I. -Iatari -I../lib
LIBS=atari
#
#		Standard compile flags

MGR=mgr

#	which bit-blit library to use

BLITDIR=atari

#	Use fast scrolling code (only works on 68010/68020)

DDEP = -DALIGN
BIT_LIB =   $(BLITDIR)/blitlib.a

#	Specify other libraries here (such as -lpixrect)

OTHERLIB =
INCL = ../lib

#	special version specific stuff goes here

# these must be set if -DALIGN
MACHDEP_H =
MACHDEP_C = 
MACHDEP_O = 
#MACHDEP_C = fast_scroll.c
#MACHDEP_O = fast_scroll.o

#	This version number is unrelated to anything

VER = 3.3.2
#
# built-in path names:
#
###########################################

INSROOT=/mgr
FLAG = -mint -O -nostdinc -I/net/acae127/home/bammi/atari/mint/mintlib/include \
-fomit-frame-pointer -fcombine-regs

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

START=.
DSAME = -DWHO -DVI -DBUCKEY -DDEBUG -DKILL -DCUT -DBELL \
			-DKBD -DALIGN32 -DFRACCHAR
#	FONTDIR:	where to find font files  (default: /usr/mgr/font)
#	ICONDIR:	where to find icons	  (default: /usr/mgr/icon)
PATHFLAGS = -DFONTDIR=\"$(INSROOT)/font\" -DICONDIR=\"$(INSROOT)/icon\"
#
DFLAGS = $(DSAME) $(DDEP)
CFLAGS = $(FLAG) $(DFLAGS) $(PATHFLAGS) -I. -I$(BLITDIR) -I$(INCL)
FONT_LIB = ../font
DEFAULT_FONT = $(FONT_LIB)/default.fnt
INSDIR = $(INSROOT)/bin
CPIO=src.cpio
TAR=src.tar
DEPEND = make.depend
LOG=make.log
#
#	Versions of MGR
#		mgr			- the default
#		colormgr		- makes color mgr using SUN's pixrect library
#		pixmgr		- makes a monochrome MGR using pixrect
#		prodmgr		- makes an optimized (production) MGR with debugging stripped
#		oldmgr		- Makes a pre 3.4 release (no special kbd and bell handling)
#		sun2mgr		- makes a sun2 version (old bitblit code) [obsolete]
#		oldsun2mgr	- makes a sun2 (release 1.x, old bitblit code) [obsolete]
#		portmgr		- makes a monochrome MGR using the portable blit code
#							Use this one for a monochrome Sparc station
#		stubmgr		- make a monochrome MGR with NO bitblit code
#		atarimgr	- make a atariST mgr
#		atari020mgr     - make an atari 020/030 mgr

ALLMGRS = mgr port_mgr stub_mgr color_mgr prod_mgr old_mgr sun2_mgr \
					oldsun2_mgr pix_mgr
ALLDOTFILES= .mgr .mgr_port .mgr_stub .mgr_color .mgr_prod .mgr_old .mgr_sun2 \
				 .mgr_oldsun2 .mgr_pix

PORTCFILES = \
	Write.c bitmaphead.c bitmapread.c border.c \
	cut.c data.c debug_flags.c destroy.c \
	do_buckey.c do_button.c do_event.c do_menu.c down_load.c \
	erase_win.c font_subs.c get_font.c get_info.c get_menus.c \
	get_rect.c get_text.c getshell.c graph_subs.c intersect.c \
	kbd.c mgr.c mouse_get.c move.c move_box.c new_window.c print.c \
	put_window.c scroll.c set_mode.c shape.c sigdata.c startup.c \
	subs.c update.c utmp.c win_make.c win_stack.c win_subs.c \
	write_ok.c 

CFILES = $(PORTCFILES) $(MACHDEP_C)

OFILES = \
	Write.o bitmaphead.o bitmapread.o border.o \
	cut.o data.o debug_flags.o destroy.o \
	do_buckey.o do_button.o do_event.o do_menu.o down_load.o \
	erase_win.o font_subs.o get_font.o get_info.o get_menus.o \
	get_rect.o get_text.o getshell.o graph_subs.o intersect.o \
	kbd.o mgr.o mouse_get.o move.o move_box.o new_window.o print.o \
	put_window.o scroll.o set_mode.o shape.o sigdata.o startup.o \
	subs.o update.o utmp.o win_make.o win_stack.o win_subs.o \
	write_ok.o \
	$(MACHDEP_O)

HFILES = \
	$(INCL)/dump.h $(INCL)/window.h \
	clip.h copyright.h default_font.h defines.h defs.h event.h \
	font.h icons.h menu.h \
	$(MACHDEP_H)

OTHER = \
	Makefile \
	copyright.c \
	compile_font.c dependencies

############################################################################
all:	$(MGR) 

############################################################################
# stub mgr, using dummy bitblit code
stubmgr:
	$(MAKE) DSAME="-DWHO -DVI -DBUCKEY -DDEBUG -DKILL" \
		INSROOT=$(INSROOT) \
		DDEP= \
		MACHDEP_C= MACHDEP_H= MACHDEP_O= \
		OTHERLIB= \
		BLITDIR=stub_lib \
		FLAG=$(FLAG) \
		MGR=mgr_stub \
		VER=2.3

############################################################################
# port mgr, using dummy bitblit code
# This will also make a sun-2 version
portmgr:
	$(MAKE) DSAME="-DDEBUG -DWHO -DVI -DBUCKEY -DKILL -DCUT \
			-DSHRINK -DALIGN32 -DBELL -DKBD -DFRACCHAR"  \
		INSROOT=$(INSROOT) \
		DDEP= \
		MACHDEP_C= MACHDEP_H= MACHDEP_O= \
		OTHERLIB= \
		BLITDIR=port \
		FLAG=$(FLAG) \
		MGR=mgr_port \
		VER=2.3

############################################################################
# atari mgr, using atari bitblit code
#
atarimgr:
	$(MAKE) DSAME="-DBUCKEY -DCUT \
			-DSHRINK -DNDEBUG"  \
		INSROOT=$(INSROOT) \
		DDEP= \
		MACHDEP_C= MACHDEP_H= MACHDEP_O= \
		OTHERLIB= \
		BLITDIR=atari \
		FLAG='$(FLAG)' \
		MGR=atari_port \
		VER=2.3
############################################################################
# atari 020 mgr, using atari bitblit code, and align with fast_scroll
#
atari020mgr:
	$(MAKE) DSAME="-DBUCKEY -DCUT \
			-DSHRINK -DNDEBUG -DALIGN"  \
		INSROOT=$(INSROOT) \
		DDEP= \
		MACHDEP_C= fast_scroll.c MACHDEP_H= MACHDEP_O= fast_scroll.o \
		OTHERLIB= \
		BLITDIR=atari \
		FLAG='$(FLAG) -m68020' \
		LFLAGS='-lgnu020'
		MGR=atari_port \
		VER=2.3
############################################################################
# color mgr, for sun 3/60, sun3/110 and sun-roadrunner
colormgr:
	$(MAKE) DSAME="-DWHO -DVI -DBUCKEY -DDEBUG -DKILL -DBELL -DKBD \
			-DCOLOR -DFASTMOUSE" \
		INSROOT=$(INSROOT) \
		DDEP= \
		MACHDEP_C= MACHDEP_H= MACHDEP_O= \
		OTHERLIB=-lpixrect \
		BLITDIR=pixrect \
		FLAG=$(FLAG) \
		MGR=mgr_color \
		VER=2.3

############################################################################
# sun 3's production release (no debugging code, optimized)
prodmgr:
	$(MAKE) DSAME="-DWHO -DVI -DBUCKEY -DKILL -DCUT -DALIGN \
			-DALIGN32 -DBELL -DKBD -DFRACCHAR"  \
		INSROOT=$(INSROOT) \
		FLAG=-O \
		MGR=mgr_prod

############################################################################
# sun 3's (68020 based) pre release 3.4
oldmgr:
	$(MAKE) DSAME="-DWHO -DVI -DBUCKEY -DDEBUG -DKILL -DCUT -DALIGN"  \
		INSROOT=$(INSROOT) \
		FLAG=$(FLAG) \
		MGR=mgr_old

############################################################################
# sun 2's (68010 based)
sun2mgr:
	$(MAKE) DSAME="-DWHO -DVI -DBUCKEY -DDEBUG -DKILL -DCUT -DBELL -DKBD \
		       -DALIGN" \
		INSROOT=$(INSROOT) \
		FLAG=$(FLAG) \
		BLITDIR=oblit \
		MGR=mgr_sun2

############################################################################
# sun 2's (68010 based) running pre-3.4 releases (i.e. 1.0)
oldsun2mgr:
	$(MAKE) DSAME="-DWHO -DVI -DBUCKEY -DDEBUG -DKILL -DCUT -DALIGN" \
		INSROOT=$(INSROOT) \
		FLAG=$(FLAG) \
		BLITDIR=oblit \
		MGR=mgr_oldsun2

############################################################################
pixmgr:
	$(MAKE) DSAME="-DWHO -DVI -DBUCKEY -DDEBUG -DKILL -DCUT -DBELL -DKBD" \
		INSROOT=$(INSROOT) \
		DDEP= MACHDEP_C= MACHDEP_H= MACHDEP_O= \
		BLITDIR=pixrect OTHERLIB=-lpixrect \
		FLAG=$(FLAG) \
		MGR=mgr_pix \
		VER=2.3

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

fast:	gang $(MGR)

#		Placing $(HFILES) and $(CFILES) in the dependency list let's us
#		see which files actually caused the rebuild in the $(LOG).
#		Other than that, and checking for their existence, they are not
#		needed for the actual build of mgr.

$(MGR):	.$(MGR) $(HFILES) $(CFILES) $(OFILES) copyright.o version.o FRClibrary
	-rm -f mgr
	-mv $(MGR) _$(MGR)
	$(CC) $(LFLAGS) $(FLAG) -o $(MGR) $(MALLOC) $(OFILES) version.o copyright.o \
		$(BIT_LIB) $(OTHERLIB)
	@date >> $(LOG)
	echo "changed $?" >> $(LOG)
	@$(CROSSBIN)/csize68 $(MGR)
	@echo "$(MGR) on `date`" > .done
	-ln $(MGR) mgr

.PRECIOUS: .$(MGR)

.$(MGR) gang:	default_font.h
	rm -f $(OFILES) $(ALLDOTFILES) copyright.o .done
	touch .$(MGR)
	$(CC) -c $(CFLAGS) $(PORTCFILES)

default_font.h:
		make compile_font
		./compile_font < $(DEFAULT_FONT) default_font \
			     > default_font.h

compile_font:	compile_font.o
		$(HOSTCC) $(HOSTCCFLAGS) -o compile_font compile_font.c

#		All versions of MGR now use the 32 bit aligned fonts and icons
#
# pick the icon file with appropriate alignment 
#	set up a link to the proper font directory as well
#
#icons.h:
#		-rm icons.h
#		-rm ../font	
#		@if [ x$(ALIGN) = 32 ]; \
#		then \
#			echo 'Creating 32-bit aligned mouse icons'; \
#			ln -s icons-32.h icons.h; \
#			echo 'Setting links to 32-bit fonts'; \
#			ln -s `pwd`/../font-32 ../font; \
#		else \
#			echo 'Setting links to 16-bit fonts'; \
#			ln -s `pwd`/../font-16 ../font; \
#			echo 'Creating 16-bit aligned mouse icons'; \
#			ln -s icons-16.h icons.h; \
#		fi

#	create mgr version information

version.c:	$(OFILES)
		echo "/* compilation info for $(MGR) */"	 > version.c
		@echo " "					>> version.c
		@echo "char *version[]={"			>> version.c
		@echo "   \"$(VER)\",\"`hostname`\",\"`date`\",">> version.c
		@echo "   \"`echo $(DFLAGS) | sed 's/-D//g'`\",">> version.c
		@echo "   \"$(INSROOT)\","			>> version.c
		@echo "   \"`whoami`\","			>> version.c
		@echo "   \"`strings /vmunix | grep 'Release'`\",">> version.c
		@echo "   };"					>> version.c 

# The optimizer botches on this one

fast_scroll.o:	fast_scroll.c
		$(CC) -O -fomit-frame-pointer -fcombine-regs -I. -c -I$(BLITDIR) fast_scroll.c

#	put copyright data into text segment
copyright.o:	copyright.c copyright.h
		$(CC) -c $(FLAG) $(DFLAGS) -I$(BLITDIR) -R copyright.c

$(BLITDIR)/blitlib.a FRClibrary:
		cd $(BLITDIR); $(MAKE) FLAG='$(FLAG)' blitlib.a
#		make blit library avaliable to the applications
		-rm -f $(INCL)/blitlib.a $(INCL)/bitmap.h
		-ln -s `pwd`/$(BLITDIR)/blitlib.a $(INCL)/blitlib.a
		-ln -s `pwd`/$(BLITDIR)/bitmap.h $(INCL)/bitmap.h

$(LOG):		
		echo "MGR version log > $(LOG)

clean:		
		rm -f *.o core version.c $(ALLDOTFILES) .done
		@for i in $(LIBS); do \
			(cd $$i; $(MAKE) clean); \
		done	

clobber:
		rm -f compile_font $(ALLMGRS)

install:	.done $(INSDIR) /dev/bwtwo0
		cd $(INSDIR);  rm -f $(MGR)
		cp $(MGR) $(INSDIR)
		-/etc/chown root $(INSDIR)/$(MGR)  && \
		 chmod u+s,go-w $(INSDIR)/$(MGR)

.done:
		@echo "No MGR available to install"

$(INSDIR):
		mkdir $@

/dev/bwtwo0:
		-/bin/su root -c 'cd /dev;  MAKEDEV bwtwo0'

tar:		
		tar cf $(TAR) `make list`
		
depend:	
		dependencies `$(MAKE) list` > $(DEPEND)
		echo " header file dependencies written to $(DEPEND)"

list:
	@for i in $(HFILES) $(CFILES) $(OTHER); do \
		echo "$(START)/$$i"; \
	done	
	@for i in $(LIBS); do \
		echo "${START}/$$i";\
		if [ -d $$i ]; then \
	 		cd $$i; $(MAKE) START=${START}/$$i list; cd ..;\
		fi \
	done	

cpio:
	make -s list  |  sort -u  |  cpio -ocv > $(CPIO)


# header file dependencies go here 

Write.o: \
	Write.c

bitmaphead.o: \
	bitmaphead.c $(INCL)/dump.h $(BLITDIR)/bitmap.h

bitmapread.o: \
	bitmapread.c $(INCL)/dump.h $(BLITDIR)/bitmap.h

border.o: \
	border.c $(BLITDIR)/bitmap.h defs.h defines.h

copyright.c:	copyright.h

copyright.o: \
	$(BLITDIR)/bitmap.h

cut.o: \
	cut.c $(BLITDIR)/bitmap.h defs.h defines.h font.h $(INCL)/window.h \
	event.h

data.o: \
	data.c $(BLITDIR)/bitmap.h defs.h defines.h font.h icons.h

debug_flags.o: \
	debug_flags.c

destroy.o: \
	destroy.c $(BLITDIR)/bitmap.h defs.h defines.h font.h event.h

do_buckey.o: \
	do_buckey.c $(BLITDIR)/bitmap.h defs.h defines.h font.h \
	event.h

do_button.o: \
	do_button.c $(BLITDIR)/bitmap.h menu.h defs.h defines.h \
	font.h event.h

do_event.o: \
	do_event.c $(BLITDIR)/bitmap.h defs.h defines.h font.h event.h

do_menu.o: \
	do_menu.c $(BLITDIR)/bitmap.h menu.h defs.h defines.h font.h

down_load.o: \
	down_load.c $(BLITDIR)/bitmap.h font.h defs.h defines.h \
	menu.h event.h $(INCL)/window.h

erase_win.o: \
	erase_win.c $(BLITDIR)/bitmap.h defs.h defines.h

font_subs.o: \
	font_subs.c $(BLITDIR)/bitmap.h font.h default_font.h $(INCL)/window.h

get_font.o: \
	get_font.c $(BLITDIR)/bitmap.h font.h

get_info.o: \
	get_info.c $(BLITDIR)/bitmap.h font.h defs.h defines.h menu.h \
	event.h $(INCL)/window.h

get_menus.o: \
	get_menus.c $(BLITDIR)/bitmap.h menu.h font.h

get_rect.o: \
	get_rect.c $(BLITDIR)/bitmap.h defs.h defines.h

get_text.o: \
	get_text.c $(BLITDIR)/bitmap.h defs.h defines.h font.h event.h

getshell.o: \
	getshell.c $(BLITDIR)/bitmap.h defs.h defines.h

graph_subs.o: \
	graph_subs.c $(BLITDIR)/bitmap.h

intersect.o: \
	intersect.c $(BLITDIR)/bitmap.h defs.h defines.h

kbd.o: \
	kbd.c $(BLITDIR)/bitmap.h defs.h defines.h

mgr.o: \
	mgr.c $(BLITDIR)/bitmap.h defs.h defines.h menu.h font.h \
	event.h

mouse_get.o: \
	mouse_get.c

move.o: \
	move.c $(BLITDIR)/bitmap.h defs.h defines.h event.h

move_box.o: \
	move_box.c $(BLITDIR)/bitmap.h defs.h defines.h

new_window.o: \
	new_window.c $(BLITDIR)/bitmap.h defs.h defines.h font.h \
	menu.h

print.o: \
	print.c

put_window.o: \
	put_window.c $(BLITDIR)/bitmap.h font.h defs.h defines.h \
	menu.h event.h $(INCL)/window.h clip.h

scroll.o: \
	scroll.c $(BLITDIR)/bitmap.h defs.h defines.h clip.h

set_mode.o: \
	set_mode.c

shape.o: \
	shape.c $(BLITDIR)/bitmap.h defs.h defines.h font.h event.h

sigdata.o: \
	sigdata.c

startup.o: \
	startup.c $(BLITDIR)/bitmap.h defs.h defines.h

subs.o: \
	subs.c $(BLITDIR)/bitmap.h font.h defs.h defines.h event.h

update.o: \
	update.c $(BLITDIR)/bitmap.h defs.h defines.h clip.h

utmp.o: \
	utmp.c

win_make.o: \
	win_make.c $(BLITDIR)/bitmap.h font.h defs.h defines.h $(INCL)/window.h \
	event.h

win_stack.o: \
	win_stack.c $(BLITDIR)/bitmap.h font.h defs.h defines.h \
	$(INCL)/window.h menu.h event.h

win_subs.o: \
	win_subs.c $(BLITDIR)/bitmap.h font.h defs.h defines.h $(INCL)/window.h \
	clip.h

write_ok.o: \
	write_ok.c defines.h

fast_scroll.o: \
	fast_scroll.c $(BLITDIR)/bitmap.h

compile_font.o: \
	compile_font.c $(BLITDIR)/bitmap.h font.h

