cosmopolitan/examples/package/build.mk
Justine Tunney 2d80bbc802 Get binaries closer to running without an o/s
blinkenlights now does a pretty good job emulating what happens when
binaries boot from BIOS into long mode. So it's been much easier to
debug the bare metal process and wrinkle out many issues.
2020-11-02 19:12:47 -08:00

73 lines
2.3 KiB
Makefile

#-*-mode:makefile-gmake;indent-tabs-mode:t;tab-width:8;coding:utf-8-*-┐
#───vi: set et ft=make ts=8 tw=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
#
# 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)
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) \
$(EXAMPLES_PACKAGE_SRCS:%=o/$(MODE)/%.zip.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_STDIO \
LIBC_STUBS \
LIBC_TINYMATH
# Evaluates the set of transitive package dependencies.
EXAMPLES_PACKAGE_DEPS := \
$(call uniq,$(foreach x,$(EXAMPLES_PACKAGE_DIRECTDEPS),$($(x))))
$(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)
@$(APELINK)
# Invalidates objects in package when makefile is edited.
$(EXAMPLES_PACKAGE_OBJS): examples/package/build.mk
# Creates target building everything in package and subpackages.
.PHONY: o/$(MODE)/examples/package
o/$(MODE)/examples/package: \
o/$(MODE)/examples/package/lib \
$(EXAMPLES_PACKAGE_BINS)