better error msg
[scilab.git] / scilab / Makemex.in
1 # see examples/mex-examples/mex-with-so/Makefile 
2 # for an example of Makemex use 
3 # some variables are defined here and other are defined in Makefile.incl 
4
5 SHELL = @SHELL@
6 top_builddir = $(SCIDIR)
7
8 DLLTOOL = @DLLTOOL@
9 LIBM = @LIBM@
10 LIBTOOL = @LIBTOOL@
11 CXX=@CXX@
12 LIBTOOL_DEPS = @LIBTOOL_DEPS@
13 LN_S = @LN_S@
14 NM = @NM@
15
16 OBJDUMP = @OBJDUMP@
17 STATIC = @STATIC@
18
19 CPPFLAGS = @CPPFLAGS@
20 LDFLAGS = @LDFLAGS@
21 LIBS = @LIBS@
22 FLIBS = @FLIBS@
23
24 INCLUDES= -I$(SCIDIR)/routines 
25 CFLAGS = $(CC_OPTIONS) 
26 FFLAGS = $(FC_OPTIONS) 
27 COMPILE = $(CC) $(INCLUDES) $(CPPFLAGS) $(CFLAGS)
28 FCOMPILE = $(FC) $(FFLAGS)
29
30 QUIET=--quiet
31
32 LTCOMPILE = $(LIBTOOL) --mode=compile $(QUIET) $(CC) $(INCLUDES) $(CPPFLAGS) $(CFLAGS)
33 FLTCOMPILE = $(LIBTOOL) --mode=compile $(QUIET) $(FC) $(FFLAGS)
34
35 LINK = $(LIBTOOL) --mode=link $(QUIET)  $(CC) $(CFLAGS) $(LDFLAGS) $(FLIBS) -o $@
36
37 OBJECTS = $(LIBRARY)_gateway.lo $(OTHEROBJECTS:.o=.lo)
38 FCTMEXLO = $(FCTMEX:.c=.lo) $(FORTRANFCTMEX:.F=.lo)
39 #******************************************************************* 
40
41 all:: all_nomes message
42
43 all_nomes : CLEAROLD GATEWAYS $(OTHEROBJECTS) $(LIBRARY)_gateway.lo $(LIBRARY).la $(LIBRARY).sce 
44
45 .SUFFIXES:
46 .SUFFIXES: .c .lo .o .F 
47
48 $(LIBRARY).la : $(OBJECTS) 
49         @MEXOBJECTS=`echo $(FCTMEXLO) | sed -e "s+[a-zA-Z0-9_%$#]*/++g"`; \
50         $(LINK) -rpath `pwd` -module -avoid-version -export-dynamic $$MEXOBJECTS $(OBJECTS) 
51         @$(LIBTOOL) --mode=install $(QUIET)  cp $(LIBRARY).la `pwd`/$(LIBRARY).la 
52
53 $(LIBRARY)_gateway.c:  Makefile 
54         @echo "-- Generating the C function $(LIBRARY)_gateway.c";
55         @echo $(FCTMEX) > tmp_sce; echo $(FORTRANFCTMEX) >> tmp_sce;
56         @echo $(LIBRARY) > tmp2_sce; 
57         @$(SCIDIR)/macros/Gensomex Xtmp_sce Xtmp2_sce;
58         @$(RM)  tmp_sce; 
59         @$(RM)  tmp2_sce;       
60         @echo "int C2F($(LIBRARY)_gateway)()" >> $(LIBRARY)_gateway.c;
61         @echo "{ Rhs = Max(0, Rhs); " >> $(LIBRARY)_gateway.c;
62         @echo "(*(Tab[Fin-1].f))(Tab[Fin-1].name,Tab[Fin-1].F);" >> $(LIBRARY)_gateway.c;
63         @echo " return 0;" >> $(LIBRARY)_gateway.c;
64         @echo "}" >> $(LIBRARY)_gateway.c;
65         @echo " /* */ " >> $(LIBRARY)_gateway.c;
66
67 $(LIBRARY).sce: Makefile 
68         @echo "-- Generating the Scilab script $(LIBRARY).sce";
69         @echo $(FCTMEX) > tmp_sce; echo $(FORTRANFCTMEX) >> tmp_sce;
70         @echo $(LIBRARY) > tmp2_sce; 
71         @$(SCIDIR)/macros/Gensosce Xtmp_sce Xtmp2_sce;
72         @$(RM)  tmp_sce; 
73         @$(RM)  tmp2_sce; 
74         @echo "LIBPATH=\"$(LIBPATH)\";" >> $(LIBRARY).sce;
75         @echo "addinter(LIBPATH+\"$(LIBRARY).so\",\"$(LIBRARY)_gateway\",scilab_functions)" >> $(LIBRARY).sce;
76         @if test "$(LIBPATH)" = ""; then \
77         echo "------------------------------------------"; \
78         echo "Check LD_LIBRARY_PATH environment variable: "; \
79         echo "LD_LIBRARY_PATH=`pwd`; export LD_LIBRARY_PATH"; \
80         echo "or"; \
81         echo "setenv LD_LIBRARY_PATH `pwd`"; \
82         echo "------------------------------------------"; \
83         fi
84
85 message:
86         @echo "------------------------------------------";
87         @echo "To load the function(s): ";
88         @if test "X$(FCTMEX)" != "X"; then for i in $(FCTMEX) ;\
89         do (\
90         name=`dirname $$i`; \
91         echo "              $$name; " \
92         ); \
93         done ; fi
94         @if test "X$(FORTRANFCTMEX)" != "X"; then for i in $(FORTRANFCTMEX) ;\
95         do (\
96         name=`dirname $$i`; \
97         echo "              $$name; " \
98         ); \
99         done ; fi
100         @echo " at Scilab prompt, enter:";
101         @echo "-->exec $(LIBRARY).sce";
102         @echo "------------------------------------------";
103
104 clean   ::
105         $(RM) *.o *.lo
106         $(RM) $(LIBRARY).sce
107         $(RM) $(LIBRARY)_gateway.c
108         $(RM) $(LIBRARY).la
109         $(RM) $(LIBRARY).so
110         $(RM) -r .libs
111
112 distclean:: clean 
113         $(RM) -f -r .libs  $(LIBRARY).*
114         $(RM) $(LIBRARY).sce
115         $(RM) $(LIBRARY)_gateway.c
116
117 $(LIBRARY)_gateway.lo: $(LIBRARY)_gateway.c
118         @$(LTCOMPILE) -c $(LIBRARY)_gateway.c
119
120 GATEWAYS:
121         @if test "X$(FCTMEX)" != "X"; then for f in $(FCTMEX); \
122         do \
123         obj=`basename $$f .c`; \
124         mex=`dirname $$f`; \
125         make $$obj.o MEX=mex_$$mex ; \
126         make $$obj.lo MEX=mex_$$mex ; \
127         done; fi
128         @if test "X$(FORTRANFCTMEX)" != "X"; then for f in $(FORTRANFCTMEX); \
129         do \
130         obj=`basename $$f .F`; \
131         mex=`dirname $$f`; \
132         make $$obj.o MEX=mex$$mex ; \
133         make $$obj.lo MEX=mex$$mex ; \
134         done; fi
135
136 .c.o:
137         @$(COMPILE) -DmexFunction=$(MEX) -c $<
138
139 .c.lo :
140         @$(LTCOMPILE) -DmexFunction=$(MEX) -c $<
141
142 .F.o:
143         @$(FCOMPILE) -Dmexfunction=$(MEX) -c $<
144
145 .F.lo :
146         @$(FLTCOMPILE) -Dmexfunction=$(MEX) -c $<
147
148 .f.o:
149         @$(FCOMPILE) -Dmexfunction=$(MEX) -c $<
150
151 .f.lo :
152         @$(FLTCOMPILE) -Dmexfunction=$(MEX) -c $<
153
154 CLEAROLD:
155         $(RM) $(LIBRARY).sce
156         $(RM) $(LIBRARY)_gateway.c
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174