summaryrefslogtreecommitdiffstats
path: root/makefile-so/Makefile
blob: 5bb41a0dfb21ad84a8aec2dba5cb7c4ffd55a6d8 (plain)
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
CC   = gcc
CCFLAGS=-pedantic -Wall
LD_OPTS=

# $< - the current dependcy file
# $@ - the current target file
# $* - the base name of the current target
# $? - all dependencies that are newer than the target
# -fPIV : emit position-independent code
# -nostartfiles : do not use the standard system startup files when linking

%.o: %.c
	$(CC) $(CCFLAGS) -c -I. -o $@ $<

default: all

clib.o: clib.h clib.c
	$(CC) $(CCFLAGS) -c -fPIC $<

libclib.so: clib.o
	$(CC) $(CCFLAGS) -shared -nostartfiles -Wl,-soname,libclib.so -o libclib.so.1.0 $<

ldlinks:
	@ldconfig -n .

main: libclib.so ldlinks clib.h main.o
	$(CC) $(LD_OPTS) main.o -L. -lclib -o main

all: main

clean:
	rm -f main *.o *.so* *~