766fccbd6cf11ee301513d4277ec7481bf370341
[project/uci.git] / Makefile
1 VERSION=0.1
2
3 COPTS=-O2
4 WOPTS=-pedantic -Wno-unused -Werror
5 FPIC=-fPIC
6 CFLAGS=$(COPTS) $(WOPTS) -Wall -std=gnu99
7
8 AR=ar
9 LD=ld
10 CC=gcc
11 LIBS=-lc
12 RANLIB=ranlib
13
14 ifneq ($(DEBUG),)
15   COPTS = -O0
16   CFLAGS += -g3 -DDEBUG_ALL
17 endif
18 OS=$(shell uname)
19 ifeq ($(OS),Darwin)
20   SHLIB_EXT=dylib
21   SHLIB_FLAGS=-dylib
22 else
23   LD=gcc
24   SHLIB_EXT=so
25   SHLIB_FLAGS=-shared -Wl,-soname,$(SHLIB_FILE)
26 endif
27 SHLIB_FILE=libuci.$(SHLIB_EXT).$(VERSION)
28
29 all: uci-static uci libuci.$(SHLIB_EXT)
30
31 cli.o: cli.c uci.h
32
33 uci: cli.o libuci.$(SHLIB_EXT)
34         $(CC) -o $@ $< -L. -luci
35
36 uci-static: cli.o libuci.a
37         $(CC) $(CFLAGS) -o $@ $^
38
39 libuci-static.o: libuci.c file.c uci.h list.c err.h util.c
40         $(CC) $(CFLAGS) -c -o $@ $<
41
42 libuci-shared.o: libuci.c file.c uci.h list.c err.h util.c
43         $(CC) $(CFLAGS) $(FPIC) -c -o $@ $<
44
45 libuci.a: libuci-static.o
46         rm -f $@
47         $(AR) rc $@ $^
48         $(RANLIB) $@
49
50 libuci.$(SHLIB_EXT): libuci-shared.o
51         $(LD) $(SHLIB_FLAGS) -o $(SHLIB_FILE) $^ $(LIBS)
52         ln -sf $(SHLIB_FILE) $@
53
54 clean:
55         rm -f uci uci-static *.[oa] *.so* *.dylib*