summaryrefslogtreecommitdiff
path: root/progs/Makefile
blob: 2f887c8688ae34d677214d716b6d2db6a7d24da8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69

topdir=$(shell pwd)/..
include $(topdir)/Make.Rules
#
# Programs: all of the examples that we will compile
#
PROGS=getpcaps getcap setcap

BUILD=$(PROGS)

all: $(BUILD) capsh

ifeq ($(DYNAMIC),yes)
LDPATH = LD_LIBRARY_PATH=../libcap
DEPS = ../libcap/libcap.so
else
# For this build variant override the LDFLAGS to link statically from
# libraries within the build tree. If you never want this, use
# make DYNAMIC=yes ...
LDFLAGS = --static
DEPS = ../libcap/libcap.a
endif

../libcap/libcap.a:
	$(MAKE) -C ../libcap libcap.a

../libcap/libcap.so:
	$(MAKE) -C ../libcap libcap.so

$(BUILD): %: %.o $(DEPS)
	$(CC) $(CFLAGS) $(LDFLAGS) -o $@ $< $(LIBCAPLIB)

%.o: %.c $(INCS)
	$(CC) $(CFLAGS) $(CPPFLAGS) -c $< -o $@

install: all
	mkdir -p -m 0755 $(FAKEROOT)$(SBINDIR)
	for p in $(PROGS) capsh ; do \
		install -m 0755 $$p $(FAKEROOT)$(SBINDIR) ; \
	done
ifeq ($(RAISE_SETFCAP),yes)
	$(FAKEROOT)$(SBINDIR)/setcap cap_setfcap=i $(FAKEROOT)$(SBINDIR)/setcap
endif

test: $(PROGS) capsh

capshdoc.h.cf: capshdoc.h ./mkcapshdoc.sh
	./mkcapshdoc.sh > $@
	diff -u capshdoc.h $@ || (rm $@ ; exit 1)

capsh: capsh.c capshdoc.h.cf $(DEPS)
	$(CC) $(CFLAGS) $(CPPFLAGS) $(CAPSH_SHELL) $(LDFLAGS) -o $@ $< $(LIBCAPLIB)

# Statically linked with minimal linkage flags to enable running in a
# chroot and in other in-tree testing contexts.
tcapsh-static: capsh.c capshdoc.h.cf $(DEPS)
	$(CC) $(CFLAGS) $(CPPFLAGS) $(CAPSH_SHELL) -o $@ $< $(LIBCAPLIB) --static

uns_test: ../tests/uns_test.c
	$(MAKE) -C ../tests uns_test
	cp ../tests/uns_test .

sudotest: test tcapsh-static uns_test
	$(SUDO) $(LDPATH) ./quicktest.sh

clean:
	$(LOCALCLEAN)
	rm -f *.o $(BUILD) privileged ping hack.sh compare-cap uns_test
	rm -f capsh tcapsh* capshdoc.h.cf