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