#
# Makefile for ./src path, used by configure
#

EXEEXT = 
PROGRAM = gocr$(EXEEXT)
# lib removed for simplification
#PGMASCLIB = Pgm2asc
#LIBPGMASCLIB = lib$(PGMASCLIB).a
#INCLUDEFILES = gocr.h

LIBOBJS=pgm2asc.o \
	box.o \
	database.o \
	detect.o \
	barcode.o \
	lines.o \
	list.o \
	ocr0.o \
	ocr0n.o \
	ocr1.o \
	otsu.o \
	output.o \
	pixel.o \
	unicode.o \
	remove.o \
	pnm.o \
	pcx.o \
	progress.o \
	job.o

# these two lines are for cross-compiling, not tested
#srcdir = .
#VPATH = .
bindir = ${exec_prefix}/bin
#  lib removed for simplification
#libdir = ${exec_prefix}/lib
#includedir = ${prefix}/include

CC=gcc
# lib removed for simplification
#RANLIB=@RANLIB@
INSTALL=/usr/bin/install -c
# shell is needed for OS/2 to let if test -r $(PROGRAM) ... work
SHELL=/bin/sh

DEFS=-DHAVE_CONFIG_H
CPPFLAGS=
# to see the config.h
CFLAGS=-g -O2 $(CPPFLAGS) -I../include $(DEFS)
LDFLAGS=-lm  -lnetpbm  -L.
DESTDIR=/usr/local

.c.o: gocr.h pgm2asc.h ../include/config.h
	$(CC) $(CFLAGS) -c -o $*.o $<

default: all

# all: $(PROGRAM) $(LIBPGMASCLIB)
all: $(PROGRAM)

gocr.o: gocr.h Makefile ../include/version.h

.c.h:

#$(PROGRAM): $(LIBPGMASCLIB) gocr.o
$(PROGRAM): $(LIBOBJS) gocr.o
	# make it conform to ld --as-needed
	#$(CC) -o $@ gocr.o ./lib$(PGMASCLIB).a $(LDFLAGS)
	$(CC) -o $@ gocr.o $(LIBOBJS) $(LDFLAGS)
	if test -r $(PROGRAM); then cp $@ ../bin; fi
#$(LIBPGMASCLIB): $(LIBOBJS)
#	-rm -f $@
#	$(AR) cru $@ $(LIBOBJS)
#	$(RANLIB) $@

$(LIBOBJS): Makefile

# PHONY = don't look at file clean, -rm = start rm and ignore errors
.PHONY : clean proper install uninstall
install: all
	#$(INSTALL) -d $(DESTDIR)$(bindir) $(DESTDIR)$(libdir) $(DESTDIR)$(includedir)
	$(INSTALL) -d $(DESTDIR)$(bindir)
	$(INSTALL) ../bin/$(PROGRAM) $(DESTDIR)$(bindir)
	$(INSTALL) ../bin/gocr.tcl   $(DESTDIR)$(bindir)  # better X11/bin?
	#$(INSTALL) $(LIBPGMASCLIB) $(DESTDIR)$(libdir)
	#$(INSTALL) $(INCLUDEFILES) $(DESTDIR)$(includedir)

# directories are not removed
uninstall:
	-rm -f $(DESTDIR)$(bindir)/$(PROGRAM)
	-rm -f $(DESTDIR)$(bindir)/gocr.tcl
	#-rm -f $(DESTDIR)$(libdir)/$(LIBPGMASCLIB)
	#for X in $(INCLUDEFILES); do rm -f $(DESTDIR)$(includedir)/$$X; done

clean:
	-rm -f *.o *~

proper: clean
	#-rm -f gocr libPgm2asc.a
	-rm -f gocr
	
