dotfiles/lib/shared.mk
James Patrick e5b9486fb3 Added Truthy shortcut for return val.
I don't really like the feel of this but this allows us to call
$(return_val_truthy) to output a value of tue or false based on the retrun value
of the last command. This saves us from having to do make the call ` && echo
true || echo false`.

I will probaby switch this in the future to just have a `echo $?` function
instead. Then check if returnVal == zero. If I do that I will also need to
change the way OS works, requiring true => 0 and false => 1, which is a little
bit conter to how it should be.
2019-04-30 23:22:02 -04:00

34 lines
1017 B
Makefile

# This will make heavy use of the "$+commands[cmd]" function in bash. Make sure its installed.
_SHELL := $(shell which zsh )
ifndef _SHELL
$(error ZSH is not installed on this machine. This makefile requires ZSH features)
endif
SHELL := $(_SHELL)
# Helper scripts for setting up and taking down links.
LIB_DIR := $(shell dirname $(realpath $(lastword $(MAKEFILE_LIST))))
mk_link := $(LIB_DIR)/helper/mk_link
rm_link := $(LIB_DIR)/helper/rm_link
report := LAST_RETURN=$$? $(LIB_DIR)/helper/report
return_val_truthy := && echo true || echo false
cmd_exist = $(shell (($$+commands[$1])) $(return_val_truthy) )
# Shortcut for the XDG dir if it exist. default to ~/.confg
XDG_DIR := $${XDG_CONFIG_DIR:-~/.config}
# Some things will OS specific.
# With this you can use `$(IS_MAC) && echo "I'm a Mac" || echo "I'm not a Mac"`
ifeq ($(shell uname), Darwin)
IS_MAC=true
else
IS_LINUX=true
endif
IS_MAC?=false
IS_LINUX?=false
# TURN THIS OFF FOR DEBUGGING
MAKEFLAGS += --silent
.PHONY: install update init remove