summaryrefslogtreecommitdiffstats
path: root/Makefile
blob: 5c47dc98270c41f725a4b202e1e9d49af5e6ff96 (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
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
## -----------------------------------------------------------------------
##   
##   Copyright 2001-2008 H. Peter Anvin - All Rights Reserved
##
##   This program is free software; you can redistribute it and/or modify
##   it under the terms of the GNU Lesser General Public License as
##   published by the Free Software Foundation, Inc.,
##   59 Temple Place Ste 330, Bostom MA 02111-1307, USA; version 2.1,
##   incorporated herein by reference.
##
## -----------------------------------------------------------------------

TEST      = teststore testbuddy testalloc testrecovery zallocevil \
	    test_mmap ftrunctest 
SONAME    = libpsm.so.0
VERSION   = $(shell cat version)
LIBPSM	  = libpsm.so.$(VERSION) libpsm.a

CFILES    = arena.c bitops.c \
	    mgmt.c malloc.c free.c realloc.c zalloc.c calloc.c \
	    stats.c allocsize.c
OSOBJ     = $(patsubst %.c,%.o,$(CFILES))
OSPICOBJ  = $(patsubst %.c,%.pic.o,$(CFILES))
# MAN1PAGES = $(patsubst %.in,%,$(wildcard *.1.in))
MAN3PAGES = $(patsubst %.in,%,$(wildcard *.3.in))
MAN7PAGES = $(patsubst %.in,%,$(wildcard *.7.in))
MANPAGES  = $(MAN3PAGES) $(MAN7PAGES)

CC	 = gcc
ifndef DEBUG
# This is a reasonable set of flags for production
# Add -NDEBUG if you don't want to retain assert()s
CFLAGS	= -I. -Wall -O3 -fomit-frame-pointer -D_FILE_OFFSET_BITS=64 # -DNDEBUG
LDFLAGS	= 
else
# This is for debugging
CFLAGS	 = -I. -Wall -O -g -DPRINT_DEBUG_INFO -D_FILE_OFFSET_BITS=64
LDFLAGS  = -g
endif
LIBS    = libpsm.a -lm
PICFLAGS = $(CFLAGS) -fPIC
SOFLAGS	 = -shared

AR	 = ar cq
RANLIB	 = ranlib

INSTALL	 = install -c

prefix     = /usr
bindir     = $(prefix)/bin
sbindir    = $(prefix)/sbin
libdir     = $(prefix)/lib
includedir = $(prefix)/include
mandir     = $(prefix)/man
man1dir    = $(mandir)/man1
man3dir    = $(mandir)/man3
man7dir    = $(mandir)/man7

all: $(LIBPSM) test man

test:	$(TEST)

man:	$(MANPAGES)

clean:
	rm -f *.o *~ core *.dat *.log $(LIBPSM) $(TEST) $(MANPAGES)
	rm -f libpsm.so libpsm.so.*

distclean: clean
	rm -f *~ \#* .depend

install: all
	mkdir -p $(INSTALLROOT)$(includedir)
	mkdir -p $(INSTALLROOT)$(libdir)
	mkdir -p $(INSTALLROOT)$(man3dir)
	$(INSTALL) $(LIBPSM) $(INSTALLROOT)$(libdir)
	cd $(INSTALLROOT)$(libdir) && ln -sf libpsm.so.$(VERSION) $(SONAME)
	cd $(INSTALLROOT)$(libdir) && ln -sf libpsm.so.$(VERSION) libpsm.so
	$(INSTALL) lpsm.h    $(INSTALLROOT)$(includedir)
	$(INSTALL) $(MAN3PAGES) $(INSTALLROOT)$(man3dir)
	cd $(INSTALLROOT)$(man3dir) && ln -sf lpsm_checkpoint.3 lpsm_need_checkpoint.3
	cd $(INSTALLROOT)$(man3dir) && ln -sf lpsm_malloc.3 lpsm_free.3
	cd $(INSTALLROOT)$(man3dir) && ln -sf lpsm_malloc.3 lpsm_realloc.3
	cd $(INSTALLROOT)$(man3dir) && ln -sf lpsm_malloc.3 lpsm_zalloc.3
	cd $(INSTALLROOT)$(man3dir) && ln -sf lpsm_malloc.3 lpsm_calloc.3
	$(INSTALL) $(MAN7PAGES) $(INSTALLROOT)$(man7dir)
	ldconfig

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

%.pic.o: %.c
	$(CC) $(PICFLAGS) -o $@ -c $<

%: %.in
	sed -e 's/@@VERSION@@/$(VERSION)/g' < $< > $@

libpsm.so.$(VERSION): $(OSPICOBJ)
	$(CC) $(SOFLAGS) -Wl,-soname,$(SONAME) -o libpsm.so.$(VERSION) $(OSPICOBJ)
	ln -sf libpsm.so.$(VERSION) $(SONAME)
	ln -sf libpsm.so.$(VERSION) libpsm.so

libpsm.a: $(OSOBJ)
	rm -f libpsm.a
	$(AR) libpsm.a $(OSOBJ)
	$(RANLIB) libpsm.a

teststore: teststore.o libpsm.a
	$(CC) $(LDFLAGS) -o $@ $< $(LIBS)

testbuddy: testbuddy.o libpsm.a
	$(CC) $(LDFLAGS) -o $@ $< $(LIBS)

testalloc: testalloc.o libpsm.a
	$(CC) $(LDFLAGS) -o $@ $< $(LIBS)

testrecovery: testrecovery.o libpsm.a
	$(CC) $(LDFLAGS) -o $@ $< $(LIBS)

zallocevil: zallocevil.o libpsm.a
	$(CC) $(LDFLAGS) -o $@ $< $(LIBS)

test_mmap: test_mmap.o
	$(CC) $(LDFLAGS) -o $@ $<

ftrunctest: ftrunctest.o 
	$(CC) $(LDFLAGS) -o $@ $<

.depend:
	rm -f .depend
	for cf in $(CFILES); do \
		$(CC) $(CFLAGS) -E -Wp,-MM $$cf >> .depend ; \
		$(CC) $(CFLAGS) -E -Wp,-MM $$cf | sed -e 's/\.o/\.pic\.o/' >> .depend ; \
	done

dep: .depend

-include .depend