# /****************************************************************
# Copyright (C) 1997, 2000 Lucent Technologies
# All Rights Reserved
#
# Permission to use, copy, modify, and distribute this software and
# its documentation for any purpose and without fee is hereby
# granted, provided that the above copyright notice appear in all
# copies and that both that the copyright notice and this
# permission notice and warranty disclaimer appear in supporting
# documentation, and that the name of Lucent or any of its entities
# not be used in advertising or publicity pertaining to
# distribution of the software without specific, written prior
# permission.
#
# LUCENT DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
# INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS.
# IN NO EVENT SHALL LUCENT OR ANY OF ITS ENTITIES BE LIABLE FOR ANY
# SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
# WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER
# IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
# ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF
# THIS SOFTWARE.
# ****************************************************************/

# For compiling on Unix systems (cp to makefile, then edit makefile).

.SUFFIXES: .c .o
CC = cc
S = ..
# "S = .." assumes this directory is solvers/mng .

CFLAGS = -g
# Add -DKR_headers to CFLAGS if your C compiler does not
# understand ANSI C function headers, e.g.
#	CFLAGS = -O -DKR_headers
# If things don't run right, you may need to change -O to -g
# so you can poke around with a debugger.

# See $S/makefile.u for other comments about CFLAGS.

.c.o:
	$(CC) -c $(CFLAGS) -I$S $*.c

L = -lm
Aa = $S/amplsolver.a

nlc = nlc.o cops.o $S/funcadd0.o $(Aa)
nlc: $(nlc)
	$(CC) -o nlc $(nlc) $L

clean:
	rm -f nlc mngnlc nl2nlc *.o

# make xsum.out to check for transmission errors.
# This assumes you have the xsum program, whose source
# you can get by asking research!netlib to
#	send xsum.c from f2c/src

xs0 = README c_op.hd cops.c makefile.u makefile.vc nlc.c nlc.h nlcmisc.c\
 opcode.hd r_ops1.hd\
 ch3.amp ch3.nl ch3.c ch3.kc ch3.f mngnlc.c ch3mng.out nl2nlc.c ch3nl2.out

xsum.out: $(xs0)
	xsum $(xs0) >xsum1.out
	cmp xsum0.out xsum1.out && mv xsum1.out xsum.out || diff xsum[01].out


# Examples of using .c files written by nlc.  These assume
# that $S/examples contains "all from ampl/solvers/examples".

E = $S/examples
A = $E/rvmsg.o $E/keywds.o $S/funcadd0.o $(Aa)
Lf2c = -lf2c
cport = $E/cport.a
# $(cport) = PORT subroutine library.
# Ask netlib@netlib.org to
#	send dmngb dmnhb dn2g dn2gb dq7rgs from port
# to get source for the relevant (small) part of PORT.
# -lf2c is for f2c's version of Fortran I/O: we assume
# $(cport) was compiled by f2c and cc.
Lp = $(cport) $(Lf2c)

$E/rvmsg.o:
	cd $E; make rvmsg.o

$E/keywds.o:
	cd $E; make keywds.o

mngnlc = mngnlc.o ch3.o nlcmisc.o $A
mngnlc: $(mngnlc)
	$(CC) -o mngnlc $(mngnlc) $(Lp) $L

nl2nlc = nl2nlc.o ch3.o nlcmisc.o $A
nl2nlc: $(nl2nlc)
	$(CC) -o nl2nlc $(nl2nlc) $(Lp) $L

mngnlc.o: mngnlc.c $E/rvmsg.h
	$(CC) -c $(CFLAGS) -I$S -I$E mngnlc.c

nl2nlc.o: nl2nlc.c $E/rvmsg.h
	$(CC) -c $(CFLAGS) -I$S -I$E nl2nlc.c

### "make test" to compare outputs...

all = nlc mngnlc nl2nlc

test: $(all)
	nlc ch3 >foo
	cmp foo ch3.c
	nlc -k ch3 >foo
	cmp foo ch3.kc
	nlc -f ch3 >foo
	cmp foo ch3.f
	mngnlc >foo 2>&1
	cmp foo ch3mng.out
	nl2nlc >foo 2>&1
	cmp foo ch3nl2.out
	rm foo
