• 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 = 1
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
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
32LD_SONAME_FLAGS=-soname,$(LIBSO),--version-script=$(LIBMAP),-z,defs
33
34LN=ln
35OS := $(shell uname)
36ifeq ($(OS), Darwin)
37LD_SONAME_FLAGS=-install_name,$(LIBSO)
38LDFLAGS += -undefined dynamic_lookup
39LN=gln
40endif
41
42all: $(LIBA) $(LIBSO) $(LIBPC)
43
44
45$(LIBA):  $(OBJS)
46	$(AR) rcs $@ $^
47	$(RANLIB) $@
48
49$(LIBSO): $(LOBJS) $(LIBMAP)
50	$(CC) $(CFLAGS) $(LDFLAGS) -shared -o $@ $(LOBJS) -Wl,$(LD_SONAME_FLAGS)
51	ln -sf $@ $(TARGET)
52
53$(LIBPC): $(LIBPC).in ../VERSION
54	sed -e 's/@VERSION@/$(VERSION)/; s:@prefix@:$(PREFIX):; s:@libdir@:$(LIBDIR):; s:@includedir@:$(INCLUDEDIR):' < $< > $@
55
56$(LIBMAP): $(LIBMAP).in
57ifneq ($(DISABLE_CIL),y)
58	cp $< $@
59else
60	sed -e '/^\s*cil_/d' < $< > $@
61endif
62
63ifneq ($(DISABLE_CIL),y)
64$(CILDIR)/src/cil_lexer.o: $(CILDIR)/src/cil_lexer.c
65	$(CC) $(filter-out -Werror, $(CFLAGS)) -fPIC -c -o $@ $<
66
67$(CILDIR)/src/cil_lexer.lo: $(CILDIR)/src/cil_lexer.c
68	$(CC) $(filter-out -Werror, $(CFLAGS)) -fPIC -DSHARED -c -o $@ $<
69
70$(CILDIR)/src/cil_lexer.c: $(CILDIR)/src/cil_lexer.l
71	$(LEX) -o $@ $<
72
73endif
74
75%.o:  %.c
76	$(CC) $(CFLAGS) -fPIC -c -o $@ $<
77
78%.lo:  %.c
79	$(CC) $(CFLAGS) -fPIC -DSHARED -c -o $@ $<
80
81install: all
82	test -d $(DESTDIR)$(LIBDIR) || install -m 755 -d $(DESTDIR)$(LIBDIR)
83	install -m 644 $(LIBA) $(DESTDIR)$(LIBDIR)
84	test -d $(DESTDIR)$(SHLIBDIR) || install -m 755 -d $(DESTDIR)$(SHLIBDIR)
85	install -m 755 $(LIBSO) $(DESTDIR)$(SHLIBDIR)
86	test -d $(DESTDIR)$(LIBDIR)/pkgconfig || install -m 755 -d $(DESTDIR)$(LIBDIR)/pkgconfig
87	install -m 644 $(LIBPC) $(DESTDIR)$(LIBDIR)/pkgconfig
88	$(LN) -sf --relative $(DESTDIR)$(SHLIBDIR)/$(LIBSO) $(DESTDIR)$(LIBDIR)/$(TARGET)
89
90relabel:
91	/sbin/restorecon $(DESTDIR)$(SHLIBDIR)/$(LIBSO)
92
93clean:
94	-rm -f $(LIBPC) $(LIBMAP) $(OBJS) $(LOBJS) $(LIBA) $(LIBSO) $(TARGET) $(CIL_GENERATED)
95
96indent:
97	../../scripts/Lindent $(wildcard *.[ch])
98
99