#
# Test/example program Makefile for the Fast Light Tool Kit (FLTK).
#
# Copyright 1998-2023 by Bill Spitzak and others.
#
# This library is free software. Distribution and use rights are outlined in
# the file "COPYING" which should have been included with this file.  If this
# file is missing or damaged, see the license at:
#
#      https://www.fltk.org/COPYING.php
#
# Please see the following page on how to report bugs and issues:
#
#      https://www.fltk.org/bugs.php
#
# -*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-
# Modified: Wed, 08 Jan 2025 17:24:21 +0000 (3rdp4r7yr3p0 <3rdp4r7yr3p0@gmail.com>)
# -*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-

include makeinclude

CPPUNITTEST = \
	unittests.cxx \
	unittest_about.cxx \
	unittest_points.cxx \
	unittest_complex_shapes.cxx \
	unittest_fast_shapes.cxx \
	unittest_circles.cxx \
	unittest_text.cxx \
	unittest_unicode.cxx \
	unittest_symbol.cxx \
	unittest_images.cxx \
	unittest_viewport.cxx \
	unittest_scrollbarsize.cxx \
	unittest_schemes.cxx \
	unittest_terminal.cxx \
	unittest_core.cxx

OBJUNITTEST = \
	$(CPPUNITTEST:.cxx=.o)

#	cairo_test.cxx
CPPFILES =\
	adjuster.cxx \
	animated.cxx \
	arc.cxx \
	ask.cxx \
	bitmap.cxx \
	blocks.cxx \
	boxtype.cxx \
	browser.cxx \
	button.cxx \
	buttons.cxx \
	checkers.cxx \
	clipboard.cxx \
	clock.cxx \
	colbrowser.cxx \
	color_chooser.cxx \
	contrast.cxx \
	cube.cxx \
	CubeMain.cxx \
	CubeView.cxx \
	cursor.cxx \
	curve.cxx \
	demo.cxx \
	device.cxx \
	doublebuffer.cxx \
	editor.cxx \
	fast_slow.cxx \
	file_chooser.cxx \
	flex_demo.cxx \
	flex_login.cxx \
	fltk-versions.cxx \
	fonts.cxx \
	forms.cxx \
	fractals.cxx \
	fracviewer.cxx \
	fullscreen.cxx \
	gl_overlay.cxx \
	glpuzzle.cxx \
	glut_test.cxx \
	grid_alignment \
	grid_buttons \
	grid_dialog \
	grid_login \
	hello.cxx \
	help_dialog.cxx \
	icon.cxx \
	iconize.cxx \
	image.cxx \
	inactive.cxx \
	input.cxx \
	input_choice.cxx \
	keyboard.cxx \
	label.cxx \
	line_style.cxx \
	list_visuals.cxx \
	mandelbrot.cxx \
	menubar.cxx \
	message.cxx \
	minimum.cxx \
	native-filechooser.cxx \
	navigation.cxx \
	offscreen.cxx \
	output.cxx \
	overlay.cxx \
	pack.cxx \
	pixmap_browser.cxx \
	pixmap.cxx \
	preferences.cxx \
	radio.cxx \
	resize.cxx \
	resizebox.cxx \
	resize-example1.cxx \
	resize-example2.cxx \
	resize-example3a.cxx \
	resize-example3b.cxx \
	resize-example3c.cxx \
	resize-example4a.cxx \
	resize-example4b.cxx \
	resize-example5a.cxx \
	resize-example5b.cxx \
	resize-example5c.cxx \
	rotated_text.cxx \
	scroll.cxx \
	shape.cxx \
	subwindow.cxx \
	sudoku.cxx \
	symbols.cxx \
	table.cxx \
	tabs.cxx \
	terminal.cxx \
	threads.cxx \
	tile.cxx \
	tiled_image.cxx \
	tree.cxx \
	twowin.cxx \
	utf8.cxx \
	valuators.cxx \
	windowfocus.cxx \
	wizard.cxx \
	$(CPPUNITTEST)

