# Generated automatically from Makefile.in by configure.
LIBS = -lslang -lm #-lefence
SHLIBS = -lslang -lm -lc

GPM_SUPPORT=@gpm_support@

CFLAGS = -Os -Wall -I/usr/include/slang
ifeq ($(RPM_OPT_FLAGS),)
CFLAGS += -Os # -O2 -I/usr/include/slang
endif

VERSION = 0.50.33
CVSTAG = r$(subst .,-,$(VERSION))
SONAME = 0.50

PROGS = test test-j whiptail whiptcl.so testgrid testgrid-j testtree testtree-j
TESTOBJS = test.o
TESTJOBJS = test-j.o
NDIALOGOBJS = whiptail.o dialogboxes.o
WHIPTCLOBJS = whiptcl.o dialogboxes.o
LIBNEWT = libnewt.a
LIBNEWTSH = libnewt.so.$(VERSION)
LIBNEWTSONAME = libnewt.so.$(SONAME)
LIBOBJS = newt.o button.o form.o checkbox.o entry.o label.o listbox.o \
          scrollbar.o textbox.o scale.o grid.o windows.o buttonbar.o \
	  checkboxtree.o

SHCFLAGS = -fPIC

prefix = /usr
includedir = $(prefix)/include
libdir = $(prefix)/lib
bindir = $(prefix)/bin
ARCHNAME = $(shell uname -m | sed 's/i.86/i386/')
pythondir = $(prefix)/lib/python1.5
pythonbindir = $(prefix)/lib/python1.5/lib-dynload

#--------------------------------------

SOURCES = $(subst .o,.c,$(TESTOBJS) $(TESTJOBJS) $(NDIALOGOBJS) $(LIBOBJS))

SHAREDDIR = shared
SHAREDOBJS = $(patsubst %,$(SHAREDDIR)/%, $(LIBOBJS))

ifeq (.depend,$(wildcard .depend))
TARGET=$(PROGS)
else
TARGET=depend $(PROGS)
endif

all:	$(TARGET) _snackmodule.so

test:	$(TESTOBJS) $(LIBNEWT)
	gcc -g -o test $(TESTOBJS) $(LIBNEWT) $(LIBS) -static

test-j: $(TESTJOBJS) $(LIBNEWT)
	gcc -g -o test-j $(TESTJOBJS) $(LIBNEWT) $(LIBS) -static

testgrid:	testgrid.o $(LIBNEWT)
	gcc -g -o testgrid testgrid.o $(LIBNEWT) $(LIBS)

testgrid-j:	testgrid-j.o $(LIBNEWT)
	gcc -g -o testgrid-j testgrid-j.o $(LIBNEWT) $(LIBS)

testtree:	testtree.o $(LIBNEWT)
	gcc -g -o testtree testtree.o $(LIBNEWT) $(LIBS)

testtree-j:	testtree-j.o $(LIBNEWT)
	gcc -g -o testtree-j testtree-j.o $(LIBNEWT) $(LIBS)

_snackmodule.so:   snackmodule.o $(LIBNEWTSH)
	gcc --shared $(SHCFLAGS) -o _snackmodule.so snackmodule.o -L . $(LIBNEWTSH)

snackmodule.o:   snackmodule.c
	gcc -I/usr/include/python1.5 -fPIC $(CFLAGS) -c snackmodule.c

whiptail: $(NDIALOGOBJS) $(LIBNEWTSH)
	gcc -g -o whiptail $(NDIALOGOBJS) -L . $(LIBNEWTSH) $(LIBS) -lpopt

whiptcl.so: $(WHIPTCLOBJS) $(LIBNEWTSH)
	gcc -shared $(SHCFLAGS) -o whiptcl.so $(WHIPTCLOBJS) -L . $(LIBNEWTSH) -ltcl -lslang -lpopt -lm

$(LIBNEWT): $(LIBNEWT)($(LIBOBJS))

newt.o: newt.c Makefile
	$(CC) $(CFLAGS) -DVERSION=\"$(VERSION)\" -c -o $@ $<

veryclean: clean
	rm -f .depend

clean:
	rm -f $(PROGS) *.o $(LIBNEWT) core $(LIBNEWTSH)  \
		$(SHAREDOBJS) *.so*

depend:
	$(CPP) $(CFLAGS) -M $(SOURCES) > .depend

$(SHAREDDIR):
	mkdir -p $(SHAREDDIR)

sharedlib: $(LIBNEWTSH)

$(LIBNEWTSH): $(SHAREDDIR) $(SHAREDOBJS)
	gcc -shared -o $(LIBNEWTSH) -Wl,-soname,$(LIBNEWTSONAME) $(SHAREDOBJS) $(SHLIBS)

$(SHAREDDIR)/%.o : %.c
	$(CC) $(SHCFLAGS) -c $(CFLAGS) -o $@ $<

$(SHAREDDIR)/newt.o: newt.c Makefile
	$(CC) $(SHCFLAGS) $(CFLAGS) -DVERSION=\"$(VERSION)\" -c -o $@ $<


install: $(LIBNEWT) install-sh whiptail
	[ -d $(instroot)/$(bindir) ] || install -m 755 -d $(instroot)/$(bindir)
	[ -d $(instroot)/$(libdir) ] || install -m 755 -d $(instroot)/$(libdir)
	[ -d $(instroot)/$(includedir) ] || install -m 755 -d $(instroot)/$(includedir)
	install -m 644 newt.h $(instroot)/$(includedir)
	install -m 644 $(LIBNEWT) $(instroot)/$(libdir)
	install -s -m 755 whiptail $(instroot)/$(bindir)

install-sh: sharedlib whiptcl.so _snackmodule.so
	[ -d $(instroot)/$(libdir) ] || install -m 755 -d $(instroot)/$(libdir)
	install -s -m 755 $(LIBNEWTSH) $(instroot)/$(libdir)
	ln -sf $(LIBNEWTSH) $(instroot)/$(libdir)/libnewt.so
	install -s -m 755 whiptcl.so $(instroot)/$(libdir)
	[ -d $(instroot)/$(pythonbindir) ] || install -m 755 -d $(instroot)/$(pythonbindir)
	install -s -m 755 _snackmodule.so $(instroot)/$(pythonbindir)
	install -m 755 snack.py $(instroot)/$(pythondir)

configure:  configure.in
	autoconf
	echo "You need to rerun ./configure before continuing"
	exit 1

archive:    configure
	@cvs tag -F $(CVSTAG)
	@rm -rf /tmp/newt-$(VERSION) /tmp/newt
	@cd /tmp; cvs export -r$(CVSTAG) newt; mv newt newt-$(VERSION)
	@cd /tmp/newt-$(VERSION); autoconf
	@cd /tmp; tar czSpf newt-$(VERSION).tar.gz newt-$(VERSION)
	@rm -rf /tmp/newt-$(VERSION)
	@cp /tmp/newt-$(VERSION).tar.gz .
	@rm -f /tmp/newt-$(VERSION).tar.gz
	@echo " "
	@echo "The final archive is ./newt-$(VERSION).tar.gz."

ifeq (.depend,$(wildcard .depend))
include .depend
endif
