Add scouts honor escape hatch for source embedding

This commit is contained in:
Justine Tunney 2020-06-15 19:01:28 -07:00
parent c91b3c5006
commit b4269930f7
547 changed files with 1516 additions and 944 deletions

View file

View file

@ -0,0 +1,63 @@
#-*-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 static library build config
#
# DESCRIPTION
#
# Your library doesn't have a main() function and can be compromised
# of sources written in multiple languages.
PKGS += EXAMPLES_PACKAGE_LIB
EXAMPLES_PACKAGE_LIB_ARTIFACTS += EXAMPLES_PACKAGE_LIB_A
EXAMPLES_PACKAGE_LIB = $(EXAMPLES_PACKAGE_LIB_A_DEPS) $(EXAMPLES_PACKAGE_LIB_A)
EXAMPLES_PACKAGE_LIB_A = o/$(MODE)/examples/package/lib/lib.a
EXAMPLES_PACKAGE_LIB_A_HDRS = $(filter %.h,$(EXAMPLES_PACKAGE_LIB_A_FILES))
EXAMPLES_PACKAGE_LIB_A_SRCS_S = $(filter %.S,$(EXAMPLES_PACKAGE_LIB_A_FILES))
EXAMPLES_PACKAGE_LIB_A_SRCS_C = $(filter %.c,$(EXAMPLES_PACKAGE_LIB_A_FILES))
EXAMPLES_PACKAGE_LIB_A_CHECKS = $(EXAMPLES_PACKAGE_LIB_A).pkg
EXAMPLES_PACKAGE_LIB_A_FILES := \
$(wildcard examples/package/lib/*) \
$(wildcard examples/package/lib/thunks/*)
EXAMPLES_PACKAGE_LIB_A_SRCS = \
$(EXAMPLES_PACKAGE_LIB_A_SRCS_S) \
$(EXAMPLES_PACKAGE_LIB_A_SRCS_C)
EXAMPLES_PACKAGE_LIB_A_OBJS = \
$(EXAMPLES_PACKAGE_LIB_A_SRCS_S:%.S=o/$(MODE)/%.o) \
$(EXAMPLES_PACKAGE_LIB_A_SRCS_C:%.c=o/$(MODE)/%.o) \
$(EXAMPLES_PACKAGE_LIB_A_SRCS:%=o/$(MODE)/%.zip.o)
EXAMPLES_PACKAGE_LIB_A_DIRECTDEPS = \
LIBC_STDIO \
LIBC_STUBS
EXAMPLES_PACKAGE_LIB_A_DEPS := \
$(call uniq,$(foreach x,$(EXAMPLES_PACKAGE_LIB_A_DIRECTDEPS),$($(x))))
$(EXAMPLES_PACKAGE_LIB_A): \
examples/package/lib/ \
$(EXAMPLES_PACKAGE_LIB_A).pkg \
$(EXAMPLES_PACKAGE_LIB_A_OBJS)
$(EXAMPLES_PACKAGE_LIB_A).pkg: \
$(EXAMPLES_PACKAGE_LIB_A_OBJS) \
$(foreach x,$(EXAMPLES_PACKAGE_LIB_A_DIRECTDEPS),$($(x)_A).pkg)
$(EXAMPLES_PACKAGE_LIB_A_OBJS): examples/package/lib/lib.mk
EXAMPLES_PACKAGE_LIB_LIBS = $(foreach x,$(EXAMPLES_PACKAGE_LIB_ARTIFACTS),$($(x)))
EXAMPLES_PACKAGE_LIB_SRCS = $(foreach x,$(EXAMPLES_PACKAGE_LIB_ARTIFACTS),$($(x)_SRCS))
EXAMPLES_PACKAGE_LIB_HDRS = $(foreach x,$(EXAMPLES_PACKAGE_LIB_ARTIFACTS),$($(x)_HDRS))
EXAMPLES_PACKAGE_LIB_BINS = $(foreach x,$(EXAMPLES_PACKAGE_LIB_ARTIFACTS),$($(x)_BINS))
EXAMPLES_PACKAGE_LIB_CHECKS = $(foreach x,$(EXAMPLES_PACKAGE_LIB_ARTIFACTS),$($(x)_CHECKS))
EXAMPLES_PACKAGE_LIB_OBJS = $(foreach x,$(EXAMPLES_PACKAGE_LIB_ARTIFACTS),$($(x)_OBJS))
EXAMPLES_PACKAGE_LIB_TESTS = $(foreach x,$(EXAMPLES_PACKAGE_LIB_ARTIFACTS),$($(x)_TESTS))
.PHONY: o/$(MODE)/examples/package/lib
o/$(MODE)/examples/package/lib: $(EXAMPLES_PACKAGE_LIB_CHECKS)

View file

@ -0,0 +1,6 @@
#include "libc/macros.h"
MyAsm: .leafprologue
call MyPrint2
.leafepilogue
.endfn MyAsm,globl

View file

@ -0,0 +1,10 @@
#include "examples/package/lib/myprint.h"
#include "libc/stdio/stdio.h"
void MyPrint(const char *s) {
MyAsm(s);
}
void MyPrint2(const char *s) {
fputs(s, stdout);
}

View file

@ -0,0 +1,11 @@
#ifndef COSMOPOLITAN_EXAMPLES_PACKAGE_LIB_MYPRINT_H_
#define COSMOPOLITAN_EXAMPLES_PACKAGE_LIB_MYPRINT_H_
#if !(__ASSEMBLER__ + __LINKER__ + 0)
COSMOPOLITAN_C_START_
void MyPrint(const char *);
void MyAsm(const char *);
COSMOPOLITAN_C_END_
#endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */
#endif /* COSMOPOLITAN_EXAMPLES_PACKAGE_LIB_MYPRINT_H_ */

33
examples/package/new.sh Executable file
View file

@ -0,0 +1,33 @@
#!/bin/sh
#
# SYNOPSIS
#
# Creates new package in repository.
#
# EXAMPLE
#
# examples/package/new.sh com/github/user/project
DIR=${1:?need directory arg}
VAR=$(echo "$DIR" | tr a-z A-Z | tr / _)
BASENAME=${DIR##*/}
FILENAME="$DIR/$BASENAME"
MAKEFILE="$DIR/$BASENAME.mk"
if [ -d "$DIR" ]; then
echo "already exists: $DIR" >&2
exit 1
fi
mkdir -p "$DIR" &&
cp -R examples/package/new/* "$DIR" &&
find "$DIR" -type f |
xargs sed -i -e "
s/EXAMPLES_PACKAGE/$VAR/g
s/examples\/package\/package/$FILENAME/g
s/examples\/package/$DIR/g
" &&
sed -i -e "
/#-φ-examples\/package\/new\.sh/i\
include $MAKEFILE
" Makefile

View file

@ -0,0 +1,74 @@
#-*-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
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_OBJS:%.o=%.com)
# 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)
EXAMPLES_PACKAGE_BINS = \
$(EXAMPLES_PACKAGE_COMS) \
$(EXAMPLES_PACKAGE_COMS:%=%.dbg)
# 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))))
# Invalidates objects in this package when this makefile is edited
$(EXAMPLES_PACKAGE_OBJS): examples/package/vizlib.mk
# Asks packager to index symbols and validate their relationships.
# @see tool/build/package.c
# @see build/rules.mk
o/$(MODE)/examples/package/build.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/package.pkg \
o/$(MODE)/examples/package/%.o \
$(CRT) \
$(APE)
-@$(APELINK)
# Creates target that builds everything in this package and subpackages.
.PHONY: o/$(MODE)/examples/package
o/$(MODE)/examples/package: \
o/$(MODE)/examples/package/lib \
$(EXAMPLES_PACKAGE_BINS) \
$(EXAMPLES_PACKAGE_CHECKS)

View file

@ -0,0 +1,6 @@
#include "examples/package/lib/myprint.h"
int main(int argc, char *argv[]) {
MyPrint("welcome to your package");
return 0;
}