-
Notifications
You must be signed in to change notification settings - Fork 24
/
Copy pathMakefile
170 lines (147 loc) · 4.94 KB
/
Makefile
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
INSTALL_DIR=/usr/local/lib/
RM= /bin/rm -vf
R_EXEC=R
PYTHON=python
IDL=idl
ARCH=UNDEFINED
COVERAGE=0
ifeq ($(CC),)
CC=gcc
endif
EDCFLAGS:= $(CFLAGS) -fopenmp -fcommon
EDLDFLAGS:= $(LDFLAGS) -fopenmp -fcommon
ifeq ($(ARCH),UNDEFINED)
ARCH=$(shell uname -m)
endif
OS=$(shell uname -s)
ifeq ($(OS),Darwin)
LIBEXT= dylib
EDCFLAGS:= -arch $(ARCH) $(EDCFLAGS)
EDLDFLAGS:= -arch $(ARCH) $(EDLDFLAGS)
LINKOPTIONS:= -dynamiclib -Wl,-single_module
RMDIR=rmdir
ECHO=echo
TRUE=TRUE
else
LIBEXT= so
LINKOPTIONS:= -shared
RMDIR=rmdir -v
ECHO=/bin/echo -e
TRUE=true
endif
TARGETLIB= libextremedeconvolution.$(LIBEXT)
ifeq ($(COVERAGE),1)
EDCFLAGS:= -O0 --coverage $(EDCFLAGS)
EDLDFLAGS:= --coverage $(EDLDFLAGS)
endif
proj_gauss_mixtures_objects= src/bovy_randvec.o \
src/calc_splitnmerge.o src/logsum.o src/minmax.o\
src/normalize_row.o src/proj_EM.o src/proj_EM_step.o \
src/proj_gauss_mixtures.o src/splitnmergegauss.o src/bovy_det.o
proj_gauss_main_objects= src/main.o src/parse_option.o src/read_data.o \
src/read_IC.o src/read_till_sep.o src/write_model.o \
src/cleanup.o
#
# The next targets are the main make targets: all,
# extremedeconvolution (the executable), and
# extremedeconvolution.so (the sharable object library)
#
all: build/$(TARGETLIB)
build:
ls build 2>/dev/null ; \
case "$$?" in \
0);; \
*) \
mkdir build ;; \
esac
# Build of main is currently broken, but this is *never* used, use the lib
# instead
build/extremedeconvolution: $(proj_gauss_mixtures_objects) $(proj_gauss_main_objects) build
$(CC) -o $@ \
$(EDCFLAGS) \
$(EDLDFLAGS) \
$(proj_gauss_mixtures_objects) \
$(proj_gauss_main_objects) \
-lm -lgsl -lgslcblas -lgomp 2>/dev/null; \
case "$$?" in \
0);; \
*) \
$(CC) -o $@ \
$(EDCFLAGS) \
$(EDLDFLAGS) \
$(proj_gauss_mixtures_objects) \
$(proj_gauss_main_objects) \
-lm -lgsl -lgslcblas;; \
esac
build/$(TARGETLIB): $(proj_gauss_mixtures_objects) \
src/proj_gauss_mixtures_IDL.o build
$(CC) $(LINKOPTIONS) -o $@ \
$(EDLDFLAGS) \
$(proj_gauss_mixtures_objects) \
src/proj_gauss_mixtures_IDL.o \
-lm -lgsl -lgslcblas -lgomp 2>/dev/null; \
case "$$?" in \
0);; \
*) \
$(CC) $(LINKOPTIONS) -o $@ \
$(EDLDFLAGS) \
$(proj_gauss_mixtures_objects) \
src/proj_gauss_mixtures_IDL.o \
-lm -lgsl -lgslcblas ;; \
esac
%.o: %.c
$(CC) $(EDCFLAGS) -fpic -Wall -c $< -o $@ -I src/
#
# INSTALL THE IDL WRAPPER
#
install: build/$(TARGETLIB)
cp $< $(INSTALL_DIR)$(TARGETLIB)
idlwrapper:
(ls $(INSTALL_DIR)$(TARGETLIB) || ($(ECHO) "Cannot find library '$(INSTALL_DIR)$(TARGETLIB)', run again with 'INSTALL_DIR=' set to the directory you installed the library in" && exit -1))
$(ECHO) 'result = CALL_EXTERNAL("$(INSTALL_DIR)$(TARGETLIB)", $$' > tmp
cat pro/projected_gauss_mixtures_c.pro_1 tmp pro/projected_gauss_mixtures_c.pro_2 > pro/projected_gauss_mixtures_c.pro
$(RM) tmp
$(ECHO) 'Successfully installed IDL wrapper'
# INSTALL THE PYTHON WRAPPER
pywrapper:
(ls $(INSTALL_DIR)$(TARGETLIB) || ($(ECHO) "Cannot find library '$(INSTALL_DIR)$(TARGETLIB)', run again with 'INSTALL_DIR=' set to the directory you installed the library in" && exit -1))
(ls py/.extreme_deconvolution.py || mv py/extreme_deconvolution.py py/.extreme_deconvolution.py)
sed "s#TEMPLATE_LIBRARY_PATH#'$(INSTALL_DIR)'#g" py/extreme_deconvolution_TEMPLATE.py > py/extreme_deconvolution.py
((cd py && $(ECHO) 'import extreme_deconvolution' | $(PYTHON)) && $(ECHO) 'Successfully installed Python wrapper' || ($(ECHO) 'Something went wrong installing Python wrapper' && exit -1))
rpackage:
cp src/*.h src/*.c r/src
patch r/src/proj_gauss_mixtures_IDL.c < r/src/proj_gauss_mixtures_R.patch
$(R_EXEC) CMD build r --no-manual
$(R_EXEC) CMD check ExtremeDeconvolution_*.tar.gz --no-manual -o $(shell mktemp -d tmp.XXXX)
rm -f r/src/*.h r/src/*.c
#
# TEST THE INSTALLATION
#
testidl:
(cd examples && export IDL_PATH=$(IDL_PATH):../pro && $(ECHO) 'fit_TF' | $(IDL))
(cd examples && ((diff TF.tex TF.out && $(ECHO) 'Ouput of test agrees with given solution') \
|| $(ECHO) 'Output of test does not agree with given solution\nManually diff the TF.tex and TF.out (given solution) file'))
testpy:
(cd py && $(PYTHON) extreme_deconvolution.py)
.PHONY: clean spotless
clean:
$(RM) $(proj_gauss_mixtures_objects)
$(RM) $(proj_gauss_main_objects)
$(RM) src/proj_gauss_mixtures_IDL.o
$(RM) $(subst src,r/src,$(proj_gauss_mixtures_objects))
$(RM) $(subst src,r/src,$(proj_gauss_main_objects))
$(RM) r/src/proj_gauss_mixtures_IDL.o
$(RM) r/src/symbols.rds
$(RM) ExtremeDeconvolution_*.tar.gz
spotless: clean rmbuild
$(RM) src/*.~
$(RM) pro/projected_gauss_mixtures.pro
$(RM) py/*.pyc
$(RM) pro/projected_gauss_mixtures_c.pro
$(RM) examples/TF.ps examples/TF.tex
$(RM) r/src/ExtremeDeconvolution.so
(ls py/.extreme_deconvolution.py && mv py/.extreme_deconvolution.py py/extreme_deconvolution.py || $(TRUE))
rmbuild: build/
$(RM) build/extremedeconvolution
$(RM) build/$(TARGETLIB)
($(RMDIR) build || $(ECHO) "Could not remove 'build/' directory, manually remove it")