-
Notifications
You must be signed in to change notification settings - Fork 38
/
Makefile
235 lines (207 loc) · 6.43 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
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
EXECUTION=normal
LEGACY=
STATA = ${HOME}/.local/stata13/stata -b
# ---------------------------------------------------------------------
# Editing/debugging
## Open current meta for working
open:
konsole -e nvim -S ~/.vim/session/gtools &
konsole --new-tab --workdir /home/mauricio/todo/now/stata-gtools &
dolphin --split ~/todo/now/stata-gtools \
~/todo/now/stata-gtools/src &
# doc xx add resid[(str)] option to docs
# doc xx what was absorb(, save(str)) meant to do?
# bug xx detect collinearity with dep var in glm
# bug xx noconstant without any covariates shouldnt' be allowed
# Update!
# -------
#
# ./lib/bumpver.py
# ./README.md
# ./docs/index.md
# ./docs/stata/gtools.sthlp
# ./src/ado/gtools.ado
# ./src/ado/_gtools_internal.ado
# ./src/plugin/gtools.h
# x ./src/plugin/gtools.c
# x ./src/test/gtools_tests.do
# ./src/gtools.pkg
# ./src/stata.toc
# ./.appveyor.yml
# x ./build.py
# x ./changelog.md
# Add a group stat
# ----------------
#
# ./README.md L318
# ./docs/index.md L308
# ./changelog.md note in new version which stats
# gcollapse
# gegen
# gstats tab
#
# ./docs/usage/gcollapse.md L29
# ./docs/usage/gegen.md L194
# ./docs/usage/gstats_summarize.md L26
# ./docs/usage/gstats_transform.md L34
# ./docs/stata/gcollapse.sthlp L50
# ./docs/stata/gegen.sthlp L223
# ./docs/stata/gstats_summarize.sthlp L278
# ./docs/stata/gstats_transform.sthlp L55
#
# ./src/ado/_gtools_internal.ado L2496, L3395, L3545, L3660, L3915, L4200, L5060, L5420, L5690, L5800, L5900
# ./src/ado/_gtools_internal.mata L1252, L1311
# ./src/ado/gcollapse.ado L1106, L1743, L1845, L1932
# ./src/ado/gegen.ado L63, L81, L820
#
# ./src/plugin/collapse/gtools_math.c
# ./src/plugin/collapse/gtools_math.h
# ./src/plugin/collapse/gtools_math_unw.c
# ./src/plugin/collapse/gtools_math_unw.h
# ./src/plugin/collapse/gtools_math_w.c
# ./src/plugin/collapse/gtools_math_w.h
# ./src/ado/_gtools_internal.ado gstats_hdfe fun
# ./src/plugin/gtools.c
# ./src/plugin/gtools.h
# gstats_scalars init
# if ( inlist("`gfunction'", "stats") ) {
# ./src/ado/gstats.ado gstats_hdfe fun
# ./docs/stata/gstats_hdfe.sthlp
# ./docs/usage/gstats_hdfe.md
# Add to gstats
# -------------
#
# ./src/ado/gstats.ado L27
# ./src/ado/_gtools_internal.ado L2470, L3685
# ./src/ado/_gtools_internal.ado L3795 add program gstats_<newfunc>
# ---------------------------------------------------------------------
# Gtools flags
SPIVER = v2
SPI = 2.0
GTOOLSOMP? = 0
ifeq ($(GTOOLSOMP),1)
CFLAGS = -Wall -O3 $(OSFLAGS) -DGTOOLSOMP=1 -fopenmp
else
CFLAGS = -Wall -O3 $(OSFLAGS)
endif
# ---------------------------------------------------------------------
# OS parsing
ifeq ($(OS),Windows_NT)
OSFLAGS = -shared -fPIC
GCC = x86_64-w64-mingw32-gcc.exe
OUT = build/gtools_windows$(LEGACY)_$(SPIVER).plugin
else
UNAME_S := $(shell uname -s)
ifeq ($(UNAME_S),Linux)
GCC = gcc
OSFLAGS = -shared -fPIC -DSYSTEM=OPUNIX
OUT = build/gtools_unix$(LEGACY)_$(SPIVER).plugin
endif
ifeq ($(UNAME_S),Darwin)
GCC = clang
OSFLAGS = -bundle -DSYSTEM=APPLEMAC
OUT = build/gtools_macosx$(LEGACY)_$(SPIVER).plugin
endif
endif
ifeq ($(EXECUTION),windows)
OSFLAGS = -shared
GCC = x86_64-w64-mingw32-gcc
OUT = build/gtools_windows$(LEGACY)_$(SPIVER).plugin
endif
# ---------------------------------------------------------------------
# Main
## Compile directory
all: clean links gtools
osx: clean links osx_combine
## Initialize git and pull sub-modules
git:
git init
git submodule add https://github.com/centaurean/spookyhash lib/spookyhash
git submodule update --init --recursive
cd lib/spookyhash && git checkout spookyhash-1.0.6 && cd -
## Download latest OSX plugin
osx_plugins:
wget https://raw.githubusercontent.com/mcaceresb/stata-gtools/osx/build/gtools_macosx_v3.plugin
wget https://raw.githubusercontent.com/mcaceresb/stata-gtools/osx/build/gtools_macosx_v2.plugin
cp -f gtools_macosx_v3.plugin build/gtools_macosx_v3.plugin
cp -f gtools_macosx_v2.plugin build/gtools_macosx_v2.plugin
mv -f gtools_macosx_v3.plugin lib/plugin/gtools_macosx_v3.plugin
mv -f gtools_macosx_v2.plugin lib/plugin/gtools_macosx_v2.plugin
## Install the Stata package (replace if necessary)
replace:
cd build/ && $(STATA) "cap noi net uninstall gtools"
cd build/ && $(STATA) "net install gtools, from(\`\"${PWD}/build\"')"
# ---------------------------------------------------------------------
# Rules
## Build gtools library links
links:
rm -f src/plugin/lib
rm -f src/plugin/spi
ln -sf ../../lib src/plugin/lib
ln -sf lib/spi-$(SPI) src/plugin/spi
GTOOLS_SRC=src/plugin/gtools.c \
src/plugin/spi/stplugin.c
SPOOKYHASH_SRC=lib/spookyhash/src/context.c \
lib/spookyhash/src/globals.c \
lib/spookyhash/src/spookyhash.c
SPOOKYHASH_INC=-Ilib/spookyhash/src
## Build gtools plugin
gtools: $(GTOOLS_SRC) $(SPOOKYHASH_SRC)
mkdir -p ./build
$(GCC) $(CFLAGS) -o $(OUT) $(SPOOKYHASH_INC) $^
cp build/*plugin lib/plugin/
## Build OSX-specific plugins
osx_combine: $(GTOOLS_SRC) $(SPOOKYHASH_SRC)
mkdir -p ./build
$(GCC) $(CFLAGS) -arch arm64 -o $(OUT).arm64 $(SPOOKYHASH_INC) $^
$(GCC) $(CFLAGS) -arch x86_64 -o $(OUT).x86_64 $(SPOOKYHASH_INC) $^
lipo -create -output $(OUT) $(OUT).x86_64 $(OUT).arm64
cp build/*plugin lib/plugin/
.PHONY: clean
clean:
rm -f $(OUT)*
#######################################################################
# #
# Self-Documenting Foo (Ignore) #
# #
#######################################################################
.DEFAULT_GOAL := show-help
.PHONY: show-help
show-help:
@echo "$$(tput bold)Available rules:$$(tput sgr0)"
@echo
@sed -n -e "/^## / { \
h; \
s/.*//; \
:doc" \
-e "H; \
n; \
s/^## //; \
t doc" \
-e "s/:.*//; \
G; \
s/\\n## /---/; \
s/\\n/ /g; \
p; \
}" ${MAKEFILE_LIST} \
| LC_ALL='C' sort --ignore-case \
| awk -F '---' \
-v ncol=$$(tput cols) \
-v indent=19 \
-v col_on="$$(tput setaf 6)" \
-v col_off="$$(tput sgr0)" \
'{ \
printf "%s%*s%s ", col_on, -indent, $$1, col_off; \
n = split($$2, words, " "); \
line_length = ncol - indent; \
for (i = 1; i <= n; i++) { \
line_length -= length(words[i]) + 1; \
if (line_length <= 0) { \
line_length = ncol - indent - length(words[i]) - 1; \
printf "\n%*s ", -indent, " "; \
} \
printf "%s ", words[i]; \
} \
printf "\n"; \
}' \
| more $(shell test $(shell uname) = Darwin && echo '--no-init --raw-control-chars')