@hybridlabor-api/aos 4.7.2 → 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 +309 -101
  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,642 @@
1
+ # Makefile Patterns Guide
2
+
3
+ ## Overview
4
+
5
+ This guide covers pattern rules, static pattern rules, implicit rules, dependency generation, and common Makefile patterns for various project types.
6
+
7
+ ## Pattern Rules
8
+
9
+ Pattern rules use `%` to match filenames and create generic build rules.
10
+
11
+ ### Basic Pattern Rules
12
+
13
+ ```makefile
14
+ # Compile .c files to .o files
15
+ %.o: %.c
16
+ $(CC) $(CPPFLAGS) $(CFLAGS) -c $< -o $@
17
+
18
+ # Generate assembly from C
19
+ %.s: %.c
20
+ $(CC) $(CPPFLAGS) $(CFLAGS) -S $< -o $@
21
+
22
+ # Preprocess C files
23
+ %.i: %.c
24
+ $(CC) $(CPPFLAGS) -E $< -o $@
25
+ ```
26
+
27
+ ### Pattern Rules with Directories
28
+
29
+ ```makefile
30
+ # Source in src/, objects in build/obj/
31
+ build/obj/%.o: src/%.c
32
+ @mkdir -p $(@D)
33
+ $(CC) $(CPPFLAGS) $(CFLAGS) -c $< -o $@
34
+
35
+ # Multiple source directories
36
+ build/obj/%.o: src/%.c
37
+ @mkdir -p $(@D)
38
+ $(CC) -c $< -o $@
39
+
40
+ build/obj/%.o: lib/%.c
41
+ @mkdir -p $(@D)
42
+ $(CC) -c $< -o $@
43
+ ```
44
+
45
+ ### Pattern Rule Variables
46
+
47
+ ```makefile
48
+ # Use stem ($*) in pattern rules
49
+ %.pdf: %.tex
50
+ pdflatex $*
51
+ # Runs: pdflatex report (for report.tex -> report.pdf)
52
+
53
+ # Multiple transformations
54
+ %.html: %.md
55
+ pandoc $< -o $@
56
+
57
+ %.pdf: %.md
58
+ pandoc $< -o $@
59
+ ```
60
+
61
+ ## Static Pattern Rules
62
+
63
+ More efficient and explicit than pattern rules for known file lists.
64
+
65
+ ### Syntax
66
+
67
+ ```makefile
68
+ $(targets): target-pattern: prereq-pattern
69
+ recipe
70
+ ```
71
+
72
+ ### Basic Example
73
+
74
+ ```makefile
75
+ OBJECTS := main.o utils.o helper.o
76
+
77
+ # Static pattern rule
78
+ $(OBJECTS): %.o: %.c
79
+ $(CC) $(CFLAGS) -c $< -o $@
80
+
81
+ # Equivalent to:
82
+ # main.o: main.c
83
+ # $(CC) $(CFLAGS) -c main.c -o main.o
84
+ # utils.o: utils.c
85
+ # $(CC) $(CFLAGS) -c utils.c -o utils.o
86
+ # helper.o: helper.c
87
+ # $(CC) $(CFLAGS) -c helper.c -o helper.o
88
+ ```
89
+
90
+ ### With Directories
91
+
92
+ ```makefile
93
+ SOURCES := $(wildcard src/*.c)
94
+ OBJECTS := $(SOURCES:src/%.c=build/obj/%.o)
95
+
96
+ $(OBJECTS): build/obj/%.o: src/%.c
97
+ @mkdir -p $(@D)
98
+ $(CC) $(CFLAGS) -c $< -o $@
99
+ ```
100
+
101
+ ### Multiple Dependencies
102
+
103
+ ```makefile
104
+ # All objects depend on config.h
105
+ $(OBJECTS): %.o: %.c config.h
106
+ $(CC) $(CFLAGS) -c $< -o $@
107
+
108
+ # Specific objects depend on additional headers
109
+ $(NETWORK_OBJS): %.o: %.c network.h common.h
110
+ $(CC) $(CFLAGS) -c $< -o $@
111
+ ```
112
+
113
+ ## Implicit Rules
114
+
115
+ GNU Make has built-in implicit rules. You can use or override them.
116
+
117
+ ### Common Built-in Rules
118
+
119
+ ```makefile
120
+ # These rules are built into make:
121
+ # %.o: %.c
122
+ # $(CC) $(CPPFLAGS) $(CFLAGS) -c $< -o $@
123
+
124
+ # %.o: %.cpp
125
+ # $(CXX) $(CPPFLAGS) $(CXXFLAGS) -c $< -o $@
126
+
127
+ # %: %.o
128
+ # $(CC) $(LDFLAGS) $^ $(LDLIBS) -o $@
129
+ ```
130
+
131
+ ### Disabling Implicit Rules
132
+
133
+ ```makefile
134
+ # Disable all built-in rules (recommended for explicit Makefiles)
135
+ .SUFFIXES:
136
+
137
+ # Re-enable specific patterns
138
+ .SUFFIXES: .c .o .h
139
+
140
+ # Or disable specific rules
141
+ %.o: %.c
142
+ # Empty recipe disables the built-in rule
143
+ ```
144
+
145
+ ### Custom Implicit Rules
146
+
147
+ ```makefile
148
+ # Add your own implicit rules
149
+ %.o: %.c
150
+ $(CC) $(CPPFLAGS) $(CFLAGS) -MMD -MP -c $< -o $@
151
+
152
+ # Language-specific rules
153
+ %.o: %.cpp
154
+ $(CXX) $(CPPFLAGS) $(CXXFLAGS) -MMD -MP -c $< -o $@
155
+
156
+ %.o: %.s
157
+ $(AS) $(ASFLAGS) -c $< -o $@
158
+ ```
159
+
160
+ ## Dependency Generation
161
+
162
+ ### Manual Dependencies (Avoid)
163
+
164
+ ```makefile
165
+ # Tedious and error-prone
166
+ main.o: main.c common.h utils.h
167
+ utils.o: utils.c utils.h common.h
168
+ helper.o: helper.c helper.h common.h
169
+ ```
170
+
171
+ ### Automatic Dependency Generation
172
+
173
+ **Method 1: Embedded in compilation:**
174
+
175
+ ```makefile
176
+ SOURCES := $(wildcard src/*.c)
177
+ OBJECTS := $(SOURCES:src/%.c=build/obj/%.o)
178
+ DEPENDS := $(OBJECTS:.o=.d)
179
+
180
+ # Generate dependencies during compilation
181
+ build/obj/%.o: src/%.c
182
+ @mkdir -p $(@D)
183
+ $(CC) $(CPPFLAGS) $(CFLAGS) -MMD -MP -c $< -o $@
184
+
185
+ # Include generated dependency files
186
+ -include $(DEPENDS)
187
+ ```
188
+
189
+ **Flags explained:**
190
+ - `-MMD`: Generate dependency file (.d)
191
+ - `-MP`: Add phony targets for headers (prevents errors if header deleted)
192
+ - `-MF file`: Specify dependency file name (optional)
193
+
194
+ **Method 2: Separate dependency generation:**
195
+
196
+ ```makefile
197
+ # Generate dependencies separately
198
+ %.d: %.c
199
+ @$(CC) $(CPPFLAGS) -MM $< | sed 's,\($*\)\.o[ :]*,\1.o $@ : ,g' > $@
200
+
201
+ -include $(DEPENDS)
202
+ ```
203
+
204
+ **Generated .d file example:**
205
+
206
+ ```makefile
207
+ # main.d (generated from main.c)
208
+ build/obj/main.o build/obj/main.d: src/main.c include/common.h \
209
+ include/utils.h
210
+ include/common.h:
211
+ include/utils.h:
212
+ ```
213
+
214
+ ## Common Project Patterns
215
+
216
+ ### Pattern 1: Simple Single-Directory C Project
217
+
218
+ ```makefile
219
+ CC ?= gcc
220
+ CFLAGS ?= -Wall -Wextra -O2
221
+
222
+ TARGET := myapp
223
+ SOURCES := $(wildcard *.c)
224
+ OBJECTS := $(SOURCES:.c=.o)
225
+ DEPENDS := $(OBJECTS:.o=.d)
226
+
227
+ .PHONY: all clean
228
+
229
+ all: $(TARGET)
230
+
231
+ $(TARGET): $(OBJECTS)
232
+ $(CC) $(LDFLAGS) $^ $(LDLIBS) -o $@
233
+
234
+ %.o: %.c
235
+ $(CC) $(CPPFLAGS) $(CFLAGS) -MMD -MP -c $< -o $@
236
+
237
+ -include $(DEPENDS)
238
+
239
+ clean:
240
+ $(RM) $(TARGET) $(OBJECTS) $(DEPENDS)
241
+ ```
242
+
243
+ ### Pattern 2: Multi-Directory C Project
244
+
245
+ ```makefile
246
+ PROJECT := myapp
247
+ CC ?= gcc
248
+ CFLAGS ?= -Wall -Wextra -O2 -Iinclude
249
+
250
+ SRCDIR := src
251
+ INCDIR := include
252
+ BUILDDIR := build
253
+ OBJDIR := $(BUILDDIR)/obj
254
+
255
+ SOURCES := $(wildcard $(SRCDIR)/*.c)
256
+ OBJECTS := $(SOURCES:$(SRCDIR)/%.c=$(OBJDIR)/%.o)
257
+ DEPENDS := $(OBJECTS:.o=.d)
258
+ TARGET := $(BUILDDIR)/$(PROJECT)
259
+
260
+ .PHONY: all clean
261
+
262
+ all: $(TARGET)
263
+
264
+ $(TARGET): $(OBJECTS)
265
+ @mkdir -p $(@D)
266
+ $(CC) $(LDFLAGS) $^ $(LDLIBS) -o $@
267
+
268
+ $(OBJDIR)/%.o: $(SRCDIR)/%.c
269
+ @mkdir -p $(@D)
270
+ $(CC) $(CPPFLAGS) $(CFLAGS) -MMD -MP -c $< -o $@
271
+
272
+ -include $(DEPENDS)
273
+
274
+ clean:
275
+ $(RM) -r $(BUILDDIR)
276
+ ```
277
+
278
+ ### Pattern 3: C++ Project with Libraries
279
+
280
+ ```makefile
281
+ PROJECT := myapp
282
+ CXX ?= g++
283
+ CXXFLAGS ?= -Wall -Wextra -std=c++17 -O2
284
+
285
+ SRCDIR := src
286
+ BUILDDIR := build
287
+ OBJDIR := $(BUILDDIR)/obj
288
+
289
+ # Source files
290
+ SOURCES := $(wildcard $(SRCDIR)/*.cpp)
291
+ OBJECTS := $(SOURCES:$(SRCDIR)/%.cpp=$(OBJDIR)/%.o)
292
+ DEPENDS := $(OBJECTS:.o=.d)
293
+
294
+ # Library
295
+ LIBNAME := $(PROJECT)
296
+ STATIC_LIB := $(BUILDDIR)/lib$(LIBNAME).a
297
+ SHARED_LIB := $(BUILDDIR)/lib$(LIBNAME).so
298
+
299
+ # Executable
300
+ TARGET := $(BUILDDIR)/$(PROJECT)
301
+
302
+ .PHONY: all static shared executable clean
303
+
304
+ all: executable
305
+
306
+ executable: $(TARGET)
307
+
308
+ static: $(STATIC_LIB)
309
+
310
+ shared: $(SHARED_LIB)
311
+
312
+ # Link executable
313
+ $(TARGET): $(OBJECTS)
314
+ @mkdir -p $(@D)
315
+ $(CXX) $(LDFLAGS) $^ $(LDLIBS) -o $@
316
+
317
+ # Create static library
318
+ $(STATIC_LIB): $(OBJECTS)
319
+ @mkdir -p $(@D)
320
+ $(AR) rcs $@ $^
321
+
322
+ # Create shared library
323
+ $(SHARED_LIB): $(OBJECTS)
324
+ @mkdir -p $(@D)
325
+ $(CXX) -shared $^ -o $@
326
+
327
+ # Compile with -fPIC for libraries
328
+ $(OBJDIR)/%.o: $(SRCDIR)/%.cpp
329
+ @mkdir -p $(@D)
330
+ $(CXX) $(CPPFLAGS) $(CXXFLAGS) -fPIC -MMD -MP -c $< -o $@
331
+
332
+ -include $(DEPENDS)
333
+
334
+ clean:
335
+ $(RM) -r $(BUILDDIR)
336
+ ```
337
+
338
+ ### Pattern 4: Mixed C/C++ Project
339
+
340
+ ```makefile
341
+ PROJECT := mixed
342
+ CC ?= gcc
343
+ CXX ?= g++
344
+ CFLAGS ?= -Wall -O2
345
+ CXXFLAGS ?= -Wall -O2 -std=c++17
346
+
347
+ SRCDIR := src
348
+ BUILDDIR := build
349
+ OBJDIR := $(BUILDDIR)/obj
350
+
351
+ # Separate C and C++ sources
352
+ C_SOURCES := $(wildcard $(SRCDIR)/*.c)
353
+ CXX_SOURCES := $(wildcard $(SRCDIR)/*.cpp)
354
+
355
+ # Separate object files
356
+ C_OBJECTS := $(C_SOURCES:$(SRCDIR)/%.c=$(OBJDIR)/%.o)
357
+ CXX_OBJECTS := $(CXX_SOURCES:$(SRCDIR)/%.cpp=$(OBJDIR)/%.o)
358
+
359
+ ALL_OBJECTS := $(C_OBJECTS) $(CXX_OBJECTS)
360
+ DEPENDS := $(ALL_OBJECTS:.o=.d)
361
+
362
+ TARGET := $(BUILDDIR)/$(PROJECT)
363
+
364
+ .PHONY: all clean
365
+
366
+ all: $(TARGET)
367
+
368
+ # Link with C++ compiler (for C++ standard library)
369
+ $(TARGET): $(ALL_OBJECTS)
370
+ @mkdir -p $(@D)
371
+ $(CXX) $(LDFLAGS) $^ $(LDLIBS) -o $@
372
+
373
+ # Compile C sources
374
+ $(OBJDIR)/%.o: $(SRCDIR)/%.c
375
+ @mkdir -p $(@D)
376
+ $(CC) $(CPPFLAGS) $(CFLAGS) -MMD -MP -c $< -o $@
377
+
378
+ # Compile C++ sources
379
+ $(OBJDIR)/%.o: $(SRCDIR)/%.cpp
380
+ @mkdir -p $(@D)
381
+ $(CXX) $(CPPFLAGS) $(CXXFLAGS) -MMD -MP -c $< -o $@
382
+
383
+ -include $(DEPENDS)
384
+
385
+ clean:
386
+ $(RM) -r $(BUILDDIR)
387
+ ```
388
+
389
+ ### Pattern 5: Go Project
390
+
391
+ ```makefile
392
+ PROJECT := myapp
393
+ GO ?= go
394
+ GOFLAGS ?=
395
+ PREFIX ?= /usr/local
396
+
397
+ # Version from git
398
+ VERSION := $(shell git describe --tags --always --dirty 2>/dev/null || echo "dev")
399
+ LDFLAGS := -ldflags "-X main.version=$(VERSION)"
400
+
401
+ # Source files
402
+ SOURCES := $(shell find . -name '*.go' -not -path './vendor/*')
403
+ # go.sum may not exist in modules with no external dependencies
404
+ GO_SUM := $(wildcard go.sum)
405
+ TARGET := $(PROJECT)
406
+
407
+ .PHONY: all build install test clean fmt lint mod-tidy
408
+
409
+ all: build
410
+
411
+ build: $(TARGET)
412
+
413
+ $(TARGET): $(SOURCES) go.mod $(GO_SUM)
414
+ $(GO) build $(GOFLAGS) $(LDFLAGS) -o $@ ./cmd/$(PROJECT)
415
+
416
+ install: $(TARGET)
417
+ install -d $(DESTDIR)$(PREFIX)/bin
418
+ install -m 755 $(TARGET) $(DESTDIR)$(PREFIX)/bin/
419
+
420
+ test:
421
+ $(GO) test -v ./...
422
+
423
+ clean:
424
+ $(RM) $(TARGET)
425
+ $(GO) clean
426
+
427
+ fmt:
428
+ $(GO) fmt ./...
429
+
430
+ lint:
431
+ golangci-lint run
432
+
433
+ mod-tidy:
434
+ $(GO) mod tidy
435
+ ```
436
+
437
+ ### Pattern 6: Python Project
438
+
439
+ ```makefile
440
+ PROJECT := mypackage
441
+ PYTHON ?= python3
442
+ PIP ?= $(PYTHON) -m pip
443
+
444
+ .PHONY: all build install develop test lint format clean
445
+
446
+ all: build
447
+
448
+ build:
449
+ $(PYTHON) -m build
450
+
451
+ install:
452
+ $(PIP) install .
453
+
454
+ develop:
455
+ $(PIP) install -e .[dev]
456
+
457
+ test:
458
+ $(PYTHON) -m pytest tests/ -v
459
+
460
+ lint:
461
+ $(PYTHON) -m flake8 src/ tests/
462
+ $(PYTHON) -m pylint src/
463
+
464
+ format:
465
+ $(PYTHON) -m black src/ tests/
466
+ $(PYTHON) -m isort src/ tests/
467
+
468
+ clean:
469
+ $(RM) -r build/ dist/ *.egg-info/
470
+ $(RM) -r .pytest_cache/ .coverage htmlcov/
471
+ find . -type d -name '__pycache__' -exec rm -r {} +
472
+ find . -type f -name '*.pyc' -delete
473
+ ```
474
+
475
+ ### Pattern 7: Multi-Binary Project
476
+
477
+ ```makefile
478
+ PROJECT := tools
479
+ CC ?= gcc
480
+ CFLAGS ?= -Wall -Wextra -O2
481
+
482
+ SRCDIR := src
483
+ BUILDDIR := build
484
+ OBJDIR := $(BUILDDIR)/obj
485
+
486
+ # Multiple programs
487
+ PROGRAMS := tool1 tool2 tool3
488
+ TARGETS := $(addprefix $(BUILDDIR)/,$(PROGRAMS))
489
+
490
+ # Common library
491
+ LIBSRC := $(wildcard $(SRCDIR)/common/*.c)
492
+ LIBOBJ := $(LIBSRC:$(SRCDIR)/%.c=$(OBJDIR)/%.o)
493
+
494
+ .PHONY: all clean $(PROGRAMS)
495
+
496
+ all: $(TARGETS)
497
+
498
+ # Individual program targets
499
+ tool1: $(BUILDDIR)/tool1
500
+ tool2: $(BUILDDIR)/tool2
501
+ tool3: $(BUILDDIR)/tool3
502
+
503
+ # Build each program
504
+ $(BUILDDIR)/tool1: $(OBJDIR)/tool1.o $(LIBOBJ)
505
+ @mkdir -p $(@D)
506
+ $(CC) $(LDFLAGS) $^ $(LDLIBS) -o $@
507
+
508
+ $(BUILDDIR)/tool2: $(OBJDIR)/tool2.o $(LIBOBJ)
509
+ @mkdir -p $(@D)
510
+ $(CC) $(LDFLAGS) $^ $(LDLIBS) -o $@
511
+
512
+ $(BUILDDIR)/tool3: $(OBJDIR)/tool3.o $(LIBOBJ)
513
+ @mkdir -p $(@D)
514
+ $(CC) $(LDFLAGS) $^ $(LDLIBS) -o $@
515
+
516
+ # Compile pattern
517
+ $(OBJDIR)/%.o: $(SRCDIR)/%.c
518
+ @mkdir -p $(@D)
519
+ $(CC) $(CPPFLAGS) $(CFLAGS) -c $< -o $@
520
+
521
+ clean:
522
+ $(RM) -r $(BUILDDIR)
523
+ ```
524
+
525
+ ### Pattern 8: Docker Integration
526
+
527
+ ```makefile
528
+ PROJECT := myapp
529
+ VERSION := 1.0.0
530
+ REGISTRY := docker.io
531
+ IMAGE := $(REGISTRY)/$(PROJECT):$(VERSION)
532
+ IMAGE_LATEST := $(REGISTRY)/$(PROJECT):latest
533
+
534
+ .PHONY: all build docker-build docker-push docker-run docker-clean
535
+
536
+ all: build
537
+
538
+ build:
539
+ $(MAKE) -f Makefile.app
540
+
541
+ docker-build:
542
+ docker build -t $(IMAGE) -t $(IMAGE_LATEST) .
543
+
544
+ docker-push: docker-build
545
+ docker push $(IMAGE)
546
+ docker push $(IMAGE_LATEST)
547
+
548
+ docker-run: docker-build
549
+ docker run --rm -it $(IMAGE)
550
+
551
+ docker-clean:
552
+ docker rmi $(IMAGE) $(IMAGE_LATEST) 2>/dev/null || true
553
+ ```
554
+
555
+ ## Advanced Patterns
556
+
557
+ ### Pattern: Recursive Directory Processing
558
+
559
+ ```makefile
560
+ # Find all .c files recursively
561
+ SOURCES := $(shell find src -name '*.c')
562
+
563
+ # Mirror directory structure in build/
564
+ OBJECTS := $(SOURCES:src/%.c=build/obj/%.o)
565
+
566
+ # Create all necessary directories
567
+ OBJDIRS := $(sort $(dir $(OBJECTS)))
568
+
569
+ $(OBJDIRS):
570
+ @mkdir -p $@
571
+
572
+ # Order-only prerequisite: directories must exist
573
+ $(OBJECTS): | $(OBJDIRS)
574
+
575
+ build/obj/%.o: src/%.c
576
+ $(CC) $(CFLAGS) -c $< -o $@
577
+ ```
578
+
579
+ ### Pattern: Multiple Build Configurations
580
+
581
+ ```makefile
582
+ BUILD_TYPES := debug release profile
583
+
584
+ .PHONY: all $(BUILD_TYPES) clean
585
+
586
+ all: release
587
+
588
+ # Target-specific variables
589
+ debug: CFLAGS += -g -O0 -DDEBUG
590
+ debug: TARGET := build/debug/$(PROJECT)
591
+ debug: $(TARGET)
592
+
593
+ release: CFLAGS += -O3 -DNDEBUG
594
+ release: TARGET := build/release/$(PROJECT)
595
+ release: $(TARGET)
596
+
597
+ profile: CFLAGS += -pg -O2
598
+ profile: TARGET := build/profile/$(PROJECT)
599
+ profile: $(TARGET)
600
+
601
+ # Generic build rule
602
+ $(TARGET): $(OBJECTS)
603
+ @mkdir -p $(@D)
604
+ $(CC) $(LDFLAGS) $^ $(LDLIBS) -o $@
605
+ ```
606
+
607
+ ### Pattern: Parallel Sub-Builds
608
+
609
+ ```makefile
610
+ SUBDIRS := lib1 lib2 lib3
611
+
612
+ .PHONY: all $(SUBDIRS)
613
+
614
+ # Build subdirs in parallel: make -j4
615
+ all: $(SUBDIRS)
616
+
617
+ $(SUBDIRS):
618
+ $(MAKE) -C $@
619
+
620
+ # Dependencies between subdirs
621
+ lib2: lib1
622
+ lib3: lib1 lib2
623
+ ```
624
+
625
+ ## Best Practices
626
+
627
+ 1. **Use static pattern rules** for known file lists (more efficient)
628
+ 2. **Generate dependencies automatically** (-MMD -MP)
629
+ 3. **Create directories with order-only prerequisites**
630
+ 4. **Disable built-in rules** (.SUFFIXES:) for explicit Makefiles
631
+ 5. **Use pattern rules** for generic transformations
632
+ 6. **Mirror source structure** in build directory
633
+ 7. **Separate C and C++ compilation** in mixed projects
634
+ 8. **Use -fPIC** when building shared libraries
635
+ 9. **Include generated dependencies** with -include
636
+ 10. **Test patterns** with make -n (dry run)
637
+
638
+ ## References
639
+
640
+ - [GNU Make Manual - Pattern Rules](https://www.gnu.org/software/make/manual/html_node/Pattern-Rules.html)
641
+ - [GNU Make Manual - Static Pattern Rules](https://www.gnu.org/software/make/manual/html_node/Static-Pattern.html)
642
+ - [GNU Make Manual - Automatic Prerequisites](https://www.gnu.org/software/make/manual/html_node/Automatic-Prerequisites.html)