-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMakefile
43 lines (32 loc) · 977 Bytes
/
Makefile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
ARCH ?= amd64
STATIC ?= 0
ARCHS32 := i386 arm
ARCHS64 := amd64 arm64
SRC = dlopen.c dlsym.c dlclose.c $(wildcard syscalls/*.c) $(wildcard libc/*.c)
HEADER = tinyld.h internals.h syscalls.h libc.h
OBJS = $(SRC:.c=.o)
LDFLAGS =
CFLAGS = -Wall -fPIC -g
# CFLAGS += -pipe -Wall -Wextra -fPIC -fno-ident -fno-stack-protector -U _FORTIFY_SOURCE
# CFLAGS += -DSTDLIB=$(STDLIB)
CFLAGS_i386 = -m32
TESTS = $(wildcard test/*.c)
ifeq "$(STATIC)" "1"
CFLAGS += -static
endif
all: tinyld tinyld.a
tinyld: prebuild main.c $(OBJS)
$(CC) -o $@ $(filter-out prebuild, $^) -O2 $(CFLAGS) $(LDFLAGS)
tinyld.a: prebuild $(OBJS)
ar rcs $@ $(filter-out prebuild, $^)
%.o: %.c $(HEADER)
$(CC) -c -o $@ $< $(CFLAGS) $(LDFLAGS)
prebuild:
rm arch/target
ln -s $(ARCH) arch/target
test: tinyld $(TESTS:.c=.so)
$(foreach var,$(TESTS:.c=.so),./tinyld $(var);)
test/%.so: test/%.c
gcc -shared -fPIC -o $@ $< $(CFLAGS) -masm=intel $(LDFLAGS)
clean:
rm -f tinyld tinyld.a $(OBJS) test/*.so