summaryrefslogtreecommitdiffstats
path: root/scilab/Makemex.in
blob: 9056b1e17721c0ec18bb62cb656336f6b2734538 (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
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
# see examples/mex-examples/mex-with-so/Makefile 
# for an example of Makemex use 
# some variables are defined here and other are defined in Makefile.incl 
# @TODO: probably dead code

SHELL = @SHELL@
top_builddir = $(SCIDIR)

DLLTOOL = @DLLTOOL@
LIBM = @LIBM@
LIBTOOL = @LIBTOOL@
CXX=@CXX@
LIBTOOL_DEPS = @LIBTOOL_DEPS@
LN_S = @LN_S@
NM = @NM@

OBJDUMP = @OBJDUMP@
STATIC = @STATIC@

CPPFLAGS = @CPPFLAGS@
LDFLAGS = @LDFLAGS@
LIBS = @LIBS@
FLIBS = @FLIBS@

INCLUDES= -I$(SCIDIR)/routines 
CFLAGS = $(CC_OPTIONS) 
FFLAGS = $(FC_OPTIONS) 
COMPILE = $(CC) $(INCLUDES) $(CPPFLAGS) $(CFLAGS)
FCOMPILE = $(FC) $(FFLAGS)

QUIET=--quiet

LTCOMPILE = $(LIBTOOL) --mode=compile $(QUIET) $(CC) $(INCLUDES) $(CPPFLAGS) $(CFLAGS)
FLTCOMPILE = $(LIBTOOL) --mode=compile $(QUIET) $(FC) $(FFLAGS)

LINK = $(LIBTOOL) --mode=link $(QUIET)  $(CC) $(CFLAGS) $(LDFLAGS) $(FLIBS) -o $@

OBJECTS = $(LIBRARY)_gateway.lo $(OTHEROBJECTS:.o=.lo)
FCTMEXLO = $(FCTMEX:.c=.lo) $(FORTRANFCTMEX:.F=.lo)
#******************************************************************* 

all:: all_nomes message

all_nomes : CLEAROLD GATEWAYS $(OTHEROBJECTS) $(LIBRARY)_gateway.lo $(LIBRARY).la $(LIBRARY).sce 

.SUFFIXES:
.SUFFIXES: .c .lo .o .F 

$(LIBRARY).la : $(OBJECTS) 
	@MEXOBJECTS=`echo $(FCTMEXLO) | sed -e "s+[a-zA-Z0-9_%$#]*/++g"`; \
	$(LINK) -rpath `pwd` -module -avoid-version -export-dynamic $$MEXOBJECTS $(OBJECTS) 
	@$(LIBTOOL) --mode=install $(QUIET)  cp $(LIBRARY).la `pwd`/$(LIBRARY).la 

$(LIBRARY)_gateway.c:  Makefile 
	@echo "-- Generating the C function $(LIBRARY)_gateway.c";
	@echo $(FCTMEX) > tmp_sce; echo $(FORTRANFCTMEX) >> tmp_sce;
	@echo $(LIBRARY) > tmp2_sce; 
	@$(SCIDIR)/macros/Gensomex Xtmp_sce Xtmp2_sce;
	@$(RM)  tmp_sce; 
	@$(RM)  tmp2_sce; 	
	@echo "int C2F($(LIBRARY)_gateway)()" >> $(LIBRARY)_gateway.c;
	@echo "{ Rhs = Max(0, Rhs); " >> $(LIBRARY)_gateway.c;
	@echo "(*(Tab[Fin-1].f))(Tab[Fin-1].name,Tab[Fin-1].F);" >> $(LIBRARY)_gateway.c;
	@echo " return 0;" >> $(LIBRARY)_gateway.c;
	@echo "}" >> $(LIBRARY)_gateway.c;
	@echo " /* */ " >> $(LIBRARY)_gateway.c;

$(LIBRARY).sce: Makefile 
	@echo "-- Generating the Scilab script $(LIBRARY).sce";
	@echo $(FCTMEX) > tmp_sce; echo $(FORTRANFCTMEX) >> tmp_sce;
	@echo $(LIBRARY) > tmp2_sce; 
	@$(SCIDIR)/macros/Gensosce Xtmp_sce Xtmp2_sce;
	@$(RM)  tmp_sce; 
	@$(RM)  tmp2_sce; 
	@echo "LIBPATH=\"$(LIBPATH)\";" >> $(LIBRARY).sce;
	@echo "addinter(LIBPATH+\"$(LIBRARY).so\",\"$(LIBRARY)_gateway\",scilab_functions)" >> $(LIBRARY).sce;
	@if test "$(LIBPATH)" = ""; then \
	echo "------------------------------------------"; \
	echo "Check LD_LIBRARY_PATH environment variable: "; \
	echo "LD_LIBRARY_PATH=`pwd`; export LD_LIBRARY_PATH"; \
	echo "or"; \
	echo "setenv LD_LIBRARY_PATH `pwd`"; \
	echo "------------------------------------------"; \
	fi

message:
	@echo "------------------------------------------";
	@echo "To load the function(s): ";
	@if test "X$(FCTMEX)" != "X"; then for i in $(FCTMEX) ;\
	do (\
	name=`dirname $$i`; \
	echo "              $$name; " \
	); \
	done ; fi
	@if test "X$(FORTRANFCTMEX)" != "X"; then for i in $(FORTRANFCTMEX) ;\
	do (\
	name=`dirname $$i`; \
	echo "              $$name; " \
	); \
	done ; fi
	@echo " at Scilab prompt, enter:";
	@echo "-->exec $(LIBRARY).sce";
	@echo "------------------------------------------";

clean	::
	$(RM) *.o *.lo
	$(RM) $(LIBRARY).sce
	$(RM) $(LIBRARY)_gateway.c
	$(RM) $(LIBRARY).la
	$(RM) $(LIBRARY).so
	$(RM) -r .libs

distclean:: clean 
	$(RM) -f -r .libs  $(LIBRARY).*
	$(RM) $(LIBRARY).sce
	$(RM) $(LIBRARY)_gateway.c

$(LIBRARY)_gateway.lo: $(LIBRARY)_gateway.c
	@$(LTCOMPILE) -c $(LIBRARY)_gateway.c

GATEWAYS:
	@if test "X$(FCTMEX)" != "X"; then for f in $(FCTMEX); \
	do \
	obj=`basename $$f .c`; \
	mex=`dirname $$f`; \
	make $$obj.o MEX=mex_$$mex ; \
	make $$obj.lo MEX=mex_$$mex ; \
	done; fi
	@if test "X$(FORTRANFCTMEX)" != "X"; then for f in $(FORTRANFCTMEX); \
	do \
	obj=`basename $$f .F`; \
	mex=`dirname $$f`; \
	make $$obj.o MEX=mex$$mex ; \
	make $$obj.lo MEX=mex$$mex ; \
	done; fi

.c.o:
	@$(COMPILE) -DmexFunction=$(MEX) -c $<

.c.lo :
	@$(LTCOMPILE) -DmexFunction=$(MEX) -c $<

.F.o:
	@$(FCOMPILE) -Dmexfunction=$(MEX) -c $<

.F.lo :
	@$(FLTCOMPILE) -Dmexfunction=$(MEX) -c $<

.f.o:
	@$(FCOMPILE) -Dmexfunction=$(MEX) -c $<

.f.lo :
	@$(FLTCOMPILE) -Dmexfunction=$(MEX) -c $<

CLEAROLD:
	$(RM) $(LIBRARY).sce
	$(RM) $(LIBRARY)_gateway.c