@hybridlabor-api/aos 4.8.0 → 4.9.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (166) hide show
  1. package/.agents/agents.md +1 -1
  2. package/.agents/nodes.json +1 -1
  3. package/.agents/vendor-manifest.json +23 -1
  4. package/.claude/agents/godmode-media-eventtech.md +1 -1
  5. package/.claude/hooks/conventional-commits.mjs +125 -0
  6. package/.claude/hooks/env-file-protection.mjs +105 -0
  7. package/.claude/hooks/go-gate.mjs +101 -81
  8. package/.claude/settings.json +13 -0
  9. package/.opencode/agents/godmode-media-eventtech.md +1 -1
  10. package/.opencode/plugins/bdb-aos.js +31 -4
  11. package/README.de.md +1 -1
  12. package/README.md +1 -1
  13. package/README.pt.md +1 -1
  14. package/THIRD_PARTY_NOTICES.md +88 -0
  15. package/docs/skills_table.md +1 -1
  16. package/installer.js +174 -46
  17. package/package.json +6 -2
  18. package/packages/aos-cli/README.md +80 -0
  19. package/packages/aos-cli/bin/aos-cli.mjs +134 -0
  20. package/packages/aos-cli/core-skills.json +12 -0
  21. package/packages/aos-cli/extensions/aos.ts +321 -0
  22. package/packages/aos-cli/package-lock.json +1923 -0
  23. package/packages/aos-cli/package.json +29 -0
  24. package/packages/aos-cli/scripts/check-theme.mjs +63 -0
  25. package/packages/aos-cli/themes/aos.json +97 -0
  26. package/scripts/build-plugin-manifest.mjs +131 -0
  27. package/scripts/validate-skills.mjs +81 -6
  28. package/skills/basic/ao-orchestrator/SKILL.md +116 -0
  29. package/skills/global_config/agenttrail/SKILL.md +6 -1
  30. package/skills/global_config/ask-tim/SKILL.md +4 -4
  31. package/skills/global_config/bash-script-generator/SKILL.md +201 -0
  32. package/skills/global_config/bash-script-generator/assets/templates/standard-template.sh +96 -0
  33. package/skills/global_config/bash-script-generator/docs/bash-scripting-guide.md +729 -0
  34. package/skills/global_config/bash-script-generator/docs/generation-best-practices.md +193 -0
  35. package/skills/global_config/bash-script-generator/docs/script-patterns.md +566 -0
  36. package/skills/global_config/bash-script-generator/docs/text-processing-guide.md +437 -0
  37. package/skills/global_config/bash-script-generator/examples/log-analyzer.sh +92 -0
  38. package/skills/global_config/bash-script-generator/scripts/generate_script_template.sh +123 -0
  39. package/skills/global_config/bash-script-generator/scripts/run_ci_checks.sh +172 -0
  40. package/skills/global_config/bash-script-generator/scripts/test_generator.sh +413 -0
  41. package/skills/global_config/bash-script-validator/SKILL.md +249 -0
  42. package/skills/global_config/bash-script-validator/docs/awk-reference.md +449 -0
  43. package/skills/global_config/bash-script-validator/docs/bash-reference.md +468 -0
  44. package/skills/global_config/bash-script-validator/docs/common-mistakes.md +623 -0
  45. package/skills/global_config/bash-script-validator/docs/grep-reference.md +395 -0
  46. package/skills/global_config/bash-script-validator/docs/regex-reference.md +391 -0
  47. package/skills/global_config/bash-script-validator/docs/sed-reference.md +454 -0
  48. package/skills/global_config/bash-script-validator/docs/shell-reference.md +463 -0
  49. package/skills/global_config/bash-script-validator/docs/shellcheck-reference.md +399 -0
  50. package/skills/global_config/bash-script-validator/examples/bad-bash.sh +55 -0
  51. package/skills/global_config/bash-script-validator/examples/bad-shell.sh +54 -0
  52. package/skills/global_config/bash-script-validator/examples/good-bash.sh +71 -0
  53. package/skills/global_config/bash-script-validator/examples/good-shell.sh +69 -0
  54. package/skills/global_config/bash-script-validator/scripts/run_ci_checks.sh +23 -0
  55. package/skills/global_config/bash-script-validator/scripts/shellcheck_wrapper.sh +174 -0
  56. package/skills/global_config/bash-script-validator/scripts/test_validate.sh +446 -0
  57. package/skills/global_config/bash-script-validator/scripts/validate.sh +512 -0
  58. package/skills/global_config/ci-pipeline/SKILL.md +135 -0
  59. package/skills/global_config/dispatching-parallel-agents/SKILL.md +170 -0
  60. package/skills/global_config/dockerfile-generator/SKILL.md +1038 -0
  61. package/skills/global_config/dockerfile-generator/examples/example.dockerignore +95 -0
  62. package/skills/global_config/dockerfile-generator/examples/golang-distroless.Dockerfile +34 -0
  63. package/skills/global_config/dockerfile-generator/examples/java-springboot.Dockerfile +45 -0
  64. package/skills/global_config/dockerfile-generator/examples/nextjs-production.Dockerfile +49 -0
  65. package/skills/global_config/dockerfile-generator/examples/nodejs-multistage.Dockerfile +55 -0
  66. package/skills/global_config/dockerfile-generator/examples/python-fastapi.Dockerfile +48 -0
  67. package/skills/global_config/dockerfile-generator/references/language_specific_guides.md +510 -0
  68. package/skills/global_config/dockerfile-generator/references/multistage_builds.md +570 -0
  69. package/skills/global_config/dockerfile-generator/references/optimization_patterns.md +492 -0
  70. package/skills/global_config/dockerfile-generator/references/security_best_practices.md +375 -0
  71. package/skills/global_config/dockerfile-generator/scripts/generate_dockerignore.sh +199 -0
  72. package/skills/global_config/dockerfile-generator/scripts/generate_golang.sh +172 -0
  73. package/skills/global_config/dockerfile-generator/scripts/generate_java.sh +185 -0
  74. package/skills/global_config/dockerfile-generator/scripts/generate_nodejs.sh +279 -0
  75. package/skills/global_config/dockerfile-generator/scripts/generate_python.sh +218 -0
  76. package/skills/global_config/dockerfile-generator/scripts/test_generator.sh +210 -0
  77. package/skills/global_config/dockerfile-validator/SKILL.md +300 -0
  78. package/skills/global_config/dockerfile-validator/examples/.dockerignore.example +34 -0
  79. package/skills/global_config/dockerfile-validator/examples/bad-example.Dockerfile +37 -0
  80. package/skills/global_config/dockerfile-validator/examples/golang-distroless.Dockerfile +50 -0
  81. package/skills/global_config/dockerfile-validator/examples/good-example.Dockerfile +52 -0
  82. package/skills/global_config/dockerfile-validator/examples/python-optimized.Dockerfile +53 -0
  83. package/skills/global_config/dockerfile-validator/examples/security-issues.Dockerfile +42 -0
  84. package/skills/global_config/dockerfile-validator/references/docker_best_practices.md +348 -0
  85. package/skills/global_config/dockerfile-validator/references/optimization_guide.md +473 -0
  86. package/skills/global_config/dockerfile-validator/references/security_checklist.md +208 -0
  87. package/skills/global_config/dockerfile-validator/scripts/dockerfile-validate.sh +699 -0
  88. package/skills/global_config/dockerfile-validator/scripts/test_validate.sh +35 -0
  89. package/skills/global_config/dockerfile-validator/tests/fixtures/copy-before-yarn-lock-read.Dockerfile +6 -0
  90. package/skills/global_config/dockerfile-validator/tests/fixtures/copy-before-yarn.Dockerfile +6 -0
  91. package/skills/global_config/dockerfile-validator/tests/fixtures/from-platform-nonroot.Dockerfile +7 -0
  92. package/skills/global_config/dockerfile-validator/tests/test_regression.sh +164 -0
  93. package/skills/global_config/finishing-a-development-branch/SKILL.md +228 -0
  94. package/skills/global_config/github-actions-generator/SKILL.md +353 -0
  95. package/skills/global_config/github-actions-generator/assets/templates/action/composite/action.yml +82 -0
  96. package/skills/global_config/github-actions-generator/assets/templates/action/docker/Dockerfile +25 -0
  97. package/skills/global_config/github-actions-generator/assets/templates/action/docker/action.yml +42 -0
  98. package/skills/global_config/github-actions-generator/assets/templates/action/docker/entrypoint.sh +27 -0
  99. package/skills/global_config/github-actions-generator/assets/templates/action/javascript/action.yml +33 -0
  100. package/skills/global_config/github-actions-generator/assets/templates/action/javascript/index.js +50 -0
  101. package/skills/global_config/github-actions-generator/assets/templates/action/javascript/package.json +27 -0
  102. package/skills/global_config/github-actions-generator/assets/templates/workflow/basic_workflow.yml +242 -0
  103. package/skills/global_config/github-actions-generator/assets/templates/workflow/reusable_workflow.yml +106 -0
  104. package/skills/global_config/github-actions-generator/examples/README.md +147 -0
  105. package/skills/global_config/github-actions-generator/examples/actions/setup-node-cached/action.yml +93 -0
  106. package/skills/global_config/github-actions-generator/examples/caching/docker-buildkit.yml +256 -0
  107. package/skills/global_config/github-actions-generator/examples/security/dependency-review.yml +62 -0
  108. package/skills/global_config/github-actions-generator/examples/security/sbom-attestation.yml +119 -0
  109. package/skills/global_config/github-actions-generator/examples/triggers/chatops-commands.yml +475 -0
  110. package/skills/global_config/github-actions-generator/examples/triggers/repository-dispatch.yml +418 -0
  111. package/skills/global_config/github-actions-generator/examples/triggers/workflow-orchestration.yml +404 -0
  112. package/skills/global_config/github-actions-generator/examples/workflows/docker-build-push.yml +68 -0
  113. package/skills/global_config/github-actions-generator/examples/workflows/go-ci.yml +161 -0
  114. package/skills/global_config/github-actions-generator/examples/workflows/monorepo-ci.yml +340 -0
  115. package/skills/global_config/github-actions-generator/examples/workflows/multi-environment-deploy.yml +406 -0
  116. package/skills/global_config/github-actions-generator/examples/workflows/nodejs-ci.yml +122 -0
  117. package/skills/global_config/github-actions-generator/examples/workflows/python-ci.yml +157 -0
  118. package/skills/global_config/github-actions-generator/examples/workflows/scheduled-tasks.yml +376 -0
  119. package/skills/global_config/github-actions-generator/references/advanced-triggers.md +917 -0
  120. package/skills/global_config/github-actions-generator/references/best-practices.md +755 -0
  121. package/skills/global_config/github-actions-generator/references/common-actions.md +715 -0
  122. package/skills/global_config/github-actions-generator/references/custom-actions.md +320 -0
  123. package/skills/global_config/github-actions-generator/references/expressions-and-contexts.md +688 -0
  124. package/skills/global_config/github-actions-generator/references/modern-features.md +421 -0
  125. package/skills/global_config/github-actions-generator/scripts/test_generator.sh +344 -0
  126. package/skills/global_config/github-actions-templates/SKILL.md +7 -0
  127. package/skills/global_config/github-actions-validator/SKILL.md +576 -0
  128. package/skills/global_config/github-actions-validator/examples/README.md +88 -0
  129. package/skills/global_config/github-actions-validator/examples/outdated-versions.yml +76 -0
  130. package/skills/global_config/github-actions-validator/examples/valid-ci.yml +79 -0
  131. package/skills/global_config/github-actions-validator/examples/with-errors.yml +47 -0
  132. package/skills/global_config/github-actions-validator/references/act_usage.md +233 -0
  133. package/skills/global_config/github-actions-validator/references/action_versions.md +122 -0
  134. package/skills/global_config/github-actions-validator/references/actionlint_usage.md +343 -0
  135. package/skills/global_config/github-actions-validator/references/common_errors.md +512 -0
  136. package/skills/global_config/github-actions-validator/references/modern_features.md +384 -0
  137. package/skills/global_config/github-actions-validator/references/runners.md +317 -0
  138. package/skills/global_config/github-actions-validator/scripts/install_tools.sh +113 -0
  139. package/skills/global_config/github-actions-validator/scripts/validate_workflow.sh +910 -0
  140. package/skills/global_config/github-actions-validator/tests/test_validate_workflow.sh +237 -0
  141. package/skills/global_config/makefile-generator/SKILL.md +614 -0
  142. package/skills/global_config/makefile-generator/assets/templates/.gitkeep +1 -0
  143. package/skills/global_config/makefile-generator/docs/makefile-structure.md +530 -0
  144. package/skills/global_config/makefile-generator/docs/optimization-guide.md +784 -0
  145. package/skills/global_config/makefile-generator/docs/patterns-guide.md +642 -0
  146. package/skills/global_config/makefile-generator/docs/security-guide.md +361 -0
  147. package/skills/global_config/makefile-generator/docs/targets-guide.md +642 -0
  148. package/skills/global_config/makefile-generator/docs/variables-guide.md +596 -0
  149. package/skills/global_config/makefile-generator/scripts/add_standard_targets.sh +539 -0
  150. package/skills/global_config/makefile-generator/scripts/generate_makefile_template.sh +690 -0
  151. package/skills/global_config/makefile-generator/test/test_helper_scripts.sh +190 -0
  152. package/skills/global_config/makefile-validator/SKILL.md +244 -0
  153. package/skills/global_config/makefile-validator/docs/bake-tool.md +1000 -0
  154. package/skills/global_config/makefile-validator/docs/best-practices.md +858 -0
  155. package/skills/global_config/makefile-validator/docs/common-mistakes.md +944 -0
  156. package/skills/global_config/makefile-validator/examples/bad-makefile.mk +77 -0
  157. package/skills/global_config/makefile-validator/examples/good-makefile.mk +103 -0
  158. package/skills/global_config/makefile-validator/scripts/test_validate.sh +382 -0
  159. package/skills/global_config/makefile-validator/scripts/validate_makefile.sh +712 -0
  160. package/skills/global_config/{MCP_Manage → mcp-manage}/SKILL.md +3 -3
  161. package/skills/global_config/requesting-code-review/SKILL.md +98 -0
  162. package/skills/global_config/requesting-code-review/code-reviewer.md +198 -0
  163. package/skills/global_config/using-git-worktrees/SKILL.md +170 -0
  164. package/skills/global_config/verification-before-completion/SKILL.md +123 -0
  165. package/skills/global_config/writing-plans/SKILL.md +126 -46
  166. package/skills/global_config/writing-plans-legacy/SKILL.md +139 -0
