-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMakefile
358 lines (293 loc) · 13.3 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
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
# +------------------------------------------------------------------+
# | Copyright (C) 2023 Roger P. Johnson, [email protected] |
# | |
# | This file is part of libbst. |
# | |
# | libbst is free software: you can redistribute it and/or modify |
# | it under the terms of the GNU Lessor General Public License as |
# | published by the Free Software Foundation, either version 3 of |
# | the License, or (at your option) any later version. |
# | |
# | libbst 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 Lessor General Public License for more details. |
# | |
# | You should have received a copy of the GNU Lessor General Public |
# | License along with libbst. If not, see www.gnu.org/licenses. |
# +------------------------------------------------------------------+
# Makefile file for managing the bst library and programs.
# OS information
OPSYS := $(shell uname -s)
SHELL = /bin/sh
ECHO = /bin/echo # (SunOS 4.x) use Sys V 'echo' for '\c' to work right.
#CC= /opt/SUNWspro/bin/cc
#CC= cc
CC = gcc
ifeq ($(CC),gcc)
#$(error is gcc platform)
# GCC compilier tools
#MAKE = gmake
#CC = gcc
AR = ar
RANLIB = ranlib
STRIP = strip
else
#$(error is Sun Studio platform)
# Sun Studio compiler tools
#MAKE = /usr/ccs/bin/make
#CC = cc
#CC = /opt/SUNWspro/bin/cc
AR = /usr/ccs/bin/ar
RANLIB = /usr/ccs/bin/ranlib
STRIP = /usr/ccs/bin/strip
endif
# use gmake on all platforms
MAKE = gmake
#
# Depends
#
# The command to generate file dependencies - Can use gcc, makedepend (if you go get build it), or others; set here:
DEPEND = $(CC)
# uncomment if you want a more friendly updating depends message other than "... not found ..."
MAKE_DEPEND_VERBOSE = 1
# Depend flags - Set according to what you use for $(DEPEND) above
ifeq ($(CC),gcc)
# gcc on all platforms
# use only local files; do reference system includes as dependencies
#DEPEND_ARGS = -M
DEPEND_ARGS = -MM
else
# platform specific compilier being used
ifeq ($(OPSYS),$(filter $(OPSYS),SunOS Linux))
# implies Sun Studio on Solaris or Linux:
# use only local files; do reference system includes as dependencies
#DEPEND_ARGS = -xM
DEPEND_ARGS = -xM1
else
# unknown OS/compilier
#DEPEND_ARGS = -xM1
$(error Unknown platform: you need to set 'DEPEND_ARGS' for the 'CC' you are using)
endif
endif
#
# library DEBUG/TRACE build flags
#
# Enable/Disable program and library trace and debug output: pick one of each:
# Note:
# If you are going to run test.c with ARRSIZ > 10 or do benchmark testing, do not
# enable these DEBUG_LIB_* defines, it generates a lot of output to the screen.
# Enable/disable informative messages as routines in the library execute (for production and test usage)
# only used one place, not much info:
DEBUG_LIB_WITH_LIBCALL_TRACING = -DDEBUG_TRACE
DEBUG_LIB_WITH_LIBCALL_TRACING =
# Enable/disable the showing of ASCII art graph boxes on allocation of nodes w/addresses from the library routines:
DEBUG_LIB_SHOW_LIBCALL_MALLOC_GRAPHS = -DDEBUG_SHOWGRAPHS
DEBUG_LIB_SHOW_LIBCALL_MALLOC_GRAPHS =
# Enable/disable the showing of allocation/deallocation malloc'd memory w/addresses from the library routines:
DEBUG_LIB_SHOW_LIBCALL_MALLOC_INFO = -DDEBUG_MALLAC_USAGE
DEBUG_LIB_SHOW_LIBCALL_MALLOC_INFO =
# Enable/disable AVL tree rebalance info from the library routines:
DEBUG_LIB_SHOW_LIBCALL_TREE_REBALANCE = -DDEBUG_SHOWREBALANCE
DEBUG_LIB_SHOW_LIBCALL_TREE_REBALANCE =
DEBUG_LIB_DEFINES = $(DEBUG_LIB_WITH_LIBCALL_TRACING) $(DEBUG_LIB_SHOW_LIBCALL_MALLOC_GRAPHS) $(DEBUG_LIB_SHOW_LIBCALL_MALLOC_INFO) $(DEBUG_LIB_SHOW_LIBCALL_TREE_REBALANCE)
# library routines include dir files:
LIB_INC_DIR = inc
LIB_INCLUDES = -I $(LIB_INC_DIR)
# Compilier Options for library objects and executables
# If development or release, select your CFLAGS to use: *_DEV or *_REL
ifeq ($(CC),gcc)
# gcc on all platforms
# code uses 0x%-5x to print pointer addresses but creates warnings
# -Wno-format is equivalent to -Wformat=0,
# valgrind: valgrind --leak-check=yes ./demo
GCC_CFLAGS_VAL = -g -Wno-format -O0
# gcc profiler; ./demo; gprof ./demo
GCC_CFLAGS_PRO = -g -Wno-format -O0 -pg
# development
GCC_CFLAGS_DEV = -g -Wno-format
# release/production
GCC_CFLAGS_REL = -O3 -Wno-format
CC_FLAGS = $(GCC_CFLAGS_DEV)
else
# platform specific compilier being used
ifeq ($(OPSYS),$(filter $(OPSYS),SunOS Linux))
# implies Sun Studio on Solaris or Linux:
# -xdryrun or -# will show what -fast expands to
# -fd warn about non-K&R styles
SS_CFLAGS_DEV = -fd -g -xtransition
SS_CFLAGS_REL = -fast -xO4
CC_FLAGS = $(SS_CFLAGS_DEV)
else
# unknown OS/compilier
SS_CFLAGS_DEV =
SS_CFLAGS_REL =
CC_FLAGS = $(SS_CFLAGS_DEV)
$(error Unknown platform: you need to set 'CC_FLAGS' for the 'CC' you are using)
endif
endif
LIB_CFLAGS = $(CC_FLAGS) $(DEBUG_LIB_DEFINES) $(LIB_INCLUDES)
# Additional library defines:
#LIB_DFLAGS = -DBSD # SVR3 or SVR4 (tid.c), or BSD environment.
LIB_DFLAGS = -DSVR4 # SVR3 or SVR4 (tid.c), or BSD environment.
#
# demo program build flags
#
# enable use of/show additional commands that use normally code abstracted/hidden from user
# (not for production use, just interactive demo usage)
DEBUG_DEMO_PVT_TREE_HDR =
DEBUG_DEMO_PVT_TREE_HDR = -DDEBUG_EXPLOIT_TREE_HDR
DEBUG_DEMO_DEFINES = $(DEBUG_DEMO_PVT_TREE_HDR)
DEMO_DFLAGS =
PROG_INCLUDES = -I./
DEMO_CFLAGS = $(CC_FLAGS) $(DEBUG_DEMO_DEFINES) $(PROG_INCLUDES)
#
# test program build flags
#
# enable use of/show additional commands that use normally code abstracted/hidden from user
# (not for production use, just interactive demo usage)
DEBUG_TEST_PVT_TREE_HDR =
DEBUG_TEST_PVT_TREE_HDR = -DDEBUG_EXPLOIT_TREE_HDR
DEBUG_TEST_DEFINES = $(DEBUG_TEST_PVT_TREE_HDR)
TEST_DFLAGS =
PROG_INCLUDES = -I./ -I $(LIB_INC_DIR)
TEST_CFLAGS = $(CC_FLAGS) $(DEBUG_TEST_DEFINES) $(PROG_INCLUDES)
#-------------------------------------------------------------------------------
# Object and Depend Directories
#-------------------------------------------------------------------------------
# With objects and depends, you can easily choose the layout where you want each to reside.
# There are 3 cases (object files for example):
# i. At the same level as src (ie ../obj).
# Set OBJDIRPFX to a path you want (i.e. ../) to move OBJDIR up one level.
# ii. Into a directory in your current directory (ie ./obj).
# Leave OBJDIRPFX blank, and let ODJDIR specify the dir name.
# iii. No segregation, just create the .o's in your current directory "."
# Leave OBJDIRPFX and OBJDIR blank.
# Object Directory: where to relocate the .o files: same dir as build or other:
#OBJDIRPFX = temp/
OBJDIRPFX =
OBJDIR = obj/
# for depend generation below, shell escaped versions of OBJDIRPFX and OBJDIR:
#OBJDIRPFX_SED = temp\/
OBJDIRPFX_SED =
OBJDIR_SED = obj\/
ifneq ( $(OBJDIRPFX)$(OBJDIR),)
MKOBJDIR := $(shell mkdir -p $(OBJDIRPFX)$(OBJDIR) )
endif
# Dependency Directory: where to relocate the .d files: same dir as build or other:
#DEPENDDIRPFX = temp/
DEPENDDIRPFX =
DEPENDDIR = dep/
# for depend generation below, shell escaped versions of DEPENDDIRPFX and DEPENDDIR:
#DEPENDDIRPFX_SED = temp\/
DEPENDDIRPFX_SED =
DEPENDDIR_SED = dep\/
ifneq ( $(DEPENDDIRPFX)$(DEPENDDIR),)
MKDEPDIR := $(shell mkdir -p $(DEPENDDIRPFX)$(DEPENDDIR) )
endif
# Finished Library Name
LIBNAME = libbst.a
# Library Modules/Components
LIBOBJECTS = \
$(OBJDIRPFX)$(OBJDIR)globals.o \
$(OBJDIRPFX)$(OBJDIR)defined.o \
$(OBJDIRPFX)$(OBJDIR)msgs.o \
$(OBJDIRPFX)$(OBJDIR)count.o \
$(OBJDIRPFX)$(OBJDIR)remove.o \
$(OBJDIRPFX)$(OBJDIR)fnode.o \
$(OBJDIRPFX)$(OBJDIR)rprint.o \
$(OBJDIRPFX)$(OBJDIR)tid.o \
$(OBJDIRPFX)$(OBJDIR)tident.o \
$(OBJDIRPFX)$(OBJDIR)graphics.o \
$(OBJDIRPFX)$(OBJDIR)tstat.o \
$(OBJDIRPFX)$(OBJDIR)delete.o \
$(OBJDIRPFX)$(OBJDIR)get.o \
$(OBJDIRPFX)$(OBJDIR)print.o \
$(OBJDIRPFX)$(OBJDIR)release.o \
$(OBJDIRPFX)$(OBJDIR)rebalance.o \
$(OBJDIRPFX)$(OBJDIR)tmem.o \
$(OBJDIRPFX)$(OBJDIR)tcp.o \
$(OBJDIRPFX)$(OBJDIR)tequal.o \
$(OBJDIRPFX)$(OBJDIR)create.o \
$(OBJDIRPFX)$(OBJDIR)empty.o \
$(OBJDIRPFX)$(OBJDIR)node.o \
$(OBJDIRPFX)$(OBJDIR)put.o \
$(OBJDIRPFX)$(OBJDIR)fheader.o \
$(OBJDIRPFX)$(OBJDIR)insnode.o \
$(OBJDIRPFX)$(OBJDIR)twalk.o \
$(OBJDIRPFX)$(OBJDIR)tdispose.o \
$(OBJDIRPFX)$(OBJDIR)qfind.o \
$(OBJDIRPFX)$(OBJDIR)fheaderlist.o
###################
# t a r g e t s #
###################
what:
@printf "CC = [$(CC)]\n"
@printf "Objects relocated to = [$(OBJDIRPFX)$(OBJDIR)]\n"
@printf "Depends relocated to = [$(DEPENDDIRPFX)$(DEPENDDIR)]\n"
@printf "Library relocated to = [$(LIBDIRPFX)$(LIBDIR)]\n"
@printf "\n"
@echo "QUICK USAGE: $(MAKE) all; ./demo or ./test"
@printf "\n"
@echo "Targets to make:"
@echo " $(MAKE) all - build all targets: library $(LIBNAME), executables: demo test"
@echo " $(MAKE) lib - build just the archive library $(LIBNAME)"
@echo " $(MAKE) strip - strip debugging symbol tables from executables"
@echo " $(MAKE) clean - delete compiled .o object files"
@echo " $(MAKE) realclean - delete compiled .o object files AND their dependency .d files"
@echo " $(MAKE) clobber - delete compiled .o object files AND their dependency .d files and executables and libraries"
all: lib demo test
@echo "all built."
strip: demo test
$(STRIP) demo test
clean:
rm -f demo test $(OBJDIRPFX)$(OBJDIR)demo.o $(OBJDIRPFX)$(OBJDIR)test.o $(OBJDIRPFX)$(OBJDIR)$(LIBNAME) $(LIBOBJECTS)
realclean: clean
rm -f $(addprefix $(DEPENDDIRPFX)$(DEPENDDIR), $(notdir $(LIBOBJECTS:.o=.d)))
clobber: realclean
rm -f demo test $(LIBDIRPFX)$(LIBDIR)$(LIBNAME)
###################################
# l i b r a r y t a r g e t s #
###################################
# How to make the main library archive file $(LIBNAME)
# THIS STYLE RULES COMPILES *ALL* THE LIBRARY OBJECTS *FIRST*, THEN CREATES THE ARCHIVE.
# Other style is to add each object to the archive library for each object as it is compiled.
# Library Directory: where to relocate the .a files: same dir as build or other:
LIBDIRPFX =
LIBDIR = lib/
ifneq ( $(LIBDIRPFX)$(LIBDIR),)
MKLIBDIR := $(shell mkdir -p $(LIBDIRPFX)$(LIBDIR) )
endif
lib: $(LIBDIRPFX)$(LIBDIR)$(LIBNAME)
@echo "info: $(LIBDIRPFX)$(LIBDIR)$(LIBNAME) OK"
# How to put an object (.o) into the archive file
$(LIBDIRPFX)$(LIBDIR)$(LIBNAME): $(LIBOBJECTS)
$(AR) r $@ $?
# rm -f $(OBJDIRPFX)$(OBJDIR)$*.o
# How to compile a library module (.o)
# -DMY_MAKE_LIB_CC_CMD_COMPILE is a visual indicator that gmake is using my rule to compile a library object and not a gmake implicit rule being used.
$(OBJDIRPFX)$(OBJDIR)%.o: $(notdir $(OBJDIRPFX)$(OBJDIR)%.c)
$(CC) -DMY_MAKE_LIB_CC_CMD_COMPILE $(LIB_CFLAGS) $(LIB_DFLAGS) -c $(notdir $(@:.o=.c)) -o $(OBJDIRPFX)$(OBJDIR)$*.o
###################################
# p r o g r a m t a r g e t s #
###################################
demo : $(OBJDIRPFX)$(OBJDIR)demo.o
$(CC) -DMY_MAKE_DEMO_CC_CMD_LINK $(DEMO_CFLAGS) $(DEMO_DFLAGS) -o $@ $(OBJDIRPFX)$(OBJDIR)demo.o $(LIBDIRPFX)$(LIBDIR)$(LIBNAME)
$(OBJDIRPFX)$(OBJDIR)demo.o: demo.c bstpkg.h leaf.h $(LIBDIRPFX)$(LIBDIR)$(LIBNAME)
$(CC) -DMY_MAKE_DEMO_CC_CMD_COMPILE $(DEMO_CFLAGS) $(DEMO_DFLAGS) -o $@ -c $<
test : $(OBJDIRPFX)$(OBJDIR)test.o
$(CC) -DMY_MAKE_TEST_CC_CMD_LINK $(TEST_CFLAGS) $(TEST_DFLAGS) -o $@ $(OBJDIRPFX)$(OBJDIR)test.o $(LIBDIRPFX)$(LIBDIR)$(LIBNAME)
$(OBJDIRPFX)$(OBJDIR)test.o: test.c bstpkg.h leaf.h $(LIBDIRPFX)$(LIBDIR)$(LIBNAME)
$(CC) -DMY_MAKE_TEST_CC_CMD_COMPILE $(TEST_CFLAGS) $(TEST_DFLAGS) -o $@ -c $<
#######################################################
# a u t o - c r e a t e d d e p e n d e n c i e s #
#######################################################
# This generates your .d include dependencies and stores them where specified in the DEPENDDIR option:
# gcc places all one one line and Sun Studio has one line per dependency.
# This sed'ing works for both compiliers:
$(DEPENDDIRPFX)$(DEPENDDIR)%.d: $(notdir $(LIBOBJECTS:.o=.c))
@$(SHELL) -ec 'if [ ! -z "$(MAKE_DEPEND_VERBOSE)" ]; then echo "<updating dependency file $@>"; fi'
@$(SHELL) -ec '$(DEPEND) $(DEPEND_ARGS) -I$(LIB_INC_DIR) $(LIB_DFLAGS) $(notdir $(@:.d=.c)) \
| sed -e '\''s/$*\.o */& $(DEPENDDIRPFX_SED)$(DEPENDDIR_SED)$(notdir $@) /g'\'' -e '\''s/^.*\.o /$(OBJDIRPFX_SED)$(OBJDIR_SED)&/'\'' > $@'
# Include all the generated .d dependencies from the rule above:
include $(addprefix $(DEPENDDIRPFX)$(DEPENDDIR), $(notdir $(LIBOBJECTS:.o=.d)))