1# 2# defines 3# 4topdir=$(shell pwd)/.. 5include ../Make.Rules 6# 7# Library version 8# 9CAPLIBNAME=$(LIBTITLE).so 10STACAPLIBNAME=$(LIBTITLE).a 11# 12PSXLIBNAME=libpsx.so 13STAPSXLIBNAME=libpsx.a 14 15CAPFILES=cap_alloc cap_proc cap_extint cap_flag cap_text cap_file 16PSXFILES=../psx/psx 17 18INCLS=libcap.h cap_names.h $(INCS) 19GPERF_OUTPUT = _caps_output.gperf 20 21CAPOBJS=$(addsuffix .o, $(CAPFILES)) 22MAJCAPLIBNAME=$(CAPLIBNAME).$(VERSION) 23MINCAPLIBNAME=$(MAJCAPLIBNAME).$(MINOR) 24 25PSXOBJS=$(addsuffix .o, $(PSXFILES)) 26MAJPSXLIBNAME=$(PSXLIBNAME).$(VERSION) 27MINPSXLIBNAME=$(MAJPSXLIBNAME).$(MINOR) 28 29all: pcs $(STACAPLIBNAME) 30ifeq ($(SHARED),yes) 31 $(MAKE) $(CAPLIBNAME) 32endif 33ifeq ($(PTHREADS),yes) 34 $(MAKE) $(STAPSXLIBNAME) 35ifeq ($(SHARED),yes) 36 $(MAKE) $(PSXLIBNAME) 37endif 38endif 39 40pcs: libcap.pc 41ifeq ($(PTHREADS),yes) 42 $(MAKE) libpsx.pc 43endif 44 45ifeq ($(BUILD_GPERF),yes) 46USE_GPERF_OUTPUT = $(GPERF_OUTPUT) 47INCLUDE_GPERF_OUTPUT = -DINCLUDE_GPERF_OUTPUT='"$(GPERF_OUTPUT)"' 48endif 49 50libcap.pc: libcap.pc.in 51 sed -e 's,@prefix@,$(prefix),' \ 52 -e 's,@exec_prefix@,$(exec_prefix),' \ 53 -e 's,@libdir@,$(LIBDIR),' \ 54 -e 's,@includedir@,$(inc_prefix)/include,' \ 55 -e 's,@VERSION@,$(VERSION).$(MINOR),' \ 56 -e 's,@deps@,$(DEPS),' \ 57 $< >$@ 58 59libpsx.pc: libpsx.pc.in 60 sed -e 's,@prefix@,$(prefix),' \ 61 -e 's,@exec_prefix@,$(exec_prefix),' \ 62 -e 's,@libdir@,$(LIBDIR),' \ 63 -e 's,@includedir@,$(inc_prefix)/include,' \ 64 -e 's,@VERSION@,$(VERSION).$(MINOR),' \ 65 -e 's,@deps@,$(DEPS),' \ 66 $< >$@ 67 68_makenames: _makenames.c cap_names.list.h 69 $(BUILD_CC) $(BUILD_CFLAGS) $< -o $@ 70 71cap_names.h: _makenames 72 ./_makenames > cap_names.h 73 74$(GPERF_OUTPUT): cap_names.list.h 75 perl -e 'print "struct __cap_token_s { const char *name; int index; };\n%{\nconst struct __cap_token_s *__cap_lookup_name(const char *, size_t);\n%}\n%%\n"; while ($$l = <>) { $$l =~ s/[\{\"]//g; $$l =~ s/\}.*// ; print $$l; }' < $< | gperf --ignore-case --language=ANSI-C --readonly --null-strings --global-table --hash-function-name=__cap_hash_name --lookup-function-name="__cap_lookup_name" -c -t -m20 $(INDENT) > $@ 76 sed -e 's/unsigned int len/size_t len/' -i $@ 77 78# Intention is that libcap keeps up with torvalds' tree, as reflected 79# by this maintained version of the kernel header. libcap dynamically 80# trims the meaning of "all" capabilities down to that of the running 81# kernel as of 2.30. 82UAPI_HEADER := $(topdir)/libcap/include/uapi/linux/capability.h 83cap_names.list.h: Makefile $(UAPI_HEADER) 84 @echo "=> making $@ from $(UAPI_HEADER)" 85 perl -e 'while ($$l=<>) { if ($$l =~ /^\#define[ \t](CAP[_A-Z]+)[ \t]+([0-9]+)\s+$$/) { $$tok=$$1; $$val=$$2; $$tok =~ tr/A-Z/a-z/; print "{\"$$tok\",$$val},\n"; } }' $(UAPI_HEADER) | fgrep -v 0x > $@ 86 87$(STACAPLIBNAME): $(CAPOBJS) 88 $(AR) rcs $@ $^ 89 $(RANLIB) $@ 90 91$(STAPSXLIBNAME): $(PSXOBJS) include/sys/psx_syscall.h 92 $(AR) rcs $@ $(PSXOBJS) 93 $(RANLIB) $@ 94 95ifeq ($(SHARED),yes) 96$(CAPLIBNAME) $(MAJCAPLIBNAME) $(MINCAPLIBNAME): $(CAPOBJS) 97 $(LD) $(CFLAGS) $(LDFLAGS) -Wl,-soname,$(MAJCAPLIBNAME) -o $(MINCAPLIBNAME) $^ 98 ln -sf $(MINCAPLIBNAME) $(MAJCAPLIBNAME) 99 ln -sf $(MAJCAPLIBNAME) $(CAPLIBNAME) 100 101$(PSXLIBNAME) $(MAJPSXLIBNAME) $(MINPSXLIBNAME): $(PSXOBJS) include/sys/psx_syscall.h 102 $(LD) $(CFLAGS) $(LDFLAGS) -Wl,-soname,$(MAJPSXLIBNAME) -o $(MINPSXLIBNAME) $(PSXOBJS) $(PSXLINKFLAGS) 103 ln -sf $(MINPSXLIBNAME) $(MAJPSXLIBNAME) 104 ln -sf $(MAJPSXLIBNAME) $(PSXLIBNAME) 105endif 106 107%.o: %.c $(INCLS) 108 $(CC) $(CFLAGS) $(IPATH) -c $< -o $@ 109 110cap_text.o: cap_text.c $(USE_GPERF_OUTPUT) $(INCLS) 111 $(CC) $(CFLAGS) $(IPATH) $(INCLUDE_GPERF_OUTPUT) -c $< -o $@ 112 113cap_test: cap_test.c libcap.h 114 $(CC) $(CFLAGS) $(IPATH) $< -o $@ 115 116test: cap_test 117 ./cap_test 118 119install: install-static 120ifeq ($(SHARED),yes) 121 $(MAKE) install-shared 122endif 123 124install-static: install-static-cap 125ifeq ($(PTHREADS),yes) 126 $(MAKE) install-static-psx 127endif 128 129install-shared: install-shared-cap 130ifeq ($(PTHREADS),yes) 131 $(MAKE) install-shared-psx 132endif 133 134install-cap: install-static-cap 135ifeq ($(SHARED),yes) 136 $(MAKE) install-shared-cap 137endif 138 139install-psx: install-static-psx 140ifeq ($(SHARED),yes) 141 $(MAKE) install-shared-psx 142endif 143 144install-static-cap: install-common-cap $(STACAPLIBNAME) 145 install -m 0644 $(STACAPLIBNAME) $(FAKEROOT)$(LIBDIR)/$(STACAPLIBNAME) 146 147install-shared-cap: install-common-cap $(MINCAPLIBNAME) 148 install -m 0644 $(MINCAPLIBNAME) $(FAKEROOT)$(LIBDIR)/$(MINCAPLIBNAME) 149 ln -sf $(MINCAPLIBNAME) $(FAKEROOT)$(LIBDIR)/$(MAJCAPLIBNAME) 150 ln -sf $(MAJCAPLIBNAME) $(FAKEROOT)$(LIBDIR)/$(CAPLIBNAME) 151ifeq ($(FAKEROOT),) 152 -/sbin/ldconfig 153endif 154 155install-static-psx: install-common-psx $(STAPSXLIBNAME) 156 install -m 0644 $(STAPSXLIBNAME) $(FAKEROOT)$(LIBDIR)/$(STAPSXLIBNAME) 157 158install-shared-psx: install-common-psx $(MINPSXLIBNAME) 159 install -m 0644 $(MINPSXLIBNAME) $(FAKEROOT)$(LIBDIR)/$(MINPSXLIBNAME) 160 ln -sf $(MINPSXLIBNAME) $(FAKEROOT)$(LIBDIR)/$(MAJPSXLIBNAME) 161 ln -sf $(MAJPSXLIBNAME) $(FAKEROOT)$(LIBDIR)/$(PSXLIBNAME) 162ifeq ($(FAKEROOT),) 163 -/sbin/ldconfig 164endif 165 166install-common-cap: install-common libcap.pc 167 install -m 0644 include/sys/capability.h $(FAKEROOT)$(INCDIR)/sys 168 install -m 0644 libcap.pc $(FAKEROOT)$(PKGCONFIGDIR)/libcap.pc 169 170include/sys/psx_syscall.h: ../psx/psx_syscall.h 171 rm -f $@ 172 ln -s ../../../psx/psx_syscall.h $@ 173 174install-common-psx: install-common libpsx.pc include/sys/psx_syscall.h 175 install -m 0644 include/sys/psx_syscall.h $(FAKEROOT)$(INCDIR)/sys 176 install -m 0644 libpsx.pc $(FAKEROOT)$(PKGCONFIGDIR)/libpsx.pc 177 178install-common: 179 mkdir -p -m 0755 $(FAKEROOT)$(INCDIR)/sys 180 mkdir -p -m 0755 $(FAKEROOT)$(PKGCONFIGDIR) 181 mkdir -p -m 0755 $(FAKEROOT)$(LIBDIR) 182 183clean: 184 $(LOCALCLEAN) 185 rm -f $(CAPOBJS) $(CAPLIBNAME)* $(STACAPLIBNAME) libcap.pc 186 rm -f $(PSXOBJS) $(PSXLIBNAME)* $(STAPSXLIBNAME) libpsx.pc 187 rm -f cap_names.h cap_names.list.h _makenames $(GPERF_OUTPUT) cap_test 188 rm -f include/sys/psx_syscall.h 189 cd include/sys && $(LOCALCLEAN) 190