Define default DESTDIR for system installation
[archipelago] / xseg / sys / user / Makefile
1 # Copyright 2012 GRNET S.A. All rights reserved.
2 #
3 # Redistribution and use in source and binary forms, with or
4 # without modification, are permitted provided that the following
5 # conditions are met:
6 #
7 #   1. Redistributions of source code must retain the above
8 #      copyright notice, this list of conditions and the following
9 #      disclaimer.
10 #   2. Redistributions in binary form must reproduce the above
11 #      copyright notice, this list of conditions and the following
12 #      disclaimer in the documentation and/or other materials
13 #      provided with the distribution.
14 #
15 # THIS SOFTWARE IS PROVIDED BY GRNET S.A. ``AS IS'' AND ANY EXPRESS
16 # OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
17 # WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
18 # PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL GRNET S.A OR
19 # CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
20 # SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
21 # LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
22 # USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
23 # AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
24 # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
25 # ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
26 # POSSIBILITY OF SUCH DAMAGE.
27 #
28 # The views and conclusions contained in the software and
29 # documentation are those of the authors and should not be
30 # interpreted as representing official policies, either expressed
31 # or implied, of GRNET S.A.
32 #
33
34 .PHONY: default all clean drivers install install-src
35
36 include $(XSEG_HOME)/base.mk
37
38 FILES="Makefile"
39 FILES+=$(shell ls *.h)
40 FILES+=$(shell ls *.c)
41
42 EFILES+="make_symbol_map.sh"
43
44 SUBDIR:=$(subst $(XSEG_HOME),,$(CURDIR))
45
46 MAJOR=0
47 MINOR=0.1
48 AR=ar
49
50 DRIVERS=xseg_posix xseg_segdev xseg_pthread
51 DRVDIR=$(BASE)/drivers/user
52 DRVOBJS=$(addsuffix .o, $(addprefix $(DRVDIR)/, $(DRIVERS)))
53 SHELL=/bin/bash
54
55 default: all
56
57 all: libxseg.a libxseg.so
58         make -C python all MAJOR=$(MAJOR) MINOR=$(MINOR)
59         make -C xq all
60         make -C xpool all
61         make -C xhash all
62         make -C xheap all
63         make -C xobj all
64
65 COMMA=,
66 _initialize.c: drivers
67         $(BASE)/tools/create_initializer $(DRIVERS) > _initialize.c
68
69 xseg.o: $(BASE)/xseg/xseg.c $(BASE)/xseg/xseg.h $(BASE)/xtypes/xq.h
70         $(CC) $(CFLAGS) $(INC) -c -o $@ $<
71
72 xseg.pic.o: $(BASE)/xseg/xseg.c $(BASE)/xseg/xseg.h _initialize.c
73         $(CC) $(CFLAGS) $(INC) -fPIC -c -o $@ $<
74
75 libxseg.so: libxseg.so.$(MAJOR)
76         ln -sf $< $@
77         cp -vaf $@ $(LIB)
78
79 libxseg.so.$(MAJOR): libxseg.so.$(MAJOR).$(MINOR)
80         ln -sf $< $@
81         cp -vaf $@ $(LIB)
82
83 drivers:
84         make -C $(DRVDIR) $(addsuffix .o, $(DRIVERS))
85
86 xq/xq.o:
87         make -C xq xq.o
88
89 xq/xq.pic.o:
90         make -C xq xq.pic.o
91
92 xpool/xpool.o:
93         make -C xpool xpool.o
94
95 xpool/xpool.pic.o:
96         make -C xpool xpool.pic.o
97
98 xhash/xhash.o:
99         make -C xhash xhash.o
100
101 xhash/xhash.pic.o:
102         make -C xhash xhash.pic.o
103
104 xheap/xheap.o:
105         make -C xheap xheap.o
106
107 xheap/xheap.pic.o:
108         make -C xheap xheap.pic.o
109
110 xobj/xobj.o:
111         make -C xobj xobj.o
112
113 xobj/xobj.pic.o:
114         make -C xobj xobj.pic.o
115
116 xseg_user.o: xseg_user.c
117         $(CC) $(CFLAGS) $(INC) -Wall -O2 -finline-functions -fPIC -c -o $@ $<
118
119 libxseg.map: $(BASE)/xtypes/xq_exports.h $(BASE)/xseg/xseg_exports.h \
120                 $(BASE)/xtypes/xpool_exports.h $(BASE)/xtypes/xhash_exports.h\
121                 $(BASE)/xtypes/xobj_exports.h
122         cat $(BASE)/xtypes/xq_exports.h $(BASE)/xseg/xseg_exports.h \
123                 $(BASE)/xtypes/xpool_exports.h $(BASE)/xtypes/xhash_exports.h \
124                 $(BASE)/xtypes/xobj_exports.h | ./make_symbol_map.sh > $@
125
126 libxseg.so.$(MAJOR).$(MINOR): xseg.pic.o xseg_user.o libxseg.map \
127                                  xq/xq.pic.o xpool/xpool.pic.o xhash/xhash.pic.o \
128                                  xheap/xheap.pic.o xobj/xobj.pic.o $(DRVOBJS)
129         $(CC) $(CFLAGS) -shared \
130                         -Wl,-soname=libxseg.so.$(MAJOR) \
131                         -o libxseg.so.$(MAJOR).$(MINOR) \
132                         xseg.pic.o xseg_user.o xq/xq.pic.o \
133                         xpool/xpool.pic.o xhash/xhash.pic.o\
134                         xheap/xheap.pic.o xobj/xobj.pic.o \
135                          _initialize.o $(DRVOBJS) \
136                         -Wl,--version-script=libxseg.map \
137                         -ldl -lrt -pthread
138         cp -vaf $@ $(LIB)
139
140 libxseg.a: xseg.o xq/xq.o drivers _initialize.o
141         $(AR) r libxseg.a xseg.o xq/xq.o _initialize.o $(DRVOBJS)
142         cp -vaf $@ $(LIB)
143
144 install:
145         make -C python install
146         install -d $(DESTDIR)$(libdir)
147         #install -t $(DESTDIR)$(libdir) libxseg.so
148         #install -t $(DESTDIR)$(libdir) libxseg.so.$(MAJOR)
149         install -o 0 -g 0 -m 644 -t $(DESTDIR)$(libdir) libxseg.so.$(MAJOR).$(MINOR)
150         cp -vaf libxseg.so.$(MAJOR) $(DESTDIR)$(libdir)
151         cp -vaf libxseg.so $(DESTDIR)$(libdir)
152
153 install-src:
154         make -C xq install-src
155         make -C xpool install-src
156         make -C xhash install-src
157         make -C xheap install-src
158         make -C xobj install-src
159         make -C python install-src
160         install -d $(DESTDIR)$(srcdir)$(SUBDIR) ;
161         @for f in $(FILES) ; do \
162                 install -o 0 -g 0 -m 644 -t $(DESTDIR)$(srcdir)$(SUBDIR) $$f ; \
163         done
164         @for f in $(EFILES) ; do \
165                 install -o 0 -g 0 -m 755 -t $(DESTDIR)$(srcdir)$(SUBDIR) $$f ; \
166         done
167
168
169 clean:
170         make -C xq clean
171         make -C xpool clean
172         make -C xhash clean
173         make -C xheap clean
174         make -C xobj clean
175         make -C python clean
176         rm -f _initialize.c _initialize.o
177         rm -f xseg.o xseg.pic.o xseg_user.o
178         rm -f libxseg.a libxseg.map
179         rm -f libxseg.so libxseg.so.$(MAJOR) libxseg.so.$(MAJOR).$(MINOR)