# Simple makefile for Gram's Commander v3.1
#
# You should also make any necessary changes to the unixcfg.h
# and doscfg.h header files before building GC3.
#
# (c) Graham Wheeler, 1993
#

#######################################
# Under DOS, uncomment the following: #
#######################################

#OSUF		= .obj
#XSUF		= .exe
#MANPAGE		=
#RSE		= rse.exe
#RM		= del

########################################
# Under UNIX, uncomment the following: #
########################################

OSUF		= .o
XSUF		= 
MANPAGE		= gc3.cat
RSE		= 
RM		= /bin/rm -f
ROFF		= nroff
RFLAGS		= -man

##########################################################
# Set the installation directories for the binaries and	 #
# man page under UNIX; ignored under DOS		 #
##########################################################

BINDEST		= /root/bin
MANSUF		= l
MANDEST		= /usr/man/man$(MANSUF)
CATDEST		= /usr/man/cat$(MANSUF)

#########################################################################
# Compiler arguments to specify output file names			#
# Output options - some systems want a space between the -o and the	#
# file name, others don't. Under DOS no space should be used.		#
#########################################################################

GC3OUT	= -o gc3
GCCCOUT	= -o gccc
DUMPOUT	= -o gcdump

#################################################################
# According to your C compiler, uncomment one of the following: #
#################################################################

# Borland/Turbo C/C++ v3.x under DOS 3.x or higher #

#CC		= bcc
#OPTS		= -ml -ls
#LDOPTS		= -ml

# Gnu project's gcc #

CC		= gcc
OPTS		= -fstrength-reduce -W -Wunused -Wpointer-arith -Wswitch -O6
# -g removed
LDOPTS		= -I/usr/local/include

# A Kernighan & Ritchie cc #

#CC		= cc
#OPTS		=
#LDOPTS		=

# An ANSI cc #

#CC		= cc
#OPTS		= -Xc -g #-DDEBUG
#LDOPTS		= -B static

# BSD using SysV compatibility: #

#CC		= /usr/5bin/cc
#OPTS		=
#LDOPTS		=

############################################################################
# TARGET O/S SPECIFIC STUFF
#
# For any particular target architecture, three macros must be defined,
# namely:
#
# DEFINES	any -D arguments for site-specific selections
# LIBS		any -l arguments to the linker
# MISSING	any -D arguments for site-specific restrictions
# 
# You may want to add some of the following to your DEFINES:
#
# -DUSE_SYSV_REGEXP		Use System V regular expressions
# -DUSE_BSD_REGEXP		Use BSD regular expressions
# -DMEM_DEBUG			Enables malloc/free checking
# -DSYS_V			Use this if you have full Sys V curses
#
# COMPILER ERRORS
# ===============
#
# IF YOU GET ERRORS ABOUT		THEN INCLUDE THIS -D ARGUMENT
#					IN "MISSING"
#
# mode_t				-DNO_MODE_T
# uid_t/gid_t				-DNO_UID_T
# string.h not being found		-DNO_STRING_H
# dirent.h not being found		-DNO_DIRENT_H
# lstat not being defined		-DNO_SYMLINKS
#
# LINKER ERRORS
# =============
#
# IF THIS IS UNDEFINED			THEN INCLUDE THIS -D ARGUMENT
#					IN "MISSING"
# ---------------------------------------------------------------------
# start_color, COLOR_PAIR, etc		-DNO_COLOR or -DNO_COLOUR
# keypad				-DNO_KEYENABLE
# wgetnstr				-DNO_WGETNSTR
# curs_set				-DNO_CURS_SET
# strerror				-DNO_STRERROR
# getcwd				-DNO_GETCWD
#
# TO CONFIGURE - Copy an entry that is similar to your configuration
#			(if there is an entry right for you then
#			  this is easy)
# 		Try compile; use the errors as a guide to what
#			should be added to the DEFINES and MISSING
#			macros below.
#		When you have a setting that works, send it to me 
#			with details of your system, and I will add
#			it to the distribution.
#
#######################################################################

