mirror of
https://github.com/jart/cosmopolitan.git
synced 2025-06-28 15:28:30 +00:00
Add scouts honor escape hatch for source embedding
This commit is contained in:
parent
c91b3c5006
commit
b4269930f7
547 changed files with 1516 additions and 944 deletions
0
examples/package/README.md
Normal file
0
examples/package/README.md
Normal file
63
examples/package/lib/lib.mk
Normal file
63
examples/package/lib/lib.mk
Normal 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)
|
6
examples/package/lib/myasm.S
Normal file
6
examples/package/lib/myasm.S
Normal file
|
@ -0,0 +1,6 @@
|
|||
#include "libc/macros.h"
|
||||
|
||||
MyAsm: .leafprologue
|
||||
call MyPrint2
|
||||
.leafepilogue
|
||||
.endfn MyAsm,globl
|
10
examples/package/lib/myprint.c
Normal file
10
examples/package/lib/myprint.c
Normal 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);
|
||||
}
|
11
examples/package/lib/myprint.h
Normal file
11
examples/package/lib/myprint.h
Normal 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
33
examples/package/new.sh
Executable 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
|
74
examples/package/package.mk
Normal file
74
examples/package/package.mk
Normal 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)
|
6
examples/package/program.c
Normal file
6
examples/package/program.c
Normal file
|
@ -0,0 +1,6 @@
|
|||
#include "examples/package/lib/myprint.h"
|
||||
|
||||
int main(int argc, char *argv[]) {
|
||||
MyPrint("welcome to your package");
|
||||
return 0;
|
||||
}
|
|
@ -19,31 +19,42 @@
|
|||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "libc/macros.h"
|
||||
|
||||
/ Raw Linux Assembly Binary Tutorial
|
||||
/ Tiny Raw Linux Binary Tutorial
|
||||
/
|
||||
/ i.e. how to not use cosmopolitan runtimes at all
|
||||
/ cosmopolitan basically abstracts this
|
||||
/ except for all major platforms
|
||||
/
|
||||
/ make o//examples/raw-linux-hello.elf
|
||||
/ o//examples/raw-linux-hello.elf # about 6kb
|
||||
/ make o//examples/raw-linux-hello.elf
|
||||
/ o/examples/raw-linux-hello.elf # about 6kb
|
||||
/
|
||||
/ Next consider doing it in C with fancy build tuning
|
||||
/ Next try C but with fancy build tuning
|
||||
/
|
||||
/ make -j8 -O \
|
||||
/ MODE=tiny \
|
||||
/ LDFLAGS=-s \
|
||||
/ CPPFLAGS=-DSUPPORT_VECTOR=0b00000001 \
|
||||
/ o/tiny/examples/hello2.elf
|
||||
/ o/tiny/examples/hello2.elf # about 8kb
|
||||
/ make -j8 -O \
|
||||
/ MODE=tiny \
|
||||
/ LDFLAGS+=-s \
|
||||
/ CPPFLAGS+=-DIM_FEELING_NAUGHTY \
|
||||
/ CPPFLAGS+=-DSUPPORT_VECTOR=0b00000001 \
|
||||
/ o/tiny/examples/hello2.elf
|
||||
/ o/tiny/examples/hello2.elf # about 8kb
|
||||
/
|
||||
/ @param rsp is [n,argv₀..argvₙ₋₁,0,envp₀..,0,auxv₀..,0,..]
|
||||
/ @see also glibc static binaries which start at 800kb!!!
|
||||
/ @see also go where interfaces sadly disempower ld prune
|
||||
/ @see also the stl where bad linkage is due to tech debt
|
||||
/ @see libc/macros-cpp.inc forthe getstr macro definition
|
||||
/ @note libc/elf/elf.lds can be tinier with page align off
|
||||
/ @note gas is more powerful than nasm due to rms notation
|
||||
/ @noreturn
|
||||
_start: mov $12,%rdx # arg no. 3 is length
|
||||
getstr "hello world\n",%rsi,%esi # arg no. 2 is memory
|
||||
mov $1,%edi # arg no. 1 is stdout
|
||||
mov $1,%eax # write()
|
||||
syscall # see libc/sysv/syscalls.sh
|
||||
syscall # libc/sysv/syscalls.sh
|
||||
mov $0,%edi # arg no. 1 is success status
|
||||
mov $0xE7,%eax # exit_group()
|
||||
syscall
|
||||
syscall # context switch
|
||||
0: rep nop # basic blockading
|
||||
jmp 0b
|
||||
.endfn _start,globl
|
||||
.source __FILE__
|
Loading…
Add table
Add a link
Reference in a new issue