@@ -0,0 +1,596 @@
1
+ # Makefile Variables Guide
2
+
3
+ ## Overview
4
+
5
+ This guide covers variable definition, assignment operators, automatic variables, standard GNU variables, and best practices for variable management in Makefiles.
6
+
7
+ ## Variable Assignment Operators
8
+
9
+ Make supports four assignment operators, each with different behavior:
10
+
11
+ ### 1. Recursive Assignment (=)
12
+
13
+ ```makefile
14
+ # Evaluated every time the variable is used
15
+ FILES = $(wildcard *.c)
16
+ OBJECTS = $(FILES:.c=.o)
17
+
18
+ # Each use of $(OBJECTS) re-expands $(FILES) and re-runs wildcard
19
+ target: $(OBJECTS)
20
+ $(CC) $(OBJECTS) -o target
21
+ ```
22
+
23
+ **Characteristics:**
24
+ - Right-hand side evaluated every time variable is used
25
+ - Can reference variables defined later
26
+ - Can cause infinite recursion
27
+ - Less efficient for frequently-used variables
28
+
29
+ **When to use:**
30
+ - Variables that reference other variables that might change
31
+ - Simple string values
32
+ - When you need delayed evaluation
33
+
34
+ ### 2. Simple Assignment (:=)
35
+
36
+ ```makefile
37
+ # Evaluated once when defined
38
+ FILES := $(wildcard *.c)
39
+ OBJECTS := $(FILES:.c=.o)
40
+
41
+ # $(OBJECTS) contains the fixed list from definition time
42
+ target: $(OBJECTS)
43
+ $(CC) $(OBJECTS) -o target
44
+ ```
45
+
46
+ **Characteristics:**
47
+ - Right-hand side evaluated immediately
48
+ - More efficient for computed values
49
+ - Cannot reference variables defined later
50
+ - Prevents infinite recursion
51
+
52
+ **When to use:**
53
+ - Variables with computed values (wildcards, substitutions)
54
+ - Frequently-referenced variables
55
+ - Most project-specific variables (SOURCES, OBJECTS, TARGET)
56
+
57
+ ### 3. Conditional Assignment (?=)
58
+
59
+ ```makefile
60
+ # Only assigns if variable is not already defined
61
+ CC ?= gcc
62
+ CFLAGS ?= -Wall -O2
63
+ PREFIX ?= /usr/local
64
+
65
+ # Users can override:
66
+ # make CC=clang
67
+ # export CC=clang; make
68
+ ```
69
+
70
+ **Characteristics:**
71
+ - Assigns only if variable undefined or empty
72
+ - Respects environment variables
73
+ - Respects command-line overrides
74
+ - Essential for user-configurable variables
75
+
76
+ **When to use:**
77
+ - User-overridable variables (CC, CFLAGS, PREFIX)
78
+ - Default values that users might want to change
79
+ - All tool and configuration variables
80
+
81
+ ### 4. Append Assignment (+=)
82
+
83
+ ```makefile
84
+ # Append to existing value
85
+ CFLAGS ?= -Wall -O2
86
+ CFLAGS += -I./include
87
+ CFLAGS += -DDEBUG
88
+
89
+ # Result: CFLAGS = -Wall -O2 -I./include -DDEBUG
90
+ ```
91
+
92
+ **Characteristics:**
93
+ - Adds to existing variable value
94
+ - Preserves type of original assignment (= vs :=)
95
+ - Automatically adds space between values
96
+
97
+ **When to use:**
98
+ - Adding project-specific flags to user flags
99
+ - Building lists incrementally
100
+ - Extending default values
101
+
102
+ ## Comparison of Assignment Operators
103
+
104
+ ```makefile
105
+ # Recursive (=): Re-evaluated each use
106
+ VAR1 = $(shell date)
107
+ # VAR1 changes every time it's used!
108
+
109
+ # Simple (:=): Evaluated once
110
+ VAR2 := $(shell date)
111
+ # VAR2 is fixed to the date when defined
112
+
113
+ # Conditional (?=): Only if undefined
114
+ VAR3 ?= default
115
+ # VAR3 = "default" unless already set
116
+
117
+ # Append (+=): Add to existing
118
+ VAR4 := first
119
+ VAR4 += second
120
+ # VAR4 = "first second"
121
+ ```
122
+
123
+ ## Standard GNU Variables
124
+
125
+ GNU Coding Standards define standard variable names that should be used:
126
+
127
+ ### Compiler and Tools
128
+
129
+ ```makefile
130
+ # C Compiler
131
+ CC ?= gcc
132
+
133
+ # C++ Compiler
134
+ CXX ?= g++
135
+
136
+ # Linker (usually same as CC)
137
+ LD ?= $(CC)
138
+
139
+ # Archiver (for creating .a libraries)
140
+ AR ?= ar
141
+
142
+ # Ranlib (for indexing .a libraries)
143
+ RANLIB ?= ranlib
144
+
145
+ # Install program
146
+ INSTALL ?= install
147
+
148
+ # Install program for data files
149
+ INSTALL_DATA ?= $(INSTALL) -m 644
150
+
151
+ # Install program for executables
152
+ INSTALL_PROGRAM ?= $(INSTALL) -m 755
153
+
154
+ # Remove files
155
+ RM ?= rm -f
156
+
157
+ # Yacc/Bison
158
+ YACC ?= bison -y
159
+
160
+ # Lex/Flex
161
+ LEX ?= flex
162
+
163
+ # pkg-config
164
+ PKG_CONFIG ?= pkg-config
165
+ ```
166
+
167
+ ### Compiler Flags
168
+
169
+ ```makefile
170
+ # C Preprocessor flags (for includes, defines)
171
+ CPPFLAGS ?=
172
+
173
+ # C Compiler flags
174
+ CFLAGS ?= -Wall -Wextra -O2
175
+
176
+ # C++ Compiler flags
177
+ CXXFLAGS ?= -Wall -Wextra -O2
178
+
179
+ # Linker flags (for library paths, etc.)
180
+ LDFLAGS ?=
181
+
182
+ # Libraries to link (-lname)
183
+ LDLIBS ?=
184
+
185
+ # Yacc/Bison flags
186
+ YFLAGS ?=
187
+
188
+ # Lex/Flex flags
189
+ LFLAGS ?=
190
+ ```
191
+
192
+ **Best practices for flags:**
193
+
194
+ ```makefile
195
+ # Preserve user-defined flags
196
+ CFLAGS ?= -Wall -Wextra -O2
197
+ # Add project-specific flags
198
+ CFLAGS += -I./include -I./src
199
+ CFLAGS += -DPROJECT_VERSION=\"$(VERSION)\"
200
+
201
+ # Use pkg-config for libraries
202
+ CFLAGS += $(shell $(PKG_CONFIG) --cflags openssl)
203
+ LDLIBS += $(shell $(PKG_CONFIG) --libs openssl)
204
+ ```
205
+
206
+ ### Installation Directories
207
+
208
+ ```makefile
209
+ # Installation prefix
210
+ PREFIX ?= /usr/local
211
+
212
+ # Executable prefix (usually same as PREFIX)
213
+ EXEC_PREFIX ?= $(PREFIX)
214
+
215
+ # Binary directory
216
+ BINDIR ?= $(EXEC_PREFIX)/bin
217
+
218
+ # Library directory
219
+ LIBDIR ?= $(EXEC_PREFIX)/lib
220
+
221
+ # Include directory
222
+ INCLUDEDIR ?= $(PREFIX)/include
223
+
224
+ # Data root directory
225
+ DATAROOTDIR ?= $(PREFIX)/share
226
+
227
+ # Read-only data directory
228
+ DATADIR ?= $(DATAROOTDIR)
229
+
230
+ # System configuration directory
231
+ SYSCONFDIR ?= $(PREFIX)/etc
232
+
233
+ # Variable data directory
234
+ LOCALSTATEDIR ?= $(PREFIX)/var
235
+
236
+ # Man pages directory
237
+ MANDIR ?= $(DATAROOTDIR)/man
238
+ MAN1DIR ?= $(MANDIR)/man1
239
+ MAN2DIR ?= $(MANDIR)/man2
240
+ # ... etc
241
+
242
+ # Info pages directory
243
+ INFODIR ?= $(DATAROOTDIR)/info
244
+
245
+ # Documentation directory
246
+ DOCDIR ?= $(DATAROOTDIR)/doc/$(PROJECT)
247
+
248
+ # DESTDIR for staged installations (package building)
249
+ DESTDIR ?=
250
+ ```
251
+
252
+ **Usage in install target:**
253
+
254
+ ```makefile
255
+ install: $(TARGET)
256
+ $(INSTALL) -d $(DESTDIR)$(BINDIR)
257
+ $(INSTALL_PROGRAM) $(TARGET) $(DESTDIR)$(BINDIR)/
258
+ $(INSTALL) -d $(DESTDIR)$(LIBDIR)
259
+ $(INSTALL_DATA) lib$(PROJECT).a $(DESTDIR)$(LIBDIR)/
260
+ $(INSTALL) -d $(DESTDIR)$(MAN1DIR)
261
+ $(INSTALL_DATA) docs/$(PROJECT).1 $(DESTDIR)$(MAN1DIR)/
262
+ ```
263
+
264
+ ## Automatic Variables
265
+
266
+ Automatic variables are set by make for each rule:
267
+
268
+ ### Basic Automatic Variables
269
+
270
+ | Variable | Description | Example |
271
+ |----------|-------------|---------|
272
+ | `$@` | Target file name | `hello` in rule for `hello` |
273
+ | `$<` | First prerequisite | `hello.c` in `hello.o: hello.c` |
274
+ | `$^` | All prerequisites (no duplicates) | `hello.o utils.o` |
275
+ | `$+` | All prerequisites (with duplicates) | Rarely needed |
276
+ | `$?` | Prerequisites newer than target | For conditional rebuild |
277
+ | `$*` | Stem of pattern match | `hello` in `%.o: %.c` |
278
+
279
+ ### Directory and File Components
280
+
281
+ | Variable | Description |
282
+ |----------|-------------|
283
+ | `$(@D)` | Directory part of `$@` |
284
+ | `$(@F)` | File part of `$@` |
285
+ | `$(<D)` | Directory part of `$<` |
286
+ | `$(<F)` | File part of `$<` |
287
+ | `$(*D)` | Directory part of `$*` |
288
+ | `$(*F)` | File part of `$*` |
289
+ | `$(^D)` | Directory parts of `$^` |
290
+ | `$(^F)` | File parts of `$^` |
291
+
292
+ ### Examples
293
+
294
+ ```makefile
295
+ # Basic usage
296
+ hello: hello.o utils.o
297
+ $(CC) $(LDFLAGS) $^ -o $@
298
+ # Expands to: gcc -o hello hello.o utils.o
299
+
300
+ # Pattern rule
301
+ %.o: %.c
302
+ $(CC) $(CFLAGS) -c $< -o $@
303
+ # For hello.c: gcc -Wall -c hello.c -o hello.o
304
+
305
+ # Creating output directory
306
+ build/%.o: src/%.c
307
+ @mkdir -p $(@D)
308
+ $(CC) $(CFLAGS) -c $< -o $@
309
+ # $(@D) = "build"
310
+ ```
311
+
312
+ ### Advanced Automatic Variables Usage
313
+
314
+ ```makefile
315
+ # Dependency generation with automatic variables
316
+ $(OBJDIR)/%.o: $(SRCDIR)/%.c
317
+ @mkdir -p $(@D)
318
+ $(CC) $(CPPFLAGS) $(CFLAGS) \
319
+ -MMD -MP \
320
+ -MF $(@:.o=.d) \
321
+ -c $< -o $@
322
+ # $@ = build/obj/main.o
323
+ # $< = src/main.c
324
+ # $(@:.o=.d) = build/obj/main.d
325
+ ```
326
+
327
+ ## Variable Substitution and Functions
328
+
329
+ ### Pattern Substitution
330
+
331
+ ```makefile
332
+ # $(var:pattern=replacement)
333
+ SOURCES := src/main.c src/utils.c src/helper.c
334
+ OBJECTS := $(SOURCES:.c=.o)
335
+ # OBJECTS = src/main.o src/utils.o src/helper.o
336
+
337
+ OBJECTS := $(SOURCES:src/%.c=build/%.o)
338
+ # OBJECTS = build/main.o build/utils.o build/helper.o
339
+ ```
340
+
341
+ ### Text Functions
342
+
343
+ ```makefile
344
+ # $(wildcard pattern)
345
+ SOURCES := $(wildcard src/*.c)
346
+
347
+ # $(patsubst pattern,replacement,text)
348
+ OBJECTS := $(patsubst %.c,%.o,$(SOURCES))
349
+
350
+ # $(filter pattern...,text)
351
+ C_FILES := $(filter %.c,$(SOURCES))
352
+
353
+ # $(filter-out pattern...,text)
354
+ NO_TEST := $(filter-out %_test.c,$(SOURCES))
355
+
356
+ # $(sort list)
357
+ SORTED := $(sort $(SOURCES))
358
+
359
+ # $(dir names...)
360
+ DIRS := $(dir $(SOURCES))
361
+
362
+ # $(notdir names...)
363
+ FILES := $(notdir $(SOURCES))
364
+
365
+ # $(basename names...)
366
+ NAMES := $(basename $(SOURCES))
367
+
368
+ # $(suffix names...)
369
+ EXTS := $(suffix $(SOURCES))
370
+
371
+ # $(addprefix prefix,names...)
372
+ FULL_PATHS := $(addprefix $(SRCDIR)/,$(FILES))
373
+
374
+ # $(addsuffix suffix,names...)
375
+ OBJ_FILES := $(addsuffix .o,$(NAMES))
376
+ ```
377
+
378
+ ### Shell Function
379
+
380
+ ```makefile
381
+ # $(shell command)
382
+ GIT_VERSION := $(shell git describe --tags --always 2>/dev/null)
383
+ DATE := $(shell date +%Y-%m-%d)
384
+ CPU_COUNT := $(shell nproc 2>/dev/null || echo 1)
385
+
386
+ # Use := to evaluate once
387
+ VERSION := $(shell cat VERSION.txt)
388
+ ```
389
+
390
+ ### Conditional Functions
391
+
392
+ ```makefile
393
+ # $(if condition,then-part,else-part)
394
+ DEBUG := 1
395
+ CFLAGS := $(if $(DEBUG),-g -O0,-O2)
396
+
397
+ # $(or conditions...)
398
+ CC := $(or $(CC),gcc)
399
+
400
+ # $(and conditions...)
401
+ BUILD_TESTS := $(and $(ENABLE_TESTS),$(HAVE_CHECK))
402
+ ```
403
+
404
+ ## Environment Variables
405
+
406
+ ### Interaction with Environment
407
+
408
+ ```makefile
409
+ # Make variables override environment by default
410
+ CC = gcc # Overrides CC from environment
411
+
412
+ # Use ?= to respect environment
413
+ CC ?= gcc # Uses environment CC if set
414
+
415
+ # Export variables to recipes
416
+ export CC
417
+ export CFLAGS
418
+
419
+ # Unexport variables
420
+ unexport INTERNAL_VAR
421
+ ```
422
+
423
+ ### Checking Environment Variables
424
+
425
+ ```makefile
426
+ # Check if variable is defined
427
+ ifndef CC
428
+ CC := gcc
429
+ endif
430
+
431
+ # Check if variable is empty
432
+ ifeq ($(strip $(CC)),)
433
+ $(error CC is not defined)
434
+ endif
435
+ ```
436
+
437
+ ## Target-Specific Variables
438
+
439
+ ```makefile
440
+ # Variables can be set for specific targets
441
+ debug: CFLAGS += -g -O0 -DDEBUG
442
+ debug: $(TARGET)
443
+
444
+ release: CFLAGS += -O3 -DNDEBUG
445
+ release: $(TARGET)
446
+
447
+ # Pattern-specific variables
448
+ tests/%: CFLAGS += -DTESTING
449
+ tests/%: LDLIBS += -lcheck
450
+ ```
451
+
452
+ ## Best Practices
453
+
454
+ ### 1. Variable Naming
455
+
456
+ ```makefile
457
+ # Use UPPERCASE for user-overridable variables
458
+ CC ?= gcc
459
+ PREFIX ?= /usr/local
460
+
461
+ # Use lowercase or mixed case for internal variables
462
+ sources := $(wildcard src/*.c)
463
+ target_name := myapp
464
+
465
+ # Use descriptive names
466
+ SOURCES := $(wildcard src/*.c) # Good
467
+ S := $(wildcard src/*.c) # Bad
468
+ ```
469
+
470
+ ### 2. Variable Organization
471
+
472
+ ```makefile
473
+ # Group related variables
474
+ # ============================================
475
+ # User Configuration
476
+ # ============================================
477
+ CC ?= gcc
478
+ CFLAGS ?= -Wall -O2
479
+ PREFIX ?= /usr/local
480
+
481
+ # ============================================
482
+ # Project Configuration
483
+ # ============================================
484
+ PROJECT := myapp
485
+ VERSION := 1.0.0
486
+ SOURCES := $(wildcard src/*.c)
487
+ ```
488
+
489
+ ### 3. Preserve User Flags
490
+
491
+ ```makefile
492
+ # WRONG: Overwrites user flags
493
+ CFLAGS = -Wall -O2
494
+
495
+ # RIGHT: Provides default, respects user override
496
+ CFLAGS ?= -Wall -O2
497
+
498
+ # Add project-specific flags
499
+ CFLAGS += -I./include
500
+ ```
501
+
502
+ ### 4. Use pkg-config
503
+
504
+ ```makefile
505
+ # WRONG: Hardcoded paths
506
+ CFLAGS += -I/usr/include/openssl
507
+ LDLIBS += -L/usr/lib -lssl -lcrypto
508
+
509
+ # RIGHT: Use pkg-config
510
+ PKG_CONFIG ?= pkg-config
511
+ CFLAGS += $(shell $(PKG_CONFIG) --cflags openssl)
512
+ LDLIBS += $(shell $(PKG_CONFIG) --libs openssl)
513
+ ```
514
+
515
+ ### 5. Use := for Computed Values
516
+
517
+ ```makefile
518
+ # WRONG: Re-computes every use (slow)
519
+ SOURCES = $(wildcard src/*.c)
520
+ OBJECTS = $(SOURCES:.c=.o)
521
+
522
+ # RIGHT: Computes once (fast)
523
+ SOURCES := $(wildcard src/*.c)
524
+ OBJECTS := $(SOURCES:.c=.o)
525
+ ```
526
+
527
+ ## Complete Example
528
+
529
+ ```makefile
530
+ # ============================================
531
+ # User-Overridable Variables
532
+ # ============================================
533
+ CC ?= gcc
534
+ CFLAGS ?= -Wall -Wextra -O2
535
+ LDFLAGS ?=
536
+ LDLIBS ?=
537
+ PREFIX ?= /usr/local
538
+ DESTDIR ?=
539
+
540
+ # ============================================
541
+ # pkg-config Dependencies
542
+ # ============================================
543
+ PKG_CONFIG ?= pkg-config
544
+ PACKAGES := openssl zlib
545
+
546
+ CFLAGS += $(shell $(PKG_CONFIG) --cflags $(PACKAGES))
547
+ LDLIBS += $(shell $(PKG_CONFIG) --libs $(PACKAGES))
548
+
549
+ # ============================================
550
+ # Project Configuration
551
+ # ============================================
552
+ PROJECT := myapp
553
+ VERSION := 1.0.0
554
+ SRCDIR := src
555
+ BUILDDIR := build
556
+
557
+ # Computed values (use :=)
558
+ SOURCES := $(wildcard $(SRCDIR)/*.c)
559
+ OBJECTS := $(SOURCES:$(SRCDIR)/%.c=$(BUILDDIR)/%.o)
560
+ DEPENDS := $(OBJECTS:.o=.d)
561
+ TARGET := $(BUILDDIR)/$(PROJECT)
562
+
563
+ # Git version
564
+ GIT_VERSION := $(shell git describe --tags --always 2>/dev/null || echo "unknown")
565
+ CFLAGS += -DVERSION=\"$(GIT_VERSION)\"
566
+
567
+ # ============================================
568
+ # Build Rules
569
+ # ============================================
570
+ all: $(TARGET)
571
+
572
+ $(TARGET): $(OBJECTS)
573
+ @mkdir -p $(@D)
574
+ $(CC) $(LDFLAGS) $^ $(LDLIBS) -o $@
575
+
576
+ $(BUILDDIR)/%.o: $(SRCDIR)/%.c
577
+ @mkdir -p $(@D)
578
+ $(CC) $(CPPFLAGS) $(CFLAGS) -MMD -MP -c $< -o $@
579
+
580
+ -include $(DEPENDS)
581
+
582
+ # ============================================
583
+ # Target-Specific Variables
584
+ # ============================================
585
+ debug: CFLAGS += -g -O0 -DDEBUG
586
+ debug: $(TARGET)
587
+
588
+ release: CFLAGS += -O3 -DNDEBUG -s
589
+ release: $(TARGET)
590
+ ```
591
+
592
+ ## References
593
+
594
+ - [GNU Make Manual - Variables](https://www.gnu.org/software/make/manual/html_node/Using-Variables.html)
595
+ - [GNU Make Manual - Automatic Variables](https://www.gnu.org/software/make/manual/html_node/Automatic-Variables.html)
596
+ - [GNU Coding Standards - Makefile Conventions](https://www.gnu.org/prep/standards/html_node/Makefile-Conventions.html)