#################
# Messy DOS	#
# THIS WORKS	#
#################

#DEFINES	= -D__MSDOS__=1 -D__STDC__=1 # -DMEM_DEBUG
#LIBS		= 
#MISSING	= -DNO_SYMLINKS

# SCO UNIX SVR3 #

#DEFINES	= -DUSE_SYSV_REGEXP -DSYS_V
#LIBS		= -ltinfo

# Ultrix #

#DEFINES	= -D__POSIX__SOURCE -DUSE_SYSV_REGEXP
#LIBS		= -ltermcap  -lcursesX

#####################
# MIPS with Risc OS #
#####################

#DEFINES	= -systype sysv -DUSE_SYSV_REGEXP -DSYS_V
#LIBS		= -lcurses
#MISSING	= -DNO_MODE_T -DNO_STRERROR # -DNO_UID

#################################################
# Hewlett Packard 9000, Series 700		#
# using gcc version 2.3.3 under HP-UX 9.01	#
# THIS COMPILES					#
#################################################

#DEFINES	=  -D_HPUX_SOURCE -DUSE_SYSV_REGEXP
#LIBS		= -lcurses
#MISSING	= -DNO_COLOR -DNO_CURS_SET

#################################################################
# NeXTstation running NeXT-OS 2.1 				#
# with gcc (NeXT Release 2.0 (v31.1) -- GNU version 1.36)	#
#################################################################

#DEFINES	= -DUSE_BSD_REGEXP -DUCBCURSES
#LIBS		= -lcurses -ltermcap
#MISSING	= -DNO_MODE_T

####################################
# SPARCstation 1+ with SunOS 4.1.1 #
####################################

#DEFINES	= -DUSE_BSD_REGEXP -DUCBCURSES
#LIBS		= -lcurses -ltermcap
#MISSING	= -DNO_COLOR -DNO_KEYENABLE -DNO_CURS_SET -DNO_STRERROR

#########################
# Cray 			#
# THIS COMPILES		#
#########################

#DEFINES	= -DSYS_V -DUSE_SYSV_REGEXP 
#LIBS		= -lcurses
#MISSING	= -DNO_COLOR

# BSD #

#DEFINES	= -DUSE_BSD_REGEXP -DUCBCURSES
#LIBS		= -lcurses -ltermcap

# BSD using SysV compatibility: #

LIBS		= -lncurses
DEFINES	= -DUSE_BSD_REGEXP

#################################
# System V Release 3/4 for i386 #
# THIS WORKS			#
#################################

#DEFINES		= -DSYS_V -DUSE_SYSV_REGEXP
#LIBS		= -lcurses -lucb # -lucb needed for -Xc ANSI compat.

##################################################
# Here goes... Don't change anything below here! #
##################################################

CFLAGS		= $(OPTS) $(DEFINES) $(MISSING) -I/usr/local/include

.man.cat:
		$(ROFF) $(RFLAGS) $< | col > $@

.c.obj:
	$(PREFIX) $(CC) $(CFLAGS) -c $< $(SUFFIX)

.SUFFIXES:	.cat .man .c .obj

###################
# PRIMARY TARGETS #
###################

all: $(RSE) gccc$(XSUF) gcdump$(XSUF) gc3$(XSUF) $(MANPAGE) gc3.cod

###############
# INTERPRETER #
###############

gc3lint:
	lint $(CFLAGS) gc3.c gcterp.c gcregexp.c gcsort.c gckey.c gcdisk.c gcscreen.c gceval.c gcmem.c gcutil.c $(LIBS)

gc3$(XSUF): gc3$(OSUF) gcterp$(OSUF) gcregexp$(OSUF) gcsort$(OSUF) gcdisk$(OSUF) gckey$(OSUF) gceval$(OSUF) gcscreen$(OSUF) gcmem$(OSUF) gcutil$(OSUF) Makefile
	$(PREFIX) $(CC) $(LDOPTS) $(GC3OUT) gc3$(OSUF) gcterp$(OSUF) gcregexp$(OSUF) gcsort$(OSUF) gckey$(OSUF) gcdisk$(OSUF) gcscreen$(OSUF) gceval$(OSUF) gcmem$(OSUF) gcutil$(OSUF) $(LIBS) $(SUFFIX)

