16cd6a6acSopenharmony_ci# Installation directories.
26cd6a6acSopenharmony_ciPREFIX ?= /usr
36cd6a6acSopenharmony_ciINCLUDEDIR ?= $(PREFIX)/include
46cd6a6acSopenharmony_ciLIBDIR ?= $(PREFIX)/lib
56cd6a6acSopenharmony_ciSHLIBDIR ?= /lib
66cd6a6acSopenharmony_ciRANLIB ?= ranlib
76cd6a6acSopenharmony_ciCILDIR ?= ../cil
86cd6a6acSopenharmony_ci
96cd6a6acSopenharmony_ciVERSION = $(shell cat ../VERSION)
106cd6a6acSopenharmony_ciLIBVERSION = 2
116cd6a6acSopenharmony_ci
126cd6a6acSopenharmony_ciLEX = flex
136cd6a6acSopenharmony_ciCIL_GENERATED = $(CILDIR)/src/cil_lexer.c
146cd6a6acSopenharmony_ci
156cd6a6acSopenharmony_ciLIBA=libsepol.a 
166cd6a6acSopenharmony_ciTARGET=libsepol.so
176cd6a6acSopenharmony_ciLIBPC=libsepol.pc
186cd6a6acSopenharmony_ciLIBMAP=libsepol.map
196cd6a6acSopenharmony_ciLIBSO=$(TARGET).$(LIBVERSION)
206cd6a6acSopenharmony_ciOBJS= $(patsubst %.c,%.o,$(sort $(wildcard *.c)))
216cd6a6acSopenharmony_ciLOBJS= $(patsubst %.c,%.lo,$(sort $(wildcard *.c)))
226cd6a6acSopenharmony_ciCFLAGS ?= -Werror -Wall -W -Wundef -Wshadow -Wmissing-format-attribute -O2 -fno-semantic-interposition
236cd6a6acSopenharmony_ci
246cd6a6acSopenharmony_cioverride CFLAGS += -I. -I../include -D_GNU_SOURCE
256cd6a6acSopenharmony_ci
266cd6a6acSopenharmony_ciifneq ($(DISABLE_CIL),y)
276cd6a6acSopenharmony_ciOBJS += $(sort $(patsubst %.c,%.o,$(sort $(wildcard $(CILDIR)/src/*.c)) $(CIL_GENERATED)))
286cd6a6acSopenharmony_ciLOBJS += $(sort $(patsubst %.c,%.lo,$(sort $(wildcard $(CILDIR)/src/*.c)) $(CIL_GENERATED)))
296cd6a6acSopenharmony_cioverride CFLAGS += -I$(CILDIR)/include
306cd6a6acSopenharmony_ciendif
316cd6a6acSopenharmony_ci
326cd6a6acSopenharmony_ci# check for reallocarray(3) availability
336cd6a6acSopenharmony_ciH := \#
346cd6a6acSopenharmony_ciifeq (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))
356cd6a6acSopenharmony_cioverride CFLAGS += -DHAVE_REALLOCARRAY
366cd6a6acSopenharmony_ciendif
376cd6a6acSopenharmony_ci
386cd6a6acSopenharmony_ciLD_SONAME_FLAGS=-soname,$(LIBSO),--version-script=$(LIBMAP),-z,defs
396cd6a6acSopenharmony_ci
406cd6a6acSopenharmony_ciLN=ln
416cd6a6acSopenharmony_ciOS := $(shell uname)
426cd6a6acSopenharmony_ciifeq ($(OS), Darwin)
436cd6a6acSopenharmony_ciLD_SONAME_FLAGS=-install_name,$(LIBSO)
446cd6a6acSopenharmony_ciLDFLAGS += -undefined dynamic_lookup
456cd6a6acSopenharmony_ciLN=gln
466cd6a6acSopenharmony_ciendif
476cd6a6acSopenharmony_ci
486cd6a6acSopenharmony_ciall: $(LIBA) $(LIBSO) $(LIBPC)
496cd6a6acSopenharmony_ci
506cd6a6acSopenharmony_ci
516cd6a6acSopenharmony_ci$(LIBA):  $(OBJS)
526cd6a6acSopenharmony_ci	$(AR) rcs $@ $^
536cd6a6acSopenharmony_ci	$(RANLIB) $@
546cd6a6acSopenharmony_ci
556cd6a6acSopenharmony_ci$(LIBSO): $(LOBJS) $(LIBMAP)
566cd6a6acSopenharmony_ci	$(CC) $(CFLAGS) $(LDFLAGS) -shared -o $@ $(LOBJS) -Wl,$(LD_SONAME_FLAGS)
576cd6a6acSopenharmony_ci	ln -sf $@ $(TARGET) 
586cd6a6acSopenharmony_ci
596cd6a6acSopenharmony_ci$(LIBPC): $(LIBPC).in ../VERSION
606cd6a6acSopenharmony_ci	sed -e 's/@VERSION@/$(VERSION)/; s:@prefix@:$(PREFIX):; s:@libdir@:$(LIBDIR):; s:@includedir@:$(INCLUDEDIR):' < $< > $@
616cd6a6acSopenharmony_ci
626cd6a6acSopenharmony_ci$(LIBMAP): $(LIBMAP).in
636cd6a6acSopenharmony_ciifneq ($(DISABLE_CIL),y)
646cd6a6acSopenharmony_ci	cp $< $@
656cd6a6acSopenharmony_cielse
666cd6a6acSopenharmony_ci	sed -e '/^\s*cil_/d' < $< > $@
676cd6a6acSopenharmony_ciendif
686cd6a6acSopenharmony_ci
696cd6a6acSopenharmony_ciifneq ($(DISABLE_CIL),y)
706cd6a6acSopenharmony_ci$(CILDIR)/src/cil_lexer.o: $(CILDIR)/src/cil_lexer.c
716cd6a6acSopenharmony_ci	$(CC) $(filter-out -Werror, $(CFLAGS)) -fPIC -c -o $@ $<
726cd6a6acSopenharmony_ci
736cd6a6acSopenharmony_ci$(CILDIR)/src/cil_lexer.lo: $(CILDIR)/src/cil_lexer.c
746cd6a6acSopenharmony_ci	$(CC) $(filter-out -Werror, $(CFLAGS)) -fPIC -DSHARED -c -o $@ $<
756cd6a6acSopenharmony_ci
766cd6a6acSopenharmony_ci$(CILDIR)/src/cil_lexer.c: $(CILDIR)/src/cil_lexer.l
776cd6a6acSopenharmony_ci	$(LEX) -o $@ $<
786cd6a6acSopenharmony_ci
796cd6a6acSopenharmony_ciendif
806cd6a6acSopenharmony_ci
816cd6a6acSopenharmony_ci%.o:  %.c 
826cd6a6acSopenharmony_ci	$(CC) $(CFLAGS) -fPIC -c -o $@ $<
836cd6a6acSopenharmony_ci
846cd6a6acSopenharmony_ci%.lo:  %.c
856cd6a6acSopenharmony_ci	$(CC) $(CFLAGS) -fPIC -DSHARED -c -o $@ $<
866cd6a6acSopenharmony_ci
876cd6a6acSopenharmony_ciinstall: all
886cd6a6acSopenharmony_ci	test -d $(DESTDIR)$(LIBDIR) || install -m 755 -d $(DESTDIR)$(LIBDIR)
896cd6a6acSopenharmony_ci	install -m 644 $(LIBA) $(DESTDIR)$(LIBDIR)
906cd6a6acSopenharmony_ci	test -d $(DESTDIR)$(SHLIBDIR) || install -m 755 -d $(DESTDIR)$(SHLIBDIR)
916cd6a6acSopenharmony_ci	install -m 755 $(LIBSO) $(DESTDIR)$(SHLIBDIR)
926cd6a6acSopenharmony_ci	test -d $(DESTDIR)$(LIBDIR)/pkgconfig || install -m 755 -d $(DESTDIR)$(LIBDIR)/pkgconfig
936cd6a6acSopenharmony_ci	install -m 644 $(LIBPC) $(DESTDIR)$(LIBDIR)/pkgconfig
946cd6a6acSopenharmony_ci	$(LN) -sf --relative $(DESTDIR)$(SHLIBDIR)/$(LIBSO) $(DESTDIR)$(LIBDIR)/$(TARGET)
956cd6a6acSopenharmony_ci
966cd6a6acSopenharmony_cirelabel:
976cd6a6acSopenharmony_ci	/sbin/restorecon $(DESTDIR)$(SHLIBDIR)/$(LIBSO)
986cd6a6acSopenharmony_ci
996cd6a6acSopenharmony_ciclean: 
1006cd6a6acSopenharmony_ci	-rm -f $(LIBPC) $(LIBMAP) $(OBJS) $(LOBJS) $(LIBA) $(LIBSO) $(TARGET) $(CIL_GENERATED)
1016cd6a6acSopenharmony_ci
1026cd6a6acSopenharmony_ciindent:
1036cd6a6acSopenharmony_ci	../../scripts/Lindent $(wildcard *.[ch])
1046cd6a6acSopenharmony_ci
105