# @(#)Makefile.in
#
# Copyright 1997 - 2025  David A. Bagley, bagleyd AT verizon.net
#
# 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 copyright notice and this permission notice appear in
# supporting documentation, and that the name of the author not be
# used in advertising or publicity pertaining to distribution of the
# software without specific, written prior permission.
#
# This program is distributed in the hope that it will be "useful",
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

# xdial Makefile.in for configure (UNIX X11 support)

NAME = dial
WIDGET = Dial
WIDGET2 = $(WIDGET)Sq
C=.c
O=.o
#O=.obj
#O=.@OBJEXT@
E=
#E=.exe
#E=@EXEEXT@
P=x
A=X
R=$(P)
V=
PROG = $(R)$(NAME)$(E)
VER = $(V)$(NAME)

# this tells GNU make not to export variables into the environment
# But other makes do not understand its significance, so it must
# not be the first target in the file. So it is here, before
# any variables are created, but after the default target
.NOEXPORT :

SHELL = /bin/sh
#MANNUM = 1
#MANNUM = 6

srcdir = @srcdir@
top_srcdir = @top_srcdir@
VPATH = @srcdir@

#prefix = @prefix@
# Gnome and KDE Desktop installation
prefix = /usr
#prefix = ${HOME}
exec_prefix = @exec_prefix@

bindir = @bindir@
gamesdir = /usr/games
#xapploaddir = @APPDEFAULTS@
#xapploaddir = @libdir@/X11/app-defaults
# Gnome and KDE Desktop installation
xapploaddir = /etc/X11/app-defaults
#xapploaddir = @libdir@/app-defaults
#xapploaddir = $(HOME)
datarootdir = @datarootdir@
datadir = @datadir@

INSTALL = @INSTALL@
INSTALL_DATA = @INSTALL_DATA@
INSTALL_PROGRAM = @INSTALL_PROGRAM@
M = @XM_PREFIX@

DESTDIR =

#CC = cc -g
#CC = acc -g
#CC = gcc -g -Wall -ansi -pedantic
#CC = gcc -g -Wall -W -Wshadow -Wpointer-arith -Wbad-function-cast -Wcast-align -Wwrite-strings -Waggregate-return -Wmissing-prototypes -Wstrict-prototypes -pedantic -Wno-long-long
#CC = gcc -std=c89
#CC = gcc -g -Wall
#CC = g++ -g -Wall
#CC = CC -g
CC = @CC@

LINT = lint
#LINT = alint

INDENT = indent

MORE = more
#MORE = less

PRINT = lpr
#PRINT = enscript -2r

LN_S = @LN_S@
RM = rm -f
RM_S = $(RM)
ECHO = echo

#BLN_S = set file/enter=[]
#RM = delete/noconfirm/nolog
#RM_S = set file/remove/nolog
#ECHO = write sys$output

DEFINES =
DEFS = @DEFS@ $(DEFINES)
# -DHAVE_USLEEP
# -DHAVE_NANOSLEEP
# -DCONSTPIXMAPS
XWIDGETINC = @XWIDGETINC@ -I$(top_srcdir) -I.
CFLAGS = @CFLAGS@
#CFLAGS = -O
#CFLAGS = -g
XWIDGETLDFLAGS = @XWIDGETLDFLAGS@
XLIBS = @XLIBS@
XWIDGETLIBS = @XWIDGETLIBS@ -lm

HDRS = $(WIDGET)P.h \
$(WIDGET).h \
$(WIDGET2)P.h \
$(WIDGET2).h \
xwin.h \
version.h \
xgui.h \
pixmaps/check.xbm \
pixmaps/box.xbm \
pixmaps/up.xbm \
pixmaps/down.xbm \
pixmaps/64x64/$(NAME).xbm \
pixmaps/16x16/$(NAME).xpm \
pixmaps/22x22/$(NAME).xpm \
pixmaps/24x24/$(NAME).xpm \
pixmaps/32x32/$(NAME).xpm \
pixmaps/48x48/$(NAME).xpm \
pixmaps/64x64/$(NAME).xpm

