cert-x-gen 1.9.2

Advanced Multi-Language Security Scanning Engine
Documentation
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
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
# CERT-X-GEN Multi-Language Template Engine Makefile
# This Makefile provides comprehensive testing, execution, and installation of templates

# Installation Configuration
PREFIX ?= /usr/local
BINDIR = $(PREFIX)/bin
SHAREDIR = $(PREFIX)/share/cert-x-gen
TEMPLATEDIR = $(SHAREDIR)/templates

# Binary name
BINARY = cxg

# Detect OS
UNAME_S := $(shell uname -s)

# Testing Configuration
TARGET_HOST ?= 127.0.0.1
TARGET_PORT ?= 80
TEST_TIMEOUT ?= 30
VERBOSE ?= false
JSON_OUTPUT ?= false
DESTDIR ?=
PREFIX ?= /usr/local

# Colors for output
RED := \033[0;31m
GREEN := \033[0;32m
YELLOW := \033[1;33m
BLUE := \033[0;34m
NC := \033[0m # No Color

# Directories
TEMPLATES_DIR := templates
SKELETON_DIR := $(TEMPLATES_DIR)/skeleton
TEST_DIR := tests
TARGET_DIR := target
RELEASE_DIR := $(TARGET_DIR)/release

# Binary paths
BINARY_NAME := cxg
CERT_X_GEN := $(RELEASE_DIR)/$(BINARY_NAME)
INSTALL_BIN_DIR := $(DESTDIR)$(PREFIX)/bin
TEST_SCRIPT := test-all-templates.sh

# Language directories
LANGUAGE_DIRS := c cpp java go python javascript rust shell ruby perl php yaml

# Template file patterns
C_TEMPLATES := $(shell find $(TEMPLATES_DIR) -name "*.c" -type f)
CPP_TEMPLATES := $(shell find $(TEMPLATES_DIR) -name "*.cpp" -o -name "*.cc" -o -name "*.cxx" -type f)
JAVA_TEMPLATES := $(shell find $(TEMPLATES_DIR) -name "*.java" -type f)
GO_TEMPLATES := $(shell find $(TEMPLATES_DIR) -name "*.go" -type f)
PYTHON_TEMPLATES := $(shell find $(TEMPLATES_DIR) -name "*.py" -type f)
JAVASCRIPT_TEMPLATES := $(shell find $(TEMPLATES_DIR) -name "*.js" -type f)
RUST_TEMPLATES := $(shell find $(TEMPLATES_DIR) -name "*.rs" -type f)
SHELL_TEMPLATES := $(shell find $(TEMPLATES_DIR) -name "*.sh" -type f)
RUBY_TEMPLATES := $(shell find $(TEMPLATES_DIR) -name "*.rb" -type f)
PERL_TEMPLATES := $(shell find $(TEMPLATES_DIR) -name "*.pl" -type f)
PHP_TEMPLATES := $(shell find $(TEMPLATES_DIR) -name "*.php" -type f)
YAML_TEMPLATES := $(shell find $(TEMPLATES_DIR) -name "*.yaml" -o -name "*.yml" -type f)

# All templates
ALL_TEMPLATES := $(C_TEMPLATES) $(CPP_TEMPLATES) $(JAVA_TEMPLATES) $(GO_TEMPLATES) \
                 $(PYTHON_TEMPLATES) $(JAVASCRIPT_TEMPLATES) $(RUST_TEMPLATES) \
                 $(SHELL_TEMPLATES) $(RUBY_TEMPLATES) $(PERL_TEMPLATES) \
                 $(PHP_TEMPLATES) $(YAML_TEMPLATES)

# Count templates by language
C_COUNT := $(words $(C_TEMPLATES))
CPP_COUNT := $(words $(CPP_TEMPLATES))
JAVA_COUNT := $(words $(JAVA_TEMPLATES))
GO_COUNT := $(words $(GO_TEMPLATES))
PYTHON_COUNT := $(words $(PYTHON_TEMPLATES))
JAVASCRIPT_COUNT := $(words $(JAVASCRIPT_TEMPLATES))
RUST_COUNT := $(words $(RUST_TEMPLATES))
SHELL_COUNT := $(words $(SHELL_TEMPLATES))
RUBY_COUNT := $(words $(RUBY_TEMPLATES))
PERL_COUNT := $(words $(PERL_TEMPLATES))
PHP_COUNT := $(words $(PHP_TEMPLATES))
YAML_COUNT := $(words $(YAML_TEMPLATES))
TOTAL_COUNT := $(words $(ALL_TEMPLATES))

# Default target
.PHONY: all
all: build test-all

# Help target
.PHONY: help
help:
	@echo "CERT-X-GEN Multi-Language Template Engine"
	@echo "=========================================="
	@echo ""
	@echo "Installation targets:"
	@echo "  install        - Install cxg and templates to $(PREFIX)"
	@echo "  uninstall      - Remove cxg from system"
	@echo "  install-system - Install to /usr instead of /usr/local"
	@echo ""
	@echo "Available targets:"
	@echo "  build          - Build the cxg binary"
	@echo "  install        - Install the cxg binary globally (requires permissions)"
	@echo "  test-all       - Test all templates across all languages"
	@echo "  test-c         - Test C templates only"
	@echo "  test-cpp       - Test C++ templates only"
	@echo "  test-java      - Test Java templates only"
	@echo "  test-go        - Test Go templates only"
	@echo "  test-python    - Test Python templates only"
	@echo "  test-javascript - Test JavaScript templates only"
	@echo "  test-rust      - Test Rust templates only"
	@echo "  test-shell     - Test Shell templates only"
	@echo "  test-ruby      - Test Ruby templates only"
	@echo "  test-perl      - Test Perl templates only"
	@echo "  test-php       - Test PHP templates only"
	@echo "  test-yaml      - Test YAML templates only"
	@echo "  test-integration - Run integration tests"
	@echo "  test-unit      - Run unit tests"
	@echo "  scan-all       - Run all templates against a target"
	@echo "  scan-c         - Run C templates against a target"
	@echo "  scan-go        - Run Go templates against a target"
	@echo "  scan-python    - Run Python templates against a target"
	@echo "  clean          - Clean build artifacts"
	@echo "  stats          - Show template statistics"
	@echo "  check-deps     - Check language runtime dependencies"
	@echo ""
	@echo "Configuration:"
	@echo "  TARGET_HOST    - Target host (default: 127.0.0.1)"
	@echo "  TARGET_PORT    - Target port (default: 80)"
	@echo "  TEST_TIMEOUT   - Test timeout in seconds (default: 30)"
	@echo "  VERBOSE        - Verbose output (default: false)"
	@echo "  JSON_OUTPUT    - JSON output format (default: false)"
	@echo ""
	@echo "Examples:"
	@echo "  make build"
	@echo "  make test-all"
	@echo "  make scan-all TARGET_HOST=192.168.1.100"
	@echo "  make test-c VERBOSE=true"
	@echo "  make stats"

# Build the cxg binary
.PHONY: build
build:
	@echo "$(BLUE)[INFO]$(NC) Building cxg..."
	@cargo build --release
	@echo "$(GREEN)[SUCCESS]$(NC) Build completed"

# Install binary and templates
.PHONY: install
install: build
	@echo "$(BLUE)[INFO]$(NC) Installing CERT-X-GEN to $(PREFIX)..."
	@echo ""
	
	# Create directories
	@mkdir -p $(BINDIR)
	@mkdir -p $(TEMPLATEDIR)
	@mkdir -p $(SHAREDIR)
	
	# Install binary
	@echo "$(BLUE)[INFO]$(NC) Installing binary to $(BINDIR)..."
	@install -m 755 target/release/$(BINARY) $(BINDIR)/$(BINARY)
	
	# Install templates if they exist
	@if [ -d "templates" ] && [ -n "$$(ls -A templates 2>/dev/null)" ]; then \
		echo "$(BLUE)[INFO]$(NC) Installing templates to $(TEMPLATEDIR)..."; \
		cp -r templates/* $(TEMPLATEDIR)/; \
		chmod -R 755 $(TEMPLATEDIR); \
	else \
		echo "$(YELLOW)[WARN]$(NC) No templates directory found, skipping template installation"; \
	fi
	
	# Create default repository config
	@echo "$(BLUE)[INFO]$(NC) Creating default repository configuration..."
	@echo "version: \"1.0\"" > $(SHAREDIR)/repositories.yaml
	@echo "default_branch: main" >> $(SHAREDIR)/repositories.yaml
	@echo "repositories:" >> $(SHAREDIR)/repositories.yaml
	@echo "  - name: official" >> $(SHAREDIR)/repositories.yaml
	@echo "    url: https://github.com/BugB-Tech/cert-x-gen-templates.git" >> $(SHAREDIR)/repositories.yaml
	@echo "    branch: main" >> $(SHAREDIR)/repositories.yaml
	@echo "    local_path: ~/.cert-x-gen/templates/official" >> $(SHAREDIR)/repositories.yaml
	@echo "    enabled: true" >> $(SHAREDIR)/repositories.yaml
	@echo "    trusted: true" >> $(SHAREDIR)/repositories.yaml
	
	@echo ""
	@echo "$(GREEN)✓ CERT-X-GEN installed successfully!$(NC)"
	@echo ""
	@echo "Binary:    $(BINDIR)/$(BINARY)"
	@echo "Templates: $(TEMPLATEDIR)"
	@echo "Config:    $(SHAREDIR)/repositories.yaml"
	@echo ""
	@echo "$(BLUE)Next steps:$(NC)"
	@echo "  1. Run '$(BINARY) template update' to download templates from GitHub"
	@echo "  2. Run '$(BINARY) --help' to see available commands"
	@echo "  3. Run '$(BINARY) scan --target example.com' to start scanning"
	@echo ""

# Uninstall
.PHONY: uninstall
uninstall:
	@echo "$(BLUE)[INFO]$(NC) Uninstalling CERT-X-GEN from $(PREFIX)..."
	@rm -f $(BINDIR)/$(BINARY)
	@rm -rf $(SHAREDIR)
	@echo "$(GREEN)✓ Uninstalled successfully$(NC)"
	@echo ""
	@echo "$(YELLOW)Note:$(NC) User templates in ~/.cert-x-gen were not removed"
	@echo "To remove them: rm -rf ~/.cert-x-gen"

# Install to /usr instead of /usr/local (requires sudo)
.PHONY: install-system
install-system:
	@echo "$(BLUE)[INFO]$(NC) Installing to /usr (system-wide)..."
	@$(MAKE) install PREFIX=/usr

# Test all templates across all languages
.PHONY: test-all
test-all: build
	@echo "$(BLUE)[INFO]$(NC) Testing all templates across all languages..."
	@./$(TEST_SCRIPT) -t $(TARGET_HOST) -p $(TARGET_PORT) -T $(TEST_TIMEOUT) $(if $(filter true,$(VERBOSE)),-v) $(if $(filter true,$(JSON_OUTPUT)),-j)

# Test templates by language
.PHONY: test-c
test-c: build
	@echo "$(BLUE)[INFO]$(NC) Testing C templates..."
	@$(CERT_X_GEN) scan --target $(TARGET_HOST) --template-language c --json

.PHONY: test-cpp
test-cpp: build
	@echo "$(BLUE)[INFO]$(NC) Testing C++ templates..."
	@$(CERT_X_GEN) scan --target $(TARGET_HOST) --template-language cpp --json

.PHONY: test-java
test-java: build
	@echo "$(BLUE)[INFO]$(NC) Testing Java templates..."
	@$(CERT_X_GEN) scan --target $(TARGET_HOST) --template-language java --json

.PHONY: test-go
test-go: build
	@echo "$(BLUE)[INFO]$(NC) Testing Go templates..."
	@$(CERT_X_GEN) scan --target $(TARGET_HOST) --template-language go --json

.PHONY: test-python
test-python: build
	@echo "$(BLUE)[INFO]$(NC) Testing Python templates..."
	@$(CERT_X_GEN) scan --target $(TARGET_HOST) --template-language python --json

.PHONY: test-javascript
test-javascript: build
	@echo "$(BLUE)[INFO]$(NC) Testing JavaScript templates..."
	@$(CERT_X_GEN) scan --target $(TARGET_HOST) --template-language javascript --json

.PHONY: test-rust
test-rust: build
	@echo "$(BLUE)[INFO]$(NC) Testing Rust templates..."
	@$(CERT_X_GEN) scan --target $(TARGET_HOST) --template-language rust --json

.PHONY: test-shell
test-shell: build
	@echo "$(BLUE)[INFO]$(NC) Testing Shell templates..."
	@$(CERT_X_GEN) scan --target $(TARGET_HOST) --template-language shell --json

.PHONY: test-ruby
test-ruby: build
	@echo "$(BLUE)[INFO]$(NC) Testing Ruby templates..."
	@$(CERT_X_GEN) scan --target $(TARGET_HOST) --template-language ruby --json

.PHONY: test-perl
test-perl: build
	@echo "$(BLUE)[INFO]$(NC) Testing Perl templates..."
	@$(CERT_X_GEN) scan --target $(TARGET_HOST) --template-language perl --json

.PHONY: test-php
test-php: build
	@echo "$(BLUE)[INFO]$(NC) Testing PHP templates..."
	@$(CERT_X_GEN) scan --target $(TARGET_HOST) --template-language php --json

.PHONY: test-yaml
test-yaml: build
	@echo "$(BLUE)[INFO]$(NC) Testing YAML templates..."
	@$(CERT_X_GEN) scan --target $(TARGET_HOST) --template-language yaml --json

# Integration tests
.PHONY: test-integration
test-integration: build
	@echo "$(BLUE)[INFO]$(NC) Running integration tests..."
	@cargo test --test multi_language_integration_test -- --nocapture

# Unit tests
.PHONY: test-unit
test-unit: build
	@echo "$(BLUE)[INFO]$(NC) Running unit tests..."
	@cargo test --lib -- --nocapture

# Python pentest tests.
# Uses PYTHON (default python3) rather than a bare `python`, which does not
# exist on many systems — including pyenv setups where only `python3` is
# shimmed — so this target failed before it ran a single test. Dependencies
# come from pentest/requirements.txt; install them with `make deps-pentest`.
PYTHON ?= python3

.PHONY: test-pentest
test-pentest:
	@echo "$(BLUE)[INFO]$(NC) Running Python pentest tests..."
	cd pentest && $(PYTHON) -m pytest -v

.PHONY: deps-pentest
deps-pentest:
	@echo "$(BLUE)[INFO]$(NC) Installing Python pentest dependencies..."
	$(PYTHON) -m pip install -r pentest/requirements.txt

# Scan targets (run templates against a target)
.PHONY: scan-all
scan-all: build
	@echo "$(BLUE)[INFO]$(NC) Running all templates against $(TARGET_HOST):$(TARGET_PORT)..."
	@$(CERT_X_GEN) scan --target $(TARGET_HOST) --port $(TARGET_PORT) --json

.PHONY: scan-c
scan-c: build
	@echo "$(BLUE)[INFO]$(NC) Running C templates against $(TARGET_HOST):$(TARGET_PORT)..."
	@$(CERT_X_GEN) scan --target $(TARGET_HOST) --port $(TARGET_PORT) --template-language c --json

.PHONY: scan-go
scan-go: build
	@echo "$(BLUE)[INFO]$(NC) Running Go templates against $(TARGET_HOST):$(TARGET_PORT)..."
	@$(CERT_X_GEN) scan --target $(TARGET_HOST) --port $(TARGET_PORT) --template-language go --json

.PHONY: scan-python
scan-python: build
	@echo "$(BLUE)[INFO]$(NC) Running Python templates against $(TARGET_HOST):$(TARGET_PORT)..."
	@$(CERT_X_GEN) scan --target $(TARGET_HOST) --port $(TARGET_PORT) --template-language python --json

.PHONY: scan-mixed
scan-mixed: build
	@echo "$(BLUE)[INFO]$(NC) Running mixed language templates against $(TARGET_HOST):$(TARGET_PORT)..."
	@$(CERT_X_GEN) scan --target $(TARGET_HOST) --port $(TARGET_PORT) --template-language c,go,python,java --json

# Template statistics
.PHONY: stats
stats:
	@echo "$(BLUE)[INFO]$(NC) Template Statistics"
	@echo "=================================="
	@echo "C Templates:        $(C_COUNT)"
	@echo "C++ Templates:      $(CPP_COUNT)"
	@echo "Java Templates:     $(JAVA_COUNT)"
	@echo "Go Templates:       $(GO_COUNT)"
	@echo "Python Templates:   $(PYTHON_COUNT)"
	@echo "JavaScript Templates: $(JAVASCRIPT_COUNT)"
	@echo "Rust Templates:     $(RUST_COUNT)"
	@echo "Shell Templates:    $(SHELL_COUNT)"
	@echo "Ruby Templates:     $(RUBY_COUNT)"
	@echo "Perl Templates:     $(PERL_COUNT)"
	@echo "PHP Templates:      $(PHP_COUNT)"
	@echo "YAML Templates:     $(YAML_COUNT)"
	@echo "----------------------------------"
	@echo "Total Templates:    $(TOTAL_COUNT)"
	@echo ""

# Check language runtime dependencies
.PHONY: check-deps
check-deps:
	@echo "$(BLUE)[INFO]$(NC) Checking language runtime dependencies..."
	@echo ""
	@echo "C/C++ Compilers:"
	@command -v gcc >/dev/null 2>&1 && echo "  ✅ gcc: $(shell gcc --version | head -n1)" || echo "  ❌ gcc: not found"
	@command -v g++ >/dev/null 2>&1 && echo "  ✅ g++: $(shell g++ --version | head -n1)" || echo "  ❌ g++: not found"
	@command -v clang >/dev/null 2>&1 && echo "  ✅ clang: $(shell clang --version | head -n1)" || echo "  ❌ clang: not found"
	@command -v clang++ >/dev/null 2>&1 && echo "  ✅ clang++: $(shell clang++ --version | head -n1)" || echo "  ❌ clang++: not found"
	@echo ""
	@echo "Java:"
	@command -v javac >/dev/null 2>&1 && echo "  ✅ javac: $(shell javac -version 2>&1)" || echo "  ❌ javac: not found"
	@command -v java >/dev/null 2>&1 && echo "  ✅ java: $(shell java -version 2>&1 | head -n1)" || echo "  ❌ java: not found"
	@echo ""
	@echo "Go:"
	@command -v go >/dev/null 2>&1 && echo "  ✅ go: $(shell go version)" || echo "  ❌ go: not found"
	@echo ""
	@echo "Python:"
	@command -v python3 >/dev/null 2>&1 && echo "  ✅ python3: $(shell python3 --version)" || echo "  ❌ python3: not found"
	@command -v python >/dev/null 2>&1 && echo "  ✅ python: $(shell python --version)" || echo "  ❌ python: not found"
	@echo ""
	@echo "JavaScript:"
	@command -v node >/dev/null 2>&1 && echo "  ✅ node: $(shell node --version)" || echo "  ❌ node: not found"
	@echo ""
	@echo "Rust:"
	@command -v rustc >/dev/null 2>&1 && echo "  ✅ rustc: $(shell rustc --version)" || echo "  ❌ rustc: not found"
	@command -v cargo >/dev/null 2>&1 && echo "  ✅ cargo: $(shell cargo --version)" || echo "  ❌ cargo: not found"
	@echo ""
	@echo "Ruby:"
	@command -v ruby >/dev/null 2>&1 && echo "  ✅ ruby: $(shell ruby --version)" || echo "  ❌ ruby: not found"
	@echo ""
	@echo "Perl:"
	@command -v perl >/dev/null 2>&1 && echo "  ✅ perl: $(shell perl --version | head -n1)" || echo "  ❌ perl: not found"
	@echo ""
	@echo "PHP:"
	@command -v php >/dev/null 2>&1 && echo "  ✅ php: $(shell php --version | head -n1)" || echo "  ❌ php: not found"
	@echo ""

# Create language directories
.PHONY: create-dirs
create-dirs:
	@echo "$(BLUE)[INFO]$(NC) Creating language directories..."
	@for dir in $(LANGUAGE_DIRS); do \
		mkdir -p $(TEMPLATES_DIR)/$$dir; \
		echo "  ✅ Created $(TEMPLATES_DIR)/$$dir"; \
	done

# List all templates
.PHONY: list-templates
list-templates:
	@echo "$(BLUE)[INFO]$(NC) All Templates"
	@echo "=================="
	@echo ""
	@echo "C Templates ($(C_COUNT)):"
	@for template in $(C_TEMPLATES); do echo "  - $$template"; done
	@echo ""
	@echo "C++ Templates ($(CPP_COUNT)):"
	@for template in $(CPP_TEMPLATES); do echo "  - $$template"; done
	@echo ""
	@echo "Java Templates ($(JAVA_COUNT)):"
	@for template in $(JAVA_TEMPLATES); do echo "  - $$template"; done
	@echo ""
	@echo "Go Templates ($(GO_COUNT)):"
	@for template in $(GO_TEMPLATES); do echo "  - $$template"; done
	@echo ""
	@echo "Python Templates ($(PYTHON_COUNT)):"
	@for template in $(PYTHON_TEMPLATES); do echo "  - $$template"; done
	@echo ""
	@echo "JavaScript Templates ($(JAVASCRIPT_COUNT)):"
	@for template in $(JAVASCRIPT_TEMPLATES); do echo "  - $$template"; done
	@echo ""
	@echo "Rust Templates ($(RUST_COUNT)):"
	@for template in $(RUST_TEMPLATES); do echo "  - $$template"; done
	@echo ""
	@echo "Shell Templates ($(SHELL_COUNT)):"
	@for template in $(SHELL_TEMPLATES); do echo "  - $$template"; done
	@echo ""
	@echo "Ruby Templates ($(RUBY_COUNT)):"
	@for template in $(RUBY_TEMPLATES); do echo "  - $$template"; done
	@echo ""
	@echo "Perl Templates ($(PERL_COUNT)):"
	@for template in $(PERL_TEMPLATES); do echo "  - $$template"; done
	@echo ""
	@echo "PHP Templates ($(PHP_COUNT)):"
	@for template in $(PHP_TEMPLATES); do echo "  - $$template"; done
	@echo ""
	@echo "YAML Templates ($(YAML_COUNT)):"
	@for template in $(YAML_TEMPLATES); do echo "  - $$template"; done

# Clean build artifacts
.PHONY: clean
clean:
	@echo "$(BLUE)[INFO]$(NC) Cleaning build artifacts..."
	@cargo clean
	@rm -rf $(TARGET_DIR)
	@echo "$(GREEN)[SUCCESS]$(NC) Clean completed"

# Install dependencies (for development)
.PHONY: install-deps
install-deps:
	@echo "$(BLUE)[INFO]$(NC) Installing development dependencies..."
	@echo "This is a placeholder for dependency installation"
	@echo "Please install the required language runtimes manually:"
	@echo "  - gcc/g++ or clang/clang++ for C/C++"
	@echo "  - openjdk for Java"
	@echo "  - go for Go"
	@echo "  - python3 for Python"
	@echo "  - node for JavaScript"
	@echo "  - rust for Rust"
	@echo "  - ruby for Ruby"
	@echo "  - perl for Perl"
	@echo "  - php for PHP"

# Continuous integration target.
# test-pentest is part of this list because it was not: the Python suite that
# decides whether the desktop scanner reports an insecure app as safe was
# reachable only by running its target by hand.
.PHONY: ci
ci: check-deps build test-unit test-integration test-pentest
	@echo "$(GREEN)[SUCCESS]$(NC) CI pipeline completed successfully"

# Development target
.PHONY: dev
dev: build test-all
	@echo "$(GREEN)[SUCCESS]$(NC) Development testing completed"

# Production target
.PHONY: prod
prod: build test-integration
	@echo "$(GREEN)[SUCCESS]$(NC) Production build completed"

# Show current configuration
.PHONY: config
config:
	@echo "$(BLUE)[INFO]$(NC) Current Configuration"
	@echo "=========================="
	@echo "TARGET_HOST:    $(TARGET_HOST)"
	@echo "TARGET_PORT:    $(TARGET_PORT)"
	@echo "TEST_TIMEOUT:   $(TEST_TIMEOUT)"
	@echo "VERBOSE:        $(VERBOSE)"
	@echo "JSON_OUTPUT:    $(JSON_OUTPUT)"
	@echo ""

# Quick test (subset of templates)
.PHONY: quick-test
quick-test: build
	@echo "$(BLUE)[INFO]$(NC) Running quick test (subset of templates)..."
	@$(CERT_X_GEN) scan --target $(TARGET_HOST) --template-language c,go,python --json

# Performance test
.PHONY: perf-test
perf-test: build
	@echo "$(BLUE)[INFO]$(NC) Running performance test..."
	@time $(CERT_X_GEN) scan --target $(TARGET_HOST) --template-language c,go,python --json

# Memory test
.PHONY: mem-test
mem-test: build
	@echo "$(BLUE)[INFO]$(NC) Running memory test..."
	@valgrind --tool=memcheck --leak-check=full $(CERT_X_GEN) scan --target $(TARGET_HOST) --template-language c --json

# Security test
.PHONY: security-test
security-test: build
	@echo "$(BLUE)[INFO]$(NC) Running security test..."
	@$(CERT_X_GEN) scan --target $(TARGET_HOST) --template-language c,go,python --json --output-format json

# Documentation
.PHONY: docs
docs:
	@echo "$(BLUE)[INFO]$(NC) Generating documentation..."
	@cargo doc --no-deps
	@echo "$(GREEN)[SUCCESS]$(NC) Documentation generated in target/doc/"

# Format code
.PHONY: fmt
fmt:
	@echo "$(BLUE)[INFO]$(NC) Formatting code..."
	@cargo fmt
	@echo "$(GREEN)[SUCCESS]$(NC) Code formatted"

# Lint code
.PHONY: lint
lint:
	@echo "$(BLUE)[INFO]$(NC) Linting code..."
	@cargo clippy -- -D warnings
	@echo "$(GREEN)[SUCCESS]$(NC) Linting completed"

# Check code
.PHONY: check
check: fmt lint
	@echo "$(GREEN)[SUCCESS]$(NC) Code check completed"

# Full test suite
.PHONY: test-full
test-full: check test-unit test-integration test-all
	@echo "$(GREEN)[SUCCESS]$(NC) Full test suite completed"

# Release preparation
.PHONY: release
release: check test-full
	@echo "$(BLUE)[INFO]$(NC) Preparing release..."
	@cargo build --release
	@echo "$(GREEN)[SUCCESS]$(NC) Release build completed"

# Show help by default
.DEFAULT_GOAL := help