• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# Installation directories.
2PREFIX ?= /usr
3INCLUDEDIR ?= $(PREFIX)/include
4LIBDIR ?= $(PREFIX)/lib
5SHLIBDIR ?= /lib
6RANLIB ?= ranlib
7CILDIR ?= ../cil
8
9VERSION = $(shell cat ../VERSION)
10LIBVERSION = 2
11
12LEX = flex
13CIL_GENERATED = $(CILDIR)/src/cil_lexer.c
14
15LIBA=libsepol.a
16TARGET=libsepol.so
17LIBPC=libsepol.pc
18LIBMAP=libsepol.map
19LIBSO=$(TARGET).$(LIBVERSION)
20OBJS= $(patsubst %.c,%.o,$(sort $(wildcard *.c)))
21LOBJS= $(patsubst %.c,%.lo,$(sort $(wildcard *.c)))
22CFLAGS ?= -Werror -Wall -W -Wundef -Wshadow -Wmissing-format-attribute -O2 -fno-semantic-interposition
23
24override CFLAGS += -I. -I../include -D_GNU_SOURCE
25
26ifneq ($(DISABLE_CIL),y)
27OBJS += $(sort $(patsubst %.c,%.o,$(sort $(wildcard $(CILDIR)/src/*.c)) $(CIL_GENERATED)))
28LOBJS += $(sort $(patsubst %.c,%.lo,$(sort $(wildcard $(CILDIR)/src/*.c)) $(CIL_GENERATED)))
29override CFLAGS += -I$(CILDIR)/include
30endif
31
32# check for reallocarray(3) availability
33H := \#
34ifeq (yes,$(shell printf '${H}define _GNU_SOURCE\n${H}include <stdlib.h>\nint main(void){void*p=reallocarray(NULL, 1, sizeof(char));return 0;}' | $(CC) -x c -o /dev/null - >/dev/null 2>&1 && echo yes))
35override CFLAGS += -DHAVE_REALLOCARRAY
36endif
37
38LD_SONAME_FLAGS=-soname,$(LIBSO),--version-script=$(LIBMAP),-z,defs
39
40LN=ln
41OS := $(shell uname)
42ifeq ($(OS), Darwin)
43LD_SONAME_FLAGS=-install_name,$(LIBSO)
44LDFLAGS += -undefined dynamic_lookup
45LN=gln
46endif
47
48all: $(LIBA) $(LIBSO) $(LIBPC)
49
50
51$(LIBA):  $(OBJS)
52	$(AR) rcs $@ $^
53	$(RANLIB) $@
54
55$(LIBSO): $(LOBJS) $(LIBMAP)
56	$(CC) $(CFLAGS) $(LDFLAGS) -shared -o $@ $(LOBJS) -Wl,$(LD_SONAME_FLAGS)
57	ln -sf $@ $(TARGET)
58
59$(LIBPC): $(LIBPC).in ../VERSION
60	sed -e 's/@VERSION@/$(VERSION)/; s:@prefix@:$(PREFIX):; s:@libdir@:$(LIBDIR):; s:@includedir@:$(INCLUDEDIR):' < $< > $@
61
62$(LIBMAP): $(LIBMAP).in
63ifneq ($(DISABLE_CIL),y)
64	cp $< $@
65else
66	sed -e '/^\s*cil_/d' < $< > $@
67endif
68
69ifneq ($(DISABLE_CIL),y)
70$(CILDIR)/src/cil_lexer.o: $(CILDIR)/src/cil_lexer.c
71	$(CC) $(filter-out -Werror, $(CFLAGS)) -fPIC -c -o $@ $<
72
73$(CILDIR)/src/cil_lexer.lo: $(CILDIR)/src/cil_lexer.c
74	$(CC) $(filter-out -Werror, $(CFLAGS)) -fPIC -DSHARED -c -o $@ $<
75
76$(CILDIR)/src/cil_lexer.c: $(CILDIR)/src/cil_lexer.l
77	$(LEX) -o $@ $<
78
79endif
80
81%.o:  %.c
82	$(CC) $(CFLAGS) -fPIC -c -o $@ $<
83
84%.lo:  %.c
85	$(CC) $(CFLAGS) -fPIC -DSHARED -c -o $@ $<
86
87install: all
88	test -d $(DESTDIR)$(LIBDIR) || install -m 755 -d $(DESTDIR)$(LIBDIR)
89	install -m 644 $(LIBA) $(DESTDIR)$(LIBDIR)
90	test -d $(DESTDIR)$(SHLIBDIR) || install -m 755 -d $(DESTDIR)$(SHLIBDIR)
91	install -m 755 $(LIBSO) $(DESTDIR)$(SHLIBDIR)
92	test -d $(DESTDIR)$(LIBDIR)/pkgconfig || install -m 755 -d $(DESTDIR)$(LIBDIR)/pkgconfig
93	install -m 644 $(LIBPC) $(DESTDIR)$(LIBDIR)/pkgconfig
94	$(LN) -sf --relative $(DESTDIR)$(SHLIBDIR)/$(LIBSO) $(DESTDIR)$(LIBDIR)/$(TARGET)
95
96relabel:
97	/sbin/restorecon $(DESTDIR)$(SHLIBDIR)/$(LIBSO)
98
99clean:
100	-rm -f $(LIBPC) $(LIBMAP) $(OBJS) $(LOBJS) $(LIBA) $(LIBSO) $(TARGET) $(CIL_GENERATED)
101
102indent:
103	../../scripts/Lindent $(wildcard *.[ch])
104
105