VERSION=1.2.3

include Makefile.sets

CPPFLAGS := $(CPPFLAGS) -Iargh

# For fbdev:
PREVIEW=fbdev

# For X11:
#PREVIEW=x11
#LDLIBS=-L/usr/X11R6/lib -lX11 -lXxf86vm -lXext

ARCHDIR=archives/
ARCHNAME=fbmodes-$(VERSION)
ARCHFILES=fbmodes.c modetest.c kaavat.txt \
          preview-fbdev.c preview.h \
          xf86mode.cc \
          Makefile.sets COPYING progdesc.php \
          argh/argh.cc argh/argh.hh argh/argh.h argh/argh-c.inc argh/docmaker.php \
          argh/Makefile argh/depfun.mak argh/Makefile.sets argh/progdesc.php \
          argh/COPYING argh/README.html \
          fb2x.rb

BINDIR=/usr/local/bin
INSTALL=install
INSTALLPROGS=modetest fbmodes
DEPFUN_INSTALL=sdirs
SUBDIRS=argh

# For DYNAMIC argh-linking, use:
ARGHLINK=-Largh -largh
# For STATIC argh-linking, use:
#ARGHLINK=argh/libargh.a

all: subdirs fbmodes modetest xf86mode

subdirs: $(SUBDIRS)
$(SUBDIRS):
	@$(MAKE) -C $@

fbmodes: fbmodes.o
	$(CC) $(CCFLAGS) $(LDFLAGS) -o $@ $^ -lm
	@echo
	@echo "fbmodes compiled."

xf86mode: xf86mode.o
	$(CXX) $(CCFLAGS) $(LDFLAGS) -o $@ $^ -lm
	@echo
	@echo "xf86mode compiled."

preview.c: preview-$(PREVIEW).c
	@#echo
	@#echo '*** Created preview.c . You should edit preview-fbdev.c and'
	@#echo '*** change FBRESETCOMMAND to be whatever you wish to use for'
	@#echo '*** setting the default screenmode for your framebuffer console!'
	@#echo
	@#sleep 3
	ln -fs $< $@

modetest: modetest.o preview.o subdirs
	$(CXX) $(CFLAGS) $(LDFLAGS) -o $@ \
	  modetest.o preview.o \
	  $(ARGHLINK) -lm $(LDLIBS)
	@echo
	@echo "modetest compiled."
modetest.o: modetest.c Makefile
fbmodes.o: fbmodes.c Makefile

include depfun.mak

install: installsdirs
	make -C argh install
uninstall: uninstallsdirs
	make -C argh uninstall

clean:
	rm -f fbmodes fbmodes.o modetest modetest.o preview.o
distclean: clean
	rm -f *~ preview.c
realclean: distclean


FORCE: ;
.PHONY: all FORCE \
        clean distclean realclean \
        subdirs $(SUBDIRS) \
        install uninstall
