Skip to content

Commit c170d2b

Browse files
committed
Restructure Makefile
1 parent 2f68b3e commit c170d2b

File tree

2 files changed

+33
-32
lines changed

2 files changed

+33
-32
lines changed

Makefile

Lines changed: 33 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,45 +1,33 @@
11
.POSIX:
22
.SUFFIXES:
3+
CC=gcc
34
PREFIX=/usr/local
45
MANPREFIX = ${PREFIX}/share/man
6+
57
IDIR=include
68
SDIR=src
7-
LIBDIR=lib
8-
CC=gcc
9-
CPPFLAGS=-D_POSIX_C_SOURCE=200809L -DNOTIFICATIONS
10-
CFLAGS= ${CPPFLAGS} -I$(IDIR) \
11-
$(shell pkg-config --cflags gtk+-3.0) $(shell pkg-config --cflags libnotify)
12-
DEBUG_CFLAGS=-DDEBUG -g3 -Wall -Wextra -Wpedantic -Wstrict-prototypes -Wdouble-promotion -Wshadow \
13-
-Wno-unused-parameter -Wno-sign-conversion -Wno-unused-function \
14-
-fsanitize=undefined,address -fsanitize-undefined-trap-on-error
15-
# DEBUG_CFLAGS+=-Wconversion
16-
# DEBUG_CFLAGS+=-fanalyzer
17-
RELEASE_CFLAGS=-O3 -flto -march=native
9+
LDIR=lib
1810

11+
CPPFLAGS=-D_POSIX_C_SOURCE=200809L -DNOTIFICATIONS -I$(IDIR)
1912
LDLIBS=-ffunction-sections -fdata-sections -Wl,--gc-sections \
2013
-lcurl -lmecab -pthread $(shell pkg-config --libs gtk+-3.0) $(shell pkg-config --libs libnotify) -llmdb
2114

22-
FILES=popup.c util.c platformdep.c deinflector.c settings.c dbreader.c ankiconnectc.c database.c jppron.c pdjson.c
23-
FILES_H=ankiconnectc.h dbreader.h deinflector.h popup.h settings.h util.h platformdep.h database.h jppron.h pdjson.h
24-
25-
# LMDB_FILES = $(LIBDIR)/lmdb/libraries/liblmdb/mdb.c $(LIBDIR)/lmdb/libraries/liblmdb/midl.c
26-
SRC=$(addprefix $(SDIR)/,$(FILES)) $(LMDB_FILES)
27-
SRC_H=$(addprefix $(IDIR)/,$(FILES_H))
28-
2915
O_HAVEX11 := 1 # X11 integration
3016
ifeq ($(strip $(O_HAVEX11)),1)
3117
CPPFLAGS += -DHAVEX11
3218
LDLIBS += -lXfixes -lX11
3319
endif
3420

35-
default: release
36-
release: dictpopup_release dictpopup-create_release
37-
debug: dictpopup_debug dictpopup-create_debug
21+
CFLAGS= ${CPPFLAGS} $(shell pkg-config --cflags gtk+-3.0) $(shell pkg-config --cflags libnotify)
22+
DEBUG_CFLAGS=-DDEBUG -g3 -Wall -Wextra -Wpedantic -Wstrict-prototypes -Wdouble-promotion -Wshadow \
23+
-Wno-unused-parameter -Wno-sign-conversion -Wno-unused-function \
24+
-fsanitize=undefined,address -fsanitize-undefined-trap-on-error
25+
RELEASE_CFLAGS=-O3 -flto -march=native
3826

