-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
209 lines (185 loc) · 7.09 KB
/
Makefile
File metadata and controls
209 lines (185 loc) · 7.09 KB
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
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
# Makefile for gitignore tool v2.0 - SMART VERSION
CC = gcc
CFLAGS = -Wall -Wextra -O2 -std=c11 -I.
LDFLAGS = -lcurl
# Smart PREFIX detection from environment or default
PREFIX ?= /usr/local
BINDIR = $(PREFIX)/bin
MANDIR = $(PREFIX)/share/man/man1
TARGET = gitignore
SRCDIR = src
SOURCES = main.c help.c init.c sync.c utils.c features.c global_backup.c cache_config.c templates.c
OBJECTS = $(SOURCES:%.c=$(SRCDIR)/%.o)
HEADERS = gitignore.h
TEMPLATE_DIR = templates
TEMPLATE_GEN = scripts/generate_templates.sh
VERSION = 2.0.0
.PHONY: all clean install uninstall dirs test package templates help
all: templates dirs $(TARGET)
# Show detected PREFIX
show-prefix:
@echo "Installation prefix: $(PREFIX)"
@echo "Binary will be installed to: $(BINDIR)"
@echo "Man page will be installed to: $(MANDIR)"
@echo ""
@echo "To change prefix, use: make PREFIX=/your/path install"
@echo "Or set environment: export PREFIX=/your/path"
dirs:
@mkdir -p $(SRCDIR) man scripts
# Generate templates.c from templates/ directory
templates: $(TEMPLATE_DIR)/*.gitignore $(TEMPLATE_GEN)
@echo "Generating templates.c from templates/ directory..."
@chmod +x $(TEMPLATE_GEN)
@$(TEMPLATE_GEN)
# If template generator doesn't exist, create it
$(TEMPLATE_GEN):
@echo "Creating template generator script..."
@mkdir -p scripts
@echo "Template generator not found. Please ensure scripts/generate_templates.sh exists"
$(TARGET): $(OBJECTS)
$(CC) $(OBJECTS) -o $(TARGET) $(LDFLAGS)
@echo ""
@echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
@echo "✓ Build complete: $(TARGET)"
@echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
@echo ""
@echo "Installation prefix: $(PREFIX)"
@echo " Binary: $(BINDIR)/$(TARGET)"
@echo " Man page: $(MANDIR)/gitignore.1"
@echo ""
@echo "Install with: make install"
@echo "Or with custom prefix: make PREFIX=/your/path install"
@echo ""
$(SRCDIR)/%.o: $(SRCDIR)/%.c $(HEADERS)
@echo "Compiling $<..."
$(CC) $(CFLAGS) -c $< -o $@
install: $(TARGET) show-prefix
@echo ""
@echo "Installing gitignore to $(PREFIX)..."
@echo ""
install -d $(BINDIR)
install -m 755 $(TARGET) $(BINDIR)
@echo " ✓ Binary installed to $(BINDIR)/$(TARGET)"
@if [ -f man/gitignore.1 ]; then \
install -d $(MANDIR); \
install -m 644 man/gitignore.1 $(MANDIR); \
echo " ✓ Manual page installed to $(MANDIR)/gitignore.1"; \
fi
@echo ""
@echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
@echo "✓ Installation complete!"
@echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
@echo ""
@echo "Run: gitignore --help"
@echo ""
uninstall:
@echo "Uninstalling from $(PREFIX)..."
rm -f $(BINDIR)/$(TARGET)
rm -f $(MANDIR)/gitignore.1
@echo "✓ Uninstalled from $(PREFIX)"
clean:
@echo "Cleaning build artifacts..."
rm -f $(OBJECTS) $(TARGET)
@echo "✓ Clean complete"
# Clean everything including generated templates.c
distclean: clean
@echo "Removing generated files..."
rm -f $(SRCDIR)/templates.c
@echo "✓ Distribution clean complete"
# Regenerate templates
regen-templates:
@echo "Regenerating templates.c..."
@rm -f $(SRCDIR)/templates.c
@$(MAKE) templates
# Test targets
test: $(TARGET)
@echo "Running tests..."
@echo ""
@./$(TARGET) --version
@echo ""
@./$(TARGET) list
@echo ""
@echo "✓ Basic tests passed"
# Development build with debug symbols
dev: CFLAGS += -g -DDEBUG
dev: clean all
# Package for distribution
package: all
@echo "Creating distribution package..."
@mkdir -p dist/gitignore-$(VERSION)
@cp $(TARGET) README.md LICENSE dist/gitignore-$(VERSION)/
@cp -r $(TEMPLATE_DIR) dist/gitignore-$(VERSION)/
@cp -r scripts dist/gitignore-$(VERSION)/
@cd dist && tar -czf gitignore-$(VERSION).tar.gz gitignore-$(VERSION)
@echo "✓ Package created: dist/gitignore-$(VERSION).tar.gz"
# Create initial template directory structure
setup-templates:
@echo "Setting up templates directory..."
@mkdir -p $(TEMPLATE_DIR)
@if [ ! -f $(TEMPLATE_DIR)/python.gitignore ]; then \
echo "Creating sample Python template..."; \
echo "# Python" > $(TEMPLATE_DIR)/python.gitignore; \
echo "__pycache__/" >> $(TEMPLATE_DIR)/python.gitignore; \
echo "*.py[cod]" >> $(TEMPLATE_DIR)/python.gitignore; \
echo "venv/" >> $(TEMPLATE_DIR)/python.gitignore; \
echo ".env" >> $(TEMPLATE_DIR)/python.gitignore; \
fi
@if [ ! -f $(TEMPLATE_DIR)/node.gitignore ]; then \
echo "Creating sample Node template..."; \
echo "# Node.js" > $(TEMPLATE_DIR)/node.gitignore; \
echo "node_modules/" >> $(TEMPLATE_DIR)/node.gitignore; \
echo "*.log" >> $(TEMPLATE_DIR)/node.gitignore; \
echo ".env" >> $(TEMPLATE_DIR)/node.gitignore; \
fi
@echo "✓ Template directory setup complete"
@echo " Add your .gitignore templates to $(TEMPLATE_DIR)/"
@echo " Then run: make templates"
# Help target
help:
@echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
@echo " Gitignore Tool - Makefile Targets"
@echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
@echo ""
@echo "BUILD TARGETS:"
@echo " make - Build the project"
@echo " make templates - Generate templates.c from templates/"
@echo " make regen-templates - Regenerate templates.c"
@echo " make dev - Build with debug symbols"
@echo ""
@echo "INSTALLATION:"
@echo " make install - Install to $(PREFIX)"
@echo " make PREFIX=/path install - Install to custom location"
@echo " make uninstall - Remove installation"
@echo " make show-prefix - Show current PREFIX"
@echo ""
@echo "CLEANING:"
@echo " make clean - Remove build artifacts"
@echo " make distclean - Remove all generated files"
@echo ""
@echo "TEMPLATES:"
@echo " make setup-templates - Create initial template directory"
@echo " make templates - Generate templates.c"
@echo ""
@echo "OTHER:"
@echo " make test - Run basic tests"
@echo " make package - Create distribution package"
@echo " make help - Show this help"
@echo ""
@echo "ENVIRONMENT VARIABLES:"
@echo " PREFIX - Installation prefix (default: /usr/local)"
@echo " CC - C compiler (default: gcc)"
@echo ""
@echo "EXAMPLES:"
@echo " make # Build with default prefix"
@echo " make PREFIX=~/.local install # Install to home directory"
@echo " export PREFIX=/opt/gitignore && make install"
@echo ""
@echo "ADDING NEW TEMPLATES:"
@echo " 1. Create templates/yourname.gitignore"
@echo " 2. Add your patterns to the file"
@echo " 3. Run: make regen-templates"
@echo " 4. Run: make"
@echo ""
@echo "Current PREFIX: $(PREFIX)"
@echo ""
.SILENT: help show-prefix