1# Copyright 2007-2021 Mitchell. See LICENSE.
2
3CC ?= gcc
4CFLAGS ?= -Os
5CXX ?= g++
6CXXFLAGS ?= -Os -std=c++17
7ifeq (win, $(findstring win, $(MAKECMDGOALS)))
8  # Cross-compile for Win32.
9  CROSS = i686-w64-mingw32-
10  CFLAGS += -mms-bitfields
11  CXXFLAGS += -mms-bitfields
12  LUA_CFLAGS = -DLUA_BUILD_AS_DLL -DLUA_LIB
13  LDFLAGS = -static-libgcc -static-libstdc++ -Wl,--retain-symbols-file \
14            -Wl,$(shell pwd)/lua.sym
15  ifeq (, $(findstring curses, $(MAKECMDGOALS)))
16    CXXFLAGS += -mwindows
17    LDFLAGS += -liconv
18  endif
19  WINDRES = windres
20  ifeq (, $(findstring curses, $(MAKECMDGOALS)))
21    plat_flag = -DGTK
22    GTK_CFLAGS = $(shell PKG_CONFIG_PATH=`pwd`/win32gtk/lib/pkgconfig \
23                         pkg-config --define-variable=prefix=win32gtk \
24                         --cflags gtk+-2.0)
25    GTK_LIBS = $(shell PKG_CONFIG_PATH=`pwd`/win32gtk/lib/pkgconfig \
26                       pkg-config --define-variable=prefix=win32gtk \
27                       --libs gtk+-2.0 gmodule-2.0)
28    GLIB_CFLAGS = $(shell PKG_CONFIG_PATH=`pwd`/win32gtk/lib/pkgconfig \
29                          pkg-config --define-variable=prefix=win32gtk \
30                          --cflags glib-2.0)
31  else
32    plat_flag = -DCURSES
33    CURSES_CFLAGS = -DLIBICONV_STATIC -Iwin32curses/include
34    CURSES_LIBS = win32curses/lib/pdcurses.a win32curses/lib/libiconv.a
35  endif
36else ifeq (osx, $(findstring osx, $(MAKECMDGOALS)))
37  # Cross-compile for macOS.
38  CC = cc
39  CXX = c++
40  CROSS = x86_64-apple-darwin17-
41  CFLAGS += -mdynamic-no-pic
42  CXXFLAGS += -mdynamic-no-pic -stdlib=libc++ -Wno-register
43  LUA_CFLAGS = -DLUA_USE_MACOSX
44  LDFLAGS = -liconv
45  ifeq (, $(findstring curses, $(MAKECMDGOALS)))
46    plat_flag = -DGTK
47    GTK_CFLAGS = $(shell PKG_CONFIG_PATH=`pwd`/gtkosx/lib/pkgconfig \
48                         pkg-config --define-variable=prefix=gtkosx \
49                         --cflags gtk+-2.0)
50    GTK_LIBS = $(shell PKG_CONFIG_PATH=`pwd`/gtkosx/lib/pkgconfig \
51                       pkg-config --define-variable=prefix=gtkosx \
52                       --libs gtk+-2.0 gmodule-2.0 gtk-mac-integration) \
53                       -framework Cocoa
54    GLIB_CFLAGS = $(shell PKG_CONFIG_PATH=`pwd`/gtkosx/lib/pkgconfig \
55                          pkg-config --define-variable=prefix=gtkosx \
56                          --cflags glib-2.0)
57  else
58    plat_flag = -DCURSES
59    CURSES_LIBS = -lncurses
60  endif
61else
62  # Build for Linux/BSD.
63  LUA_CFLAGS = -DLUA_USE_LINUX
64  # See PR https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=220103
65  #LDFLAGS = -rdynamic -Wl,--retain-symbols-file -Wl,$(shell pwd)/lua.sym
66  ifeq (Linux, $(shell uname -s))
67    LDFLAGS += -ldl
68  else
69    CC ?= cc
70    CXX ?= c++
71    # Correct spelling on FreeBSD is USES+=iconv :)
72    #LDFLAGS += -liconv
73  endif
74  PREFIX ?= /usr/local
75  bin_dir = $(PREFIX)/bin
76  data_dir = $(PREFIX)/share/textadept
77  XDG_DATA_DIR ?= $(PREFIX)/share/applications
78  PIXMAPS_DIR ?= $(PREFIX)/share/pixmaps
79  desktop_files := $(wildcard *.desktop)
80  ifeq (, $(findstring curses, $(MAKECMDGOALS)))
81    plat_flag = -DGTK
82    ifndef GTK3
83      GTK_CFLAGS = $(shell pkg-config --cflags gtk+-2.0 gmodule-2.0)
84      GTK_LIBS = $(shell pkg-config --libs gtk+-2.0 gmodule-2.0)
85    else
86      GTK_CFLAGS = $(shell pkg-config --cflags gtk+-3.0 gmodule-2.0) \
87                   -Wno-deprecated-declarations
88      GTK_LIBS = $(shell pkg-config --libs gtk+-3.0 gmodule-2.0)
89    endif
90    GLIB_CFLAGS = $(shell pkg-config --cflags glib-2.0)
91    install_targets = ../textadept
92  else
93    plat_flag = -DCURSES
94    CURSES_CFLAGS = $(shell pkg-config --silence-errors --cflags ncursesw || \
95                            pkg-config --silence-errors --cflags ncurses || \
96                            pkg-config --silence-errors --cflags curses)
97    CURSES_LIBS = $(shell pkg-config --silence-errors --libs ncursesw || \
98                          pkg-config --silence-errors --libs ncurses || \
99                          pkg-config --silence-errors --libs curses || \
100                          echo -lncursesw)
101    install_targets = ../textadept-curses
102  endif
103endif
104version = $(shell grep -m 1 _RELEASE ../core/init.lua | cut -d ' ' -f4- | \
105                  tr ' ' '_' | tr -d "'")
106WGET = : wget-is-forbidden-during-build -O $@
107
108# Scintilla.
109
110sci_flags = -pedantic $(plat_flag) -DSCI_LEXER -DSCI_EMPTYCATALOGUE -DNDEBUG \
111            -Iscintilla/include -Iscintilla/src -Iscintilla/lexlib -Wall
112
113sci_objs = AutoComplete.o CallTip.o CaseConvert.o CaseFolder.o Catalogue.o \
114           CellBuffer.o CharClassify.o ContractionState.o Decoration.o \
115           Document.o EditModel.o Editor.o EditView.o ExternalLexer.o \
116           Indicator.o KeyMap.o LineMarker.o MarginView.o PerLine.o \
117           PositionCache.o RESearch.o RunStyles.o ScintillaBase.o Selection.o \
118           Style.o UniConversion.o ViewStyle.o UniqueString.o XPM.o
119sci_lex_objs = Accessor.o CharacterCategory.o CharacterSet.o DefaultLexer.o \
120               LexerBase.o LexerModule.o LexerNoExceptions.o LexerSimple.o \
121               PropSetSimple.o StyleContext.o WordList.o
122sci_lexer_objs = LexLPeg.o LexLPeg-curses.o
123sci_gtk_objs = PlatGTK.o ScintillaGTK.o ScintillaGTKAccessible.o
124sci_curses_objs = ScintillaCurses.o
125
126# Textadept.
127
128ta_flags = -std=c99 -pedantic $(plat_flag) -Iscintilla/include -Igtdialog -Wall
129
130textadept_gtk_objs = textadept.o
131textadept_curses_objs = textadept-curses.o
132textadept_objs = $(textadept_gtk_objs) $(textadept_curses_objs)
133lua_objs = lapi.o lcode.o lctype.o ldebug.o ldo.o ldump.o lfunc.o lgc.o \
134           linit.o llex.o lmem.o lobject.o lopcodes.o lparser.o lstate.o \
135           lstring.o ltable.o ltm.o lundump.o lvm.o lzio.o \
136           lauxlib.o lbaselib.o lbitlib.o lcorolib.o ldblib.o liolib.o \
137           lmathlib.o loadlib.o lstrlib.o ltablib.o lutf8lib.o
138lua_oslib_objs = loslib.o loslib-curses.o
139lua_lib_objs = lpcap.o lpcode.o lpprint.o lptree.o lpvm.o lfs.o
140gtdialog_objs = gtdialog.o gtdialog-curses.o
141termkey_unix_objs = driver-ti.o driver-csi.o
142termkey_win32_objs = driver-win32-pdcurses.o
143termkey_objs = termkey.o $(termkey_unix_objs) $(termkey_win32_objs)
144cdk_objs = $(addprefix cdk-, binding.o buttonbox.o cdk.o cdk_display.o \
145                             cdk_objs.o cdkscreen.o draw.o entry.o fselect.o \
146                             itemlist.o label.o mentry.o popup_label.o \
147                             scroll.o scroller.o select_file.o selection.o \
148                             slider.o traverse.o version.o)
149
150# Add debugging symbols and disable optimizations when DEBUG=1.
151# Notes:
152# In order to profile with gprof (-pg), do not retain symbols in LDFLAGS.
153# In order to report code coverage with gcov (-fprofile-arcs -ftest-coverage):
154#   Run test suite with textadept, run gcov textadept.c, then examine
155#     textadept.c.gcov
156#   Run test suite with textadept-curses, run gcov textadept-curses.c, then
157#     examine textadept.c.gcov.
158ifdef DEBUG
159  CFLAGS += -g -O0
160  CXXFLAGS += -g -O0
161  LUA_CFLAGS += -DLUA_USE_APICHECK
162  sci_flags += -UNDEBUG -DDEBUG
163endif
164
165# Build.
166
167all:
168	for tgt in $(TA_TARGETS) ; do $(MAKE) $$tgt ; \
169	find . -type f -name \*.o -delete ; done
170
171gtk: textadept
172curses: textadept-curses
173win32: textadept.exe
174win32-curses: textadept-curses.exe
175osx: textadept
176osx-curses: textadept-curses
177
178$(sci_objs): %.o: scintilla/src/%.cxx
179	$(CROSS)$(CXX) -c $(CXXFLAGS) $(sci_flags) $< -o $@
180$(sci_lex_objs): %.o: scintilla/lexlib/%.cxx
181	$(CROSS)$(CXX) -c $(CXXFLAGS) $(sci_flags) $< -o $@
182$(sci_lexer_objs): LexLPeg.cxx
183	$(CROSS)$(CXX) -c $(CXXFLAGS) $(LUA_CFLAGS) $(sci_flags) -DNO_SCITE -DNO_DLL \
184		$< -o $@
185$(sci_gtk_objs): %.o: scintilla/gtk/%.cxx
186	$(CROSS)$(CXX) -c $(CXXFLAGS) $(sci_flags) $(GTK_CFLAGS) $< -o $@
187scintilla-marshal.o: scintilla/gtk/scintilla-marshal.c
188	$(CROSS)$(CC) -c $(CFLAGS) $(GTK_CFLAGS) $< -o $@
189$(sci_curses_objs): %.o: scintilla/curses/%.cxx
190	$(CROSS)$(CXX) -c $(CXXFLAGS) $(sci_flags) $(CURSES_CFLAGS) $< -o $@
191$(textadept_objs): textadept.c
192	$(CROSS)$(CC) -c $(CFLAGS) $(LUA_CFLAGS) $(ta_flags) $< -o $@
193$(lua_objs): %.o: lua/src/%.c
194	$(CROSS)$(CC) -c $(CFLAGS) $(LUA_CFLAGS) -ULUA_LIB $< -o $@
195$(lua_oslib_objs): lua/src/loslib.c
196	$(CROSS)$(CC) -c $(CFLAGS) $(LUA_CFLAGS) -ULUA_LIB -std=c99 -pedantic $< -o $@
197$(lua_lib_objs): %.o: lua/src/lib/%.c
198	$(CROSS)$(CC) -c $(CFLAGS) $(LUA_CFLAGS) $< -o $@
199$(gtdialog_objs): gtdialog/gtdialog.c
200	$(CROSS)$(CC) -c $(CFLAGS) -std=c99 -pedantic $(plat_flag) -DNOHELP \
201		-DLIBRARY $(gtdialog_flags) $< -o $@
202$(cdk_objs): cdk-%.o: cdk/%.c
203	$(CROSS)$(CC) -c $(CFLAGS) -D_GNU_SOURCE -Itermkey -Icdk $(CURSES_CFLAGS) $< \
204		-o $@
205$(termkey_objs): %.o: termkey/%.c
206	$(CROSS)$(CC) -c $(CFLAGS) -std=c99 $(CURSES_CFLAGS) $< -o $@
207textadept_rc.o: textadept.rc ; $(CROSS)$(WINDRES) $< $@
208
209# Target-specific variables.
210
211LexLPeg-curses.o: sci_flags += -DCURSES $(CURSES_CFLAGS)
212lua_dep_objs = LexLPeg.o LexLPeg-curses.o textadept.o textadept-curses.o \
213               $(lua_objs) $(lua_oslib_objs) $(lua_lib_objs)
214$(lua_dep_objs): LUA_CFLAGS += -Ilua/src
215$(textadept_gtk_objs): ta_flags += $(GTK_CFLAGS)
216$(textadept_curses_objs): \
217  ta_flags += -Iscintilla/curses -Itermkey -Icdk $(CURSES_CFLAGS)
218loslib.o: LUA_CFLAGS += -DGTK $(GLIB_CFLAGS)
219gtdialog.o: gtdialog_flags += $(GTK_CFLAGS)
220gtdialog-curses.o: gtdialog_flags += -I. -Icdk $(CURSES_CFLAGS)
221
222# Executables.
223
224textadept: $(sci_objs) $(sci_lex_objs) LexLPeg.o $(sci_gtk_objs) \
225           scintilla-marshal.o textadept.o $(lua_objs) loslib.o \
226           $(lua_lib_objs) gtdialog.o
227	$(CROSS)$(CXX) $(CXXFLAGS) -o ../$@ $^ $(GTK_LIBS) $(LDFLAGS)
228textadept-curses: $(sci_objs) $(sci_lex_objs) LexLPeg-curses.o \
229                  $(sci_curses_objs) textadept-curses.o $(lua_objs) \
230                  loslib-curses.o $(lua_lib_objs) gtdialog-curses.o termkey.o \
231                  $(termkey_unix_objs) $(cdk_objs)
232	$(CROSS)$(CXX) $(CXXFLAGS) -o ../$@ $^ $(CURSES_LIBS) $(LDFLAGS)
233textadept.exe: $(sci_objs) $(sci_lex_objs) LexLPeg.o $(sci_gtk_objs) \
234               scintilla-marshal.o textadept.o textadept_rc.o $(lua_objs) \
235               loslib.o $(lua_lib_objs) gtdialog.o
236	$(CROSS)$(CXX) $(CXXFLAGS) -o ../$@ $^ $(GTK_LIBS) $(LDFLAGS)
237textadept-curses.exe: $(sci_objs) $(sci_lex_objs) LexLPeg-curses.o \
238                      $(sci_curses_objs) textadept-curses.o textadept_rc.o \
239                      $(lua_objs) loslib-curses.o $(lua_lib_objs) \
240                      gtdialog-curses.o termkey.o $(termkey_win32_objs) \
241                      $(cdk_objs)
242	$(CROSS)$(CXX) $(CXXFLAGS) -o ../$@ $^ $(CURSES_LIBS) $(LDFLAGS)
243
244# Install/uninstall.
245
246install: $(wildcard ../textadept*) | ../core ../docs ../init.lua ../lexers \
247                              ../modules ../themes
248	install -d $(DESTDIR)$(bin_dir) $(DESTDIR)$(data_dir)
249	install $^ $(DESTDIR)$(data_dir)
250	cp -rL $| $(DESTDIR)$(data_dir)
251	ln -s $(subst ..,..$(subst $(PREFIX),,$(data_dir)),$^) $(DESTDIR)$(bin_dir)
252	if : ; then \
253		install -d $(DESTDIR)$(XDG_DATA_DIR); \
254		install $(desktop_files) $(DESTDIR)$(XDG_DATA_DIR); \
255	fi
256	if : ; then \
257		install -d $(DESTDIR)$(PIXMAPS_DIR); \
258		ln -s ../..$(subst $(PREFIX),,$(data_dir))/core/images/textadept.svg \
259			$(DESTDIR)$(PIXMAPS_DIR); \
260		ln -s ../..$(subst $(PREFIX),,$(data_dir))/core/images/ta_48x48.png \
261			$(DESTDIR)$(PIXMAPS_DIR)/textadept.png; \
262	fi
263uninstall:
264	rm -r $(DESTDIR)$(bin_dir)/textadept* $(DESTDIR)$(data_dir)
265	if [ -d "$(XDG_DATA_DIR)" ]; then \
266		rm $(DESTDIR)$(XDG_DATA_DIR)/textadept*.desktop; \
267	fi
268	if [ -d "$(PIXMAPS_DIR)" ]; then rm $(DESTDIR)$(PIXMAPS_DIR)/textadept*; fi
269
270# Clean.
271
272clean: ; rm -f *.o ../textadept*
273
274# Documentation.
275
276ifndef ALL_MODULES
277  modules = $(addprefix ../modules/,ansi_c lua textadept)
278else
279  modules = ../modules
280endif
281ta_home = $(shell dirname `pwd`)
282
283docs: luadoc manual
284manual: ../docs/api.md $(wildcard ../docs/*.md) | ../docs/_layouts/default.html
285	for file in $(basename $^); do \
286		cat $| | ../scripts/fill_layout.lua $$file.md > $$file.html; \
287	done
288	sed -i \
289		"s/\(\# Textadept\).\+\?\(Manual\|API\)/\1 $(subst _, ,$(version)) \2/;" \
290		../docs/*.md
291luadoc: ../core $(modules) ../lexers/lexer.lua | ../modules/lua/lua.luadoc
292	cd ../scripts && luadoc --doclet markdowndoc $^ > ../docs/api.md
293	cd ../modules && luadoc -d lua --doclet lua/tadoc $^ --ta-home=$(ta_home)
294	cd ../modules/lua && mv tags ta_tags && mv api ta_api
295	cd ../modules && luadoc -d lua --doclet lua/tadoc $| --ta-home=$(ta_home)
296
297# Releases.
298
299ifndef NIGHTLY
300  basedir = textadept_$(version)
301else
302  basedir = textadept_nightly_$(shell date +"%F")
303endif
304osxapp = Textadept.app
305osxapp_bin = $(osxapp)/Contents/MacOS
306osxapp_res = $(osxapp)/Contents/Resources
307osxapp_libs = libatk-1.0.0.dylib libcairo.2.dylib libexpat.1.dylib \
308              libffi.6.dylib libfontconfig.1.dylib libfreetype.6.dylib \
309              libgdk_pixbuf-2.0.0.dylib libgdk-quartz-2.0.0.dylib \
310              libgio-2.0.0.dylib libglib-2.0.0.dylib libgmodule-2.0.0.dylib \
311              libgobject-2.0.0.dylib libgthread-2.0.0.dylib \
312              libgtkmacintegration.2.dylib libgtk-quartz-2.0.0.dylib \
313              libharfbuzz.0.dylib libintl.8.dylib libpango-1.0.0.dylib \
314              libpangocairo-1.0.0.dylib libpangoft2-1.0.0.dylib \
315              libpixman-1.0.dylib libpng16.16.dylib charset.alias \
316              gdk-pixbuf-2.0 gtk-2.0
317
318release-all: release win32-release osx-release #modules-release
319
320ifneq (, $(shell hg summary 2>/dev/null))
321  archive = hg archive -X ".hg*" $(1)
322else
323  archive = cd ../ && git archive HEAD --prefix src/$(1)/ | tar -xf -
324endif
325modules = css ctags debugger export file_diff html lsp lua_repl open_file_mode \
326  python rest ruby spellcheck yaml
327
328$(basedir).linux: ; $(call archive,$@)
329release: $(basedir).linux
330	make deps clean docs
331	make -j4 CXXFLAGS="$(CXXFLAGS) -static-libstdc++"
332	make -j4 CXXFLAGS="$(CXXFLAGS) -static-libstdc++" curses
333	cp -rL ../docs ../lexers ../textadept* $<
334	tar czf $<.tgz $< && rm -rf $<
335$(basedir).win32: ; $(call archive,$@)
336win32-release: $(basedir).win32
337	make -j4 clean win32-deps
338	cp win32gtk/bin/*.dll $< && cp -r win32gtk/etc \
339		win32gtk/lib win32gtk/share $<
340	rm -r $</lib/*.a $</lib/glib-2.0 $</lib/gtk-2.0/include $</lib/pkgconfig
341	make -j4 win32
342	make -j4 win32-curses
343	cp -rL ../docs ../lexers ../textadept* $<
344	zip -r $<.zip $< && rm -rf $<
345$(basedir).macOS: ; mkdir $@ && cp ../scripts/osx/ta $@
346osx-release: $(basedir).macOS
347	make clean osx-deps
348	make -j4 osx
349	make -j4 osx-curses
350	make osx-app && mv $(osxapp) $<
351	zip -r $<.zip $< && rm -rf $<
352$(basedir).modules:
353	mkdir -p $@/modules
354	for module in $(modules); do \
355		make -C ../modules/$$module release; \
356		unzip -d $@/modules ../modules/$$module/$$module.zip; \
357	done
358modules-release: $(basedir).modules ; zip -r $<.zip $< && rm -r $<
359
360osx-app: ../textadept ../textadept-curses ../scripts/osx/textadept_osx
361	mkdir -p $(osxapp_bin) $(osxapp_res)
362	cp Info.plist $(osxapp_bin)/../
363	cp $^ $(osxapp_bin)/
364	$(call archive,$(osxapp_res))
365	cp -rL ../docs ../lexers $(osxapp_res)
366	mv $(osxapp_res)/core/images/textadept.icns $(osxapp_res)/
367	cp -r gtkosx/etc gtkosx/share $(osxapp_res)/ && mkdir $(osxapp_res)/lib/
368	cp -r $(addprefix gtkosx/lib/, $(osxapp_libs)) $(osxapp_res)/lib/
369	rm -r $(osxapp_res)/lib/gtk-2.0/include $(osxapp_res)/lib/gtk-2.0/modules
370	rm $(osxapp_res)/lib/gtk-2.0/2.10.0/printbackends/*
371
372# External dependencies.
373
374base_deps = scintilla scinterm scintillua lua lualibs gtdialog cdk
375deps: $(base_deps) termkey
376win32-deps: $(base_deps) win32gtk win32curses
377osx-deps: $(base_deps) gtkosx termkey
378
379root_url = https://github.com/orbitalquark
380ifndef NIGHTLY
381  scinterm_url = $(root_url)/scinterm/archive/$@
382  scintillua_url = $(root_url)/scintillua/archive/$@
383  gtdialog_url = $(root_url)/gtdialog/archive/$@
384else
385  scinterm_url = $(root_url)/scinterm/archive/default.zip
386  scintillua_url = $(root_url)/scintillua/archive/default.zip
387  gtdialog_url = $(root_url)/gtdialog/archive/default.zip
388endif
389
390scintilla_tgz = scintilla445.tgz
391scinterm_zip = 6a774158d8a3c7bc7ea120bc01cdb016fa351a7e.zip
392scintillua_zip = scintillua_4.4.5-2.zip
393lua_tgz = lua-5.3.5.tar.gz
394lpeg_tgz = lpeg-1.0.2.tar.gz
395lfs_zip = v1_8_0.zip
396gtdialog_zip = 64587546482a1a6324706d75c80b77d2f87118a4.zip
397cdk_tgz = cdk-5.0-20200923.tgz
398termkey_tgz = libtermkey-0.20.tar.gz
399win32gtk_zip = win32gtk-2.24.32.zip
400win32curses_zip = win32curses39.zip
401pdcurses_zip = PDCurses-3.9.zip
402gtkosx_tgz = gtkosx-2.24.31.tar.gz
403cloc = cloc-1.60.pl
404
405LexLPeg = LexLPeg.cxx LexLPeg.h
406
407$(scintilla_tgz): ; $(WGET) https://www.scintilla.org/$@
408scintilla: scintilla.patch | $(scintilla_tgz)
409	if [ -d $@/.hg ]; then \
410		hg --cwd $@ update -C; \
411	else \
412		if [ -d $@ ]; then rm -r $@; fi; \
413		tar xzf $|; \
414	fi
415	for patch in $^; do echo Applying $$patch; patch -d $@ -N -p1 < $$patch; done
416$(scinterm_zip): ; $(WGET) $(scinterm_url) -O $@
417scinterm: scintilla/curses
418scintilla/curses: | $(scinterm_zip) ; unzip -d $@ -j $| "*/*.cxx" "*/*.h"
419$(scintillua_zip): ; $(WGET) $(scintillua_url) -O $@
420scintillua: ../lexers $(LexLPeg)
421../lexers: | $(scintillua_zip) ; unzip -d $@ -j $| "*/lexers/*" -x "*/themes/*"
422$(LexLPeg): | $(scintillua_zip) ; unzip -j $| "*/*.cxx" "*/*.h"
423$(lua_tgz): ; $(WGET) https://www.lua.org/ftp/$@
424$(lpeg_tgz): ; $(WGET) http://www.inf.puc-rio.br/~roberto/lpeg/$@
425$(lfs_zip): ; $(WGET) https://github.com/keplerproject/luafilesystem/archive/$@
426lua: lua.patch | $(lua_tgz)
427	if [ -d $@ ]; then rm -rf $@; fi
428	mkdir $@ && tar xzf $| -C $@ && mv $@/*/* $@
429	patch -d $@ -N -p1 < $<
430lualibs: lua/src/lib/lpeg lua/src/lib/lfs
431lua/src/lib/lpeg: | $(lpeg_tgz)
432	mkdir -p $@ && tar xzf $| -C $@ && mv $@/*/*.c $@/*/*.h $(dir $@)
433lua/src/lib/lfs: | $(lfs_zip)
434	if [ -d $@ ]; then rm -r $@; fi
435	mkdir -p $@ && unzip -d $(dir $@) -j $| "*/src/*.c" "*/src/*.h"
436$(gtdialog_zip): ; $(WGET) $(gtdialog_url) -O $@
437gtdialog: | $(gtdialog_zip) ; unzip -d $@ -j $| "*/*.c" "*/*.h"
438$(cdk_tgz): ; $(WGET) https://invisible-mirror.net/archives/cdk/$@
439cdk: cdk.patch | $(cdk_tgz)
440	if [ -d $@ ]; then rm -r $@; fi
441	mkdir $@ && tar xzf $| -C $@ && mv $@/*/* $@
442	mv $@/include/*.h $@
443	$@/gen-scale.sh SLIDER Slider Int int $@/gen-slider.h > $@/slider.h
444	$@/gen-scale.sh SLIDER Slider Int int $@/gen-slider.c > $@/slider.c
445	patch -d $@ -N -p1 < $<
446$(termkey_tgz): ; $(WGET) http://www.leonerd.org.uk/code/libtermkey/$@
447termkey: termkey.patch | $(termkey_tgz)
448	if [ -d $@ ]; then rm -r $@; fi
449	mkdir $@ && tar xzf $| -C $@ && mv $@/*/* $@ && chmod +w $@/termkey.h
450	patch -d $@ -N -p1 < $<
451$(win32gtk_zip): ; $(WGET) $(root_url)/textadept-build/raw/default/$@
452win32gtk: | $(win32gtk_zip) ; unzip $|
453$(win32curses_zip): ; $(WGET) $(root_url)/textadept-build/raw/default/$@
454$(pdcurses_zip): ; $(WGET) http://prdownloads.sourceforge.net/pdcurses/$@
455win32curses: pdcurses.patch | $(win32curses_zip) $(pdcurses_zip)
456	unzip $(win32curses_zip)
457	mkdir $@/src && unzip -d $@/src $(pdcurses_zip) && mv $@/src/*/* $@/src
458	cp $@/src/curses.h $@/include
459	patch -d $@/src -N -p1 < $<
460	cd $@/src/wincon && $(MAKE) CC="$(CROSS)$(CC) $(CFLAGS)" LIBEXE=$(CROSS)ar \
461		LINK="$(CROSS)$(CC) $(CFLAGS)" WIDE=Y UTF8=Y libs
462	cp $@/src/wincon/pdcurses.a $@/lib/
463$(gtkosx_tgz): ; $(WGET) $(root_url)/textadept-build/raw/default/$@
464gtkosx: | $(gtkosx_tgz) ; mkdir $@ && tar xzf $| -C $@ && mv $@/*/* $@
465$(cloc): ; $(WGET) http://prdownloads.sourceforge.net/cloc/$@
466
467clean-deps:
468	rm -rf scintilla ../lexers $(LexLPeg) lua gtdialog cdk termkey win32gtk \
469		win32curses gtkosx $(scinterm_zip) $(scintillua_zip) $(gtdialog_zip)
470
471# Count lines of code.
472
473sources = ../core ../modules/ansi_c ../modules/lua ../modules/textadept \
474          textadept.c Makefile ../init.lua
475count: $(cloc) ; perl $< $(sources) --not-match-f=tadoc.lua
476plots: ; ../scripts/gen_plots.sh
477