This is a maintenance fork
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

346 lines
9.8 KiB

1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
  1. #-*-mode:makefile-gmake;indent-tabs-mode:t;tab-width:8;coding:utf-8-*-┐
  2. #───vi: set et ft=make ts=8 tw=8 fenc=utf-8 :vi───────────────────────┘
  3. #
  4. # SYNOPSIS
  5. #
  6. # Freestanding Hermetically-Sealed Monolithic Repository
  7. #
  8. # REQUIREMENTS
  9. #
  10. # You can run your programs on any operating system, but you have
  11. # to build them on Linux 2.6+ (or WSL) using GNU Make. A modern C
  12. # compiler that's statically-linked comes included as a courtesy.
  13. #
  14. # EXAMPLES
  15. #
  16. # # build and run everything
  17. # make -j8 -O
  18. # make -j8 -O MODE=dbg
  19. # make -j8 -O MODE=opt
  20. # make -j8 -O MODE=rel
  21. # make -j8 -O MODE=tiny
  22. #
  23. # # build individual target
  24. # make -j8 -O o//examples/hello.com
  25. # o//examples/hello.com
  26. #
  27. # # view source
  28. # less examples/hello.c
  29. #
  30. # # view binary
  31. # o//tool/viz/bing.com o//examples/hello.com |
  32. # o//tool/viz/fold.com
  33. #
  34. # # view transitive closure of legalese
  35. # o//tool/viz/bing.com -n o//examples/hello.com |
  36. # o//tool/viz/fold.com
  37. #
  38. # # basic debugging
  39. # make -j8 -O MODE=dbg o/dbg/examples/crashreport.com
  40. # o/dbg/examples/crashreport.com
  41. # less examples/crashreport.c
  42. #
  43. # # extremely tiny binaries (scout's honor escape hatch)
  44. # # please pay the $1k for commercial license if you can
  45. # make -j8 -O MODE=tiny \
  46. # LDFLAGS+=-s \
  47. # CPPFLAGS+=-DIM_FEELING_NAUGHTY \
  48. # CPPFLAGS+=-DSUPPORT_VECTOR=0b00000001 \
  49. # o/tiny/examples/hello4.elf
  50. # ls -hal o/tiny/examples/hello4.elf
  51. # o/tiny/examples/hello4.elf
  52. #
  53. # TROUBLESHOOTING
  54. #
  55. # make -j8 -O SILENT=0 o//examples/hello.com
  56. # make o//examples/life.elf -pn |& less
  57. # etc.
  58. #
  59. # SEE ALSO
  60. #
  61. # build/config.mk
  62. SHELL = /bin/sh
  63. HOSTS ?= freebsd openbsd alpine
  64. SANITY := $(shell build/sanitycheck $$PPID)
  65. GNUMAKEFLAGS += --output-sync
  66. .SUFFIXES:
  67. .DELETE_ON_ERROR:
  68. .FEATURES: output-sync
  69. .PHONY: all o bins check test depend tags
  70. all: o
  71. o: o/$(MODE)/ape \
  72. o/$(MODE)/dsp \
  73. o/$(MODE)/net \
  74. o/$(MODE)/libc \
  75. o/$(MODE)/test \
  76. o/$(MODE)/tool \
  77. o/$(MODE)/examples \
  78. o/$(MODE)/third_party
  79. PKGS =
  80. -include ~/.cosmo.mk #──No.1
  81. include build/functions.mk #─┐
  82. include build/definitions.mk # ├──meta
  83. include build/config.mk # │
  84. include build/rules.mk # │
  85. include build/online.mk # │
  86. include libc/stubs/stubs.mk #─┘
  87. include libc/nexgen32e/nexgen32e.mk #─┐
  88. include libc/intrin/intrin.mk # │
  89. include libc/linux/linux.mk # │
  90. include libc/math/math.mk # ├──metal
  91. include libc/tinymath/tinymath.mk # │
  92. include third_party/compiler_rt/compiler_rt.mk # │
  93. include libc/bits/bits.mk # │
  94. include libc/str/str.mk # │
  95. include third_party/xed/xed.mk # │
  96. include third_party/zlib/zlib.mk # │
  97. include libc/elf/elf.mk # │
  98. include ape/lib/apelib.mk # │
  99. include ape/ape.mk #─┘
  100. include libc/sysv/sysv.mk #─┐
  101. include libc/nt/nt.mk # ├──system
  102. include libc/fmt/fmt.mk # │
  103. include libc/rand/rand.mk #─┘
  104. include libc/calls/calls.mk #─┐
  105. include libc/runtime/runtime.mk # ├──systems
  106. include libc/crt/crt.mk # │
  107. include libc/unicode/unicode.mk # │
  108. include third_party/dlmalloc/dlmalloc.mk # │
  109. include libc/mem/mem.mk # │
  110. include libc/ohmyplus/ohmyplus.mk # │
  111. include libc/zipos/zipos.mk # │
  112. include third_party/gdtoa/gdtoa.mk # │
  113. include libc/time/time.mk # │
  114. include libc/alg/alg.mk # │
  115. include libc/calls/hefty/hefty.mk # │
  116. include libc/stdio/stdio.mk # │
  117. include third_party/f2c/f2c.mk # │
  118. include third_party/blas/blas.mk # │
  119. include net/net.mk # │
  120. include libc/log/log.mk # │
  121. include dsp/core/core.mk # │
  122. include libc/x/x.mk # │
  123. include third_party/stb/stb.mk # │
  124. include dsp/scale/scale.mk # │
  125. include dsp/mpeg/mpeg.mk # │
  126. include dsp/dsp.mk # │
  127. include third_party/musl/musl.mk # │
  128. include third_party/getopt/getopt.mk # │
  129. include libc/libc.mk #─┘
  130. include libc/sock/sock.mk #─┐
  131. include dsp/tty/tty.mk # ├──online
  132. include libc/dns/dns.mk # │
  133. include libc/crypto/crypto.mk # │
  134. include net/http/http.mk #─┘
  135. include third_party/lemon/lemon.mk
  136. include third_party/duktape/duktape.mk
  137. include third_party/regex/regex.mk
  138. include third_party/ctags/ctags.mk
  139. include third_party/third_party.mk
  140. include libc/testlib/testlib.mk
  141. include tool/viz/lib/vizlib.mk
  142. include examples/examples.mk
  143. include third_party/lz4cli/lz4cli.mk
  144. include tool/build/lib/buildlib.mk
  145. include third_party/chibicc/chibicc.mk
  146. include third_party/chibicc/test/test.mk
  147. include tool/build/emucrt/emucrt.mk
  148. include tool/build/emubin/emubin.mk
  149. include tool/build/build.mk
  150. include tool/calc/calc.mk
  151. include tool/decode/lib/decodelib.mk
  152. include tool/decode/decode.mk
  153. include tool/hash/hash.mk
  154. include tool/net/net.mk
  155. include tool/viz/viz.mk
  156. include tool/tool.mk
  157. include test/libc/alg/test.mk
  158. include test/libc/tinymath/test.mk
  159. include test/libc/math/test.mk
  160. include test/libc/intrin/test.mk
  161. include test/libc/mem/test.mk
  162. include test/libc/nexgen32e/test.mk
  163. include test/libc/runtime/test.mk
  164. include test/libc/sock/test.mk
  165. include test/libc/bits/test.mk
  166. include test/libc/crypto/test.mk
  167. include test/libc/str/test.mk
  168. include test/libc/unicode/test.mk
  169. include test/libc/calls/test.mk
  170. include test/libc/x/test.mk
  171. include test/libc/xed/test.mk
  172. include test/libc/fmt/test.mk
  173. include test/libc/dns/test.mk
  174. include test/libc/rand/test.mk
  175. include test/libc/time/test.mk
  176. include test/libc/stdio/test.mk
  177. include test/libc/release/test.mk
  178. include test/libc/test.mk
  179. include test/ape/lib/test.mk
  180. include test/ape/test.mk
  181. include test/net/http/test.mk
  182. include test/net/test.mk
  183. include test/tool/build/lib/test.mk
  184. include test/tool/build/test.mk
  185. include test/tool/viz/lib/test.mk
  186. include test/tool/viz/test.mk
  187. include test/tool/test.mk
  188. include test/dsp/core/test.mk
  189. include test/dsp/scale/test.mk
  190. include test/dsp/tty/test.mk
  191. include test/dsp/test.mk
  192. include examples/package/lib/build.mk
  193. include examples/package/build.mk
  194. #-φ-examples/package/new.sh
  195. include test/test.mk
  196. OBJS = $(foreach x,$(PKGS),$($(x)_OBJS))
  197. SRCS = $(foreach x,$(PKGS),$($(x)_SRCS))
  198. HDRS = $(foreach x,$(PKGS),$($(x)_HDRS))
  199. BINS = $(foreach x,$(PKGS),$($(x)_BINS))
  200. TESTS = $(foreach x,$(PKGS),$($(x)_TESTS))
  201. CHECKS = $(foreach x,$(PKGS),$($(x)_CHECKS))
  202. bins: $(BINS)
  203. check: $(CHECKS)
  204. test: $(TESTS)
  205. depend: o/$(MODE)/depend
  206. tags: TAGS HTAGS
  207. o/$(MODE)/.x:
  208. @$(MKDIR) $(@D) && touch $@
  209. o/$(MODE)/srcs.txt: o/$(MODE)/.x $(MAKEFILES) $(call uniq,$(foreach x,$(SRCS),$(dir $(x))))
  210. $(file >$@) $(foreach x,$(SRCS),$(file >>$@,$(x)))
  211. o/$(MODE)/hdrs.txt: o/$(MODE)/.x $(MAKEFILES) $(call uniq,$(foreach x,$(HDRS),$(dir $(x))))
  212. $(file >$@) $(foreach x,$(HDRS),$(file >>$@,$(x)))
  213. o/$(MODE)/depend: o/$(MODE)/.x o/$(MODE)/srcs.txt o/$(MODE)/hdrs.txt $(SRCS) $(HDRS)
  214. @build/mkdeps -o $@ -r o/$(MODE)/ o/$(MODE)/srcs.txt o/$(MODE)/hdrs.txt
  215. TAGS: o/$(MODE)/srcs.txt $(SRCS)
  216. @rm -f $@
  217. @ACTION=TAGS TARGET=$@ build/do $(TAGS) $(TAGSFLAGS) -L $< -o $@
  218. HTAGS: o/$(MODE)/hdrs.txt $(HDRS)
  219. @rm -f $@
  220. @ACTION=TAGS TARGET=$@ build/do build/htags -L $< -o $@
  221. loc: o/$(MODE)/tool/build/summy.com
  222. find -name \*.h -or -name \*.c -or -name \*.S | \
  223. $(XARGS) wc -l | grep total | awk '{print $$1}' | $<
  224. COSMOPOLITAN_OBJECTS = \
  225. APE_LIB \
  226. LIBC \
  227. LIBC_ALG \
  228. LIBC_BITS \
  229. LIBC_CALLS \
  230. LIBC_CALLS_HEFTY \
  231. LIBC_CRYPTO \
  232. LIBC_DNS \
  233. LIBC_ELF \
  234. LIBC_FMT \
  235. LIBC_INTRIN \
  236. LIBC_LOG \
  237. LIBC_MEM \
  238. LIBC_NEXGEN32E \
  239. LIBC_NT \
  240. LIBC_OHMYPLUS \
  241. LIBC_RAND \
  242. LIBC_RUNTIME \
  243. LIBC_SOCK \
  244. LIBC_STDIO \
  245. LIBC_STR \
  246. LIBC_STUBS \
  247. LIBC_SYSV \
  248. LIBC_TIME \
  249. LIBC_TINYMATH \
  250. LIBC_UNICODE \
  251. LIBC_X \
  252. LIBC_ZIPOS \
  253. THIRD_PARTY_COMPILER_RT \
  254. THIRD_PARTY_DLMALLOC \
  255. THIRD_PARTY_GDTOA \
  256. THIRD_PARTY_GETOPT \
  257. THIRD_PARTY_MUSL \
  258. THIRD_PARTY_REGEX
  259. COSMOPOLITAN_HEADERS = \
  260. LIBC \
  261. LIBC_ALG \
  262. LIBC_BITS \
  263. LIBC_CALLS \
  264. LIBC_CRYPTO \
  265. LIBC_DNS \
  266. LIBC_ELF \
  267. LIBC_FMT \
  268. LIBC_INTRIN \
  269. LIBC_LOG \
  270. LIBC_MEM \
  271. LIBC_NEXGEN32E \
  272. LIBC_NT \
  273. LIBC_OHMYPLUS \
  274. LIBC_RAND \
  275. LIBC_RUNTIME \
  276. LIBC_SOCK \
  277. LIBC_STDIO \
  278. LIBC_STR \
  279. LIBC_SYSV \
  280. LIBC_TIME \
  281. LIBC_TINYMATH \
  282. LIBC_UNICODE \
  283. LIBC_X \
  284. LIBC_ZIPOS \
  285. THIRD_PARTY_DLMALLOC \
  286. THIRD_PARTY_GDTOA \
  287. THIRD_PARTY_GETOPT \
  288. THIRD_PARTY_MUSL \
  289. THIRD_PARTY_ZLIB \
  290. THIRD_PARTY_REGEX
  291. o/$(MODE)/cosmopolitan.a: $(filter-out o/libc/stubs/exit11.o,$(foreach x,$(COSMOPOLITAN_OBJECTS),$($(x)_OBJS)))
  292. o/cosmopolitan.h: \
  293. o/$(MODE)/tool/build/rollup.com \
  294. libc/integral/normalize.inc \
  295. $(foreach x,$(COSMOPOLITAN_HEADERS),$($(x)_HDRS))
  296. @ACTION=ROLLUP TARGET=$@ build/do $^ >$@
  297. o/cosmopolitan.html: o/$(MODE)/third_party/chibicc/chibicc.com.dbg
  298. o/$(MODE)/third_party/chibicc/chibicc.com.dbg -J -fno-common -include libc/integral/normalize.inc -o $@ $(filter-out %.s,$(foreach x,$(COSMOPOLITAN_OBJECTS),$($(x)_SRCS)))
  299. # UNSPECIFIED PREREQUISITES TUTORIAL
  300. #
  301. # A build rule must exist for all files that make needs to consider in
  302. # order to build the requested goal. That includes input source files,
  303. # even if the rule is empty and does nothing. Otherwise, the .DEFAULT
  304. # rule gets triggered.
  305. #
  306. # This is a normal and neecssary behavior when source files get deleted.
  307. # The build reacts automatically to this happening, by simply deleting
  308. # and regenerating the dependency graph; so we can safely use wildcard.
  309. #
  310. # This is abnormal if it needs to keep doing that repeatedly. That can
  311. # only mean the build config is broken.
  312. #
  313. # Also note that a suboptimal in-between state may exist, where running
  314. # `make -pn` reveals rules being generated with the .DEFAULT target, but
  315. # never get executed since they're not members of the transitive closure
  316. # of `make all`. In that case the build config could be improved.
  317. %.mk:
  318. ~/.cosmo.mk:
  319. $(SRCS):
  320. $(HDRS):
  321. .DEFAULT:
  322. @echo >&2
  323. @echo NOTE: deleting o/$(MODE)/depend because of an unspecified prerequisite: $@ >&2
  324. @echo >&2
  325. rm -f o/$(MODE)/depend
  326. -include o/$(MODE)/depend