aboutsummaryrefslogtreecommitdiff
path: root/03_hello_dynld/Makefile
blob: 5764166798587436c15ba2d963d0ec7f56f8b89d (plain) (blame)
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
# Copyright (c) 2021 Johannes Stoelp

COMMON_CFLAGS := -g -O0 -Wall -Wextra \
                 -I../lib/include -nostdlib

run: main
	./$<

main: dynld.so main.c ../lib/libcommon.a
	gcc -o $@                                   \
	    $(COMMON_CFLAGS)                        \
	    -Wl,--dynamic-linker=$(CURDIR)/dynld.so \
	    $(filter %.c %.a, $^)

	readelf -W --dynamic $@
	readelf -W --string-dump .interp $@
	readelf -W --program-headers $@

dynld.so: dynld.S dynld.c ../lib/libcommon.a
	gcc -o $@                          \
	    $(COMMON_CFLAGS)               \
	    -fPIC                          \
	    -fvisibility=hidden            \
	    -Wl,--entry=dl_start           \
	    -Wl,--no-allow-shlib-undefined \
	    $^

../lib/libcommon.a:
	make -C ../lib

clean:
	rm -f main
	rm -f dynld.so