-
Notifications
You must be signed in to change notification settings - Fork 2
/
makefile
175 lines (128 loc) · 4.23 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
171
172
173
174
175
# ======== COMPILER ========
CC = gcc
OPT = -std=c99 -pedantic -Wall -O3 -fopenmp -DSSHT_VERSION=\"1.5.2\" -DSSHT_BUILD=\"`git rev-parse HEAD`\"
#OPT = -Wall -g -fopenmp -DSSHT_VERSION=\"1.0b1\" -DSSHT_BUILD=\"`git rev-parse HEAD`\"
# ======== LINKS ========
UNAME := $(shell uname)
PROGDIR = ..
MLAB = ${MATLAB}
MLABINC = ${MLAB}/extern/include
MLABLIB = ${MLAB}/extern/lib
# --------------------
ifeq ($(UNAME), Linux)
MEXEXT = mexa64
endif
ifeq ($(UNAME), Darwin)
MEXEXT = mexmaci64
endif
# --------------------
MEX = ${MLAB}/bin/mex
MEXFLAGS = -cxx
SSHTDIR = $(PROGDIR)/ssht
SSHTLIB = $(SSHTDIR)/lib/c
SSHTLIBNM= ssht
SSHTSRC = $(SSHTDIR)/src/c
SSHTBIN = $(SSHTDIR)/bin/c
SSHTOBJ = $(SSHTSRC)
SSHTINC = $(SSHTDIR)/src/c
SSHTDOC = $(SSHTDIR)/docs/c
FFTWDIR = $(FFTW)
FFTWINC = $(FFTWDIR)/include
FFTWLIB = $(FFTWDIR)/lib
FFTWLIBNM = fftw3
#FFTWOMPLIBNM = fftw3_threads
SSHTSRCMAT = $(SSHTDIR)/src/matlab
SSHTOBJMAT = $(SSHTSRCMAT)
SSHTOBJMEX = $(SSHTSRCMAT)
# ======== SOURCE LOCATIONS ========
vpath %.c $(SSHTSRC)
vpath %.h $(SSHTSRC)
vpath %_mex.c $(SSHTSRCMAT)
# ======== FFFLAGS ========
FFLAGS = -I$(FFTWINC) -I$(SSHTINC)
ifeq ($(UNAME), Linux)
# Add -fPIC flag (required for mex build).
# (Note that fftw must also be built with -fPIC.)
FFLAGS += -fPIC
endif
# ======== LDFLAGS ========
LDFLAGS = -L$(SSHTLIB) -l$(SSHTLIBNM) -L$(FFTWLIB) -l$(FFTWLIBNM) -lm
#LDFLAGS = -L$(SSHTLIB) -l$(SSHTLIBNM) -L$(FFTWLIB) -l$(FFTWOMPLIBNM) -l$(FFTWLIBNM) -lm
LDFLAGSMEX = -L$(SSHTLIB) -l$(SSHTLIBNM) -L$(FFTWLIB) -l$(FFTWLIBNM)
#LDFLAGSMEX = -L$(SSHTLIB) -l$(SSHTLIBNM) -L$(FFTWLIB) -l$(FFTWOMPLIBNM) -l$(FFTWLIBNM)
# ======== OBJECT FILES TO MAKE ========
SSHTOBJS = $(SSHTOBJ)/ssht_sampling.o \
$(SSHTOBJ)/ssht_dl.o \
$(SSHTOBJ)/ssht_core.o \
$(SSHTOBJ)/ssht_adjoint.o
SSHTHEADERS = ssht_types.h \
ssht_error.h \
ssht_sampling.h \
ssht_dl.h \
ssht_core.h \
ssht_adjoint.h
SSHTOBJSMAT = $(SSHTOBJMAT)/ssht_sampling_mex.o \
$(SSHTOBJMAT)/ssht_dl_mex.o \
$(SSHTOBJMAT)/ssht_dln_mex.o \
$(SSHTOBJMAT)/ssht_forward_mex.o \
$(SSHTOBJMAT)/ssht_inverse_mex.o \
$(SSHTOBJMAT)/ssht_forward_adjoint_mex.o \
$(SSHTOBJMAT)/ssht_inverse_adjoint_mex.o
SSHTOBJSMEX = $(SSHTOBJMEX)/ssht_sampling_mex.$(MEXEXT) \
$(SSHTOBJMEX)/ssht_dl_mex.$(MEXEXT) \
$(SSHTOBJMEX)/ssht_dln_mex.$(MEXEXT) \
$(SSHTOBJMEX)/ssht_forward_mex.$(MEXEXT) \
$(SSHTOBJMEX)/ssht_inverse_mex.$(MEXEXT) \
$(SSHTOBJMEX)/ssht_forward_adjoint_mex.$(MEXEXT) \
$(SSHTOBJMEX)/ssht_inverse_adjoint_mex.$(MEXEXT)
# ======== MAKE RULES ========
$(SSHTOBJ)/%.o: %.c $(SSHTHEADERS)
$(CC) $(OPT) $(FFLAGS) -c $< -o $@
.PHONY: default
default: lib test about
.PHONY: test
test: $(SSHTBIN)/ssht_test about
$(SSHTBIN)/ssht_test: $(SSHTOBJ)/ssht_test.o $(SSHTLIB)/lib$(SSHTLIBNM).a
$(CC) $(OPT) $< -o $(SSHTBIN)/ssht_test $(LDFLAGS)
.PHONY: about
about: $(SSHTBIN)/ssht_about
$(SSHTBIN)/ssht_about: $(SSHTOBJ)/ssht_about.o
$(CC) $(OPT) $< -o $(SSHTBIN)/ssht_about
.PHONY: runtest
runtest: test
$(SSHTBIN)/ssht_test 64 0 32
.PHONY: all
all: lib test about matlab
# Library
.PHONY: lib
lib: $(SSHTLIB)/lib$(SSHTLIBNM).a
$(SSHTLIB)/lib$(SSHTLIBNM).a: $(SSHTOBJS)
ar -r $(SSHTLIB)/lib$(SSHTLIBNM).a $(SSHTOBJS)
# Matlab
$(SSHTOBJMAT)/%_mex.o: %_mex.c $(SSHTLIB)/lib$(SSHTLIBNM).a
$(CC) $(OPT) $(FFLAGS) -c $< -o $@ -I${MLABINC}
$(SSHTOBJMEX)/%_mex.$(MEXEXT): $(SSHTOBJMAT)/%_mex.o $(SSHTLIB)/lib$(SSHTLIBNM).a
$(MEX) $< -output $@ $(LDFLAGSMEX) $(MEXFLAGS) -L$(MLABLIB)
.PHONY: matlab
matlab: $(SSHTOBJSMEX)
# Documentation
.PHONY: doc
doc:
doxygen $(SSHTSRC)/doxygen.config
.PHONY: cleandoc
cleandoc:
rm -f $(SSHTDOC)/html/*
# Cleaning up
.PHONY: clean
clean: tidy
rm -f $(SSHTOBJ)/*.o
rm -f $(SSHTLIB)/lib$(SSHTLIBNM).a
rm -f $(SSHTBIN)/ssht_test
rm -f $(SSHTBIN)/ssht_about
rm -f $(SSHTOBJMAT)/*.o
rm -f $(SSHTOBJMEX)/*.$(MEXEXT)
.PHONY: tidy
tidy:
rm -f *~
.PHONY: cleanall
cleanall: clean cleandoc