# Edited for Debian GNU/Linux.

EXAMPLES = $(DESTDIR)/usr/share/doc/amiwm/examples
srcdir = @srcdir@
VPATH = @srcdir@
SHELL = /bin/sh
CC = @CC@
LEX = @LEX@
YACC = @YACC@
CFLAGS = @CFLAGS@
YFLAGS = -d
DEFS = @DEFS@
ALL_CFLAGS = -I@srcdir@ -I@srcdir@/libami $(DEFS) $(CFLAGS) @X_CFLAGS@
LIBS = @X_LIBS@ @X_PRE_LIBS@ -Llibami -lami @XT_LIB_KLUDGE@ -lXext -lXmu \
	-lX11 @X_EXTRA_LIBS@ @LIBS@
prefix = @prefix@
exec_prefix = @exec_prefix@
bindir = $(DESTDIR)/usr/bin
obindir = $(DESTDIR)/usr/bin
libdir = $(DESTDIR)/usr/lib
mandir = $(DESTDIR)/usr/share/man
xmandir = $(DESTDIR)/usr/share/man
INSTALL = @INSTALL@
LN_S = @LN_S@
RM = -rm -f
LIBAMI=libami/libami.a
DT_DIR = /etc/dt

PROGS = amiwm requestchoice executecmd ppmtoinfo

MODULES = Background Keyboard

OBJS  = main.o screen.o client.o frame.o icc.o \
		icon.o menu.o diskobject.o gram.o lex.o rc.o \
		module.o

SRCS = main.c screen.c client.c frame.c icc.c \
		icon.c menu.c diskobject.c gram.c lex.c rc.c \
		module.c \
		requestchoice.c executecmd.c kbdmodule.c kbdlexer.c

