-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMakefile
executable file
·161 lines (115 loc) · 4.37 KB
/
Makefile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
##--Define Variables--##
# SUFFIX_OF_SCRIPTS
SUFFIX := sh
# SCRIPTS
## paths
PREINITDIR := etc/init/00_pre
LAZYINITDIR := etc/init/10_lazy
## get items
PREINITSCRIPTS := $(sort $(wildcard $(PREINITDIR)/??*.$(SUFFIX)))
LAZYINITSCRIPTS := $(sort $(wildcard $(LAZYINITDIR)/??*.$(SUFFIX)))
# DOTFILES
DOTPATH := $(realpath $(dir $(lastword $(MAKEFILE_LIST))))
CANDIDATES := $(wildcard .??* .config/??*.??* .config/??*rc .config/??*/??*.??* )
CONFIGDIRS := $(filter-out %rc %.toml %.ini %.cfg %.dirs, $(wildcard .config/??* .config/??*/??*.d))
CANDIDATES := $(CANDIDATES) $(foreach DIR,$(CONFIGDIRS),$(wildcard $(DIR)/??*/config)) package.json $(wildcard .jupyter/??*.??* ) Pipfile aqua.yaml
CONFIGDIRS := $(sort $(CONFIGDIRS) $(patsubst %/,%,$(dir $(CANDIDATES))))
CONFIGDIRS := $(filter-out .,$(CONFIGDIRS))
EXCLUSIONS := .DS_Store .git .gitmodules .gitignore .travis.yml .config .vscode .Xresources-regolith $(CONFIGDIRS) .themes .icons .venv
DOTFILES := $(sort $(filter-out $(EXCLUSIONS),$(CANDIDATES)))
# SUBMODULES
SUBMODULES = $(wildcard .themes/??* .icons/??*)
# for WIN
WIN_HOME := /mnt/c/Users/kmise
EXCLUSIONS_WIN := $(wildcard .config/??*.??* .config/??*/??* .config/??*/??*/??* .??*) %rc
DOTFILES_WIN := $(sort $(filter-out $(EXCLUSIONS_WIN),$(DOTFILES)))
DOTFILES_WIN_ONCONFIG := $(wildcard .config/??*.toml)
#--Define Functions--#
# DEFINE FUNCTIONS
# - ON LINUX
define mkdir_safety
mkdir -p $1
endef
define deploy_file
ln -sfv $1 $2
endef
define deploy_dir
ln -sfvn $1 $2
endef
define run
./etc/util/logexec $1
endef
define rm_recursive
rm -vrf $1
endef
# - ON WINDOWS
define set_config_home_win
$(subst .config,AppData/Local,$1)
endef
# - ON EACH_OS
define _list
echo "$1"
endef
##--Setup all tasks--##
DEPLOY = $(foreach val, $(CONFIGDIRS), \
$(call mkdir_safety,$(HOME)/$(val)))\
$(foreach val,$(DOTFILES), \
$(call deploy_file,$(realpath $(val)),$(HOME)/$(val)))
DEPLOY-MODULE = $(foreach val, $(SUBMODULES), \
$(call deploy_dir, $(realpath $(val)), $(HOME)/$(val)))
DEPLOY_WIN = cd $(WIN_HOME)/Dotfiles\
$(foreach val, $(CONFIGDIRS), \
$(call mkdir_safety,$(WIN_HOME)/$(val)) \
$(call mkdir_safety,$(WIN_HOME)/$(call set_config_home_win,$(val))))\
$(foreach val,$(DOTFILES_WIN), \
$(call deploy_file,$(val),../$(call set_config_home_win,$(val))))\
$(foreach val,$(DOTFILES_WIN_ONCONFIG), \
$(call deploy_file,$(val),../$(val)))\
$(call deploy_file,$(WIN_HOME)/Dotfiles/powershell/profile.ps1,$(WIN_HOME)/OneDrive/ドキュメント/PowerShell/Microsoft.PowerShell_profile.ps1)
INIT_PRE := $(foreach val, $(PREINITSCRIPTS),$(call run, $(abspath $(val))))
INIT_LAZY := $(foreach val, $(LAZYINITSCRIPTS),$(call run, $(abspath $(val))))
CLEAN = $(foreach val, $(DOTFILES), \
$(call rm_recursive,$(HOME)/$(val)))
UPDATE := $(foreach val,$(UPDATES),$(call run,$(abspath $(val))))
##--MAIN--##
.DEFAULT_GOAL := help
all:
credit:## Show credit
@echo 'Copyright (c) 2013-2015 BABAROT, 2019- BORLEY All Rights Reserved.'
@echo ''
list:## Show dot files in this repo
@echo '--DOTFILES--'
@$(foreach val, $(DOTFILES), $(call _list,$(val)))
@echo ''
@echo '--CONFIG DIRS--'
@$(foreach val, $(CONFIGDIRS), $(call _list,$(val)))
deploy-file:## Create symlink to home directory (FILES)
@$(DEPLOY)
deploy-submodule:## Create symlink to home directory (SUBMODULES)
@$(DEPLOY-MODULE)
deploy:credit deploy-file deploy-submodule ## Create symlink to home directory
deploy-win:## Create symlink to WIN_HOME directory
@$(DEPLOY_WIN)
init-pre:## Setup environment settings (PRE)
@$(INIT_PRE)
init-lazy:## Setup environment settings (LAZY)
@$(INIT_LAZY)
init-fake:## Test for init
@$(call run,./etc/util/do_nothing)
init:init-pre init-lazy ## Setup HEAD and LAZY environment settings
test:## Test dotfiles and init scripts (now DEPRECATED)
@#DOTPATH = $(DOTPATH)bash $(DOTPATH)/etc/test/test.sh
@echo "test is inactive temporarily"
update:## Fetch changes for this repo
git pull origin master
git submodule init
git submodule update --remote
git submodule foreach git pull origin master
install:update deploy init ## Run make update, deploy, init
clean:## Remove the dot files
@echo '==> Remove dotfiles in your home directory...'
@$(CLEAN)
purge:clean ## Run 'clean' and remove self
$(call rm_recursive, $(DOTPATH))
help:credit ## Self - documented Makefile
@grep -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST)\ | sort \ | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}'