2018-06-22 02:40:11 -07:00
# Nomsu makefile
# To build, run `make`
2018-12-14 17:49:36 -08:00
# To install, run `make install`
2018-06-22 02:40:11 -07:00
# ========= 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
2018-06-24 16:11:08 -07:00
PREFIX =
2019-01-10 16:33:37 -08:00
PACKAGEPATH =
2018-06-24 18:28:14 -07:00
UNINSTALL_VERSION =
2018-06-22 02:40:11 -07:00
# ========= You shouldn't need to mess with any of these variables below ================
2018-08-29 19:38:14 -07:00
MOON_FILES = code_obj.moon error_handling.moon files.moon nomsu.moon nomsu_compiler.moon \
2018-09-14 14:42:12 -07:00
syntax_tree.moon containers.moon bitops.moon parser.moon pretty_errors.moon \
2019-01-25 15:49:29 -08:00
text.moon nomsu_decompiler.moon nomsu_environment.moon bootstrap.moon \
2019-01-29 16:16:45 -08:00
builtin_metatables.moon colors.moon
2019-01-14 15:42:48 -08:00
LUA_FILES = code_obj.lua error_handling.lua files.lua nomsu.lua nomsu_compiler.lua \
2018-11-06 15:13:55 -08:00
syntax_tree.lua containers.lua bitops.lua parser.lua pretty_errors.lua \
2019-01-25 15:49:29 -08:00
text.lua nomsu_decompiler.lua nomsu_environment.lua bootstrap.lua \
2019-01-29 16:16:45 -08:00
builtin_metatables.lua colors.lua
2019-01-14 15:42:48 -08:00
CORE_NOM_FILES = $( shell cat lib/core/init.nom | sed -n 's;export "\(.*\)";lib/\1.nom;p' ) lib/core/init.nom
2019-01-15 14:41:30 -08:00
CORE_LUA_FILES = $( patsubst %.nom,%.lua, $( CORE_NOM_FILES) )
COMPAT_NOM_FILES = $( wildcard lib/compatibility/*.nom)
2019-01-15 15:21:18 -08:00
COMPAT_LUA_FILES = $( patsubst %.nom,%.lua, $( COMPAT_NOM_FILES) )
2019-01-15 14:41:30 -08:00
TOOL_NOM_FILES = $( wildcard lib/tools/*.nom)
2019-01-15 15:21:18 -08:00
TOOL_LUA_FILES = $( patsubst %.nom,%.lua, $( TOOL_NOM_FILES) )
2019-01-15 14:41:30 -08:00
LIB_NOM_FILES = $( wildcard lib/*.nom) $( filter-out $( CORE_NOM_FILES) $( TOOL_NOM_FILES) $( COMPAT_NOM_FILES) , $( wildcard lib/*/*.nom) )
LIB_LUA_FILES = $( patsubst %.nom,%.lua, $( LIB_NOM_FILES) )
2019-01-27 02:12:57 -08:00
NOM_FILES = $( CORE_NOM_FILES) $( COMPAT_NOM_FILES) $( TOOL_NOM_FILES) $( LIB_NOM_FILES)
2018-07-18 01:42:12 -07:00
PEG_FILES = $( wildcard 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
2019-05-02 15:41:45 -07:00
all : lua optimize optimize_extra
2018-06-22 02:40:11 -07:00
.PHONY : test
2018-12-14 17:49:36 -08:00
test : lua optimize
2019-09-20 14:22:51 -07:00
@printf "\033[1;4mRunning unoptimized tests...\033[0m\n"
2019-01-15 14:41:30 -08:00
@$( LUA_BIN) nomsu.lua -O0 -t test $( CORE_NOM_FILES) $( LIB_NOM_FILES)
2019-09-20 14:22:51 -07:00
@printf "\n\033[1;4mRunning optimized tests...\033[0m\n"
2019-01-15 14:41:30 -08:00
@$( LUA_BIN) nomsu.lua -O1 -t test $( CORE_LUA_FILES) $( LIB_LUA_FILES)
2018-06-22 02:40:11 -07:00
%.lua : %.moon
@moonc $<
%.lua : %.nom
2018-06-24 18:21:40 -07:00
@$( LUA_BIN) nomsu.lua -c $<
2018-06-22 02:40:11 -07:00
2018-06-24 16:11:08 -07:00
.DELETE_ON_ERROR : version
2019-01-15 14:41:30 -08:00
version : $( LUA_FILES ) $( CORE_NOM_FILES ) $( LIB_NOM_FILES )
2018-06-24 16:11:08 -07:00
@$( LUA_BIN) nomsu.lua --version > version || exit
2018-06-22 02:40:11 -07:00
2018-12-14 17:49:36 -08:00
lua : $( LUA_FILES )
2018-06-22 02:40:11 -07:00
.PHONY : optimize
2019-01-15 14:41:30 -08:00
optimize : lua $( CORE_LUA_FILES ) $( LIB_LUA_FILES )
2018-06-22 02:40:11 -07:00
2019-01-15 15:21:18 -08:00
.PHONY : optimize_extra
optimize_extra : lua $( COMPAT_LUA_FILES ) $( TOOL_LUA_FILES )
2018-06-22 02:40:11 -07:00
.PHONY : clean
clean :
2019-09-20 14:22:51 -07:00
@printf "\033[1mDeleting...\033[0m"
2019-01-14 17:14:34 -08:00
@rm -rvf version lib/*.lua lib/*/*.lua
2018-06-22 02:40:11 -07:00
.PHONY : install
2019-01-15 15:21:18 -08:00
install : lua version optimize optimize_extra
2018-06-24 16:11:08 -07:00
@prefix= " $( PREFIX) " ; \
if [ [ ! $$ prefix ] ] ; then \
read -p $$ '\033[1mWhere do you want to install Nomsu? (default: /usr/local) \033[0m' prefix; \
fi ; \
2019-01-10 16:33:37 -08:00
if [ [ ! $$ prefix ] ] ; then prefix = "/usr/local" ; fi ; \
packagepath = " $( PACKAGEPATH) " ; \
if [ [ ! $$ packagepath ] ] ; then \
read -p $$ '\033[1mWhere do you want Nomsu to put packages you install in the future? (default: /opt) \033[0m' packagepath; \
2019-01-04 14:50:51 -08:00
fi ; \
2019-01-10 16:33:37 -08:00
if [ [ ! $$ packagepath ] ] ; then packagepath = "/opt" ; fi ; \
2018-06-24 16:11:08 -07:00
if [ [ $$ prefix != " `realpath $$ prefix` " ] ] ; then \
2019-09-20 14:22:51 -07:00
printf $$ '\033[1;31mWarning: ' $$ prefix$$ ' is not an absolute path. This may cause problems.\033[0m\n' ; \
2018-06-24 16:11:08 -07:00
read -p $$ '\033[1mWould you rather use ' ` realpath $$ prefix` $$ ' instead? (recommended)[Y/n]\033[0m ' use_real; \
if [ [ ! $$ use_real = ~ ^[ Nn] ] ] ; then \
prefix = " `realpath $$ prefix` " ; \
fi ; \
fi ; \
version = "`cat version`" ; \
2019-01-10 16:33:37 -08:00
mkdir -pv $$ prefix/bin $$ prefix/lib/nomsu/$$ version $$ prefix/share/nomsu/$$ version $$ prefix/share/man/man1 $$ packagepath/nomsu \
2019-09-20 14:22:51 -07:00
&& printf " #! $( LUA_BIN) \nNOMSU_PREFIX, NOMSU_PACKAGEPATH = [[ $$ prefix]], [[ $$ packagepath/nomsu]] " \
2019-01-10 16:33:37 -08:00
| cat - nomsu.lua > $$ prefix/bin/nomsu$$ version \
2018-06-24 17:27:09 -07:00
&& chmod +x $$ prefix/bin/nomsu$$ version \
&& cp -v nomsu $$ prefix/bin \
2018-06-24 18:28:14 -07:00
&& cp -v doc/nomsu.1 $$ prefix/share/man/man1 \
2019-01-14 17:14:34 -08:00
&& cp -rv $( LUA_FILES) $( PEG_FILES) lib $$ prefix/share/nomsu/$$ version;
2018-06-22 02:40:11 -07:00
.PHONY : uninstall
2018-06-24 16:11:08 -07:00
uninstall : version
@prefix= " $( PREFIX) " ; \
if [ [ ! $$ prefix ] ] ; then \
read -p $$ '\033[1mWhere do you want to uninstall Nomsu from? (default: /usr/local) \033[0m' prefix; \
fi ; \
2019-01-10 16:33:37 -08:00
if [ [ ! $$ prefix ] ] ; then prefix = "/usr/local" ; fi ; \
2019-09-20 14:22:51 -07:00
printf "\033[1mNomsu will be uninstalled from:\033[0m\n" ; \
2018-06-24 16:11:08 -07:00
echo " $$ prefix/bin " ; \
echo " $$ prefix/lib " ; \
echo " $$ prefix/share " ; \
read -p $$ '\033[1mis this okay? [Y/n]\033[0m ' ans; \
if [ [ $$ ans = ~ ^[ Nn] ] ] ; then exit; fi ; \
2019-09-20 14:22:51 -07:00
printf "\033[1mDeleting...\033[0m\n" ; \
2018-06-24 18:28:14 -07:00
version = " $( UNINSTALL_VERSION) " ; \
if [ [ ! $$ version ] ] ; then version = "`cat version`" ; fi ; \
2018-06-24 16:11:08 -07:00
rm -rvf $$ prefix/lib/nomsu/$$ version $$ prefix/share/nomsu/$$ version $$ prefix/bin/nomsu$$ version; \
2018-12-31 00:19:00 -08:00
if [ [ " `find $$ prefix/bin -type f -regex '.*/nomsu[0-9.]+\$ $'` " = = "" ] ] ; then \
2018-06-24 18:20:11 -07:00
rm -vf $$ prefix/bin/nomsu $$ prefix/share/man/man1/nomsu.1; \
2018-06-24 16:11:08 -07:00
else \
if [ -f $$ prefix/bin/nomsu ] ; then \
read -p $$ '\033[1mIt looks like there are other versions of Nomsu installed. Is it okay to leave the "nomsu" cross-version launcher in place? (recommended) [Y/n]\033[0m ' ans; \
if [ [ $$ ans = ~ ^[ Nn] ] ] ; then \
2019-09-20 14:22:51 -07:00
printf "\033[1mDeleting...\033[0m\n" ; \
2018-06-24 18:20:11 -07:00
rm -vf $$ prefix/bin/nomsu $$ prefix/share/man/man1/nomsu.1; \
2018-06-23 17:22:23 -07:00
fi ; \
fi ; \
2018-06-24 16:11:08 -07:00
fi ; \
if [ " `ls $$ prefix/lib/nomsu 2>/dev/null` " = = "" ] ; then rm -rvf $$ prefix/lib/nomsu; fi ; \
if [ " `ls $$ prefix/share/nomsu 2>/dev/null` " = = "" ] ; then rm -rvf $$ prefix/share/nomsu; fi ; \
2019-09-20 14:22:51 -07:00
printf $$ '\033[1mDone.\033[0m\n' ;
2019-01-14 15:42:48 -08:00
uninstallpackages :
@packagepath= " $( PACKAGEPATH) " ; \
if [ [ ! $$ packagepath ] ] ; then \
read -p $$ '\033[1mWhere have your Nomsu packages been installed? (default: /opt) \033[0m' packagepath; \
fi ; \
if [ [ ! $$ packagepath ] ] ; then packagepath = "/opt" ; fi ; \
2019-01-10 16:33:37 -08:00
if [ -d $$ packagepath/nomsu ] ; then \
read -p $$ '\033[1mDo you want to delete all installed libraries from /opt? [y/n] \033[0m' confirm; \
if [ [ $$ confirm = = "y" ] ] ; then \
rm -rvf $$ packagepath/nomsu; \
fi ; \
2019-01-14 15:42:48 -08:00
fi ;