# RetroForth 6.20                                     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 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_TARGETS = nasm-linux-console nasm-linux-sdl nasm-linux-svga nasm-native
FASM_TARGETS = fasm-linux-console fasm-windows-console
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: $(NASM_TARGETS) $(FASM_TARGETS) clean

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

nasm-linux-svga:
	@echo linux-svga, nasm
	@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

nasm-linux-sdl:
	@echo linux-sdl, nasm
	@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

nasm-native:
	@echo native/dos, nasm
	@cd ports/native && $(NASM) retro.asm -oretro
	@cd ports/native && $(NASM) raw.asm -orawfloppy

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

fasm-windows-console:
	@echo windows-console, fasm
	@cd ports/fasm-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
