-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmakefile
100 lines (60 loc) · 2.31 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
## ~ UbioZur - https://github.com/UbioZur ~ ##
#### Makefile to copy and "install" / "update" my dotfiles
#### Directories to use for a headless target
DIRS_HEADLESS := bash fastfetch fonts wget
#### Files to Exclude in the install
EXCLUDE_FILES := *.md
#### Directories to excludes in the copy for all (non . diretories used for the repo)
EXCLUDE_DIRS :=
#### Used Variables
# User home directory
HOME_DIR := $(shell echo ~)/
# Determine the current directory of the Makefile
MAKEFILE_DIR := $(dir $(abspath $(lastword $(MAKEFILE_LIST))))
# List of all directories in the Makefile's directory (excluding hidden directories/files)
DIRS_ALL := $(filter-out $(wildcard $(MAKEFILE_DIR).*), $(wildcard $(MAKEFILE_DIR)*/))
# Directories to copy for all targets
COPY_DIRS := $(filter-out $(EXCLUDE_DIRS), $(DIRS_ALL))
# Directories to copy for headless target (excluding hidden/excluded directories)
COPY_DIRS_HEADLESS := $(foreach dir,$(DIRS_HEADLESS),$(filter $(MAKEFILE_DIR)$(dir)%/,$(COPY_DIRS)))
# Define the lock file used for the update target
LOCK_FILE := $(MAKEFILE_DIR)directory.lock
#### Usefull functions
# Function to extract basename from path (handles trailing slash)
get_basename = $(notdir $(patsubst %/,%,$(1)))
#### Copy ALL dotfiles as a default target
.PHONY: all
all: $(COPY_DIRS)
#### Dynamic targets building, each folder can have it's own target
.PHONY: $(COPY_DIRS)
$(COPY_DIRS): %:
@echo "Copying dotfiles from $* ..."
@rsync -avr --exclude=$(EXCLUDE_FILES) $*/ $(HOME_DIR)
@grep -qxF $* $(LOCK_FILE) || echo $* >> $(LOCK_FILE)
#### Copy dotfiles only usefull for headless system
.PHONY: headless
headless: $(COPY_DIRS_HEADLESS)
#### Clean up the lock file
.PHONY: clean
clean:
@echo "Cleaning up..."
@rm -f $(LOCK_FILE)
#### Update dotfiles based on the lockfile
.PHONY: update
update:
@echo "Updating dotfiles based on $(LOCK_FILE)..."
@while IFS= read -r line; do \
@rsync -avr --exclude=$(EXCLUDE_FILES) $*/ $(HOME_DIR); \
done < $(LOCK_FILE)
#### To use for debugging
.PHONY: debug
debug:
@echo "MAKEFILE_DIR $(MAKEFILE_DIR)"
@echo "---"
@echo "DIRS_ALL $(DIRS_ALL)"
@echo "COPY_DIRS $(COPY_DIRS)"
@echo "---"
@echo "DIRS_HEADLESS $(DIRS_HEADLESS)"
@echo "COPY_DIRS_HEADLESS $(COPY_DIRS_HEADLESS)"
@echo "---"
@echo "$(foreach dir,$(COPY_DIRS_HEADLESS),$(call get_basename,$(dir)))"