aboutsummaryrefslogtreecommitdiff
blob: ee1a7f043738635f7443c33590b99d10ec925828 (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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
# Copyright 2003 Ned Ludd <solar@linbsd.net>
# Distributed under the terms of the GNU General Public License v2
# $Header: /var/cvsroot/gentoo-projects/pax-utils/Makefile,v 1.52 2006/04/11 01:04:23 vapier Exp $
####################################################################

check_gcc=$(shell if $(CC) $(1) -S -o /dev/null -xc /dev/null > /dev/null 2>&1; \
	then echo "$(1)"; else echo "$(2)"; fi)

####################################################################
WFLAGS    := -Wall -Wunused -Wimplicit -Wshadow -Wformat=2 \
             -Wmissing-declarations -Wmissing-prototypes -Wwrite-strings \
             -Wbad-function-cast -Wnested-externs -Wcomment -Winline \
             -Wchar-subscripts -Wcast-align -Wno-format-nonliteral \
             $(call check_gcc, -Wdeclaration-after-statement) \
             $(call check-gcc, -Wsequence-point) \
             $(call check-gcc, -Wextra)

CFLAGS    ?= -O2 -pipe
WFLAGS    += -D_GNU_SOURCE
#CFLAGS   += -DEBUG -g
#LDFLAGS  := -pie
DESTDIR    =
PREFIX    := $(DESTDIR)/usr
STRIP     := strip
MKDIR     := mkdir -p
CP        := cp

ifdef PV
HFLAGS    += -DVERSION=\"$(PV)\"
endif

####################################################################
ELF_TARGETS  = scanelf pspax dumpelf
ELF_OBJS     = $(ELF_TARGETS:%=%.o) paxelf.o
MACH_TARGETS = scanmacho
MACH_OBJS    = $(MACH_TARGETS:%=%.o) paxmacho.o
OBJS         = $(ELF_OBJS) $(MACH_OBJS) paxinc.o
TARGETS      = $(ELF_TARGETS) $(MACH_TARGETS)
MPAGES       = $(TARGETS:%=man/%.1)
SOURCES      = $(OBJS:%.o=%.c)

ifneq ($(MACH),1)
MACH_TARGETS = 
MACH_OBJS    = 
endif

all: $(OBJS) $(TARGETS)
	@:

debug:
	$(MAKE) CFLAGS="$(CFLAGS) -g3 -ggdb -nopie" clean all
	@-/sbin/chpax  -permsx $(ELF_TARGETS)
	@-/sbin/paxctl -permsx $(ELF_TARGETS)

%.o: %.c
ifeq ($(findstring s,$(MAKEFLAGS)),)
	@echo $(CC) $(CFLAGS) -c $<
endif
	@$(CC) $(CFLAGS) $(WFLAGS) $(HFLAGS) -c $<

$(ELF_TARGETS): $(ELF_OBJS) paxinc.o
	$(CC) $(CFLAGS) $(LDFLAGS) paxinc.o paxelf.o -o $@ $@.o

$(MACH_TARGETS): $(MACH_OBJS) paxinc.o
	$(CC) $(CFLAGS) $(LDFLAGS) paxinc.o paxmacho.o -o $@ $@.o

%.so: %.c
	$(CC) -shared -fPIC -o $@ $<

depend:
	$(CC) $(CFLAGS) -MM $(SOURCES) > .depend

clean:
	-rm -f $(OBJS) $(TARGETS)

distclean: clean
	-rm -f *~ core *.o

strip: all
	$(STRIP) $(TARGETS)
strip-more:
	$(STRIP) --strip-unneeded $(TARGETS)

install: all
	-$(MKDIR) $(PREFIX)/bin/ $(PREFIX)/share/man/man1/
	$(CP) $(TARGETS) $(PREFIX)/bin/
ifeq ($(S),)
	-$(MKDIR) $(PREFIX)/share/doc/pax-utils/
	$(CP) README BUGS TODO $(PREFIX)/share/doc/pax-utils/
endif
	for mpage in $(MPAGES) ; do \
		[ -e $$mpage ] \
			&& cp $$mpage $(PREFIX)/share/man/man1/ || : ;\
	done

dist: distclean
	@tempfiles=`ls .#* *.o 2>/dev/null` ; \
	if [ -n "$$tempfiles" ] ; then \
		echo "Please remove these files first:" ; \
		echo "$$tempfiles" ; \
		exit 1 ; \
	fi
	@if [ "$(PV)" = "" ] ; then \
		echo "Please run 'make dist PV=<ver>'" ; \
		exit 1 ; \
	fi
	$(MAKE) -s distclean
	rm -rf ../pax-utils-$(PV)*
	mkdir ../pax-utils-$(PV)
	cp -R * .depend ../pax-utils-$(PV)/
	rm -rf ../pax-utils-$(PV)/CVS ../pax-utils-$(PV)/*/CVS ../pax-utils-$(PV)/make-tarball.sh
	tar jcf ../pax-utils-$(PV).tar.bz2 -C .. pax-utils-$(PV)
	rm -rf ../pax-utils-$(PV)
	du -b ../pax-utils-$(PV).tar.bz2

-include .depend