2 # Copyright Neil Brown ©2015-2020 <neil@brown.name>
3 # May be distrubuted under terms of GPLv2 - see file:COPYING
7 export SMATCH_CHECK_SAFE
9 # if C=0 is given on command line, disable all checking.
10 # if C=1 is given, enable it
12 ifeq "$(wildcard .CHECK)" ".CHECK"
17 # if D=0 is given, don't add debug flags, fully optimize
18 # if D=1, add debugging, no optimization
19 # otherwise, .DEBUG file means compile with debugging
21 ifeq "$(wildcard .DEBUG)" ".DEBUG"
26 VERSION = $(shell [ -e .git ] && git describe --always HEAD | sed 's/edlib-//')
27 VERS_DATE = $(shell [ -e .git ] && date --iso-8601 --date="`git log -n1 --format=format:%cd --date=iso --date=short`")
28 DVERS = $(if $(VERSION),-DVERSION=\"$(VERSION)\",)
29 DDATE = $(if $(VERS_DATE),-DVERS_DATE="\"$(VERS_DATE)\"",)
30 VCFLAGS += $(DVERS) $(DDATE)
34 floats= 16 32 64 128 16X 32X 64X 128X
35 have_float=$(foreach n,$(floats),-D__HAVE_FLOAT$(n)=0 -D__HAVE_DISTINCT_FLOAT$(n)=0)
36 SMATCH_FLAGS= -D_BITS_FLOATN_H $(have_float) -D__FLT_EVAL_METHOD__=1 $(VCFLAGS)
38 SPARSEFLAGS= -Wsparse-all -Wno-transparent-union -Wsparse-error $(SMATCH_FLAGS) $(VCFLAGS)
39 # Create files .DEBUG and .LEAK for extra checking
41 DBG := -Werror -fno-omit-frame-pointer
42 ifeq "$(wildcard .SANITIZE)" ".SANITIZE"
43 DBG += -fsanitize=undefined
45 ifeq "$(wildcard .LEAK)" ".LEAK"
46 DBG += -fsanitize=leak
52 QUIET_CHECK = $(Q:@=@echo ' CHECK '$<;)
57 ifeq "$(wildcard .SMATCH) $(CHECK)" ".SMATCH 1"
58 # SYMLINK .SMATCH to the smatch binary for testing.
59 SMATCH_CMD=$(shell readlink .SMATCH) $(SMATCH_FLAGS)
60 QUIET_SMATCH = $(Q:@=@echo ' SMATCH '$<;)$(SMATCH_CMD)
62 QUIET_SMATCH = @: skip
64 CFLAGS= -g -Wall -Wstrict-prototypes -Wextra -Wno-unused-parameter $(DBG) $(VCFLAGS)
65 #CFLAGS= -pg -fno-pie -fno-PIC -g -Wall -Wstrict-prototypes -Wextra -Wno-unused-parameter $(DBG) $(VCFLAGS)
66 #Doesn't work :-( -fsanitize=address
68 all: edlib checksym lib shared
69 test: edlib lib shared test-rexel
73 LIBOBJ = O/core-mark.o O/core-doc.o O/core-editor.o O/core-attr.o \
74 O/core-keymap.o O/core-pane.o O/core-misc.o O/core-log.o \
76 SHOBJ = O/doc-text.o O/doc-dir.o O/doc-docs.o \
77 O/doc-email.o O/doc-multipart.o \
78 O/render-hex.o O/render-lines.o \
79 O/render-format.o O/render-complete.o \
80 O/lib-view.o O/lib-tile.o O/lib-popup.o O/lib-linecount.o O/lib-keymap.o \
81 O/lib-search.o O/lib-messageline.o O/lib-input.o O/lib-libevent.o \
82 O/lib-history.o O/lib-crop.o O/lib-markup.o O/lib-rfc822header.o \
83 O/lib-viewer.o O/lib-base64.o O/lib-qprint.o O/lib-utf8.o \
84 O/lib-copybuf.o O/lib-whitespace.o O/lib-colourmap.o \
85 O/lib-renderline.o O/lib-x11selection.o O/lib-autosave.o \
90 XOBJ = O/rexel.o O/emacs-search.o
92 # From python 3.8 on we need python3-embed to get the right libraries
93 pypkg=$(shell pkg-config --atleast-version=3.8 python3 && echo python3-embed || echo python3)
94 LIBS-lang-python = $(shell pkg-config --libs $(pypkg))
95 INC-lang-python = $(shell pkg-config --cflags $(pypkg))
97 LIBS-display-ncurses = $(shell pkg-config --libs panelw ncursesw)
98 INC-display-ncurses = $(shell pkg-config --cflags panelw ncursesw)
99 O/display-ncurses.o : md5.h
101 LIBS-lib-libevent = $(shell pkg-config --libs libevent)
103 LIBS-lib-x11selection = $(shell pkg-config --libs gtk+-3.0)
104 INC-lib-x11selection = $(shell pkg-config --cflags gtk+-3.0)
106 O/core-editor-static.o : O/mod-list-decl.h O/mod-list.h
108 STATICOBJ = $(SHOBJ:.o=-static.o) $(LIBOBJ:.o=-static.o)
111 # Pretty print - borrowed from 'sparse'
115 QUIET_CC = $(Q:@=@echo ' CC '$@;)
116 QUIET_CCSTATIC= $(Q:@=@echo ' CCstatic '$@;)
117 QUIET_AR = $(Q:@=@echo ' AR '$@;)
118 QUIET_GEN = $(Q:@=@echo ' GEN '$@;)
119 QUIET_LINK = $(Q:@=@echo ' LINK '$@;)
120 QUIET_LIB = $(Q:@=@echo ' LIB '$@;)
121 QUIET_SCRIPT = $(Q:@=@echo ' SCRIPT '$@;)
123 SO = $(patsubst O/%.o,lib/edlib-%.so,$(SHOBJ))
124 H = list.h core.h misc.h safe.h vfunc.h
125 edlib: $(OBJ) lib/libedlib.so
126 $(QUIET_LINK)$(CC) $(CPPFLAGS) $(CFLAGS) -rdynamic -Wl,--disable-new-dtags -o $@ $(OBJ) -Llib -Wl,-rpath=`pwd`/lib -ledlib $(LDLIBS)
128 edlib-static: $(OBJ) $(STATICOBJ) $(XOBJ) O/core-version.o
129 $(QUIET_LINK)$(CC) $(CPPFLAGS) $(CFLAGS) -o $@ $^ $(LIBS-lang-python) $(LIBS-display-ncurses) $(LIBS-lib-libevent)
131 $(OBJ) $(SHOBJ) $(LIBOBJ) $(XOBJ) $(STATICOBJ) : $(H) O/.exists
132 $(LIBOBJ) : internal.h
135 $(QUIET_CC)$(CC) $(CPPFLAGS) $(INC-$*) $(CFLAGS) -c -o $@ $<
136 $(QUIET_CHECK)sparse $(CPPFLAGS) $(INC-$*) $(SPARSEFLAGS) $<
137 $(QUIET_SMATCH) $(CPPFLAGS) $(INC-$*) $<
139 $(SHOBJ) $(LIBOBJ) $(XOBJ) : O/%.o : %.c
140 $(QUIET_CC)$(CC) -fPIC $(CPPFLAGS) $(INC-$*) $(CFLAGS) -c -o $@ $<
141 $(QUIET_CHECK)sparse $(CPPFLAGS) $(INC-$*) $(SPARSEFLAGS) $<
142 $(QUIET_SMATCH) $(CPPFLAGS) $(INC-$*) $<
144 $(STATICOBJ) : O/%-static.o : %.c
145 $(QUIET_CCSTATIC)$(CC) -Dedlib_init=$(subst -,_,$*)_edlib_init $(CPPFLAGS) $(INC-$*) $(CFLAGS) -c -o $@ $<
149 etags -o TAGS.tmp Makefile *.h *.c python/*.py
150 @sed 's/[\o177,].*//' TAGS > .TAGS1
151 @sed 's/[\o177,].*//' TAGS.tmp > .TAGS2
152 @if cmp -s .TAGS1 .TAGS2 ; then \
164 @ln -s ../python lib/python
168 lib: lib/libedlib.so lib/.exists
169 lib/libedlib.so: $(LIBOBJ)
171 $(QUIET_CC)$(CC) -shared -Wl,-soname,libedlib.so -o $@ $(LIBOBJ)
174 lib/edlib-lib-search.so : O/lib-search.o O/rexel.o
175 lib/edlib-mode-emacs.so : O/mode-emacs.o O/emacs-search.o
177 $(SO) : lib/edlib-%.so : O/%.o O/core-version.o lib/.exists
179 $(QUIET_LIB)$(CC) -shared -Wl,-soname,edlib-$*.so -o $@ $(filter %.o,$^) $(LIBS-$*)
181 O/mod-list.h : Makefile
182 $(QUIET_SCRIPT)for file in $(patsubst O/%.o,%,$(subst -,_,$(SHOBJ))); do echo "{ \"$$file\", $${file}_edlib_init}," ; done | sort > $@
183 O/mod-list-decl.h : Makefile
184 $(QUIET_SCRIPT)for file in $(patsubst O/%.o,%_edlib_init,$(subst -,_,$(SHOBJ))); do echo void $$file"(struct pane *ed);" ; done > $@
189 @for f in $(CSRC); do sed -n -e 's/^#ifdef TEST_\(.*\)$$/\1/p' $$f | \
190 while read test; do cc -g -o test_$$test -DTEST_$$test $(CSRC) && \
191 ./test_$$test || exit 2; \
195 rexel: rexel.c rexel.h core-misc.c
196 $(CC) -DDEBUG -g -o rexel rexel.c core-misc.c
202 @nm edlib | awk '$$2 == "T" {print $$3}' | while read a; do grep $$a *.h > /dev/null || echo $$a; done | grep -vE '^(_.*|main)$$' ||:
206 rm -f edlib edlib-static