COREOBJS = $(WIDGET)$(O) \
$(WIDGET2)$(O)
UTILOBJS = xwin$(O) \
xgui$(O)
OBJS = $(UTILOBJS) \
$(COREOBJS) \
$(P)$(NAME)$(O)

CORESRCS = $(WIDGET)$(C) \
$(WIDGET2)$(C)
UTILSRCS = xwin$(C) \
xgui$(C)
SRCS = $(UTILSRCS) \
$(CORESRCS) \
$(P)$(NAME)$(C)

all : $(PROG)

constpixmaps :
	@ $(ECHO) "USE with -DCONSTPIXMAPS"
	cd pixmaps;\
	for pix in */*.xpm; do\
		dir=`dirname $$pix`;\
		mkdir -p ../icons/$$dir;\
		sed 's/static char/static const char/' $$pix > ../icons/$$pix;\
	done;\
	cd ..

$(PROG) : $(OBJS)
	$(CC) -o $@ $(OBJS) $(XWIDGETLDFLAGS) $(XWIDGETLIBS)
	@ $(ECHO) "$@ BUILD COMPLETE"
	@ $(ECHO) ""
	@ $(ECHO) "To install: \"make install\" for Gnome/KDE Desktop install"
	@ $(ECHO) "\t\"make install-bin-all\" for System V style install"
	@ $(ECHO) "\t\"make install-games-all\" for BSD style install"

$(WIDGET)$(O) : $(WIDGET)$(C) $(WIDGET)P.h $(WIDGET).h xwin.h
$(WIDGET2)$(O) : $(WIDGET2)$(C) $(WIDGET2)P.h $(WIDGET2).h
xwin$(O) : xwin$(C) xwin.h
xgui$(O) : xgui$(C) xgui.h
$(P)$(NAME)$(O) : $(P)$(NAME)$(C) $(WIDGET).h xwin.h version.h xgui.h

# Gnome and KDE Desktop installation
install : install-games install-xappload install-png install-desktop

uninstall : uninstall-xappload uninstall-png uninstall-desktop uninstall-games

#System V style installation
install-bin-all : install-bin install-xappload

uninstall-bin-all : uninstall-xappload uninstall-bin

#BSD style installation
install-games-all : install-games install-xappload

uninstall-games-all : uninstall-xappload uninstall-games

install-games : $(PROG)$(E)
	$(srcdir)/mkinstalldirs $(DESTDIR)$(gamesdir)
	$(INSTALL_PROGRAM) $(PROG)$(E) $(DESTDIR)$(gamesdir)/$(R)$(M)$(NAME)$(E)

uninstall-games :
	$(RM) $(DESTDIR)$(gamesdir)/$(R)$(M)$(NAME)$(E)
	rmdir $(DESTDIR)$(gamesdir) 2> /dev/null || true

install-bin : $(PROG)$(E)
	$(srcdir)/mkinstalldirs $(DESTDIR)$(bindir)
	$(INSTALL_PROGRAM) $(PROG)$(E) $(DESTDIR)$(bindir)/$(R)$(M)$(NAME)$(E)

uninstall-bin :
	$(RM) $(DESTDIR)$(bindir)/$(R)$(M)$(NAME)$(E)
	rmdir $(DESTDIR)$(bindir) 2> /dev/null || true

install-xappload :
	$(srcdir)/mkinstalldirs $(DESTDIR)$(xapploaddir)
	sed 's;.READ_PATH;$(DESTDIR)$(readdir);g' $(srcdir)/$(A)$(WIDGET).ad > $(A)$(WIDGET).ad.tmp
	$(INSTALL_DATA) $(A)$(WIDGET).ad.tmp $(DESTDIR)$(xapploaddir)/$(A)$(WIDGET)
	rm -f $(A)$(WIDGET).ad.tmp
	sed 's;.READ_PATH;$(DESTDIR)$(readdir);g' $(srcdir)/$(A)$(WIDGET2).ad > $(A)$(WIDGET2).ad.tmp
	$(INSTALL_DATA) $(srcdir)/$(A)$(WIDGET2).ad.tmp $(DESTDIR)$(xapploaddir)/$(A)$(WIDGET2)
	rm -f $(A)$(WIDGET2).ad.tmp

uninstall-xappload :
	$(RM) $(DESTDIR)$(xapploaddir)/$(A)$(WIDGET)
	$(RM) $(DESTDIR)$(xapploaddir)/$(A)$(WIDGET2)
	rmdir $(DESTDIR)$(xapploaddir) 2> /dev/null || true

install-png :
	for i in 16x16 22x22 24x24 32x32 48x48; do\
		$(srcdir)/mkinstalldirs $(DESTDIR)$(datadir)/icons/hicolor/$$i/apps;\
		$(INSTALL_DATA) pixmaps/$$i/$(NAME).png $(DESTDIR)$(datadir)/icons/hicolor/$$i/apps/$(NAME).png;\
	done

uninstall-png :
	for i in 16x16 22x22 24x24 32x32 48x48; do\
		$(RM) $(DESTDIR)$(datadir)/icons/hicolor/$$i/apps/$(NAME).png;\
		rmdir $(DESTDIR)$(datadir)/icons/hicolor/$$i/apps 2> /dev/null || true;\
		rmdir $(DESTDIR)$(datadir)/icons/hicolor/$$i 2> /dev/null || true;\
	done
	rmdir $(DESTDIR)$(datadir)/icons/hicolor 2> /dev/null || true
	rmdir $(DESTDIR)$(datadir)/icons 2> /dev/null || true
	rmdir $(DESTDIR)$(datadir) 2> /dev/null || true

install-desktop :
	mkdir -p $(DESTDIR)$(datadir)/applications
	echo "[Desktop Entry]" > $(DESTDIR)$(datadir)/applications/$(PROG).desktop
	echo "Name=${WIDGET}" >> $(DESTDIR)$(datadir)/applications/$(PROG).desktop
	echo "Version=`grep VERSION version.h | cut -f2 -d\\\"`" >> $(DESTDIR)$(datadir)/applications/$(PROG).desktop
	echo "GenericName=${WIDGET} demo" >> $(DESTDIR)$(datadir)/applications/$(PROG).desktop
	echo "Comment=demo" >> $(DESTDIR)$(datadir)/applications/$(PROG).desktop
	echo "Exec=${PROG}" >> $(DESTDIR)$(datadir)/applications/$(PROG).desktop
	echo "Icon=$(datarootdir)/icons/hicolor/48x48/apps/$(NAME).png" >> $(DESTDIR)$(datadir)/applications/$(PROG).desktop
	echo "Terminal=false" >> $(DESTDIR)$(datadir)/applications/$(PROG).desktop
	echo "Type=Application" >> $(DESTDIR)$(datadir)/applications/$(PROG).desktop
	echo "X-MutlipleArgs=false" >> $(DESTDIR)$(datadir)/applications/$(PROG).desktop
	echo "Categories=Games;Demo" >> $(DESTDIR)$(datadir)/applications/$(PROG).desktop
	echo "StartupNotify=true" >> $(DESTDIR)$(datadir)/applications/$(PROG).desktop
	echo "Keywords=Games;Demo" >> $(DESTDIR)$(datadir)/applications/$(PROG).desktop

uninstall-desktop :
	$(RM) $(DESTDIR)$(datadir)/applications/$(PROG).desktop
	rmdir $(DESTDIR)$(datadir)/applications 2> /dev/null || true
	rmdir $(DESTDIR)$(datadir) 2> /dev/null || true

#CDE
install-xpm :
	$(srcdir)/mkinstalldirs $(DESTDIR)$(datadir)/dt/appconfig/icons/C
	$(INSTALL_DATA) pixmaps/16x16/$(NAME).xpm $(DESTDIR)$(datadir)/dt/appconfig/icons/C/$(NAME).t.pm
	$(INSTALL_DATA) pixmaps/24x24/$(NAME).xpm $(DESTDIR)$(datadir)/dt/appconfig/icons/C/$(NAME).s.pm
	$(INSTALL_DATA) pixmaps/32x32/$(NAME).xpm $(DESTDIR)$(datadir)/dt/appconfig/icons/C/$(NAME).m.pm
	$(INSTALL_DATA) pixmaps/48x48/$(NAME).xpm $(DESTDIR)$(datadir)/dt/appconfig/icons/C/$(NAME).l.pm

uninstall-xpm :
	for i in t s m l; do\
		$(RM) $(DESTDIR)$(datadir)/dt/appconfig/icons/C/$(NAME).$$i.pm;\
	done
	rmdir $(DESTDIR)$(datadir)/dt/appconfig/icons/C 2> /dev/null || true
	rmdir $(DESTDIR)$(datadir)/dt/appconfig/icons 2> /dev/null || true
	rmdir $(DESTDIR)$(datadir)/dt/appconfig 2> /dev/null || true
	rmdir $(DESTDIR)$(datadir)/dt 2> /dev/null || true
	rmdir $(DESTDIR)$(datadir) 2> /dev/null || true

#CDE HOME directory
install-xpm-home :
	$(srcdir)/mkinstalldirs $(HOME)/.dt/icons/C
	$(INSTALL_DATA) pixmaps/16x16/$(NAME).xpm $(HOME)/.dt/icons/C/$(NAME).t.pm
	$(INSTALL_DATA) pixmaps/24x24/$(NAME).xpm $(HOME)/.dt/icons/C/$(NAME).s.pm
	$(INSTALL_DATA) pixmaps/32x32/$(NAME).xpm $(HOME)/.dt/icons/C/$(NAME).m.pm
	$(INSTALL_DATA) pixmaps/48x48/$(NAME).xpm $(HOME)/.dt/icons/C/$(NAME).l.pm

uninstall-xpm-home :
	for i in t s m l; do\
		$(RM) $(HOME)/.dt/icons/C/$(NAME).$$i.pm;\
	done
	rmdir $(HOME)/.dt/icons/C 2> /dev/null || true
	rmdir $(HOME)/.dt/icons 2> /dev/null || true
	rmdir $(HOME)/.dt 2> /dev/null || true

SUFFIXES : $(C) $(O) $(E)

$(C)$(O) :
	$(CC) -c $(CPPFLAGS) $(DEFS) $(XWIDGETINC) $(CFLAGS) $<

Makefile : Makefile.in config.status
	$(SHELL) config.status
config.status : configure
	$(SHELL) config.status --recheck
#configure : configure.ac
# enable this rule if you want autoconf to be executed automatically when
# configure.ac is changed. This is commented out, since patching might give
# configure.ac a newer timestamp than configure and not everybody has autoconf
#	cd $(srcdir); autoconf

run :
	./$(PROG)

run.help :

run.version :

lldb :
	lldb ./$(PROG)

gdb :
	gdb ./$(PROG)

dbx :
	dbx ./$(PROG)

valgrind :
	valgrind --track-origins=yes --leak-check=full --show-leak-kinds=all \
./$(PROG)

clean :
	$(RM) *.o *.exe* core *~ *% *.bak make.log MakeOut Makefile.dep \
$(PROG) $(PROG).errs $(PROG).1.html *.tmp

distclean : clean
	$(RM) config.cache config.log
	$(RM)r autom4te.cache
	$(RM)r icons
	$(RM) make.com

clean.all : distclean
	$(RM) Makefile config.status*

autoconf :
	autoconf
	$(RM)r autom4te.cache

PACKAGE=$(VER)/$(WIDGET).h $(VER)/$(WIDGET)P.h \
$(VER)/$(WIDGET2).h $(VER)/$(WIDGET2)P.h $(VER)/xwin.h \
$(VER)/version.h $(VER)/xgui.h \
$(VER)/pixmaps/mouse-l.xbm $(VER)/pixmaps/mouse-r.xbm \
$(VER)/pixmaps/*x*/$(NAME).* $(VER)/pixmaps/check.xbm \
$(VER)/pixmaps/box.xbm $(VER)/pixmaps/up.xbm $(VER)/pixmaps/down.xbm \
$(VER)/$(WIDGET)$(C) $(VER)/$(WIDGET2)$(C) $(VER)/$(P)$(NAME)$(C) \
$(VER)/xwin$(C) $(VER)/xgui$(C) \
$(VER)/Imakefile $(VER)/$(A)$(WIDGET).ad $(VER)/$(A)$(WIDGET2).ad \
$(VER)/configure $(VER)/Makefile.in $(VER)/configure.ac \
$(VER)/config.guess $(VER)/config.sub $(VER)/config.cygport \
$(VER)/install-sh $(VER)/mkinstalldirs \
$(VER)/AUTHORS $(VER)/ChangeLog $(VER)/COPYING $(VER)/NEWS \
$(VER)/vms/README.vms $(VER)/vms/make.com $(VER)/vms/descrip.mms

