cosmopolitan/examples/package/BUILD.mk

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

74 lines
2.3 KiB
Makefile
Raw Normal View History

#-*-mode:makefile-gmake;indent-tabs-mode:t;tab-width:8;coding:utf-8-*-┐
#── vi: set noet ft=make ts=8 sw=8 fenc=utf-8 :vi ────────────────────┘
#
# SYNOPSIS
#
# Your package build config for executable programs
#
# DESCRIPTION
#
# We assume each .c file in this directory has a main() function, so
# that it becomes as easy as possible to write lots of tiny programs
#
# EXAMPLE
#
# make o//examples/package
# o/examples/package/program.com
2020-06-16 02:59:12 +00:00
#
# AUTHORS
#
# %AUTHOR%
PKGS += EXAMPLES_PACKAGE
# Reads into memory the list of files in this directory.
EXAMPLES_PACKAGE_FILES := $(wildcard examples/package/*)
# Defines sets of files without needing further iops.
EXAMPLES_PACKAGE_SRCS = $(filter %.c,$(EXAMPLES_PACKAGE_FILES))
EXAMPLES_PACKAGE_HDRS = $(filter %.h,$(EXAMPLES_PACKAGE_FILES))
EXAMPLES_PACKAGE_COMS = $(EXAMPLES_PACKAGE_SRCS:%.c=o/$(MODE)/%.com)
2020-06-16 02:59:12 +00:00
EXAMPLES_PACKAGE_BINS = \
$(EXAMPLES_PACKAGE_COMS) \
$(EXAMPLES_PACKAGE_COMS:%=%.dbg)
# Remaps source file names to object names.
# Also asks a wildcard rule to automatically run tool/build/zipobj.c
EXAMPLES_PACKAGE_OBJS = \
$(EXAMPLES_PACKAGE_SRCS:%.c=o/$(MODE)/%.o)
# Lists packages whose symbols are or may be directly referenced here.
# Note that linking stubs is always a good idea due to synthetic code.
EXAMPLES_PACKAGE_DIRECTDEPS = \
EXAMPLES_PACKAGE_LIB \
LIBC_INTRIN \
Make malloc() go 200x faster If pthread_create() is linked into the binary, then the cosmo runtime will create an independent dlmalloc arena for each core. Whenever the malloc() function is used it will index `g_heaps[sched_getcpu() / 2]` to find the arena with the greatest hyperthread / numa locality. This may be configured via an environment variable. For example if you say `export COSMOPOLITAN_HEAP_COUNT=1` then you can restore the old ways. Your process may be configured to have anywhere between 1 - 128 heaps We need this revision because it makes multithreaded C++ applications faster. For example, an HTTP server I'm working on that makes extreme use of the STL went from 16k to 2000k requests per second, after this change was made. To understand why, try out the malloc_test benchmark which calls malloc() + realloc() in a loop across many threads, which sees a a 250x improvement in process clock time and 200x on wall time The tradeoff is this adds ~25ns of latency to individual malloc calls compared to MODE=tiny, once the cosmo runtime has transitioned into a fully multi-threaded state. If you don't need malloc() to be scalable then cosmo provides many options for you. For starters the heap count variable above can be set to put the process back in single heap mode plus you can go even faster still, if you include tinymalloc.inc like many of the programs in tool/build/.. are already doing since that'll shave tens of kb off your binary footprint too. Theres also MODE=tiny which is configured to use just 1 plain old dlmalloc arena by default Another tradeoff is we need more memory now (except in MODE=tiny), to track the provenance of memory allocation. This is so allocations can be freely shared across threads, and because OSes can reschedule code to different CPUs at any time.
2024-06-05 08:31:21 +00:00
LIBC_MEM \
LIBC_STDIO \
LIBC_TINYMATH
# Evaluates the set of transitive package dependencies.
EXAMPLES_PACKAGE_DEPS := \
$(call uniq,$(foreach x,$(EXAMPLES_PACKAGE_DIRECTDEPS),$($(x))))
2020-06-16 02:59:12 +00:00
$(EXAMPLES_PACKAGE_A).pkg: \
$(EXAMPLES_PACKAGE_OBJS) \
$(foreach x,$(EXAMPLES_PACKAGE_DIRECTDEPS),$($(x)_A).pkg)
# Specifies how to build programs as ELF binaries with DWARF debug info.
# @see build/rules.mk for definition of rule that does .com.dbg -> .com
o/$(MODE)/examples/package/%.com.dbg: \
$(EXAMPLES_PACKAGE_DEPS) \
o/$(MODE)/examples/package/%.o \
$(CRT) \
$(APE_NO_MODIFY_SELF)
2020-06-16 02:59:12 +00:00
@$(APELINK)
# Invalidates objects in package when makefile is edited.
$(EXAMPLES_PACKAGE_OBJS): examples/package/BUILD.mk
2020-06-16 02:59:12 +00:00
# Creates target building everything in package and subpackages.
.PHONY: o/$(MODE)/examples/package
o/$(MODE)/examples/package: \
o/$(MODE)/examples/package/lib \
2020-06-16 02:59:12 +00:00
$(EXAMPLES_PACKAGE_BINS)