#	cairo_test 
ALL =	\
	animated \
	adjuster \
	arc \
	ask \
	bitmap \
	blocks \
	boxtype \
	browser \
	button \
	buttons \
	clipboard \
	clock \
	colbrowser \
	color_chooser \
	contrast \
	cursor \
	curve \
	demo \
	device \
	doublebuffer \
	editor \
	file_chooser \
	flex_demo \
	flex_login \
	fltk-versions \
	fonts \
	forms \
	grid_alignment \
	grid_buttons \
	grid_dialog \
	grid_login \
	hello \
	help_dialog \
	icon \
	iconize \
	image \
	input \
	input_choice \
	label \
	line_style \
	list_visuals \
	menubar \
	message \
	minimum \
	native-filechooser \
	navigation \
	offscreen \
	output \
	overlay \
	pack \
	pixmap \
	pixmap_browser \
	device \
	resizebox \
	resize-example1 \
	resize-example2 \
	resize-example3a \
	resize-example3b \
	resize-example3c \
	resize-example4a \
	resize-example4b \
	resize-example5a \
	resize-example5b \
	resize-example5c \
	rotated_text \
	scroll \
	subwindow \
	sudoku \
	symbols \
	table \
	terminal \
	threads \
	tile \
	tiled_image \
	twowin \
	utf8 \
	windowfocus \
	wizard

FLUIDALL = \
	checkers \
	fast_slow \
	inactive \
	keyboard \
	mandelbrot \
	preferences \
	radio \
	resize \
	tabs \
	tree \
	valuators \
	CubeView

GLALL = \
	cube \
	fractals \
	fullscreen \
	gl_overlay \
	glpuzzle \
	glut_test \
	shape \
	unittests

all:	$(ALL) $(GLALL) $(FLUIDALL)

clean:
	$(RM) $(ALL) $(GLALL) $(FLUIDALL) core
	$(RM) *.o core.* *~ *.bck *.bak
	$(RM) CubeViewUI.cxx CubeViewUI.h
	$(RM) checkers_pieces.cxx checkers_pieces.h
	$(RM) fast_slow.cxx fast_slow.h
	$(RM) inactive.cxx inactive.h
	$(RM) keyboard_ui.cxx keyboard_ui.h
	$(RM) mandelbrot_ui.cxx mandelbrot_ui.h
	$(RM) preferences.cxx preferences.h
	$(RM) radio.cxx radio.h
	$(RM) resize.cxx resize.h
	$(RM) tabs.cxx tabs.h
	$(RM) terminal.cxx terminal.h
	$(RM) tree.cxx tree.h
	$(RM) valuators.cxx valuators.h

install: all install-examples install-linux

