2018-06-22 02:40:11 -07:00
# Nomsu makefile
# To build, run `make`
# To install,
# ========= User-controlled variables ========
LUA = lua
2018-06-22 03:18:06 -07:00
LUA_BIN = $( shell which $( LUA) )
2018-06-22 02:40:11 -07:00
PREFIX = /usr/local
2018-06-22 03:18:06 -07:00
NOMSU_BIN_DIR = $( PREFIX) /bin
NOMSU_LIB_DIR = $( PREFIX) /lib/nomsu
2018-06-23 17:22:23 -07:00
NOMSU_SHARE_DIR = $( PREFIX) /share/nomsu
2018-06-22 02:40:11 -07:00
# ========= You shouldn't need to mess with any of these variables below ================
2018-06-23 17:22:23 -07:00
MOON_FILES = code_obj.moon error_handling.moon files.moon nomsu.moon nomsu_compiler.moon nomsu_tree.moon parser.moon
LUA_FILES = code_obj.lua consolecolors.lua error_handling.lua files.lua nomsu.lua nomsu_compiler.lua \
2018-06-22 02:40:11 -07:00
nomsu_tree.lua parser.lua utils.lua uuid.lua
CORE_NOM_FILES = $( wildcard core/*.nom)
CORE_LUA_FILES = $( patsubst %.nom,%.lua,$( CORE_NOM_FILES) )
LIB_NOM_FILES = $( wildcard lib/*.nom)
LIB_LUA_FILES = $( patsubst %.nom,%.lua,$( LIB_NOM_FILES) )
PEG_FILE = nomsu.peg
2018-06-23 00:57:31 -07:00
GET_VERSION = $( LUA_BIN) nomsu.lua --version
2018-06-22 02:40:11 -07:00
all : build optimize
.PHONY : test
test : build optimize
2018-06-23 00:57:31 -07:00
./nomsu_latest tests
2018-06-22 02:40:11 -07:00
%.lua : %.moon
@moonc $<
%.lua : %.nom
2018-06-23 00:57:31 -07:00
@./nomsu_latest -c $<
2018-06-22 02:40:11 -07:00
.PHONY : check_header
2018-06-23 01:43:14 -07:00
check_header : $( PEG_FILE ) nomsu .lua $( CORE_NOM_FILES ) $( LIB_NOM_FILES )
2018-06-23 00:57:31 -07:00
@if [ -f nomsu_latest ] ; then \
2018-06-23 17:22:23 -07:00
NOMSU_HEADER = " #! $( LUA_BIN) \\nlocal NOMSU_VERSION, NOMSU_LIB, NOMSU_SHARE = [[` $( GET_VERSION) `]], [[ $( NOMSU_LIB_DIR) ]], [[ $( NOMSU_SHARE_DIR) ]] " ; \
2018-06-23 00:57:31 -07:00
if [ "`head -n 3 nomsu_latest 2>/dev/null`" != " `echo $$ NOMSU_HEADER` " ] ; then \
rm -f nomsu_latest; \
fi ; \
fi ;
nomsu_latest : nomsu .lua
@rm -f nomsu_latest
2018-06-23 17:22:23 -07:00
@NOMSU_HEADER= " #! $( LUA_BIN) \\nlocal NOMSU_VERSION, NOMSU_LIB, NOMSU_SHARE = [[` $( GET_VERSION) `]], [[ $( NOMSU_LIB_DIR) ]], [[ $( NOMSU_SHARE_DIR) ]] " ; \
2018-06-23 00:57:31 -07:00
echo $$ NOMSU_HEADER | cat - nomsu.lua > nomsu_latest
@chmod +x nomsu_latest
2018-06-23 01:43:14 -07:00
@mv -f nomsu_latest nomsu` $( GET_VERSION) `
@ln -s nomsu` $( GET_VERSION) ` nomsu_latest
2018-06-22 02:40:11 -07:00
@echo "Built nomsu binary"
2018-06-23 01:43:14 -07:00
build : $( LUA_FILES ) check_header nomsu_latest
2018-06-22 02:40:11 -07:00
.PHONY : optimize
optimize : build $( CORE_LUA_FILES ) $( LIB_LUA_FILES )
.PHONY : clean
clean :
2018-06-23 00:57:31 -07:00
@echo "Deleting..."
2018-06-23 01:43:14 -07:00
@rm -rvf nomsu` $( GET_VERSION) ` nomsu_latest core/*.lua lib/*.lua
2018-06-22 02:40:11 -07:00
.PHONY : install
install : all
2018-06-23 17:22:23 -07:00
@echo "Nomsu will be installed to:"
@echo " $( NOMSU_BIN_DIR) "
@echo " $( NOMSU_LIB_DIR) "
@echo " $( NOMSU_SHARE_DIR) "
@read -p "is that okay? [Y/n] " ans; \
if [ [ ! $$ ans = ~ ^[ Nn] ] ] ; then \
mkdir -pv $( NOMSU_BIN_DIR) $( NOMSU_LIB_DIR) /` $( GET_VERSION) ` $( NOMSU_SHARE_DIR) /` $( GET_VERSION) ` \
&& cp -v nomsu nomsu` $( GET_VERSION) ` $( NOMSU_BIN_DIR) \
&& cp -rv $( LUA_FILES) $( PEG_FILE) core lib tests $( NOMSU_SHARE_DIR) /` $( GET_VERSION) ` ; \
fi
2018-06-22 02:40:11 -07:00
.PHONY : uninstall
uninstall : all
2018-06-23 17:22:23 -07:00
@echo "Nomsu will be uninstalled from:"
@echo " $( NOMSU_BIN_DIR) "
@echo " $( NOMSU_LIB_DIR) "
@echo " $( NOMSU_SHARE_DIR) "
@read -p "is that okay? [Y/n] " ans; \
if [ [ ! $$ ans = ~ ^[ Nn] ] ] ; then \
echo "Deleting..." ; \
rm -rvf $( NOMSU_LIB_DIR) /` $( GET_VERSION) ` $( NOMSU_SHARE_DIR) /` $( GET_VERSION) ` $( NOMSU_BIN_DIR) /nomsu` $( GET_VERSION) ` ; \
if [ " `ls $( NOMSU_BIN_DIR) /nomsu* 2> /dev/null` " = = "nomsu" ] ; then \
rm -vf $( NOMSU_BIN_DIR) /nomsu; \
else \
if [ " `ls $( NOMSU_BIN_DIR) /nomsu* 2> /dev/null` " != "" ] ; then \
read -p "It looks like there are other versions of Nomsu installed. Is it okay to leave the 'nomsu' cross-version launcher in place? (recommended) [Y/n]" ans; \
if [ [ $$ ans = ~ ^[ Nn] ] ] ; then \
echo "Deleting..." ; \
rm -vf $( NOMSU_BIN_DIR) /nomsu; \
fi ; \
fi ; \
fi ; \
if [ " `ls $( NOMSU_LIB_DIR) 2>/dev/null` " = = "" ] ; then rm -rvf $( NOMSU_LIB_DIR) ; \
else \
echo " Retaining $( NOMSU_LIB_DIR) , since there are other files there. " ; \
fi ; \
if [ " `ls $( NOMSU_SHARE_DIR) 2>/dev/null` " = = "" ] ; then rm -rvf $( NOMSU_SHARE_DIR) ; \
else \
echo " Retaining $( NOMSU_SHARE_DIR) , since there are other files there. " ; \
fi ; \
fi
2018-06-22 02:40:11 -07:00
# eof