1# Installation directories. 2PREFIX ?= $(DESTDIR)/usr 3INCLUDEDIR ?= $(PREFIX)/include 4LIBDIR ?= $(PREFIX)/lib 5SHLIBDIR ?= $(DESTDIR)/lib 6RANLIB ?= ranlib 7LIBBASE ?= $(shell basename $(LIBDIR)) 8CILDIR ?= ../cil 9 10VERSION = $(shell cat ../VERSION) 11LIBVERSION = 1 12 13LEX = flex 14CIL_GENERATED = $(CILDIR)/src/cil_lexer.c 15 16LIBA=libsepol.a 17TARGET=libsepol.so 18LIBPC=libsepol.pc 19LIBMAP=libsepol.map 20LIBSO=$(TARGET).$(LIBVERSION) 21OBJS= $(patsubst %.c,%.o,$(sort $(wildcard *.c))) 22LOBJS= $(patsubst %.c,%.lo,$(sort $(wildcard *.c))) 23CFLAGS ?= -Werror -Wall -W -Wundef -Wshadow -Wmissing-format-attribute -O2 24 25override CFLAGS += -I. -I../include -D_GNU_SOURCE 26 27ifneq ($(DISABLE_CIL),y) 28OBJS += $(sort $(patsubst %.c,%.o,$(sort $(wildcard $(CILDIR)/src/*.c)) $(CIL_GENERATED))) 29LOBJS += $(sort $(patsubst %.c,%.lo,$(sort $(wildcard $(CILDIR)/src/*.c)) $(CIL_GENERATED))) 30override CFLAGS += -I$(CILDIR)/include 31endif 32 33LD_SONAME_FLAGS=-soname,$(LIBSO),--version-script=$(LIBMAP),-z,defs 34 35LN=ln 36OS := $(shell uname) 37ifeq ($(OS), Darwin) 38LD_SONAME_FLAGS=-install_name,$(LIBSO) 39LDFLAGS += -undefined dynamic_lookup 40LN=gln 41endif 42 43all: $(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 58ifneq ($(DISABLE_CIL),y) 59 cp $< $@ 60else 61 sed -e '/^\s*cil_/d' < $< > $@ 62endif 63 64ifneq ($(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 74endif 75 76%.o: %.c 77 $(CC) $(CFLAGS) -fPIC -c -o $@ $< 78 79%.lo: %.c 80 $(CC) $(CFLAGS) -fPIC -DSHARED -c -o $@ $< 81 82install: 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 91relabel: 92 /sbin/restorecon $(SHLIBDIR)/$(LIBSO) 93 94clean: 95 -rm -f $(LIBPC) $(LIBMAP) $(OBJS) $(LOBJS) $(LIBA) $(LIBSO) $(TARGET) $(CIL_GENERATED) 96 97indent: 98 ../../scripts/Lindent $(wildcard *.[ch]) 99 100