########
#
# The DJGPP Makefile for LP_Solve
# created from original Makefile by Michal Jarski 1995
#
########

# Well, we use the gcc compiler from DJGPP 1.12maint4
CC= gcc

#CFLAGS= -g -DCHECK -DREAL='long double'

#should be OK in most situations:
#CFLAGS= -O -DCHECK

# HP/UX 9.0X 
#CFLAGS= +O3 +Oaggressive +Olibcalls -Aa -D_POSIX_SOURCE -DCHECK +FP VZOUiD

# nice for gcc, so let's use it
CFLAGS= -O3 -ansi -DCHECK -DREAL='long double'

# option -DCHECK checks for numerical problems during rounding of numbers
# it will slow things down a bit.
# you can add a -DREAL=<float type> to the CFLAGS, to change the default float
# type used in lp_solve (double) to float or 'long double'. However, type float
# might be fast on your computer, but it is not accurate enough to solve even
# moderately sized problems without running into numerical problems.
# the use of long doubles does increase the numerical stability of lp_solve,
# if your compiler actually implements them with more bits than a double. But
# it slows down things quite a bit.

LPKSRC.c= lpkit.c solve.c debug.c read.c readmps.c
LEXFILE.l= lex.l
YACCFILE.y= lp.y
ALLFILES= lpkit.c solve.c debug.c read.c readmps.c lex.l lp.y ex1.lp ex2.lp ex3.lp ex4.lp ex5.lp ex6.lp ex7.lp demo_lag.lp lpglob.h lpkit.h patchlevel.h debug.h read.h lp_solve.c demo.c README Makefile
TESTFILES= lp_examples/ex1.lp lp_examples/ex2.lp lp_examples/ex3.lp lp_examples/ex4.lp lp_examples/ex5.lp lp_examples/ex6.lp lp_examples/ex7.lp

TARGET=lp_solve
LEXFILE.c= $(LEXFILE.l:.l=.c)
YACCFILE.c= $(YACCFILE.y:.y=.c)
YACCFILE.o= $(YACCFILE.y:.y=.o)
CSOURCES=lpkit.c solve.c debug.c read.c readmps.c lp_solve.c demo.c $(LEXFILE.c) $(YACCFILE.c)
COBJ=$(CSOURCES:.c=.o)
LPKSRC= $(LPKSRC.c) $(YACCFILE.c)
LPKOBJ= $(LPKSRC:.c=.o)
HEADERS=lpkit.h lpglob.h patchlevel.h debug.h read.h

LDFLAGS= -lfl -lbison -lm

all:	demo $(TARGET) lp2mps mps2lp
	@echo The LP_Solve port to MSDOS via DJGPP 1.12maint4
	@echo After making 'all' target you can:
	@echo	make exe	create executables dependent on go32 extender
	@echo	make standalone	create EXEs containing extender

$(COBJ): $(HEADERS)

demo:	demo.o lpklib.a
	$(CC) -o demo demo.o lpklib.a $(LDFLAGS)

lp2mps:	lp2mps.o lpklib.a
	$(CC) -o lp2mps lp2mps.o lpklib.a $(LDFLAGS)

mps2lp: mps2lp.o lpklib.a
	$(CC) -o mps2lp mps2lp.o lpklib.a $(LDFLAGS)

$(TARGET): lp_solve.o lpklib.a
	$(CC) -o $(TARGET) lp_solve.o $(LPKOBJ) $(LDFLAGS) $(CFLAGS)

lpklib.a: $(LPKOBJ)
	ar rv $@ $(LPKOBJ)
	ranlib lpklib.a

$(YACCFILE.o): $(LEXFILE.c)

$(LEXFILE.c): $(LEXFILE.l)
	flex -l $(LEXFILE.l)
	ren lexyy.c $(LEXFILE.c)

$(YACCFILE.c): $(YACCFILE.y)
	bison -y $(YACCFILE.y)
	ren y_tab.c $(YACCFILE.c)

test:
	-for i in $(TESTFILES); do\
		./$(TARGET) -p -s < $$i > xxx.tmp;\
		if diff xxx.tmp lp_examples/`basename $$i .lp`.out > /dev/null; then\
			echo "$$i gives the correct result";\
		else\
			echo "$$i gives different result, please check";\
		fi;\
	done;\
	rm xxx.tmp

$(TARGET).man: $(TARGET).1
	nroff -man $(TARGET).1 > $(TARGET).man

MANIFEST: clean
	ls -lR > MANIFEST; ls -lR > MANIFEST

clean:
	rm -f *.a *.o  $(TARGET).man TAGS $(LEXFILE.c) $(YACCFILE.c) demo $(TARGET) lp2mps mps2lp

distrib: $(TARGET).man MANIFEST
	cd ..; tar -czvf lp_solve_2.0.tar.gz lp_solve_2.0

sweep:
	del *.a
	del *.o
	del $(YACCFILE.c)
	del $(LEXFILE.c)

exe: all
	coff2exe lp_solve
	coff2exe demo
	coff2exe lp2mps
	coff2exe mps2lp
	del lp_solve
	del demo
	del lp2mps
	del mps2lp

standalone: all
	coff2exe -s go32.exe lp_solve
	coff2exe -s go32.exe demo
	coff2exe -s go32.exe lp2mps
	coff2exe -s go32.exe mps2lp
	del lp_solve
	del demo
	del lp2mps
	del mps2lp
	