zip :
	cd .. ; zip $(VER) $(PACKAGE)

pkzip :
	cd .. ; pkzip $(VER) $(PACKAGE)

tar :
	cd .. ; tar cvf $(VER).tar $(PACKAGE)

compress :
	cd .. ; tar cvf - $(PACKAGE) | compress > $(VER).tar.Z

gzip :
	cd .. ; tar cvf - $(PACKAGE) | gzip > $(VER).tar.gz

bzip2 :
	cd .. ; tar cvf - $(PACKAGE) | bzip2 > $(VER).tar.bz2

xz :
	cd .. ; tar cvf - $(PACKAGE) | xz > $(VER).tar.xz

dist : xz

print:
	$(PRINT) $(HDRS) $(SRCS)

read :
	$(MORE) README

AUTOMAKE=/usr/share/automake-1.16

automake :
	cp -p ${AUTOMAKE}/config.guess .;\
	cp -p ${AUTOMAKE}/config.sub .;\
	cp -p ${AUTOMAKE}/install-sh .;\
	cp -p ${AUTOMAKE}/mkinstalldirs .

antic :
	antic *.h *.c */*/*.xpm */*/*.xbm */*.xbm

cppcheck :
	cppcheck -f -q *.c

lint :
	$(LINT) -ax -DLINT $(DEFS) $(XWIDGETINC) $(SRCS) $(XWIDGETLIBS)

indent :
	$(INDENT) $(HDRS) $(SRCS)

ICONS=\
	16x16/$(NAME).png\
	22x22/$(NAME).png\
	24x24/$(NAME).png\
	32x32/$(NAME).png\
	48x48/$(NAME).png

PNGS=$(ICONS:%.png=pixmaps/%.png)

pixmaps/%.png : pixmaps/%.xpm
	if grep None $< > /dev/null; then\
		sed -e 's/None/White/' $< | xpmtoppm |\
		pnmtopng -transparent 1,1,1 > $@;\
	else\
		xpmtoppm $< | pnmtopng > $@;\
	fi;\
	pngcrush -ow -rem allb -reduce $@

pixmap : $(PNGS)

pixmaps/64x64/$(NAME).xbm : pixmaps/64x64/$(NAME).xpm
	xpmtoppm -alphaout=pixmaps/$(NAME)_64x64.pbm $< > /dev/null
	pbmtoxbm pixmaps/$(NAME)_64x64.pbm > pixmaps/64x64/$(NAME).xbm
	rm -f pixmaps/$(NAME)_64x64.pbm
