Add further clarity to example package

This commit is contained in:
Justine Tunney 2020-06-18 16:14:47 -07:00
parent d2b20422c8
commit a2c2d14100
6 changed files with 40 additions and 14 deletions

View file

@ -20,7 +20,7 @@
# EXAMPLE
#
# make o//examples/package/lib # build library w/ sanity checks
# at t o//examples/package/lib/lib.a
# ar t o//examples/package/lib/lib.a
#
# AUTHORS
#
@ -28,19 +28,22 @@
PKGS += EXAMPLES_PACKAGE_LIB
# Declares build package.
# Other packages may list this variable in their deps list.
# Please note package relationships aren't allowed to be cyclic.
# Declares package i.e. library w/ transitive dependencies.
# We define packages as a thing that lumps similar sources.
# It's needed, so linkage can have a higher level overview.
# Mostly due to there being over 9,000 objects in the repo.
EXAMPLES_PACKAGE_LIB = \
$(EXAMPLES_PACKAGE_LIB_A_DEPS) \
$(EXAMPLES_PACKAGE_LIB_A)
# While build configs might seem somewhat complicated but rest
# assured they're mostly maintainence free, thanks to wildcard
EXAMPLES_PACKAGE_LIB_A_FILES := $(wildcard examples/package/lib/*)
EXAMPLES_PACKAGE_LIB_ARTIFACTS += EXAMPLES_PACKAGE_LIB_A
EXAMPLES_PACKAGE_LIB_A_HDRS = $(filter %.h,$(EXAMPLES_PACKAGE_LIB_A_FILES))
# Declares library w/o transitive dependencies.
EXAMPLES_PACKAGE_LIB_A = o/$(MODE)/examples/package/lib/lib.a
EXAMPLES_PACKAGE_LIB_ARTIFACTS += EXAMPLES_PACKAGE_LIB_A
# Build configs might seem somewhat complicated. Rest assured they're
# mostly maintainence free. That's largely thanks to how we wildcard.
EXAMPLES_PACKAGE_LIB_A_FILES := $(wildcard examples/package/lib/*)
EXAMPLES_PACKAGE_LIB_A_HDRS = $(filter %.h,$(EXAMPLES_PACKAGE_LIB_A_FILES))
# Define sets of source files without needing further iops.
EXAMPLES_PACKAGE_LIB_A_SRCS_S = \
@ -57,6 +60,7 @@ EXAMPLES_PACKAGE_LIB_A_OBJS = \
$(EXAMPLES_PACKAGE_LIB_A_SRCS_C:%.c=o/$(MODE)/%.o) \
$(EXAMPLES_PACKAGE_LIB_A_SRCS:%=o/$(MODE)/%.zip.o)
# Does the two most important things for C/C++ code sustainability.
# 1. Guarantees each header builds, i.e. includes symbols it needs.
# 2. Guarantees transitive closure of packages is directed acyclic.
EXAMPLES_PACKAGE_LIB_A_CHECKS = \

View file

@ -1,6 +1,16 @@
#include "libc/macros.h"
MyAsm: .leafprologue
/ Example assembly function.
/
/ @note param agnostic
/ @note we love stack frames
/ easiest way to do backtraces
/ somehow they usually make code faster
/ it's convention for keeping stack 16-byte aligned
/ cpus still devote much to pushing & popping b/c i386
MyAsm: push %rbp
mov %rsp,%rbp
call MyPrint2
.leafepilogue
pop %rbp
ret
.endfn MyAsm,globl

View file

@ -1,10 +1,19 @@
#include "examples/package/lib/myprint.h"
#include "libc/stdio/stdio.h"
/**
* Calls MyPrint2() indirected via assembly function.
*/
void MyPrint(const char *s) {
MyAsm(s);
}
/**
* Prints string to output.
*
* @param s is null-terminated c string usually having \n
* @see printf() which has domain-specific language
*/
void MyPrint2(const char *s) {
fputs(s, stdout);
}