# vlibc — top-level build (see building/C.md and layouts/C.md). SUBDIRS = benchmarks # Build-dir include FIRST: configure generates include/vlibc/features.h # (from the .in template) into the BUILD tree, and a VPATH build must find # the generated header before the source tree's checked-in headers. AM_CPPFLAGS = -I$(top_builddir)/include -I$(top_srcdir)/include AM_CFLAGS = @VLIBC_CFLAGS@ # ---- Library ------------------------------------------------------------- # Authoritative source-dir inventory (todo 6). Every directory a later plan # todo creates is enumerated here ONCE, so no area can be forgotten; each is # appended to libvlibc_la_SOURCES WHEN ITS TODO LANDS — the list grows # incrementally and never references a directory that does not exist yet: # # W1 (wired now): src/internal, src/start, src/errno, # src/setjmp/x86_64, src/string, crt/ (crt1.o) # todo 7 src/malloc todo 39-42 src/math todo 50 src/multibyte # todo 11-14 src/stdlib todo 43 src/complex todo 53-54 src/regex # todo 15-18 src/stdio todo 9,51 src/ctype todo 57-58 src/network # todo 19,38 src/unistd todo 55 src/search todo 59 src/mq # todo 20,23,56 src/process todo 66 src/crypt todo 60 src/aio # todo 21 src/fcntl todo 44-48 src/thread todo 61 src/ipc # todo 22,34 src/stat todo 49,52 src/locale todo 62-63 src/ldso # todo 24 src/dirent todo 42 src/fenv/x86_64 # todo 25 src/select # todo 26-27 src/time # todo 28 src/signal # todo 29 src/termios # todo 30 src/uio # todo 31 src/resource # todo 32,36,54,61,67 src/misc # todo 33 src/mman # todo 35 src/sys # todo 37 src/passwd # todo 37 src/group # # NOTE: crt/x86_64/crt1.s is NOT a library source — it is assembled into the # standalone crt1.o below (the sole crt owner; todo 64 reuses, never rebuilds). # Level-independent L1 core (wired today + the pre-plan string slice). VLIBC_CORE_SRCS = \ src/vlibc.c \ src/internal/assert_fail.c \ src/internal/errno.c \ src/internal/syscall_ret.c \ src/start/libc_start_main.c \ src/start/exit.c \ src/start/environ.c \ src/start/tls.c \ src/errno/strerror.c \ src/setjmp/x86_64/setjmp.s \ src/setjmp/x86_64/longjmp.s \ src/setjmp/x86_64/sigsetjmp.s \ src/setjmp/x86_64/siglongjmp.s \ src/string/strlen.c \ src/string/strcmp.c \ src/string/memcpy.c \ src/string/memmove.c \ src/string/memset.c # Profile-gated sources, EXISTING gates preserved (strlcpy/strlcat stay L2 # BSD, strcasestr stays L3 GNU — NOT promoted). VLIBC_LEVEL2_SRCS = src/string/strlcpy.c src/string/strlcat.c VLIBC_LEVEL3_SRCS = src/string/strcasestr.c vlibc_lib_LTLIBRARIES = libvlibc.la libvlibc_la_SOURCES = $(VLIBC_CORE_SRCS) if PROFILE_GE_2 libvlibc_la_SOURCES += $(VLIBC_LEVEL2_SRCS) endif if PROFILE_GE_3 libvlibc_la_SOURCES += $(VLIBC_LEVEL3_SRCS) endif libvlibc_la_LDFLAGS = -version-info 0:0:0 -no-undefined # ---- Public headers ------------------------------------------------------ # The whole public header inventory (the 3 scaffold headers plus todo 5's # skeleton); the profile-gated generated features.h is installed separately # below. vlibc_include_HEADERS = \ include/vlibc.h \ include/stddef.h \ include/string.h \ include/errno.h \ include/setjmp.h \ include/assert.h \ include/cpio.h \ include/float.h \ include/iso646.h \ include/limits.h \ include/stdalign.h \ include/stdarg.h \ include/stdatomic.h \ include/stdbit.h \ include/stdbool.h \ include/stdckdint.h \ include/stdint.h \ include/stdnoreturn.h \ include/tar.h \ include/tgmath.h \ include/threads.h \ include/uchar.h \ include/sys/types.h # Install location depends on the install method (see configure.ac). if INSTALL_OVERWRITE vlibc_includedir = $(includedir) vlibc_libdir = $(libdir) else vlibc_includedir = $(prefix)/lib/vlibc/include vlibc_libdir = $(prefix)/lib/vlibc/lib endif # Generated per-profile feature header (see configure.ac); installed under # $(vlibc_includedir)/vlibc/. A dedicated primary is used because # nodist_nobase_vlibc_include_HEADERS is rejected by automake (the "nobase" # prefix is unsupported for this directory) and loses the vlibc/ path. vlibc_featuresdir = $(vlibc_includedir)/vlibc nodist_vlibc_features_HEADERS = include/vlibc/features.h # ---- Compiler drivers ---------------------------------------------------- bin_SCRIPTS = tools/vlibc-gcc tools/vlibc-clang # ---- crt objects --------------------------------------------------------- # crt1.o (from crt/x86_64/crt1.s) is built here and ONLY here: todo 64 # reuses these objects for the shared build and must NOT rebuild them. # Built by `make all` via all-local so a static vlibc link always has its # entry object available next to the archive. crt1.o: crt/x86_64/crt1.s $(AM_V_GEN)$(CC) $(AM_CPPFLAGS) $(CPPFLAGS) -c -o $@ $< all-local: crt1.o # ---- Targets ------------------------------------------------------------- # layouts/C.md requires `make debug`, `make release`, `make bench` and # `make clean`; build outputs land in bin/{release,debug}. DEBUG_CFLAGS = -O0 -g3 -DDEBUG RELEASE_CFLAGS = -O3 -DNDEBUG debug: $(MAKE) clean $(MAKE) all AM_CFLAGS="$(AM_CFLAGS) $(DEBUG_CFLAGS)" $(MKDIR_P) bin/debug -cp -P .libs/libvlibc.so* bin/debug/ -cp .libs/libvlibc.a bin/debug/ -cp crt1.o bin/debug/ release: $(MAKE) clean $(MAKE) all AM_CFLAGS="$(AM_CFLAGS) $(RELEASE_CFLAGS)" $(MKDIR_P) bin/release -cp -P .libs/libvlibc.so* bin/release/ -cp .libs/libvlibc.a bin/release/ -cp crt1.o bin/release/ bench: all $(MAKE) -C benchmarks bench # Regenerate compile_commands.json (requires `bear`). Captures both the # library sources and the on-demand benchmark harness. compile-commands: clean bear -- $(MAKE) all bear --append -- $(MAKE) -C benchmarks bench_vlibc .PHONY: debug release bench compile-commands # ---- make check ---------------------------------------------------------- # # Every test binary is a STATIC VLIBC EXECUTABLE: linked with -nostdlib # -static -no-pie against crt1.o + a dedicated level-2 test archive. No # glibc symbol can resolve, so each test genuinely proves self-hosting. # # The test archive (libvlibc-check.a) is compiled from the FULL source list # (all levels included) at VLIBC_LEVEL=2 — the complete L1+L2 surface — # INDEPENDENT of the configured profile. Rationale: some tests exercise # L2-gated functions (test_strerror calls strerror_r, future tests call # bcopy etc.), which a level-1 configured archive does not provide; the # shipped libvlibc.a keeps the profile gating configured at build time. # Object files are plain `ar` members compiled directly with $(CC) — no # libtool (libtool's build-dir libvlibc.a is a wrapper script, and only # .libs/libvlibc.a is linkable, which is a level-gated profile archive). # # Mechanics (extend here for future tests): # - Add the binary to check_PROGRAMS + TESTS with # `_SOURCES = tests/test_x.c`, # `_CFLAGS = $(VLIBC_TEST_CFLAGS)` (renames the object to # `-.o` automatically), # `_LINK = $(VLIBC_TEST_LINK)` and # `_LDADD = $(VLIBC_TEST_LDADD)` (static vlibc link; the crt # object + archive must be in LDADD so they follow the test object). # - Multi-mode tests run through tests/startup_modes.sh (see that file). VLIBC_TEST_LEVEL = 2 VLIBC_CHECK_SRCS = $(VLIBC_CORE_SRCS) $(VLIBC_LEVEL2_SRCS) \ $(VLIBC_LEVEL3_SRCS) VLIBC_CHECK_OBJECTS_FROM_C = $(VLIBC_CHECK_SRCS:.c=.check.o) VLIBC_CHECK_OBJECTS = $(VLIBC_CHECK_OBJECTS_FROM_C:.s=.check.o) VLIBC_CHECK_CFLAGS = @VLIBC_CFLAGS@ -DVLIBC_LEVEL=$(VLIBC_TEST_LEVEL) -fno-pic # The archive itself (plain ar: members compiled at the test level). libvlibc-check.a: $(VLIBC_CHECK_OBJECTS) $(AR) $(ARFLAGS) $@ $^ # Library sources compiled at the test level. Deliberately no # -DHAVE_CONFIG_H and no $(DEFS): config.h pins the PROFILE level, which # would override -DVLIBC_LEVEL (last definition wins), so the check objects # must get their level from alone. %.check.o: %.c $(AM_V_CC)$(CC) $(AM_CPPFLAGS) $(CPPFLAGS) $(VLIBC_CHECK_CFLAGS) -c -o $@ $< %.check.o: %.s $(AM_V_CCAS)$(CC) $(AM_CPPFLAGS) $(CPPFLAGS) -c -o $@ $< # Static vlibc link for every check program. automake links # "$(_LINK) $(_OBJECTS) $(_LDADD) $(LIBS)", so the entry # object, the level-2 archive and libgcc go in LDADD — they MUST follow the # test object or the archive would see no undefined symbols and stay # unextracted. -nostdlib means -lgcc is not auto-added, so it is spelled # out (permitted libgcc helpers). VLIBC_TEST_LINK = $(CC) -nostdlib -static -no-pie -o $@ VLIBC_TEST_LDADD = crt1.o libvlibc-check.a -lgcc # Test TUs: no stack protector (the library is protector-free at this stage), # non-PIC, level overridden to the test level so L2 declarations are visible. VLIBC_TEST_CFLAGS = -DVLIBC_LEVEL=$(VLIBC_TEST_LEVEL) -fno-stack-protector \ -fno-pic -fno-pie check_PROGRAMS = test_syscall test_strerror test_setjmp test_headers \ test_startup test_syscall_SOURCES = tests/syscall_test.c test_syscall_CFLAGS = $(VLIBC_TEST_CFLAGS) test_syscall_DEPENDENCIES = crt1.o libvlibc-check.a test_syscall_LINK = $(VLIBC_TEST_LINK) test_syscall_LDADD = $(VLIBC_TEST_LDADD) test_strerror_SOURCES = tests/test_strerror.c test_strerror_CFLAGS = $(VLIBC_TEST_CFLAGS) test_strerror_DEPENDENCIES = crt1.o libvlibc-check.a test_strerror_LINK = $(VLIBC_TEST_LINK) test_strerror_LDADD = $(VLIBC_TEST_LDADD) test_setjmp_SOURCES = tests/test_setjmp.c test_setjmp_CFLAGS = $(VLIBC_TEST_CFLAGS) test_setjmp_DEPENDENCIES = crt1.o libvlibc-check.a test_setjmp_LINK = $(VLIBC_TEST_LINK) test_setjmp_LDADD = $(VLIBC_TEST_LDADD) test_headers_SOURCES = tests/test_headers.c test_headers_CFLAGS = $(VLIBC_TEST_CFLAGS) test_headers_DEPENDENCIES = crt1.o libvlibc-check.a test_headers_LINK = $(VLIBC_TEST_LINK) test_headers_LDADD = $(VLIBC_TEST_LDADD) test_startup_SOURCES = tests/test_startup.c test_startup_CFLAGS = $(VLIBC_TEST_CFLAGS) test_startup_DEPENDENCIES = crt1.o libvlibc-check.a test_startup_LINK = $(VLIBC_TEST_LINK) test_startup_LDADD = $(VLIBC_TEST_LDADD) # test_startup's default mode exits 42 by design, so it is NOT a bare TESTS # entry; tests/startup_modes.sh runs its full mode matrix and the -f failure # scenarios of the other four binaries. TESTS = test_syscall test_strerror test_setjmp test_headers \ tests/startup_modes.sh CLEANFILES = crt1.o libvlibc-check.a $(VLIBC_CHECK_OBJECTS) # Distributed but not installed / not otherwise picked up by automake. # (TESTS scripts are not auto-distributed, so the mode runner is explicit.) EXTRA_DIST = \ crt/x86_64/crt1.s \ include/vlibc/internal/test.h \ tests/conformance/symbols.list \ tests/startup_modes.sh \ arch/x86_64/syscall_arch.h \ src/internal/atomic.h \ src/internal/errno.h \ src/internal/libc.h \ src/internal/syscall.h \ src/internal/types.h \ src/start/start.h \ src/start/tcb.h