forked from libusual/libusual
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
148 lines (116 loc) · 3.32 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
-include config.mak
# config
MKAR = $(AR) rcs
CFLAGS += $(WFLAGS)
CPPFLAGS = $(USUAL_CPPFLAGS)
# sources
USUAL_DIR = .
USUAL_OBJDIR = obj
USUAL_MODULES = $(filter-out pgsocket, $(subst .h,, $(notdir $(wildcard $(USUAL_DIR)/usual/*.h))))
include $(USUAL_DIR)/Setup.mk
# tgz generation
FULL = libusual-$(shell date +%Y-%m-%d)
DIRS = usual m4 test
IGNORE = usual/config.h test/config.h test/test_config.h
FILES = $(filter-out $(IGNORE), $(wildcard usual/*.[ch] test/*.[ch])) \
m4/usual.m4 configure configure.ac COPYRIGHT \
Makefile README config.mak.in Setup.mk \
find_modules.sh test/force_compat.sed test/Makefile
# pgutil_kwlookup generation
PG_CONFIG ?= pg_config
KWLIST = $(shell $(PG_CONFIG) --includedir-server)/parser/kwlist.h
GPERF = gperf -m5
# full path for files
srcs = $(USUAL_SRCS)
hdrs = $(USUAL_HDRS)
objs = $(USUAL_OBJS)
# Quiet by default, 'make V=1' shows commands
V=0
ifeq ($(V), 0)
Q = @
E = @echo
else
Q =
E = @true
endif
# rules follow
all: info libusual.a obj/testcompile
libusual.a: $(objs)
$(E) " AR" $@
$(Q) $(MKAR) $@ $(objs)
$(USUAL_OBJDIR)/%.o: $(USUAL_DIR)/usual/%.c config.mak $(hdrs)
@mkdir -p $(USUAL_OBJDIR)
$(E) " CC" $<
$(Q) $(CC) -c -o $@ $(DEFS) $(CPPFLAGS) $(CFLAGS) $<
$(USUAL_OBJDIR)/%.s: $(USUAL_DIR)/usual/%.c config.mak $(hdrs)
@mkdir -p $(USUAL_OBJDIR)
$(E) " CC -S" $<
$(Q) $(CC) -S -fverbose-asm -o - $(DEFS) $(CPPFLAGS) $(CFLAGS) $< \
| cleanasm > $@
obj/testcompile: test/compile.c libusual.a config.mak $(hdrs)
$(E) " CHECK" $<
$(Q) $(CC) -o $@ $(DEFS) $(CPPFLAGS) $(CFLAGS) $< $(USUAL_LDFLAGS) $(USUAL_LIBS) $(LIBS)
test/test_string: test/test_string.c libusual.a config.mak $(hdrs)
$(E) " TEST" $@
$(Q) $(CC) -o $@ $(DEFS) $(CPPFLAGS) $(CFLAGS) $< $(USUAL_LDFLAGS) $(USUAL_LIBS) $(LIBS)
$(Q) ./$@
check: config.mak
mkdir -p test/usual
sed -f test/compat.sed usual/config.h > test/usual/config.h
make clean
make CPPFLAGS="-I./test $(CPPFLAGS)" all
make CPPFLAGS="-I./test $(CPPFLAGS)" test/test_string
clean:
rm -f libusual.a obj/*.[os] obj/test* aclocal* config.log
rm -rf autom4te*
rm -f usual/pgutil_kwlookup.h.gp
distclean: clean
rm -f config.mak usual/config.h config.status
realclean:
rm -f usual/pgutil_kwlookup.h
boot:
./autogen.sh
#config.mak:
# @echo "Config out-of-date, please run ./configure again"
# @exit 1
#usual/config.h:
# @echo "Please run ./configure first"
# @exit 1
# run sparse over code
sparse: config.mak
REAL_CC="$(CC)" \
$(MAKE) clean libusual.a CC="cgcc -Wsparse-all -Wno-transparent-union"
asms = $(objs:.o=.s)
asm: $(asms)
dbg: flags
@echo srcs=$(srcs)
@echo objs=$(objs)
@echo hdrs=$(hdrs)
flags:
@echo DEFS=$(DEFS)
@echo CFLAGS=$(CFLAGS)
@echo CPPFLAGS=$(CPPFLAGS)
info:
@echo CC: $(CC) $(DEFS) $(CPPFLAGS) $(CFLAGS)
@echo LD: $(LD) $(USUAL_LDFLAGS) $(USUAL_LIBS) $(LIBS)
.PHONY: flags dbg info
# requires 8.4+
kws:
@test -f "$(KWLIST)" || { echo "kwlist.h not found"; exit 1; }
grep '^PG_KEYWORD' "$(KWLIST)" \
| grep -v UNRESERVED \
| sed 's/.*"\(.*\)",.*, *\(.*\)[)].*/\1/' \
>> usual/pgutil_kwlookup.gp
kwh:
$(GPERF) usual/pgutil_kwlookup.g \
| sed '/^#line/d' \
> usual/pgutil_kwlookup.h
tgz: config.mak $(DISTFILES)
# create tarfile
rm -rf $(FULL) $(FULL).tgz usual/config.h
mkdir $(FULL)
(for f in $(DIRS) $(FILES); do echo $$f; done) | cpio -pm $(FULL)
tar czf $(FULL).tgz $(FULL)
rm -rf $(FULL)
dox:
doxygen doc/Doxyfile