Skip to content
Snippets Groups Projects
Makefile 4.57 KiB
Newer Older
# Binaries that should generate the same output every time
EXPECT_NAMES=\
Nagy Tibor's avatar
Nagy Tibor committed
	alloca \
	args \
	arpainet \
	assert \
	constructor \
	ctype \
	destructor \
jD91mZM2's avatar
jD91mZM2 committed
	dirent/scandir \
	error \
	fcntl/create \
	fcntl/fcntl \
	fnmatch \
8tab's avatar
8tab committed
	futimens \
Michał Zwonek's avatar
Michał Zwonek committed
	libgen \
	locale \
	math \
jD91mZM2's avatar
jD91mZM2 committed
	ptrace \
	regex \
	select \
	setjmp \
8tab's avatar
8tab committed
	stdio/all \
	stdio/buffer \
	stdio/fgets \
lmiskiew's avatar
lmiskiew committed
	stdio/fputs \
jD91mZM2's avatar
jD91mZM2 committed
	stdio/fread \
8tab's avatar
8tab committed
	stdio/freopen \
jD91mZM2's avatar
jD91mZM2 committed
	stdio/fseek \
	stdio/fwrite \
8tab's avatar
8tab committed
	stdio/getc_unget \
Jeremy Soller's avatar
Jeremy Soller committed
	stdio/popen \
	stdio/printf \
	stdio/rename \
	stdio/scanf \
8tab's avatar
8tab committed
	stdio/setvbuf \
	stdio/sprintf \
	stdio/printf_space_pad \
8tab's avatar
8tab committed
	stdio/ungetc_multiple \
	stdio/fscanf_offby1 \
	stdio/fscanf \
	stdio/printf_neg_pad \
	stdlib/a64l \
	stdlib/atof \
	stdlib/atoi \
	stdlib/div \
	stdlib/env \
	stdlib/mkostemps \
	stdlib/rand \
	stdlib/rand48 \
	stdlib/random \
	stdlib/strtod \
	stdlib/strtol \
	stdlib/strtoul \
	stdlib/system \
	string/mem \
Jeremy Soller's avatar
Jeremy Soller committed
	string/strcat \
	string/strchr \
	string/strcpy \
	string/strcspn \
	string/strlen \
	string/strncmp \
	string/strpbrk \
	string/strrchr \
	string/strspn \
	string/strstr \
	string/strtok \
	string/strtok_r \
	string/strsignal \
	strings \
jD91mZM2's avatar
jD91mZM2 committed
	sys_mman \
	time/asctime \
	time/constants \
	time/gmtime \
8tab's avatar
8tab committed
	time/localtime \
	time/mktime \
	time/strftime \
	time/time \
8tab's avatar
8tab committed
	tls \
	unistd/access \
	unistd/brk \
	unistd/dup \
	unistd/exec \
	unistd/fchdir \
jD91mZM2's avatar
jD91mZM2 committed
	unistd/fork \
	unistd/fsync \
	unistd/ftruncate \
8tab's avatar
8tab committed
	unistd/getopt \
	unistd/getopt_long \
	unistd/pipe \
	unistd/rmdir \
	unistd/sleep \
lmiskiew's avatar
lmiskiew committed
	unistd/swab \
	unistd/write \
	waitpid \
	wchar/mbrtowc \
	wchar/mbsrtowcs \
	wchar/printf-on-wchars \
	wchar/putwchar \
	wchar/wcrtomb \
	wchar/wcscspn \
jD91mZM2's avatar
jD91mZM2 committed
	wchar/wcsrchr \
8tab's avatar
8tab committed
	wchar/wcstok \
	wchar/wcstol \
	wchar/wcscasecmp \
	wchar/wcsncasecmp \
8tab's avatar
8tab committed
	wctype/towlower \
	wctype/towupper
	# TODO: Fix these
8tab's avatar
8tab committed
	# netdb/netdb \

8tab's avatar
8tab committed
DYNAMIC_ONLY_NAMES=\
	dlfcn

# Binaries that may generate varied output
NAMES=\
	$(EXPECT_NAMES) \
jD91mZM2's avatar
jD91mZM2 committed
	dirent/main \
	stdio/tempnam \
	stdio/tmpnam \
	stdlib/bsearch \
	stdlib/mktemp \
jD91mZM2's avatar
jD91mZM2 committed
	stdlib/realpath \
	sys_epoll/epoll \
Nagy Tibor's avatar
Nagy Tibor committed
	sys_utsname/uname \
	time/gettimeofday \
	unistd/chdir \
	unistd/getcwd \
	unistd/gethostname \
	unistd/getid \
	unistd/getpagesize \
	unistd/isatty \
	unistd/link \
	unistd/pathconf \
	unistd/setid \
	unistd/stat \
	unistd/sysconf