install-examples:
	echo "Installing example programs to $(DESTDIR)$(DOCDIR)/examples..."
	-$(INSTALL_DIR) $(DESTDIR)$(DOCDIR)/examples
	for file in Makefile makeinclude *.h *.H *.c* *.fl *.html demo.menu rgb.txt; do \
		$(INSTALL_DATA) $$file $(DESTDIR)$(DOCDIR)/examples; \
	done
	-$(INSTALL_DIR) $(DESTDIR)$(DOCDIR)/examples/images
	for file in images/*.gif images/*.png; do \
		$(INSTALL_DATA) $$file $(DESTDIR)$(DOCDIR)/examples/images; \
	done
	-$(INSTALL_DIR) $(DESTDIR)$(DOCDIR)/examples/pixmaps
	for file in pixmaps/*.xbm pixmaps/*.xpm pixmaps/*.png pixmaps/*.h; do \
		$(INSTALL_DATA) $$file $(DESTDIR)$(DOCDIR)/examples/pixmaps; \
	done

install-linux:
	echo Installing games to $(DESTDIR)$(BINDIR)...
	-$(INSTALL_DIR) $(DESTDIR)$(BINDIR)
	-$(INSTALL_DIR) $(DESTDIR)$(PREFIX)/share/applications
	-$(INSTALL_DIR) $(DESTDIR)$(PREFIX)/share/icons/hicolor/32x32/apps
	-$(INSTALL_DIR) $(DESTDIR)$(PREFIX)/share/icons/hicolor/128x128/apps
	for game in blocks checkers sudoku; do \
		$(INSTALL_BIN) $$game $(DESTDIR)$(BINDIR); \
		$(INSTALL_DATA) desktop/$$game.desktop  $(DESTDIR)$(PREFIX)/share/applications; \
		$(INSTALL_DATA) desktop/$$game-32.png $(DESTDIR)$(PREFIX)/share/icons/hicolor/32x32/apps/$$game.png; \
		$(INSTALL_DATA) desktop/$$game-128.png $(DESTDIR)$(PREFIX)/share/icons/hicolor/128x128/apps/$$game.png; \
	done

uninstall:
	echo "Removing examples programs from $(DESTDIR)$(DOCDIR)/examples..."
	-$(RMDIR) $(DESTDIR)$(DOCDIR)/examples

uninstall-linux:
	echo Removing games from $(DESTDIR)$(BINDIR)...
	for game in blocks checkers sudoku; do \
		$(RM) $(DESTDIR)$(BINDIR)/$$game; \
		$(RM) $(DESTDIR)$(PREFIX)/share/applications/$$game.desktop; \
		$(RM) $(DESTDIR)$(PREFIX)/share/icons/hicolor/32x32/apps/$$game.png; \
		$(RM) $(DESTDIR)$(PREFIX)/share/icons/hicolor/128x128/apps/$$game.png; \
	done

# FLUID file rules
.fl.cxx .fl.h:
	echo Generating $@ and header from $<...
	$(FLTK_FLUID_BIN) -c $<

# General demos...
unittests: $(OBJUNITTEST)

adjuster: adjuster.o

animated: animated.o

arc: arc.o

ask: ask.o

bitmap: bitmap.o

boxtype: boxtype.o

browser: browser.o

button: button.o

buttons: buttons.o

blocks: blocks.o
	echo Linking $@...
	$(CXX) $(CXXFLAGS) $(LDFLAGS) blocks.o -o $@ $(AUDIOLIBS) $(LDLIBS)

checkers: checkers.o checkers_pieces.o
	echo Linking $@...
	$(CXX) $(CXXFLAGS) $(LDFLAGS) checkers.o checkers_pieces.o -o $@ $(LDLIBS)

checkers.cxx:		checkers_pieces.h
checkers_pieces.o:	checkers_pieces.h
checkers_pieces.h:	checkers_pieces.fl
checkers_pieces.cxx:	checkers_pieces.fl

clipboard: clipboard.o
	echo Linking $@...
	$(CXX) $(CXXFLAGS) $(LDFLAGS) clipboard.o -o $@ $(LDLIBS)
	$(FLTK_CONFIG) --post $@

clock: clock.o

colbrowser: colbrowser.o
	echo Linking $@...
	$(CXX) $(CXXFLAGS) $(LDFLAGS) -o $@ colbrowser.o $(LDLIBS)
	$(FLTK_CONFIG) --post $@

color_chooser: color_chooser.o

contrast: contrast.o

cursor: cursor.o

curve: curve.o

demo: demo.o
	echo Linking $@...
	$(CXX) $(CXXFLAGS) $(LDFLAGS) -o $@ demo.o $(LDLIBS)
	$(FLTK_CONFIG) --post $@

device: device.o
	echo Linking $@...
	$(CXX) $(CXXFLAGS) $(LDFLAGS) device.o -o $@ $(LDLIBS)
	$(FLTK_CONFIG) --post $@

doublebuffer: doublebuffer.o

editor: editor.o
	echo Linking $@...
	$(CXX) $(CXXFLAGS) $(LDFLAGS) editor.o -o $@ $(LDLIBS)
	$(FLTK_CONFIG) --post $@

fast_slow: fast_slow.o
fast_slow.cxx:	fast_slow.fl

file_chooser: file_chooser.o
	echo Linking $@...
	$(CXX) $(CXXFLAGS) $(LDFLAGS) file_chooser.o -o $@ $(LDLIBS)
	$(FLTK_CONFIG) --post $@

flex_demo: flex_demo.o

flex_login: flex_login.o

fltk-versions: fltk-versions.o

fonts: fonts.o

forms: forms.o
	echo Linking $@...
	$(CXX) $(CXXFLAGS) $(LDFLAGS) -o $@ forms.o $(LDLIBS)
	$(FLTK_CONFIG) --post $@

grid_alignment: grid_alignment.o

grid_buttons: grid_buttons.o

grid_dialog: grid_dialog.o

grid_login: grid_login.o

hello: hello.o

help_dialog: help_dialog.o
	echo Linking $@...
	$(CXX) $(CXXFLAGS) $(LDFLAGS) help_dialog.o -o $@ $(LDLIBS)
	$(FLTK_CONFIG) --post $@

icon: icon.o

iconize: iconize.o

image: image.o

inactive: inactive.o
inactive.cxx:	inactive.fl

input: input.o

input_choice: input_choice.o

keyboard: keyboard_ui.o keyboard.o
	echo Linking $@...
	$(CXX) $(CXXFLAGS) $(LDFLAGS) -o $@ keyboard.o keyboard_ui.o $(LDLIBS)
	$(FLTK_CONFIG) --post $@
keyboard_ui.o:	keyboard_ui.h
keyboard_ui.cxx:	keyboard_ui.fl

label: label.o
	echo Linking $@...
	$(CXX) $(CXXFLAGS) $(LDFLAGS) -o $@ label.o $(LDLIBS)
	$(FLTK_CONFIG) --post $@

line_style: line_style.o

list_visuals: list_visuals.o

mandelbrot: mandelbrot_ui.o mandelbrot.o
	echo Linking $@...
	$(CXX) $(CXXFLAGS) $(LDFLAGS) -o $@ mandelbrot.o mandelbrot_ui.o $(LDLIBS)
	$(FLTK_CONFIG) --post $@
mandelbrot_ui.o:	mandelbrot_ui.h
mandelbrot_ui.cxx:	mandelbrot_ui.fl

menubar: menubar.o

message: message.o

minimum: minimum.o

native-filechooser: native-filechooser.o
	echo Linking $@...
	$(CXX) $(CXXFLAGS) $(LDFLAGS) native-filechooser.o -o $@ $(LDLIBS)
	$(FLTK_CONFIG) --post $@

navigation: navigation.o

offscreen: offscreen.o

output: output.o
	echo Linking $@...
	$(CXX) $(CXXFLAGS) $(LDFLAGS) -o $@ output.o $(LDLIBS)
	$(FLTK_CONFIG) --post $@

overlay: overlay.o

pack: pack.o

pixmap: pixmap.o
	echo Linking $@...
	$(CXX) $(CXXFLAGS) $(LDFLAGS) -o $@ pixmap.o $(LDLIBS)
	$(FLTK_CONFIG) --post $@

pixmap_browser: pixmap_browser.o
	echo Linking $@...
	$(CXX) $(CXXFLAGS) $(LDFLAGS) pixmap_browser.o -o $@ $(LDLIBS)
	$(FLTK_CONFIG) --post $@

preferences:	preferences.o
preferences.cxx:	preferences.fl

device: device.o

radio: radio.o
radio.cxx:	radio.fl

resize: resize.o
resize.cxx:	resize.fl

resizebox: resizebox.o

resize-example1: resize-example1.o resize-arrows.o
	echo Linking $@...
	$(CXX) $(CXXFLAGS) $(LDFLAGS) resize-example1.o resize-arrows.o -o $@ $(LDLIBS)
	$(FLTK_CONFIG) --post $@

resize-example2: resize-example2.o resize-arrows.o
	echo Linking $@...
	$(CXX) $(CXXFLAGS) $(LDFLAGS) resize-example2.o resize-arrows.o -o $@ $(LDLIBS)
	$(FLTK_CONFIG) --post $@

resize-example3a: resize-example3a.o resize-arrows.o
	echo Linking $@...
	$(CXX) $(CXXFLAGS) $(LDFLAGS) resize-example3a.o resize-arrows.o -o $@ $(LDLIBS)
	$(FLTK_CONFIG) --post $@

resize-example3b: resize-example3b.o resize-arrows.o
	echo Linking $@...
	$(CXX) $(CXXFLAGS) $(LDFLAGS) resize-example3b.o resize-arrows.o -o $@ $(LDLIBS)
	$(FLTK_CONFIG) --post $@

resize-example3c: resize-example3c.o resize-arrows.o
	echo Linking $@...
	$(CXX) $(CXXFLAGS) $(LDFLAGS) resize-example3c.o resize-arrows.o -o $@ $(LDLIBS)
	$(FLTK_CONFIG) --post $@

resize-example4a: resize-example4a.o resize-arrows.o
	echo Linking $@...
	$(CXX) $(CXXFLAGS) $(LDFLAGS) resize-example4a.o resize-arrows.o -o $@ $(LDLIBS)
	$(FLTK_CONFIG) --post $@

resize-example4b: resize-example4b.o resize-arrows.o
	echo Linking $@...
	$(CXX) $(CXXFLAGS) $(LDFLAGS) resize-example4b.o resize-arrows.o -o $@ $(LDLIBS)
	$(FLTK_CONFIG) --post $@

resize-example5a: resize-example5a.o resize-arrows.o
	echo Linking $@...
	$(CXX) $(CXXFLAGS) $(LDFLAGS) resize-example5a.o resize-arrows.o -o $@ $(LDLIBS)
	$(FLTK_CONFIG) --post $@

resize-example5b: resize-example5b.o resize-arrows.o
	echo Linking $@...
	$(CXX) $(CXXFLAGS) $(LDFLAGS) resize-example5b.o resize-arrows.o -o $@ $(LDLIBS)
	$(FLTK_CONFIG) --post $@

resize-example5c: resize-example5c.o resize-arrows.o
	echo Linking $@...
	$(CXX) $(CXXFLAGS) $(LDFLAGS) resize-example5c.o resize-arrows.o -o $@ $(LDLIBS)
	$(FLTK_CONFIG) --post $@

rotated_text: rotated_text.o

scroll: scroll.o

subwindow: subwindow.o

sudoku: sudoku.o
	echo Linking $@...
	$(CXX) $(CXXFLAGS) $(LDFLAGS) sudoku.o -o $@ $(AUDIOLIBS) $(LDLIBS)

sudoku.exe: sudoku.o sudoku.rc
	echo Linking $@...
	$(RC) sudoku.rc sudokures.o
	$(CXX) $(CXXFLAGS) $(LDFLAGS) sudoku.o sudokures.o -o $@ $(AUDIOLIBS) $(LDLIBS)

symbols: symbols.o

table: table.o

tabs: tabs.o
tabs.cxx:	tabs.fl

terminal: terminal.o
terminal.cxx:	terminal.fl

threads: threads.o
# This ensures that we have this dependency even if threads are not
# enabled in the current tree...
threads.o:	threads.h

tile: tile.o

tiled_image: tiled_image.o

tree: tree.o
tree.cxx:	tree.fl

twowin: twowin.o

valuators: valuators.o
valuators.cxx:	valuators.fl

# OpenGL demos...
CubeView: CubeMain.o CubeView.o CubeViewUI.o
	echo Linking $@...
	$(CXX) $(CXXFLAGS) $(LDFLAGS) -o $@ \
		CubeMain.o CubeView.o CubeViewUI.o $(LDLIBS)
	$(FLTK_CONFIG) --post $@
CubeMain.o: CubeViewUI.h CubeView.h CubeViewUI.cxx
CubeView.o: CubeView.h
CubeViewUI.o:	CubeViewUI.cxx CubeViewUI.h
CubeViewUI.cxx:	CubeViewUI.fl

cube: cube.o
	echo Linking $@...
	$(CXX) $(CXXFLAGS) $(LDFLAGS) -o $@ cube.o $(LDLIBS)
	$(FLTK_CONFIG) --post $@

fractals: fractals.o fracviewer.o
	echo Linking $@...
	$(CXX) $(CXXFLAGS) $(LDFLAGS) -o $@ fractals.o fracviewer.o $(LDLIBS)
	$(FLTK_CONFIG) --post $@

fullscreen: fullscreen.o
	echo Linking $@...
	$(CXX) $(CXXFLAGS) $(LDFLAGS) -o $@ fullscreen.o $(LDLIBS)
	$(FLTK_CONFIG) --post $@

glpuzzle: glpuzzle.o
	echo Linking $@...
	$(CXX) $(CXXFLAGS) $(LDFLAGS) -o $@ glpuzzle.o $(LDLIBS)
	$(FLTK_CONFIG) --post $@

gl_overlay: gl_overlay.o
	echo Linking $@...
	$(CXX) $(CXXFLAGS) $(LDFLAGS) -o $@ gl_overlay.o $(LDLIBS)
	$(FLTK_CONFIG) --post $@

glut_test: glut_test.o
	echo Linking $@...
	$(CXX) $(CXXFLAGS) $(LDFLAGS) -o $@ glut_test.o $(LDLIBS)
	$(FLTK_CONFIG) --post $@

unittests: $(OBJUNITTEST)
	echo Linking $@...
	$(CXX) $(CXXFLAGS) $(LDFLAGS) -o $@ $(OBJUNITTEST) $(LDLIBS)
	$(FLTK_CONFIG) --post $@

shape: shape.o
	echo Linking $@...
	$(CXX) $(CXXFLAGS) $(LDFLAGS) -o $@ shape.o $(LDLIBS)
	$(FLTK_CONFIG) --post $@

cairo_test: cairo_test.o
	echo Linking $@...
	$(CXX) $(CXXFLAGS) $(LDFLAGS) -o $@ cairo_test.o $(LDLIBS)
	$(FLTK_CONFIG) --post $@
