1+ # Directories to exclude from processing (space-separated)
2+ EXCLUDE_DIRS := .git
3+
4+ # Convert to find-compatible format
5+ FIND_EXCLUDE := $(foreach dir,$(EXCLUDE_DIRS ) ,-path "./$(dir ) " -prune -o)
6+
7+ .PHONY : format all check-deps show clean help
8+
9+ default : help
10+
11+ # Check if tools are installed and give installation instructions
12+ check-deps :
13+ @echo " Checking dependencies..."
14+ @if ! which perltidy > /dev/null 2>&1 ; then \
15+ echo " ❌ perltidy not found" ; \
16+ echo " Install with: brew install perltidy OR cpm install -g Perl::Tidy" ; \
17+ else \
18+ echo " ✅ perltidy found" ; \
19+ fi
20+ @if ! which Rscript > /dev/null 2>&1 ; then \
21+ echo " ❌ Rscript not found" ; \
22+ echo " Install R from: https://r-project.org OR brew install r" ; \
23+ else \
24+ echo " ✅ Rscript found" ; \
25+ fi
26+ @if ! which prettier > /dev/null 2>&1 ; then \
27+ echo " ❌ prettier not found" ; \
28+ echo " Install with: npm install -g prettier OR brew install prettier" ; \
29+ else \
30+ echo " ✅ prettier found" ; \
31+ fi
32+ @if ! which shfmt > /dev/null 2>&1 ; then \
33+ echo " ❌ shfmt not found" ; \
34+ echo " Install with: brew install shfmt OR go install mvdan.cc/sh/v3/cmd/shfmt@latest" ; \
35+ else \
36+ echo " ✅ shfmt found" ; \
37+ fi
38+ @echo " "
39+ @echo " Please manually check R::styler is installed."
40+ @echo " To install: Rscript src/install_r_packages.R styler"
41+ @echo " "
42+
43+ format :
44+ @echo " Formatting files..."
45+ @if which perltidy > /dev/null 2>&1 ; then \
46+ find . $(FIND_EXCLUDE ) \( -name " *.pl" -o -name " *.pm" -o -name " *.t" \) -print0 | xargs -0 perltidy --pro=.perltidyrc -b; \
47+ else \
48+ echo " ⚠️ Skipping Perl files (perltidy not installed - run 'make check-deps')" ; \
49+ fi
50+ @if which Rscript > /dev/null 2>&1 ; then \
51+ if Rscript -e " if (!requireNamespace('styler', quietly=TRUE)) quit(status=1)" 2> /dev/null; then \
52+ find . $(FIND_EXCLUDE ) -name " *.R" -print0 | xargs -0 -I {} Rscript -e " styler::style_file('{}')" ; \
53+ else \
54+ echo " ⚠️ Skipping R files (styler package not installed)" ; \
55+ fi ; \
56+ else \
57+ echo " ⚠️ Skipping R files (Rscript not installed - run 'make check-deps')" ; \
58+ fi
59+ @if which prettier > /dev/null 2>&1 ; then \
60+ find . $(FIND_EXCLUDE ) \( -name " *.md" -o -name " *.markdown" \) -print0 | xargs -0 prettier --write; \
61+ else \
62+ echo " ⚠️ Skipping markdown files (prettier not installed - run 'make check-deps')" ; \
63+ fi
64+ @if which shfmt > /dev/null 2>&1 ; then \
65+ find . $(FIND_EXCLUDE ) \( -name " *.sh" -o -name " *.bash" \) -print0 | xargs -0 shfmt -w -i 2 -ci -sr; \
66+ else \
67+ echo " ⚠️ Skipping shell files (shfmt not installed - run 'make check-deps')" ; \
68+ fi
69+
70+ show :
71+ @echo " Files that would be processed:"
72+ @echo " Excluded directories: $( EXCLUDE_DIRS) "
73+ @echo " "
74+ @echo " Perl files:"
75+ @find . $(FIND_EXCLUDE ) \( -name " *.pl" -o -name " *.pm" -o -name " *.t" \) -print | head -5
76+ @echo " R files:"
77+ @find . $(FIND_EXCLUDE ) -name " *.R" -print | head -5
78+ @echo " Markdown files:"
79+ @find . $(FIND_EXCLUDE ) \( -name " *.md" -o -name " *.markdown" \) -print | head -5
80+ @echo " Shell files:"
81+ @find . $(FIND_EXCLUDE ) \( -name " *.sh" -o -name " *.bash" \) -print | head -5
82+
83+ clean :
84+ @find . $(FIND_EXCLUDE ) -name " *.bak" -print0 | xargs -0 rm -f
85+
86+ help :
87+ @echo " Available targets:"
88+ @echo " check-deps Check if required tools are installed"
89+ @echo " format Format all code files"
90+ @echo " show Show files that would be processed"
91+ @echo " clean Remove backup files"
92+ @echo " all Run format"
93+ @echo " help Show this help"
94+ @echo " "
95+ @echo " Excluded directories: $( EXCLUDE_DIRS) "
0 commit comments