-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathMakefile
127 lines (101 loc) · 4.21 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
## Description:
## This file is part of the Reflective Persistent System. refpersys.org
##
## It is its Makefile, for the GNU make automation builder.
##
## Author(s):
## Basile Starynkevitch <[email protected]>
## Abhishek Chakravarti <[email protected]>
## Nimesh Neema <[email protected]>
##
## © Copyright 2019 - 2022 The Reflective Persistent System Team
##
## License:
## This program is free software: you can redistribute it and/or modify
## it under the terms of the GNU General Public License as published by
## the Free Software Foundation, either version 3 of the License, or
## (at your option) any later version.
##
## This program is distributed in the hope that it will be useful,
## but WITHOUT ANY WARRANTY; without even the implied warranty of
## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
## GNU General Public License for more details.
##
## You should have received a copy of the GNU General Public License
## along with this program. If not, see <http://www.gnu.org/licenses>
## tell GNU make to export all variables by default
export
RPS_GIT_ID:= $(shell tools/generate-gitid.sh)
RPS_SHORTGIT_ID:= $(shell tools/generate-gitid.sh -s)
RPS_PKG_CONFIG= pkg-config
## libcurl is on curl.se/libcurl/ - a good HTTP client library
## jansson is on digip.org/jansson/ - a C library for JSON
## GTK3 is from gtk.org/ - a graphical interface library
RPS_PKG_NAMES= libcurl jansson gtk+-3.0
RPS_PKG_CFLAGS:= $(shell $(RPS_PKG_CONFIG) --cflags $(RPS_PKG_NAMES)) -I $(shell pwd)
RPS_PKG_LIBS:= $(shell $(RPS_PKG_CONFIG) --libs $(RPS_PKG_NAMES))
## handwritten C source files
RPS_C_SOURCES := $(sort $(wildcard src/[a-z]*_rps.c))
RPS_C_OBJECTS := $(patsubst %.c, %.o, $(RPS_C_SOURCES))
## unistring for UTF8 and Unicode: www.gnu.org/software/libunistring/
## libbacktrace for symbolic backtracing: github.com/ianlancetaylor/libbacktrace
## the libdl is POSIX dlopen and Linux dladdr
LDLIBES:= $(RPS_PKG_LIBS) -lunistring -lbacktrace -ldl
RM= rm -f
MV= mv
## the GNU indent program from www.gnu.org/software/indent/
INDENT= indent
# Generated timestamp file prefix
RPS_TSTAMP:=generated/__timestamp
.PHONY: all clean objects indent redump load tarball testdump
.SECONDARY: $(RPS_TSTAMP).c
# the GCC compiler (at least GCC 9, preferably GCC 11, see gcc.gnu.org ....)
CC := gcc
## extra compile flags (debugging, profiling, etc); in particular use CXTRAFLAGS=-fsanitize=address
CXTRAFLAGS=
## extra link flags
LINKXTRAFLAGS=
## should be changed later to -Og, once loading succeeds
CFLAGS := -O0 -ggdb3 $(CXTRAFLAGS)
## preprocessor flags for gcc
CPPFLAGS += $(RPS_PKG_CFLAGS) \
-DRPS_GITID=\"$(RPS_GIT_ID)\" \
-DRPS_SHORTGITID=\"$(RPS_SHORTGIT_ID)\" \
-I $(PWD)/include/
LDFLAGS += -rdynamic -pie -Bdynamic -pthread -L /usr/local/lib -L /usr/lib
all:
if [ -f refpersys ] ; then $(MV) -f --backup refpersys refpersys~ ; fi
$(RM) $(RPS_TSTAMP).c $(RPS_TSTAMP).o
@echo "RPS_C_OBJECTS= " $(RPS_C_OBJECTS)
sync
$(MAKE) -$(MAKEFLAGS) refpersys
sync
clean:
$(RM) *.o */*.o */*.i *.orig *~ *% *# */*~ */*% */*# refpersys gmon.out core* vgcore*
indent:
for f in $(RPS_C_SOURCES) ; do \
$(INDENT) $$f ; \
done
$(INDENT) Refpersys.h
objects: $(RPS_C_OBJECTS)
# Target to generate timestamp source file
$(RPS_TSTAMP).c: | Makefile tools/generate-timestamp.sh
tools/generate-timestamp.sh $@ > $@-tmp
printf 'const char rps_c_compiler_version[]="%s";\n' "$$($(CC) --version | head -1)" >> $@-tmp
printf 'const char _rps_git_short_id[] = "%s";\n' "$(RPS_SHORTGIT_ID)" >> $@-tmp
$(MV) --backup $@-tmp $@
tarball:
git archive --prefix=refpersys-in-c-$(RPS_SHORTGIT_ID)/ --output=/tmp/refpersys-in-c.tar.gz HEAD
## preprocessed form
src/%_rps.i: src/%_rps.c
$(CC) $(CPPFLAGS) -C -E $^ -o $@%
sed '1,$$s:^#\(.*\)://\1:g' $@% > $@
## object files depend on common header file
src/%_rps.o: src/%_rps.c Refpersys.h kavl.h
$(CC) $(CPPFLAGS) $^ -o $@
refpersys: objects $(RPS_TSTAMP).o
$(LINK.c) $(LDFLAGS) $(RPS_C_OBJECTS) $(RPS_TSTAMP).o $(LDLIBES) -o $@
## a test for dumping
testdump: refpersys
./refpersys --shell-before-load='rm -rf /tmp/rpsdump' --debug-load=GARBCOLL --debug-after=DUMP --dump=/tmp/rpsdump