#	resource/getrusage
#	time/times
#TODO: dynamic tests currently broken
8tab's avatar
8tab committed
BINS=$(patsubst %,bins_static/%,$(NAMES))
#BINS+=$(patsubst %,bins_dynamic/%,$(NAMES))
#BINS+=$(patsubst %,bins_dynamic/%,$(DYNAMIC_ONLY_NAMES))
8tab's avatar
8tab committed
EXPECT_BINS=$(patsubst %,bins_static/%,$(EXPECT_NAMES))
#EXPECT_BINS+=$(patsubst %,bins_dynamic/%,$(EXPECT_NAMES))
#EXPECT_BINS+=$(patsubst %,bins_dynamic/%,$(DYNAMIC_ONLY_NAMES))
CARGO_TEST?=cargo
TEST_RUNNER?=
.PHONY: all clean run expected verify
all: $(BINS)
Jeremy Soller's avatar
Jeremy Soller committed
clean:
8tab's avatar
8tab committed
	rm -rf bins_* gen *.out
8tab's avatar
8tab committed
	for bin in $(BINS); \
Paul Sajna's avatar
Paul Sajna committed
	do \
8tab's avatar
8tab committed
		echo "# $${bin} #"; \
		"$${bin}" test args || exit $$?; \
expected: | $(EXPECT_BINS)
	rm -rf expected
Jeremy Soller's avatar
Jeremy Soller committed
	mkdir -p expected
8tab's avatar
8tab committed
	for bin in $(EXPECT_BINS); \
8tab's avatar
8tab committed
		echo "# $${bin} #"; \
		mkdir -p expected/`dirname $${bin}`; \
		"$${bin}" test args > "expected/$${bin}.stdout" 2> "expected/$${bin}.stderr" || exit $$?; \
bins_verify/relibc-tests: src/main.rs
	$(CARGO_TEST) build --release --bin relibc-tests --out-dir bins_verify -Z unstable-options

verify: bins_verify/relibc-tests | $(EXPECT_BINS)
	$(TEST_RUNNER) $< $(EXPECT_BINS)
Jeremy Soller's avatar
Jeremy Soller committed

8tab's avatar
8tab committed
FLAGS=\
	-fno-builtin \
	-fno-stack-protector \
	-Wall \
Jeremy Soller's avatar
Jeremy Soller committed

8tab's avatar
8tab committed
STATIC_FLAGS=\
	-static
Jeremy Soller's avatar
Jeremy Soller committed

8tab's avatar
8tab committed
DYNAMIC_FLAGS=\
	-Wl,--enable-new-dtags \
	-Wl,-export-dynamic

../sysroot:
	$(MAKE) -C .. sysroot

NATIVE_RELIBC?=0
ifeq ($(NATIVE_RELIBC),0)
8tab's avatar
8tab committed
FLAGS+=\
	-nostdinc \
	-nostdlib \
	-isystem ../sysroot/include \
	../sysroot/lib/crt0.o \
8tab's avatar
8tab committed
	../sysroot/lib/crti.o \
	../sysroot/lib/crtn.o
Jeremy Soller's avatar
Jeremy Soller committed

8tab's avatar
8tab committed
SYSROOT_LIB=$(shell realpath ../sysroot/lib/)

8tab's avatar
8tab committed
STATIC_FLAGS+=\
	$(SYSROOT_LIB)/libc.a

DYNAMIC_FLAGS+=\
8tab's avatar
8tab committed
	-Wl,-dynamic-linker=$(SYSROOT_LIB)/ld64.so.1 \
8tab's avatar
8tab committed
	-Wl,-rpath=$(SYSROOT_LIB):\$$ORIGIN \
8tab's avatar
8tab committed
	-L $(SYSROOT_LIB) \
	-lc

8tab's avatar
8tab committed
DEPS=../sysroot
8tab's avatar
8tab committed
else
DYNAMIC_FLAGS+=\
	-Wl,-rpath=\$$ORIGIN
8tab's avatar
8tab committed
endif

bins_static/%: %.c $(DEPS)
8tab's avatar
8tab committed
	mkdir -p "$$(dirname "$@")"
	$(CC) "$<" -o "$@" $(FLAGS) $(STATIC_FLAGS)

8tab's avatar
8tab committed
bins_dynamic/%.so: %.c $(DEPS)
	mkdir -p "$$(dirname "$@")"
	$(CC) "$<" -o "$@" -shared -fpic $(FLAGS) $(DYNAMIC_FLAGS)

bins_dynamic/dlfcn: dlfcn.c bins_dynamic/sharedlib.so $(DEPS)
	mkdir -p "$$(dirname "$@")"
	$(CC) "$<" -o "$@" $(FLAGS) $(DYNAMIC_FLAGS)

8tab's avatar
8tab committed
bins_dynamic/%: %.c $(DEPS)
	mkdir -p "$$(dirname "$@")"
8tab's avatar
8tab committed
	$(CC) "$<" -o "$@" $(FLAGS) $(DYNAMIC_FLAGS)