]> git.neil.brown.name Git - edlib.git/blob - Makefile
Makefile: add rexel tests to 'make test'
[edlib.git] / Makefile
1 #
2 # Copyright Neil Brown ©2015-2020 <neil@brown.name>
3 # May be distrubuted under terms of GPLv2 - see file:COPYING
4 #
5
6 SMATCH_CHECK_SAFE=1
7 export SMATCH_CHECK_SAFE
8
9 # if C=0 is given on command line, disable all checking.
10 # if C=1 is given, enable it
11 C=auto
12 ifeq "$(wildcard .CHECK)" ".CHECK"
13  CHECK=$(C:auto=1)
14 else
15  CHECK=$(C:auto=0)
16 endif
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
20 D=auto
21 ifeq "$(wildcard .DEBUG)" ".DEBUG"
22  DEBUG=$(D:auto=1)
23 else
24  DEBUG=$(D:auto=0)
25 endif
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)
31
32 LDLIBS= -ldl
33 CC = gcc
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)
37
38 SPARSEFLAGS= -Wsparse-all -Wno-transparent-union -Wsparse-error $(SMATCH_FLAGS) $(VCFLAGS)
39 # Create files .DEBUG and .LEAK for extra checking
40 ifeq "$(DEBUG)" "1"
41  DBG := -Werror -fno-omit-frame-pointer
42  ifeq "$(wildcard .SANITIZE)" ".SANITIZE"
43   DBG += -fsanitize=undefined
44  endif
45  ifeq "$(wildcard .LEAK)" ".LEAK"
46   DBG += -fsanitize=leak
47  endif
48 else
49  DBG=-O3
50 endif
51 ifeq "$(CHECK)" "1"
52  QUIET_CHECK   = $(Q:@=@echo    '     CHECK    '$<;)
53 else
54  QUIET_CHECK   = @: skip
55 endif
56
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)
61 else
62  QUIET_SMATCH  = @: skip
63 endif
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
67
68 all: edlib checksym lib shared
69 test: edlib lib shared test-rexel
70         ./tests run
71
72 OBJ = O/edlib.o
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 \
75         O/core-version.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 \
86         O/lib-linefilter.o \
87         O/lang-python.o \
88         O/mode-emacs.o \
89         O/display-ncurses.o
90 XOBJ = O/rexel.o O/emacs-search.o
91
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))
96
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
100
101 LIBS-lib-libevent = $(shell pkg-config --libs libevent)
102
103 LIBS-lib-x11selection = $(shell pkg-config --libs gtk+-3.0)
104 INC-lib-x11selection = $(shell pkg-config --cflags gtk+-3.0)
105
106 O/core-editor-static.o : O/mod-list-decl.h O/mod-list.h
107
108 STATICOBJ = $(SHOBJ:.o=-static.o) $(LIBOBJ:.o=-static.o)
109
110 #
111 # Pretty print - borrowed from 'sparse'
112 #
113 V             = @
114 Q             = $(V:1=)
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   '$@;)
122
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)
127
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)
130
131 $(OBJ) $(SHOBJ) $(LIBOBJ) $(XOBJ) $(STATICOBJ) : $(H) O/.exists
132 $(LIBOBJ) : internal.h
133
134 $(OBJ) : O/%.o : %.c
135         $(QUIET_CC)$(CC) $(CPPFLAGS) $(INC-$*) $(CFLAGS) -c -o $@ $<
136         $(QUIET_CHECK)sparse $(CPPFLAGS) $(INC-$*) $(SPARSEFLAGS) $<
137         $(QUIET_SMATCH) $(CPPFLAGS) $(INC-$*) $<
138
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-$*) $<
143
144 $(STATICOBJ) : O/%-static.o : %.c
145         $(QUIET_CCSTATIC)$(CC) -Dedlib_init=$(subst -,_,$*)_edlib_init $(CPPFLAGS) $(INC-$*) $(CFLAGS) -c -o $@ $<
146
147 .PHONY: TAGS
148 TAGS :
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 \
153             rm -f TAGS.tmp ; \
154         else \
155             mv TAGS.tmp TAGS ;\
156         fi
157         @rm -f .TAGS1 .TAGS2
158
159 O/.exists:
160         @mkdir -p O
161         @touch $@
162 lib/.exists:
163         @mkdir -p lib
164         @ln -s ../python lib/python
165         @touch $@
166
167 .PHONY: lib
168 lib: lib/libedlib.so lib/.exists
169 lib/libedlib.so: $(LIBOBJ)
170         @mkdir -p lib
171         $(QUIET_CC)$(CC) -shared -Wl,-soname,libedlib.so -o $@ $(LIBOBJ)
172
173 shared: $(SO)
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
176
177 $(SO) : lib/edlib-%.so : O/%.o O/core-version.o lib/.exists
178         @mkdir -p lib
179         $(QUIET_LIB)$(CC) -shared -Wl,-soname,edlib-$*.so -o $@ $(filter %.o,$^) $(LIBS-$*)
180
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 > $@
185
186 CSRC= attr.c
187
188 test2:
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; \
192                 done || exit 2; \
193         done; echo SUCCESS
194
195 rexel: rexel.c rexel.h core-misc.c
196         $(CC) -DDEBUG -g -o rexel rexel.c core-misc.c
197
198 test-rexel: rexel
199         ./rexel -T
200
201 checksym: edlib
202         @nm edlib  | awk '$$2 == "T" {print $$3}' | while read a; do grep $$a *.h > /dev/null || echo  $$a; done | grep -vE '^(_.*|main)$$' ||:
203
204 .PHONY: clean
205 clean:
206         rm -f edlib edlib-static
207         rm -rf lib O