• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1#
2# defines
3#
4topdir=$(shell pwd)/..
5include ../Make.Rules
6#
7# Library version
8#
9CAPLIBNAME=$(LIBTITLE).so
10STACAPLIBNAME=$(LIBTITLE).a
11#
12PSXTITLE=libpsx
13PSXLIBNAME=$(PSXTITLE).so
14STAPSXLIBNAME=$(PSXTITLE).a
15
16CAPFILES=cap_alloc cap_proc cap_extint cap_flag cap_text cap_file
17CAPMAGICOBJ=cap_magic.o
18PSXFILES=../psx/psx
19PSXMAGICOBJ=psx_magic.o
20
21# The linker magic needed to build a dynamic library as independently
22# executable
23MAGIC=-Wl,-e,__so_start
24
25INCLS=libcap.h cap_names.h $(INCS)
26GPERF_OUTPUT = _caps_output.gperf
27
28CAPOBJS=$(addsuffix .o, $(CAPFILES))
29MAJCAPLIBNAME=$(CAPLIBNAME).$(VERSION)
30MINCAPLIBNAME=$(MAJCAPLIBNAME).$(MINOR)
31
32PSXOBJS=$(addsuffix .o, $(PSXFILES))
33MAJPSXLIBNAME=$(PSXLIBNAME).$(VERSION)
34MINPSXLIBNAME=$(MAJPSXLIBNAME).$(MINOR)
35
36all: pcs $(STACAPLIBNAME)
37ifeq ($(SHARED),yes)
38	$(MAKE) $(CAPLIBNAME)
39endif
40ifeq ($(PTHREADS),yes)
41	$(MAKE) $(STAPSXLIBNAME)
42ifeq ($(SHARED),yes)
43	$(MAKE) $(PSXLIBNAME)
44endif
45endif
46
47pcs: $(LIBTITLE).pc
48ifeq ($(PTHREADS),yes)
49	$(MAKE) $(PSXTITLE).pc
50endif
51
52ifeq ($(BUILD_GPERF),yes)
53USE_GPERF_OUTPUT = $(GPERF_OUTPUT)
54INCLUDE_GPERF_OUTPUT = -DINCLUDE_GPERF_OUTPUT='"$(GPERF_OUTPUT)"'
55endif
56
57$(LIBTITLE).pc: $(LIBTITLE).pc.in
58	sed -e 's,@prefix@,$(prefix),' \
59		-e 's,@exec_prefix@,$(exec_prefix),' \
60		-e 's,@libdir@,$(LIBDIR),' \
61		-e 's,@includedir@,$(inc_prefix)/include,' \
62		-e 's,@VERSION@,$(VERSION).$(MINOR),' \
63		-e 's,@deps@,$(DEPS),' \
64		$< >$@
65
66$(PSXTITLE).pc: $(PSXTITLE).pc.in
67	sed -e 's,@prefix@,$(prefix),' \
68		-e 's,@exec_prefix@,$(exec_prefix),' \
69		-e 's,@libdir@,$(LIBDIR),' \
70		-e 's,@includedir@,$(inc_prefix)/include,' \
71		-e 's,@VERSION@,$(VERSION).$(MINOR),' \
72		-e 's,@deps@,$(DEPS),' \
73		$< >$@
74
75_makenames: _makenames.c cap_names.list.h
76	$(BUILD_CC) $(BUILD_CFLAGS) $< -o $@
77
78cap_names.h: _makenames
79	./_makenames > cap_names.h
80
81$(GPERF_OUTPUT): cap_names.list.h
82	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) > $@
83	sed -e 's/unsigned int len/size_t len/' -i $@
84
85# Intention is that libcap keeps up with torvalds' tree, as reflected
86# by this maintained version of the kernel header. libcap dynamically
87# trims the meaning of "all" capabilities down to that of the running
88# kernel as of 2.30.
89UAPI_HEADER := $(topdir)/libcap/include/uapi/linux/capability.h
90cap_names.list.h: Makefile $(UAPI_HEADER)
91	@echo "=> making $@ from $(UAPI_HEADER)"
92	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 > $@
93
94$(STACAPLIBNAME): $(CAPOBJS)
95	$(AR) rcs $@ $^
96	$(RANLIB) $@
97
98$(STAPSXLIBNAME): $(PSXOBJS) include/sys/psx_syscall.h
99	$(AR) rcs $@ $(PSXOBJS)
100	$(RANLIB) $@
101
102ifeq ($(SHARED),yes)
103
104empty: empty.c
105	$(CC) -o $@ $<
106
107loader.txt: empty
108	$(OBJCOPY) --dump-section .interp=$@ $<
109
110cap_magic.o: execable.h execable.c loader.txt
111	$(CC) $(CFLAGS) $(IPATH) -DLIBRARY_VERSION=\"$(LIBTITLE)-$(VERSION).$(MINOR)\" -DSHARED_LOADER=\"$(shell cat loader.txt)\" -c execable.c -o $@
112
113$(CAPLIBNAME) $(MAJCAPLIBNAME) $(MINCAPLIBNAME): $(CAPOBJS) $(CAPMAGICOBJ)
114	$(LD) $(CFLAGS) $(LDFLAGS) -Wl,-soname,$(MAJCAPLIBNAME) -o $(MINCAPLIBNAME) $^ $(MAGIC)
115	ln -sf $(MINCAPLIBNAME) $(MAJCAPLIBNAME)
116	ln -sf $(MAJCAPLIBNAME) $(CAPLIBNAME)
117
118psx_magic.o: execable.h execable.c loader.txt
119	$(CC) $(CFLAGS) $(IPATH) -DLIBRARY_VERSION=\"$(PSXTITLE)-$(VERSION).$(MINOR)\" -DSHARED_LOADER=\"$(shell cat loader.txt)\" -c execable.c -o $@
120
121$(PSXLIBNAME) $(MAJPSXLIBNAME) $(MINPSXLIBNAME): $(PSXOBJS) include/sys/psx_syscall.h $(PSXMAGICOBJ)
122	$(LD) $(CFLAGS) $(LDFLAGS) -Wl,-soname,$(MAJPSXLIBNAME) -o $(MINPSXLIBNAME) $(PSXOBJS) $(PSXMAGICOBJ) $(MAGIC) $(PSXLINKFLAGS)
123	ln -sf $(MINPSXLIBNAME) $(MAJPSXLIBNAME)
124	ln -sf $(MAJPSXLIBNAME) $(PSXLIBNAME)
125endif
126
127%.o: %.c $(INCLS)
128	$(CC) $(CFLAGS) $(IPATH) -c $< -o $@
129
130cap_text.o: cap_text.c $(USE_GPERF_OUTPUT) $(INCLS)
131	$(CC) $(CFLAGS) $(IPATH) $(INCLUDE_GPERF_OUTPUT) -c $< -o $@
132
133cap_test: cap_test.c libcap.h $(CAPOBJS)
134	$(CC) $(CFLAGS) $(IPATH) $< $(CAPOBJS) -o $@
135
136libcapsotest: $(CAPLIBNAME)
137	./$(CAPLIBNAME)
138
139libpsxsotest: $(PSXLIBNAME)
140	./$(PSXLIBNAME)
141
142test: cap_test
143	./cap_test
144ifeq ($(SHARED),yes)
145	$(MAKE) libcapsotest
146ifeq ($(PTHREADS),yes)
147	$(MAKE) libpsxsotest
148endif
149endif
150
151install: install-static
152ifeq ($(SHARED),yes)
153	$(MAKE) install-shared
154endif
155
156install-static: install-static-cap
157ifeq ($(PTHREADS),yes)
158	$(MAKE) install-static-psx
159endif
160
161install-shared: install-shared-cap
162ifeq ($(PTHREADS),yes)
163	$(MAKE) install-shared-psx
164endif
165
166install-cap: install-static-cap
167ifeq ($(SHARED),yes)
168	$(MAKE) install-shared-cap
169endif
170
171install-psx: install-static-psx
172ifeq ($(SHARED),yes)
173	$(MAKE) install-shared-psx
174endif
175
176install-static-cap: install-common-cap $(STACAPLIBNAME)
177	install -m 0644 $(STACAPLIBNAME) $(FAKEROOT)$(LIBDIR)/$(STACAPLIBNAME)
178
179install-shared-cap: install-common-cap $(MINCAPLIBNAME)
180	install -m 0644 $(MINCAPLIBNAME) $(FAKEROOT)$(LIBDIR)/$(MINCAPLIBNAME)
181	ln -sf $(MINCAPLIBNAME) $(FAKEROOT)$(LIBDIR)/$(MAJCAPLIBNAME)
182	ln -sf $(MAJCAPLIBNAME) $(FAKEROOT)$(LIBDIR)/$(CAPLIBNAME)
183ifeq ($(FAKEROOT),)
184	-/sbin/ldconfig
185endif
186
187install-static-psx: install-common-psx $(STAPSXLIBNAME)
188	install -m 0644 $(STAPSXLIBNAME) $(FAKEROOT)$(LIBDIR)/$(STAPSXLIBNAME)
189
190install-shared-psx: install-common-psx $(MINPSXLIBNAME)
191	install -m 0644 $(MINPSXLIBNAME) $(FAKEROOT)$(LIBDIR)/$(MINPSXLIBNAME)
192	ln -sf $(MINPSXLIBNAME) $(FAKEROOT)$(LIBDIR)/$(MAJPSXLIBNAME)
193	ln -sf $(MAJPSXLIBNAME) $(FAKEROOT)$(LIBDIR)/$(PSXLIBNAME)
194ifeq ($(FAKEROOT),)
195	-/sbin/ldconfig
196endif
197
198install-common-cap: install-common $(LIBTITLE).pc
199	install -m 0644 include/sys/capability.h $(FAKEROOT)$(INCDIR)/sys
200	install -m 0644 $(LIBTITLE).pc $(FAKEROOT)$(PKGCONFIGDIR)/$(LIBTITLE).pc
201
202include/sys/psx_syscall.h: ../psx/psx_syscall.h
203	rm -f $@
204	ln -s ../../../psx/psx_syscall.h $@
205
206install-common-psx: install-common $(PSXTITLE).pc include/sys/psx_syscall.h
207	install -m 0644 include/sys/psx_syscall.h $(FAKEROOT)$(INCDIR)/sys
208	install -m 0644 $(PSXTITLE).pc $(FAKEROOT)$(PKGCONFIGDIR)/$(PSXTITLE).pc
209
210install-common:
211	mkdir -p -m 0755 $(FAKEROOT)$(INCDIR)/sys
212	mkdir -p -m 0755 $(FAKEROOT)$(PKGCONFIGDIR)
213	mkdir -p -m 0755 $(FAKEROOT)$(LIBDIR)
214
215clean:
216	$(LOCALCLEAN)
217	rm -f $(CAPOBJS) $(CAPLIBNAME)* $(STACAPLIBNAME) $(LIBTITLE).pc
218	rm -f $(PSXOBJS) $(PSXLIBNAME)* $(STAPSXLIBNAME) $(PSXTITLE).pc
219	rm -f cap_names.h cap_names.list.h _makenames $(GPERF_OUTPUT) cap_test
220	rm -f include/sys/psx_syscall.h
221	rm -f $(CAPMAGICOBJ) $(PSXMAGICOBJ) empty loader.txt
222	cd include/sys && $(LOCALCLEAN)
223