mirror of
https://github.com/jart/cosmopolitan.git
synced 2025-07-30 14:30:27 +00:00
Introduce new linker for fat ape binaries
This commit is contained in:
parent
e3c456d23a
commit
0105e3e2b6
44 changed files with 3140 additions and 867 deletions
|
@ -1,6 +1,9 @@
|
|||
#-*-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───────────────────────┘
|
||||
|
||||
# qemu-user execve() is broken so we need to build/bootstrap/ commands
|
||||
ifeq ($(ARCH), x86_64)
|
||||
|
||||
PKGS += TOOL_HELLO
|
||||
|
||||
TOOL_HELLO_FILES := $(wildcard tool/hello/*)
|
||||
|
@ -9,20 +12,77 @@ TOOL_HELLO_SRCS_C = $(filter %.c,$(TOOL_HELLO_FILES))
|
|||
TOOL_HELLO_SRCS_S = $(filter %.S,$(TOOL_HELLO_FILES))
|
||||
TOOL_HELLO_SRCS = $(TOOL_HELLO_SRCS_C) $(TOOL_HELLO_SRCS_S)
|
||||
TOOL_HELLO_OBJS = $(TOOL_HELLO_SRCS_C:%.c=o/$(MODE)/%.o) $(TOOL_HELLO_SRCS_S:%.S=o/$(MODE)/%.o)
|
||||
TOOL_HELLO_BINS = o/$(MODE)/tool/hello/hello.com.dbg
|
||||
TOOL_HELLO_BINS = $(TOOL_HELLO_COMS) $(TOOL_HELLO_COMS:%=%.dbg)
|
||||
|
||||
o/$(MODE)/tool/hello/hello.com.dbg: \
|
||||
o/$(MODE)/tool/hello/systemcall.o \
|
||||
o/$(MODE)/tool/hello/hello.o \
|
||||
o/$(MODE)/tool/hello/start.o
|
||||
@$(COMPILE) -ALINK.elf $(LINK) $(LINKARGS) $(OUTPUT_OPTION) -q -zmax-page-size=4096
|
||||
TOOL_HELLO_COMS = \
|
||||
o/$(MODE)/tool/hello/hello.com \
|
||||
o/$(MODE)/tool/hello/hello-pe.com \
|
||||
o/$(MODE)/tool/hello/hello-elf.com \
|
||||
o/$(MODE)/tool/hello/hello-unix.com
|
||||
|
||||
o/$(MODE)/tool/hello/hello.com: \
|
||||
o/$(MODE)/tool/hello/hello.com.dbg \
|
||||
TOOL_HELLO_DIRECTDEPS = \
|
||||
LIBC_CALLS \
|
||||
LIBC_RUNTIME \
|
||||
LIBC_ZIPOS
|
||||
|
||||
TOOL_HELLO_DEPS := \
|
||||
$(call uniq,$(foreach x,$(TOOL_HELLO_DIRECTDEPS),$($(x))))
|
||||
|
||||
o/$(MODE)/tool/hello/hello.pkg: \
|
||||
$(TOOL_HELLO_OBJS) \
|
||||
$(foreach x,$(TOOL_HELLO_DIRECTDEPS),$($(x)_A).pkg)
|
||||
|
||||
# generates debuggable executable using gcc
|
||||
o/$(MODE)/tool/hello/hello.com.dbg: \
|
||||
$(TOOL_HELLO_DEPS) \
|
||||
o/$(MODE)/tool/hello/hello.o \
|
||||
o/$(MODE)/tool/hello/hello.pkg \
|
||||
$(CRT) \
|
||||
$(APE)
|
||||
@$(APELINK)
|
||||
|
||||
# uses apelink to turn it into an ape executable
|
||||
# support vector is set to all operating systems
|
||||
o/$(MODE)/tool/hello/hello.com: \
|
||||
o/$(MODE)/tool/hello/hello.com.dbg \
|
||||
o/$(MODE)/tool/build/apelink.com \
|
||||
o/$(MODE)/tool/build/pecheck.com \
|
||||
o/$(MODE)/ape/ape.elf
|
||||
@$(COMPILE) -ALINK.ape o/$(MODE)/tool/build/apelink.com -o $@ -l o/$(MODE)/ape/ape.elf $<
|
||||
@$(COMPILE) -APECHECK -wT$@ o/$(MODE)/tool/build/pecheck.com $@
|
||||
|
||||
# uses apelink to generate elf-only executable
|
||||
# support vector = linux/freebsd/openbsd/netbsd/metal
|
||||
o/$(MODE)/tool/hello/hello-elf.com: \
|
||||
o/$(MODE)/tool/hello/hello.com.dbg \
|
||||
o/$(MODE)/tool/build/apelink.com \
|
||||
o/$(MODE)/ape/ape.elf
|
||||
@$(COMPILE) -ALINK.ape o/$(MODE)/tool/build/apelink.com -s elf -o $@ -l o/$(MODE)/ape/ape.elf $<
|
||||
|
||||
# uses apelink to generate non-pe ape executable
|
||||
# support vector = macos/linux/freebsd/openbsd/netbsd
|
||||
# - great way to avoid attention from bad virus scanners
|
||||
# - creates tinier executable by reducing alignment requirement
|
||||
o/$(MODE)/tool/hello/hello-unix.com: \
|
||||
o/$(MODE)/tool/hello/hello.com.dbg \
|
||||
o/$(MODE)/tool/build/apelink.com \
|
||||
o/$(MODE)/ape/ape.elf
|
||||
@$(COMPILE) -ALINK.ape o/$(MODE)/tool/build/apelink.com -s unix -o $@ -l o/$(MODE)/ape/ape.elf $<
|
||||
|
||||
# elf2pe generates optimal pe binaries
|
||||
# windows is the only platform supported
|
||||
# doesn't depend on ape or the cosmopolitan c library
|
||||
o/$(MODE)/tool/hello/hello-pe.com.dbg: \
|
||||
o/$(MODE)/tool/hello/hello-pe.o
|
||||
@$(COMPILE) -ALINK.elf $(LINK) $(LINKARGS) $(OUTPUT_OPTION) -q -e WinMain
|
||||
o/$(MODE)/tool/hello/hello-pe.com: \
|
||||
o/$(MODE)/tool/hello/hello-pe.com.dbg \
|
||||
o/$(MODE)/tool/build/elf2pe.com
|
||||
o/$(MODE)/tool/build/elf2pe.com -o $@ $<
|
||||
@$(COMPILE) -AELF2PE o/$(MODE)/tool/build/elf2pe.com -o $@ $<
|
||||
|
||||
$(TOOL_HELLO_OBJS): tool/hello/hello.mk
|
||||
|
||||
.PHONY: o/$(MODE)/tool/hello
|
||||
o/$(MODE)/tool/hello: $(TOOL_HELLO_BINS)
|
||||
|
||||
endif
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue