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