DISTFILES = README README.modules INSTALL LICENSE amiwm.1 \
	configure configure.in Makefile.in install-sh smakefile scoptions \
	*.[chly] system.amiwmrc def_tool.info *.map \
	Background Xresources.amiwm.in Amilogo.?m Xsession*.in Xinitrc.in \
	amiwm-init libami/Makefile.in libami/*.[chly]

PACKAGENAME = amiwm

AMIWM_HOME = $(libdir)/amiwm

all : $(PROGS) $(MODULES)

lib :
	@( cd libami; $(MAKE) libami.a )

.c.o:
	$(CC) -c $(CPPFLAGS) $(ALL_CFLAGS) $<

menu.o : menu.c
	$(CC) -c $(CPPFLAGS) $(ALL_CFLAGS) -DAMIWM_HOME=\"$(AMIWM_HOME)\" $<

rc.o : rc.c
	$(CC) -c $(CPPFLAGS) $(ALL_CFLAGS) -DAMIWM_HOME=\"$(AMIWM_HOME)\" $<

diskobject.o : diskobject.c
	$(CC) -c $(CPPFLAGS) $(ALL_CFLAGS) -DAMIWM_HOME=\"$(AMIWM_HOME)\" $<

ppmtoinfo.o : ppmtoinfo.c
	$(CC) -c $(CPPFLAGS) $(ALL_CFLAGS) -DAMIWM_HOME=\"$(AMIWM_HOME)\" $<

gram.h gram.c: gram.y
	$(YACC) $(YFLAGS) gram.y
	mv y.tab.c gram.c
	mv y.tab.h gram.h

lex.c : lex.l
	$(LEX) -t lex.l > lex.c

kbdmodule.h kbdmodule.c: kbdmodule.y
	$(YACC) $(YFLAGS) kbdmodule.y
	mv y.tab.c kbdmodule.c
	mv y.tab.h kbdmodule.h

kbdlexer.c : kbdlexer.l
	$(LEX) -t kbdlexer.l > kbdlexer.c

install : $(PROGS) $(MODULES) Xsession Xsession2 Xinitrc amiwm-init
	-mkdir -p $(AMIWM_HOME)
	$(INSTALL) -s requestchoice $(AMIWM_HOME)/requestchoice
	$(INSTALL) -s executecmd $(AMIWM_HOME)/executecmd
	for module in $(MODULES); do \
	  if [ "$$module" = "Background" ]; then \
	    $(INSTALL) $$module $(AMIWM_HOME)/$$module; \
	  else \
	    $(INSTALL) -s $$module $(AMIWM_HOME)/$$module; \
	  fi \
	done
	$(INSTALL) -m 644 system.amiwmrc $(AMIWM_HOME)/system.amiwmrc
	$(INSTALL) -m 644 def_tool.info $(AMIWM_HOME)/def_tool.info
	$(INSTALL) -m 644 system.map $(AMIWM_HOME)/system.map
	$(INSTALL) -m 644 magicwb.map $(AMIWM_HOME)/magicwb.map
	$(INSTALL) -m 644 schwartz.map $(AMIWM_HOME)/schwartz.map
	-mkdir -p $(EXAMPLES)
	$(INSTALL) -m 755 Xsession $(EXAMPLES)/Xsession
	$(INSTALL) -m 755 Xsession2 $(EXAMPLES)/Xsession2
	$(INSTALL) -m 755 Xinitrc $(EXAMPLES)/Xinitrc
	$(INSTALL) -m 755 amiwm-init $(EXAMPLES)/amiwm-init
	$(INSTALL) -s amiwm $(bindir)/amiwm
	$(INSTALL) -s ppmtoinfo $(obindir)/ppmtoinfo
	$(RM) $(obindir)/requestchoice
	$(LN_S) ../lib/amiwm/requestchoice $(obindir)/requestchoice
	-mkdir -p $(mandir)/man1
	$(INSTALL) -m 644 amiwm.1 $(xmandir)/man1/amiwm.1
	$(INSTALL) -m 644 debian/ppmtoinfo.1 $(mandir)/man1/ppmtoinfo.1
	$(INSTALL) -m 644 debian/requestchoice.1 $(mandir)/man1/requestchoice.1

cde-install : Xresources.amiwm Amilogo.bm Amilogo.pm
	-mkdir -p $(DT_DIR)/config/C/Xresources.d
	$(INSTALL) -m 644 Xresources.amiwm $(DT_DIR)/config/C/Xresources.d/Xresources.amiwm
	-mkdir -p $(DT_DIR)/appconfig/icons/C
	$(INSTALL) -m 644 Amilogo.bm $(DT_DIR)/appconfig/icons/C/Amilogo.bm
	$(INSTALL) -m 644 Amilogo.pm $(DT_DIR)/appconfig/icons/C/Amilogo.pm


amiwm : $(OBJS) lib
	$(CC) -o amiwm $(OBJS) $(LIBS)

requestchoice : requestchoice.o lib
	$(CC) -o requestchoice requestchoice.o $(LIBS)

executecmd : executecmd.o lib
	$(CC) -o executecmd executecmd.o $(LIBS)

Keyboard : kbdmodule.o kbdlexer.o lib
	$(CC) -o Keyboard kbdmodule.o kbdlexer.o $(LIBS)

ppmtoinfo : ppmtoinfo.o
	$(CC) -o ppmtoinfo ppmtoinfo.o -lm

clean :
	$(RM) core $(PROGS) $(LIBAMI) Keyboard *.o libami/*.o
	$(RM) lex.yy.c lex.c y.tab.c y.tab.h gram.h gram.c
	$(RM) kbdlexer.c kbdmodule.h kbdmodule.c
	$(RM) config.log

distclean : clean
	$(RM) config.status config.cache *~
	$(RM) Makefile Xresources.amiwm Xsession Xsession2 Xinitrc

spotless : distclean

TAGS:
	etags *.[ch] libami/*.[ch]

patch :
	mv version.h old_version.h
	sed < old_version.h 's/l/"/' | awk '-F"' '{ printf "%s\"%sl%s\"\n",$$1,$$2,1+$$3 }' > version.h
	rm old_version.h

dist : version.h clean
	( version=`sed < version.h -e 's/^[^"]*"//' -e 's/"[^"]*$$//'`; \
	  tarname="$(PACKAGENAME)$$version.tar"; \
	  mkdir $(PACKAGENAME)$$version; \
	  tar cf - $(DISTFILES) | (cd $(PACKAGENAME)$$version/; tar xf - ); \
	  rm -f $$tarname $$tarname.gz; \
	  tar cf $$tarname $(PACKAGENAME)$$version; \
	  rm -rf $(PACKAGENAME)$$version; \
	  gzip $$tarname; \
	)

$(srcdir)/configure: $(srcdir)/configure.in
	autoconf $(srcdir)/configure.in > $(srcdir)/configure

config.status: $(srcdir)/configure
	$(srcdir)/configure

Makefile: $(srcdir)/Makefile.in config.status
	./config.status

libami/Makefile: $(srcdir)/libami/Makefile.in config.status
	./config.status

Xresources.amiwm: $(srcdir)/Xresources.amiwm.in
	sed -e 's:[@]bindir[@]:$(bindir):g' -e 's:[@]AMIWM_HOME[@]:$(AMIWM_HOME):g' < $(srcdir)/Xresources.amiwm.in > Xresources.amiwm

Xsession: $(srcdir)/Xsession.in config.status
	sed -e 's:[@]bindir[@]:$(bindir):g' -e 's:[@]AMIWM_HOME[@]:$(AMIWM_HOME):g' < $(srcdir)/Xsession.in > Xsession

Xsession2: $(srcdir)/Xsession2.in config.status
	sed -e 's:[@]bindir[@]:$(bindir):g' -e 's:[@]AMIWM_HOME[@]:$(AMIWM_HOME):g' < $(srcdir)/Xsession2.in > Xsession2

Xinitrc: $(srcdir)/Xinitrc.in config.status
	sed -e 's:[@]bindir[@]:$(bindir):g' -e 's:[@]AMIWM_HOME[@]:$(AMIWM_HOME):g' < $(srcdir)/Xinitrc.in > Xinitrc


depend:: $(SRCS)
	-@rm Makefile.bak
	mv Makefile Makefile.bak
	( sed '/^#--DO NOT REMOVE THIS LINE--$$/q' < Makefile.bak ; \
	  $(CC) -MM $(ALL_CFLAGS) $(SRCS) ) > Makefile

depend::
	@( cd libami; $(MAKE) depend )

#--DO NOT REMOVE THIS LINE--