gc3$(OSUF): gc3.c gc3.h gckey.h Makefile gcopcnt.c

gcregexp$(OSUF): gcregexp.c gc3.h Makefile

gcscreen$(OSUF): gcscreen.c gc3.h Makefile

gcsort$(OSUF): gcsort.c gc3.h Makefile

gcdisk$(OSUF): gcdisk.c gc3.h Makefile

gcterp$(OSUF): gcterp.c gc3.h gckey.h Makefile

gceval$(OSUF): gceval.c gcerr.h Makefile

gckey$(OSUF): gckey.c gckey.h gc3.h Makefile

##############
# DECOMPILER #
##############

gcdump$(XSUF): gcdump$(OSUF) gcutil$(OSUF)
	$(PREFIX) $(CC) $(LDOPTS) $(DUMPOUT) gcdump$(OSUF) gcutil$(OSUF) $(SUFFIX)

gcdump$(OSUF): gcdump.c gcopcnt.c Makefile

gc3.h: gcerr.h gcmem.h gcboth.h doscfg.h unixcfg.h
	touch gc3.h

###################
# SCRIPT COMPILER #
###################

gccc$(XSUF): gccc$(OSUF) gcparse$(OSUF) gcsym$(OSUF) gclex$(OSUF) gclink$(OSUF) gcmem$(OSUF) gcutil$(OSUF) Makefile
	$(PREFIX) $(CC) $(LDOPTS) $(GCCCOUT) gccc$(OSUF) gcparse$(OSUF) gcsym$(OSUF) gclex$(OSUF) gclink$(OSUF) gcmem$(OSUF) gcutil$(OSUF) $(SUFFIX)

gccc$(OSUF): gccc.c gccc.h Makefile

gcparse$(OSUF): gcparse.c gccc.h Makefile

gclex$(OSUF): gclex.c gccc.h Makefile

gcsym$(OSUF): gcsym.c gccc.h Makefile

gclink$(OSUF): gclink.c gccc.h gcopcnt.c Makefile

gcmem$(OSUF): gcmem.c gcmem.h Makefile

gcutil$(OSUF): gcutil.c gcboth.h Makefile

gccc.h: gcerr.h gcmem.h gcboth.h doscfg.h unixcfg.h
	touch gccc.h

##############################################	
# STANDARD ERROR REDIRECTOR (NEEDED FOR DOS) #
##############################################
	
rse$(XSUF): rse.c
	$(CC) $(CFLAGS) rse.c

############################	
# KEYCODE UTILITY FOR UNIX #
############################
	
keycode$(XSUF): keycode.c
	$(CC) $(CFLAGS) keycode.c $(LIBS)
	mv a.out keycode

#################
# OTHER TARGETS	#
#################

gc3.cod: gc3.key gccc$(XSUF) gc3$(XSUF)
	gccc

clean:
	$(RM) gc3$(XSUF) gcdump$(XSUF) gccc$(XSUF) gc.cat *.o

gc3.cat : gc3.man

install: gc3 gccc gc3.cat
	-mv $(BINDEST)/gc3 $(BINDEST)/gc3.old 2>/dev/null
	cp gc3 $(BINDEST)
	chmod 511 $(BINDEST)/gc3
	rm $(BINDEST)/gc3.old
	-mv $(BINDEST)/gccc $(BINDEST)/gccc.old 2>/dev/null
	cp gccc $(BINDEST)
	chmod 511 $(BINDEST)/gccc
	rm $(BINDEST)/gccc.old

      
package: 
	tar cvf gc3pkg.tar *.c *.h Makefile gc3.key gc3.doc README gc3.man

