summaryrefslogtreecommitdiffstats
path: root/Makefile
blob: ee13bbd434e76153bc5cdd34872eb9dbe79aab33 (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
34
35
36
37
38
39
40
41
42
43
44
PREFIX ?= /usr/local
LIBDIR ?= /lib
INCLDIR ?= /include

CFLAGS = -Wconversion -Wunused-function -Wunused-variable
CFLAGS += -I lib/liballoc/include -I include

all: build/libstr.a build/libstr.so build/test

clean:
	rm -rf build

cleanall: clean
	make -C lib/liballoc cleanall

build:
	mkdir build

lib/liballoc/build/liballoc.a:
	make -C lib/liballoc build/liballoc.a

build/libstr.a: src/str.c include/str.h libstr.api lib/liballoc/build/liballoc.a | build
	$(CC) -o build/tmp.o src/str.c $(CFLAGS) -r
	objcopy --keep-global-symbols=libstr.api build/tmp.o build/fixed.o
	ar rcs $@ build/fixed.o

build/libstr.so: src/str.c include/str.h libstr.lds | build
	$(CC) -o $@ src/str.c $(CFLAGS) \
		-shared -Wl,-version-script libstr.lds

build/test: src/test.c build/libstr.a lib/liballoc/build/liballoc.a | build
	$(CC) -o $@ $^ -g -I include -I lib/liballoc/include

install:
	install -m755 build/libstr.a -t "$(DESTDIR)$(PREFIX)$(LIBDIR)"
	install -m755 build/libstr.so -t "$(DESTDIR)$(PREFIX)$(LIBDIR)"
	install -m644 include/str.h -t "$(DESTDIR)$(PREFIX)$(INCLDIR)"

uninstall:
	rm -f "$(DESTDIR)$(PREFIX)$(LIBDIR)/libstr.a"
	rm -f "$(DESTDIR)$(PREFIX)$(LIBDIR)/libstr.so"
	rm -f "$(DESTDIR)$(PREFIX)$(INCLDIR)/str.h"

.PHONY: all clean cleanall install uninstall