-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMakefile
178 lines (128 loc) · 6.57 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
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
# Top-level Makefile for TCG code.
# export GOPATH := $(realpath .)
export GOPATH := $(realpath ..):$(realpath .)
# The current definition here is a placeholder for whatever we actually
# want to use according to some sort of project-standard file tree.
BUILD_TARGET_DIRECTORY = build
# We need a place to store header files as a final result of our code
# construction, where we can specify some parent directory for header
# files that is not either "build" (which is totally non-descriptive)
# or "include" (which also is not specific to this package).
INSTALL_BASE_DIRECTORY = install
CONVERT_GO_TO_C_BUILD_OBJECTS = \
gotocjson/_c_code/convert_go_to_c.c \
gotocjson/_c_code/convert_go_to_c.h
GENERIC_DATATYPES_BUILD_OBJECTS = \
${BUILD_TARGET_DIRECTORY}/generic_datatypes.c \
${BUILD_TARGET_DIRECTORY}/generic_datatypes.h
TIME_BUILD_OBJECTS = \
${BUILD_TARGET_DIRECTORY}/time.c \
${BUILD_TARGET_DIRECTORY}/time.h
MILLISECONDS_BUILD_OBJECTS = \
${BUILD_TARGET_DIRECTORY}/milliseconds.c \
${BUILD_TARGET_DIRECTORY}/milliseconds.h
TRANSIT_BUILD_OBJECTS = \
${BUILD_TARGET_DIRECTORY}/transit.c \
${BUILD_TARGET_DIRECTORY}/transit.h
LIBTRANSITJSON_OBJECTS = \
${BUILD_TARGET_DIRECTORY}/convert_go_to_c.o \
${BUILD_TARGET_DIRECTORY}/generic_datatypes.o \
${BUILD_TARGET_DIRECTORY}/milliseconds.o \
${BUILD_TARGET_DIRECTORY}/transit.o
LIBTRANSIT_DIRECTORY = libtransit
LIBTRANSIT_SOURCE = ${LIBTRANSIT_DIRECTORY}/libtransit.go
LIBTRANSIT_HEADER = ${LIBTRANSIT_DIRECTORY}/libtransit.h
LIBTRANSIT_LIBRARY = ${LIBTRANSIT_DIRECTORY}/libtransit.so
LIBTRANSITJSON_LIBRARY = ${BUILD_TARGET_DIRECTORY}/libtransitjson.so
BUILD_HEADER_FILES = \
${LIBTRANSIT_HEADER} \
gotocjson/_c_code/convert_go_to_c.h \
${BUILD_TARGET_DIRECTORY}/time.h \
${BUILD_TARGET_DIRECTORY}/generic_datatypes.h \
${BUILD_TARGET_DIRECTORY}/milliseconds.h \
${BUILD_TARGET_DIRECTORY}/transit.h
BUILD_DYNAMIC_LIBRARIES = \
${LIBTRANSIT_LIBRARY} \
${LIBTRANSITJSON_LIBRARY}
INSTALL_DIRECTORIES = \
${INSTALL_BASE_DIRECTORY}/include/tcg \
${INSTALL_BASE_DIRECTORY}/lib
INSTALL_HEADER_FILES = $(addprefix ${INSTALL_BASE_DIRECTORY}/include/tcg/,$(notdir ${BUILD_HEADER_FILES}))
INSTALL_DYNAMIC_LIBRARIES = $(addprefix ${INSTALL_BASE_DIRECTORY}/lib/,$(notdir ${BUILD_DYNAMIC_LIBRARIES}))
# We currently specify "-g" to assist in debugging and possibly also in memory-leak detection.
CFLAGS = -std=c11 -g -D_REENTRANT -D_GNU_SOURCE -fPIC -Wall
CC = gcc ${CFLAGS}
.PHONY : all
all : ${LIBTRANSIT_LIBRARY} ${LIBTRANSITJSON_LIBRARY}
.PHONY : install
install : ${INSTALL_HEADER_FILES} ${INSTALL_DYNAMIC_LIBRARIES} | ${INSTALL_DIRECTORIES}
# called with arguments: install directory, build-file path
define INSTALLED_FILE_template =
$(1)/$(notdir $(2)) : $(2) | $(1)
cp -p $$< $$@
endef
$(foreach path,${BUILD_HEADER_FILES},$(eval $(call INSTALLED_FILE_template,${INSTALL_BASE_DIRECTORY}/include/tcg,$(path))))
$(foreach path,${BUILD_DYNAMIC_LIBRARIES},$(eval $(call INSTALLED_FILE_template,${INSTALL_BASE_DIRECTORY}/lib,$(path))))
# Fetch all third-party Go packages needed either directly or indirectly
# by the TCG software.
get :
mkdir -p ../src
# [ -h src ] || ln -s ../src
mkdir -p ../src/github.com/gwos
[ -h ../src/github.com/gwos/tcg ] || ln -s ../../../tcg ../src/github.com/gwos/tcg
# FIX MAJOR: It is not yet clear that the next step here will get us exactly
# what we want: nothing changed with respect to the checked-out and possibly
# locally-modified files of the branch of github.com/gwos/tcg that we are
# already using. All we want is to have it analyze the dependencies and
# pull those in to make them available for our TCG builds.
go get github.com/gwos/tcg
go get github.com/nats-io/go-nats-streaming
go get github.com/nats-io/nats-streaming-server/server
# For the ${LIBTRANSIT_HEADER} and ${LIBTRANSIT_LIBRARY} targets, there are many more
# dependencies than we ought to be keeping track of here, and they are all tracked
# instead in the subsidiary Makefile where those targets are actually built. So instead
# of just depending on ${LIBTRANSIT_SOURCE}, which is of course the principal source file
# involved (but by no means the only one used to create the library), we simply force an
# unconditional descent into the subdirectory and attempt to make there. That will handle
# all the details of build dependencies, at the cost of one unconditional recursive make.
.PHONY : ${LIBTRANSIT_DIRECTORY}
${LIBTRANSIT_HEADER} ${LIBTRANSIT_LIBRARY} : ${LIBTRANSIT_DIRECTORY}
make -C ${LIBTRANSIT_DIRECTORY}
${BUILD_TARGET_DIRECTORY} :
mkdir -p $@
${INSTALL_BASE_DIRECTORY}/include/tcg :
mkdir -p $@
${INSTALL_BASE_DIRECTORY}/lib :
mkdir -p $@
gotocjson/gotocjson : gotocjson/gotocjson.go
make -C gotocjson gotocjson
${GENERIC_DATATYPES_BUILD_OBJECTS} : gotocjson/gotocjson gotocjson/generic_datatypes/generic_datatypes.go | ${BUILD_TARGET_DIRECTORY}
gotocjson/gotocjson -g -o ${BUILD_TARGET_DIRECTORY} gotocjson/generic_datatypes/generic_datatypes.go
${TIME_BUILD_OBJECTS} : gotocjson/gotocjson time/time.go | ${BUILD_TARGET_DIRECTORY}
gotocjson/gotocjson -o ${BUILD_TARGET_DIRECTORY} time/time.go
${MILLISECONDS_BUILD_OBJECTS} : gotocjson/gotocjson ${TIME_BUILD_OBJECTS} milliseconds/milliseconds.go | ${BUILD_TARGET_DIRECTORY}
gotocjson/gotocjson -o ${BUILD_TARGET_DIRECTORY} milliseconds/milliseconds.go
${TRANSIT_BUILD_OBJECTS} : gotocjson/gotocjson ${MILLISECONDS_BUILD_OBJECTS} transit/transit.go | ${BUILD_TARGET_DIRECTORY}
gotocjson/gotocjson -o ${BUILD_TARGET_DIRECTORY} transit/transit.go
${BUILD_TARGET_DIRECTORY}/convert_go_to_c.o : ${CONVERT_GO_TO_C_BUILD_OBJECTS} | ${BUILD_TARGET_DIRECTORY}
${CC} -c gotocjson/_c_code/convert_go_to_c.c -o $@
${BUILD_TARGET_DIRECTORY}/generic_datatypes.o : ${GENERIC_DATATYPES_BUILD_OBJECTS}
${CC} -c ${BUILD_TARGET_DIRECTORY}/generic_datatypes.c -o $@ -Igotocjson/_c_code
${BUILD_TARGET_DIRECTORY}/milliseconds.o : ${TIME_BUILD_OBJECTS} ${MILLISECONDS_BUILD_OBJECTS} ${BUILD_TARGET_DIRECTORY}/generic_datatypes.h
${CC} -c ${BUILD_TARGET_DIRECTORY}/milliseconds.c -o $@ -Igotocjson/_c_code
${BUILD_TARGET_DIRECTORY}/transit.o : ${MILLISECONDS_BUILD_OBJECTS} ${TRANSIT_BUILD_OBJECTS} ${BUILD_TARGET_DIRECTORY}/generic_datatypes.h
${CC} -c ${BUILD_TARGET_DIRECTORY}/transit.c -o $@ -Igotocjson/_c_code
${LIBTRANSITJSON_LIBRARY} : ${LIBTRANSITJSON_OBJECTS}
${LINK.c} -shared -o $@ -fPIC ${LIBTRANSITJSON_OBJECTS} -ljansson
.PHONY : clean
clean :
rm -rf ${BUILD_TARGET_DIRECTORY}
make -C gotocjson clean
.PHONY : realclean
realclean :
rm -rf bin pkg src ../src
make -C gotocjson realclean
.PHONY : distclean
distclean : realclean
rm -rf ${INSTALL_BASE_DIRECTORY}
make -C gotocjson distclean