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