# RetroForth 6.21                                     http://www.retroforth.org
# -----------------------------------------------------------------------------
# This Makefile replaces the older build scripts used in previous releases. It
# is far simpler, and should solve most of the distro-specific problems that
# arose with the older build scripts.
# -----------------------------------------------------------------------------
# To use:
#    make -k
#
# This will build all possible ports using both NASM and FASM. If a port can't
# be built, the -k option will cause make to skip it and compile the rest.
# -----------------------------------------------------------------------------
# Todo List
#  * Eliminate need for use of GCC to link with SVGALIB and libSDL
#  * Better way to find libSDL
#  * Handle fetching updates from http://www.retroforth.org using 'wget' or
#    a similar tool.
#  * Build documentation (as it is written) in various formats (ps, pdf, txt,
#    etc).
#  * Better 'clean' function
# -----------------------------------------------------------------------------
NASM = nasm	# Name of the executable for NASM
FASM = fasm	# Name of the executable for FASM

NASM_ARGS = -felf -g -oretro.o	# NASM command line arguments
SDL = /usr/lib/libSDL-1.2.so.0	# Path to libSDL (or a command to locate it)
CC = gcc -s			# Req. for proper linking with SVGALIB & libSDL
COMMON = ports/*		# Forth Core for various assemblers

all:
	@echo "RetroForth Release 6.21"
	@echo "---------------------------------------------------------------"
	@echo "FASM Targets"
	@make -k -i -s fasm-windows-console
	@make -k -i -s fasm-linux-console
	@echo "NASM Targets"
	@make -k -i -s nasm-linux-console
	@make -k -i -s nasm-linux-svga
	@make -k -i -s nasm-linux-sdl

nasm-linux-console:
	@echo "| linux-console"
	@cd ports/nasm-linux-console && $(NASM) retro.asm $(NASM_ARGS)
	@cd ports/nasm-linux-console && ld retro.o -orf
	@cd ports/nasm-linux-console && chmod +x rf
	@cd ports/nasm-linux-console && rm -f retro.o

nasm-linux-svga:
	@echo "| linux-svga"
	@cd ports/linux-svga && $(NASM) retro.asm $(NASM_ARGS)
	@cd ports/linux-svga && gcc retro.o -lvga -orf
	@cd ports/linux-svga && chmod +x rf
	@cd ports/linux-svga && chmod u+s rf
	@cd ports/linux-svga && rm -f retro.o

nasm-linux-sdl:
	@echo "| linux-sdl"
	@cd ports/linux-sdl && $(NASM) retro.asm $(NASM_ARGS)
	@cd ports/linux-sdl && gcc retro.o $(SDL) -orf
	@cd ports/linux-sdl && chmod +x rf
	@cd ports/linux-sdl && rm -f retro.o

fasm-linux-console:
	@echo "| linux-console"
	@cd ports/linux-console && $(FASM) retro.asm rf
	@cd ports/linux-console && chmod +x rf

fasm-windows-console:
	@echo "| windows-console"
	@cd ports/windows-console && $(FASM) retro.asm rf.exe

clean:
	@echo "cleaning up..."
	@find | grep \\~ >a
	@sed 's/./rm -f ./' a >b
	@. b
	@rm -f a b