39-
dictpopup_release: $(SRC) $(SRC_H)
40-
$(CC) -o dictpopup src/dictpopup.c $(CFLAGS) $(RELEASE_CFLAGS) $(LDLIBS) $(SRC)
41-
dictpopup_debug: $(SRC) $(SRC_H)
42-
$(CC) -o dictpopup src/dictpopup.c $(CFLAGS) $(DEBUG_CFLAGS) $(LDLIBS) $(SRC)
27+
FILES=popup.c util.c platformdep.c deinflector.c settings.c dbreader.c ankiconnectc.c database.c jppron.c pdjson.c
28+
FILES_H=ankiconnectc.h dbreader.h deinflector.h popup.h settings.h util.h platformdep.h database.h jppron.h pdjson.h
29+
SRC=$(addprefix $(SDIR)/,$(FILES))
30+
SRC_H=$(addprefix $(IDIR)/,$(FILES_H))
4331

4432

4533
CFLAGS_CREATE=-I$(IDIR) -isystem$(LIBDIR)/lmdb/libraries/liblmdb -D_POSIX_C_SOURCE=200809L $(shell pkg-config --cflags glib-2.0)
@@ -52,11 +40,22 @@ FILES_H_CREATE=dbwriter.h pdjson.h util.h buf.h settings.h
5240
SRC_CREATE=$(addprefix $(SDIR)/,$(FILES_CREATE)) $(LMDB_FILES)
5341
SRC_H_CREATE=$(addprefix $(IDIR)/,$(FILES_H_CREATE))
5442

55-
dictpopup-create_release: $(SRC_CREATE) $(SRC_H_CREATE)
56-
$(CC) -o dictpopup-create src/dictpopup_create.c $(CFLAGS_CREATE) $(RELEASE_CFLAGS) $(LDLIBS_CREATE) $(SRC_CREATE)
43+
default: dictpopup dictpopup-create
44+
debug: dictpopup-debug dictpopup-create-debug
45+
46+
dictpopup: $(SRC) $(SRC_H)
47+
$(CC) $(CFLAGS) $(RELEASE_CFLAGS) -o $@ src/dictpopup.c $(SRC) $(LDLIBS)
48+
dictpopup-debug: $(SRC) $(SRC_H)
49+
$(CC) $(CFLAGS) $(DEBUG_CFLAGS) -o $@ src/dictpopup.c $(SRC) $(LDLIBS)
50+
51+
dictpopup-create: $(SRC_CREATE) $(SRC_H_CREATE)
52+
$(CC) $(CFLAGS_CREATE) $(RELEASE_CFLAGS) -o $@ src/dictpopup_create.c $(SRC_CREATE) $(LDLIBS_CREATE)
53+
dictpopup-create-debug: $(SRC_CREATE) $(SRC_H_CREATE)
54+
$(CC) $(CFLAGS_CREATE) $(DEBUG_CFLAGS) -o $@ src/dictpopup_create.c $(SRC_CREATE) $(LDLIBS_CREATE)
5755

58-
dictpopup-create_debug: $(SRC_CREATE) $(SRC_H_CREATE)
59-
$(CC) -o dictpopup-create src/dictpopup_create.c $(CFLAGS_CREATE) $(DEBUG_CFLAGS) $(LDLIBS_CREATE) $(SRC_CREATE) $(SRC_H_CREATE)
56+
release:
57+
version=$$(git describe); prefix=dictpopup-$${version#v}; \
58+
git archive --prefix=$$prefix/ HEAD | gzip -9 >$$prefix.tar.gz
6059

6160
CONFIG_DIR=${DESTDIR}${PREFIX}/share/dictpopup
6261

@@ -85,8 +84,10 @@ uninstall:
8584
clean:
8685
rm -f dictpopup dictpopup-create test
8786

88-
test: $(SRC) $(SRC_H)
89-
gcc -o test $(SDIR)/test.c $(CFLAGS) $(LDLIBS) $(SRC)
87+
tests: $(SRC) $(SRC_H)
88+
$(CC) $(CFLAGS) $(DEBUG_CFLAGS) -o $@ $(SDIR)/test.c $(SRC) $(LDLIBS)
9089

90+
check test: tests
91+
./tests
9192

92-
.PHONY: clean install uninstall test debug
93+
.PHONY: all clean install uninstall tests debug
File renamed without changes.

0 commit comments

Comments
 (0)