# NetHack 5.0  luahelper    $NHDT-Date: $  $NHDT-Branch: NetHack-3.7 $
#
#  Makefile to assist developers in adding lines to various build
#  Makefiles, or project files, as lua files are added or removed.
#  NetHack may be freely redistributed.  See license for details.
#
#  Must be run while your current directory is the top of the
#  NetHack source tree.
#
#     make -f dat/luahelper [target]
#
#  Target examples:
#
#  Visual Studio nmake  : make -f dat/luahelper devhelp-nmake >file.txt
#
#  Visual Studio project: make -f dat/luahelper devhelp-vstudio >file.txt
#
#  MSYS2 GNUmakefile    : make -f dat/luahelper devhelp-msys2 >file.txt
#
#  Xcode project.pbxproj: make -f dat/luahelper devhelp-xcode >file.txt
#
#

MAKEFLAGS += --no-print-directory
AWK=awk


luanames = asmodeus baalz bigrm-* castle fakewiz? juiblex knox medusa-? \
	minend-? minefill minetn-? oracle orcus sanctum soko?-? tower? \
	valley wizard? nhcore nhlib themerms astral air earth fire water \
	hellfill tut-? ???-goal ???-fil? ???-loca ???-strt \
	dungeon quest

alllua = $(wildcard $(addsuffix .lua,$(addprefix dat/, $(luanames))))

#
# generates lines to insert into
# sys/windows/Makefile.nmake
# 
devhelp-nmake:
	@echo "$(notdir $(alllua))" | \
	    $(AWK) '{for (i=1; i<=NF; ++i)printf "%s%s%s%s", \
	        i == 1? "LUA_FILES = " : "", \
	        "$$(DAT)", \
		$$i, \
	        i % 3? " ": ((i == NF)? "\n" : " \\\n\t")} \
	        i % 3{print ""}'
	@echo ""

#
# generates lines to insert into
# sys/windows/GNUmakefile
#
devhelp-msys2:
	@echo "$(basename $(notdir $(alllua)))" | \
	    $(AWK) '{for (i=1; i<=NF; ++i)printf "%s%s%s", \
	        i == 1? "LUALIST = " : "", \
		$$i, \
	        i % 5? " ": ((i == NF)? "\n" : " \\\n\t")} \
	        i % 5{print ""}'
	@echo ""

xcodeextra = bogusmon cmdhelp data engrave epitaph help hh \
	    history keyhelp opthelp optmenu options oracles \
	    rumors tribute wizhelp
#
# generates lines to insert into
# sys/unix/NetHack.xcodeproj/project.pbxproj
#
devhelp-xcode:
	@echo "\t\t\tinputPaths = ("
	@echo "$(xcodeextra) $(notdir $(alllua))" | \
	    $(AWK) '{for (i=1; i<=NF; ++i)printf "%s%s%s%s%s", \
	        i == 1? "\t" : "", \
		"\t\t\t\042$$(NH_DAT_DIR)/", \
		$$i, \
		"\042", \
		i % 1? " ": ((i == NF)? "\n" : ",\n\t")} \
		i % 1{print ""}'
	@echo "\t\t\t);"
#
# generates lines to insert into
# sys/windows/vs/files.props
#
devhelp-vstudio:
	@echo "  <ItemGroup>"
	@echo "$(notdir $(alllua))" | \
	    $(AWK) '{for (i=1; i<=NF; ++i)printf "%s%s%s%s%s", \
	        i == 1? "    " : "", \
		"<Luafiles Include = \042", \
		$$i, \
		"\042/>", \
		i % 1? " ": ((i == NF)? "\n" : "\n    ")} \
		i % 1{print ""}'
	@echo "  </ItemGroup>"

all:
	make -f dat/luahelper devhelp-nmake >./luahelp-nmake.txt
	make -f dat/luahelper devhelp-msys2 >./luahelp-msys2.txt
	make -f dat/luahelper devhelp-xcode >./luahelp-xcode.txt
	make -f dat/luahelper devhelp-vstudio >./luahelp-vstudio.txt
# end
