Login
Check-in [d5a3e3ed86]
Login

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:Remove now-obsolete GNUmakefile.in.
Downloads: Tarball | ZIP archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA3-256: d5a3e3ed86392d9cd7eb73214f52e5aeabcfbd47a899bf169ff538ad7e07f55e
User & Date: stephan 2025-05-17 06:25:02.876
Context
2025-05-17
07:26
Doc updates. check-in: 94e276d0f1 user: stephan tags: trunk
06:25
Remove now-obsolete GNUmakefile.in. check-in: d5a3e3ed86 user: stephan tags: trunk
06:22
Rework the makefile zoo into something which is hopefully more maintainable. Add support for out-of-tree builds and installation rules. The most visible change here is that the f-apps binaries are now all resulting binaries (e.g. the f-apps) are emitted to the top build directory, not their source subdirs. check-in: f3902cd22b user: stephan tags: trunk
Changes
Unified Diff Ignore Whitespace Patch
Deleted GNUmakefile.in.
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
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
#!/usr/bin/make # help out emacs
#
# Top-level autosetup-filtered GNUmakefile for libfossil. This
# particular build is for Unix-ish platforms with GNU Make 4+. It is
# somewhat... involved.
all:
# Our recipes require The Bash Shell
SHELL := @BIN_BASH@
MAKEFILE.top := $(word $(words $(MAKEFILE_LIST)),$(MAKEFILE_LIST))
#TOP_DIR := $(patsubst %/,%,$(dir $(MAKEFILE.top)))
TOP_SRCDIR_REL := $(patsubst %/,%,$(dir $(MAKEFILE.top)))
TOP_SRCDIR_ABS := $(realpath $(TOP_SRCDIR_REL))

# Build tools, set via autosetup's cc-check-tools
CC = @CC@
AR = @AR@
STRIP = @STRIP@

# FLAGS/LIBS
CC.PROFILE_FLAG := @CC_PROFILE_FLAG@
CFLAGS += @CFLAGS@ $(CC.PROFILE_FLAG)
LDFLAGS += @LDFLAGS@ $(CC.PROFILE_FLAG)
# LDLIBS += @LIBS@

# ??? HAVE_DLOPEN := @HAVE_DLOPEN@
HAVE_LIBDL := @HAVE_LIBDL@
HAVE_LIBLTDL := @HAVE_LIBLTDL@
ENABLE_MODULES ?= @FSL_ENABLE_MODULE_LOADER@
LIBFOSSIL_SHARED := @LIBFOSSIL_SHARED@
LIBFOSSIL_STATIC := @LIBFOSSIL_STATIC@

# Install destination
prefix = @prefix@
exec_prefix = @exec_prefix@
DESTDIR ?=

# Enable MAKE_COMPILATION_DB = yes to generate a JSON compilation database. For
# each *.c source file being compiled, a corresponding JSON file will be created
# in the './compile_commands' sub-directory, and will be used to generate the
# 'compile_commands.json' compilation database in the repository root. This is
# only available with compilers that support the '-MJ' option (e.g., clang).
MAKE_COMPILATION_DB = @MAKE_COMPILATION_DB@

########################################################################

ifeq ($(MAKE_COMPILATION_DB),yes)
compdb_dir = compile_commands
mkdir_compdb = $(TOP_SRCDIR_REL)/$(compdb_dir)
$(mkdir_compdb):
	@mkdir -p $@

compdb_file = $(TOP_SRCDIR_REL)/$(compdb_dir)/$(subst /,-,$@.json)
compdb_args = -MJ $(compdb_file)
CFLAGS += $(compdb_args)
else
mkdir_compdb =
endif


########################################################################
# Some common vars used by shakenmake.make and/or the sub-makes
# (make-*.make).
DIR.top := @srcdir@
DIR.src := $(DIR.top)/src
DIR.extsrc := $(DIR.top)/extsrc
DIR.client := $(DIR.top)/client
DIR.tools := $(DIR.top)/tools
DIR.include := $(DIR.top)/include
DIR.bindings := $(DIR.top)/bindings
DIR.f-apps := $(DIR.top)/f-apps
DIR.fnc := $(DIR.client)/fnc
DIR.sql := $(DIR.top)/sql

LDFLAGS_CURSES := @LDFLAGS_CURSES@
CFLAGS_CURSES := @CFLAGS_CURSES@
LDFLAGS_LIBBSD := @LDFLAGS_LIBBSD@
LDFLAGS_RPATH := @LDFLAGS_RPATH@
LDFLAGS_MODULE_LOADER += @LDFLAGS_MODULE_LOADER@
LDFLAGS_ICONV := @LDFLAGS_ICONV@

# Project-specific CFLAGS
INCLUDES.global := -I$(DIR.include) -I$(DIR.include)/fossil-scm
# Reminder: adding -I$(DIR.extsrc) can cause us to pick a local sqlite3.h
# when we should be using an external one.
#
#this can cause us to pick up the wrong sqlite3.h:
#ifneq (,$(wildcard $(HOME)/include/*))
#  # This is admittedly primarily for my own sake!
#  INCLUDES.global += -I$(HOME)/include
#endif
CPPFLAGS += $(INCLUDES.global)
# Assume gcc-compatible compilation flags...
CFLAGS += -Wall -Werror -Wsign-compare -pedantic @CC_FLAG_C99@
PLATFORM_UNAME := @PLATFORM_UNAME@

ShakeNMake.QUIET ?= @BUILD_QUIETLY@
ShakeNMake.USE_MKDEPS := 0
ShakeNMake.ETAGS.DISABLE := 1
ShakeNMake.EXTENSIONS.DLL := @TARGET_DLLEXT@
#ShakeNMake.DLL.FLAG_shared := @SH_LDFLAGS@
#ShakeNMake.ETAGS.FILTER := | grep -v 'libfossil*.[ch]'
include shakenmake.make

########################################################################
# [ce]tags support. This is a tree-specific variant of the one found in
# shakenmake.make.
ifeq (.,$(TOP_SRCDIR_REL))
  # $1 = tagger binary (ctags or etags)
  define CALL.tagger
    TAG.dirs ?= $$(DIR.src) $$(DIR.include) $$(DIR.f-apps) $$(DIR.client) $$(DIR.bindings)
    # ^^^ don't scan "." because we need to avoid that libfossil[-.]*[ch]
    # to get tagged (it breaks tag navigation during development).
    TAG.files ?= $$(shell find $$(TAG.dirs) -name '*.[ch]' -o -name '*.?pp')
    TAG.$(1).flags := $$(TAG.files)
    ifeq (,$$(filter %/etags,$(1)))
      TAG.$(1).tagfile := tags
    else
      TAG.$(1).tagfile := TAGS
    endif
    CLEAN.root += $$(TAG.$(1).tagfile)
    all: $$(TAG.$(1).tagfile)
    $$(TAG.$(1).tagfile): $$(TAG.$(1).files) $$(MAKEFILE.top)
		@echo "Generating $$@..."; $(1) $$(TAG.$(1).flags)
  endef
  # ^^ CALL.tagger
  BIN.ETAGS := @BIN_ETAGS@
  ifneq (,$(BIN.ETAGS))
    $(eval $(call CALL.tagger,$(BIN.ETAGS)))
    tags: $(TAG.$(BIN.ETAGS).tagfile)
  endif
  BIN.CTAGS := @BIN_CTAGS@
  ifneq (,$(BIN.CTAGS))
    $(eval $(call CALL.tagger,$(BIN.CTAGS)))
  endif
endif
# ^^^ TOP_SRCDIR_REL==.
# /[ce]tags support
#########################################################################

$(call ShakeNMake.CALL.CLEAN-SET,root)
DISTCLEAN.root = \
  $(MAKEFILE.top) \
  $(DIR.include)/fossil-scm/autoconfig.h \
  libfossil-config.h libfossil.* \
  config.log config.defines.txt \
  autosetup/jimsh0 \
  $(wildcard compile_commands/*) compile_commands.json+
CLEAN.root += $(wildcard $(DIR.top)/*~)

########################################################################
# Dependencies generation.
deps:
########################################################################
# $(eval $(call CALL.ADD_C_DEPS...))
# $1 = deps set name: must match the X part of one of the project's
#      rule set names.
# $2 = the list of .c/.cpp files to generate deps for.
#
# Creates and imports deps file named $(DEPS.$(1).make).
#
# Optionally set DEPS.$(1).EXTRADEPS to any extra files the generated
# deps file should depend on.
#
# Optionally set DEPS.$(1).INCDIRS to any additional directories which
# should be added to the -I CPPFLAGS. The directories containing the
# files in $(2) are automatically added, as are $(INCLUDES.global).
#
# Sidebar: because of an old design mis-decision, in which we have two
# distinctly different files named libfossil.h, we have to be careful
# to avoid adding -I$(DIR.top) to the deps flags, as we want these
# deps to be on $(DIR.include)/libfossil.h rather than
# $(DIR.top)/libfossil.h. It's a long story.
########################################################################
# C_DEPS_MAKEFILES = list of makefiles all .o files depend on.
C_DEPS_MAKEFILES := $(MAKEFILE.top) shakenmake.make
BIN.MKCDEP := $(DIR.tools)/mkcdep
# ^^^ Frankly, this does a better job than (gcc -e -E ...) and is tons
# faster. It is less portable, though.
$(BIN.MKCDEP): $(BIN.MKCDEP).c
	$(CC) -o $@ $^
CLEAN.root += $(BIN.MKCDEP)
define CALL.ADD_C_DEPS
DEPS.$(1).make := .deps.$(1).make
CLEAN.$(1) += $$(DEPS.$(1).make)
ifneq (1,$(MAKING_CLEAN))
$$(DEPS.$(1).make): $(BIN.MKCDEP) $(MAKEFILE.top) $$(DEPS.$(1).EXTRADEPS) $(2)
	@echo "Generating deps set [$(1)] [$$@]..."; \
	$$(BIN.MKCDEP) $$(INCLUDES.global) \
		$$(patsubst %,-I%,$$(sort $$(dir $(2)))) \
		$$(patsubst %,-I%,$$(DEPS.$(1).INCDIRS)) \
		-- $(2) > $$@
deps-$(1): $$(DEPS.$(1).make)
deps: deps-$(1)
$$(eval -include $$(DEPS.$(1).make))
endif
endef
# ^^^ CALL.ADD_C_DEPS
########################################################################

########################################################################
# Transform schema SQL files into source form. We don't use fossil(1)'s
# approach because it relies on unspecified length limits on C string
# literals. Yeah, it works, but i'm funny about the C Standard.
#include $(TOP_SRCDIR_REL)/tools.make
BIN.TEXT2C := $(DIR.tools)/text2c
$(BIN.TEXT2C): $(DIR.tools)/text2c.c
	cc $< -o $@
DISTCLEAN.root += $(BIN.TEXT2C)

########################################################################
# Transforms file $(2) to $(1).c in the form of a byte array and
# accessor function.
define CALL.FILE2C
$(2):
$(1).c: $(2) $$(BIN.TEXT2C) $(C_DEPS_MAKEFILES)
ifneq (1,$(MAKING_CLEAN))
	@echo "Creating $$@ from $(2)..."; \
	{ \
		echo '/** @page page_$$(notdir $1) $$(notdir $(2))'; echo; \
    echo 'Binary form of file $(2).'; echo; \
		echo '*/'; \
		$$(BIN.TEXT2C) fsl_$$(notdir $1) < $(2); \
		echo '/* end of $(2) */'; \
	} > $$@;
endif
endef
# /CALL.FILE2C
#########################################################################

########################################################################
# libfossil library...
all: libf

$(call ShakeNMake.CALL.CLEAN-SET,libf)
libf.CPPFLAGS :=
libf.EXTRA_LIBS := @F_PIC@ -lz -lm $(LDFLAGS_MODULE_LOADER) $(LDFLAGS_ICONV)
# ^^^^ The -lm dep (via log(3)) is coming from -DSQLITE_ENABLE_FTS5.
libf.CLIENT.LDFLAGS := @F_PIC@
libf.CLIENT.STATIC.LDFLAGS := $(libf.CLIENT.LDFLAGS)
ifeq (,$(CC.PROFILE_FLAG))
  # SH_LINKFLAGS fails on QNX, whereas SH_LINKRPATH and
  # $(LDFLAGS_RPATH) work.
  libf.CLIENT.LDFLAGS += -L$(DIR.top) -lfossil $(LDFLAGS_RPATH)
else
  # For profiling builds to report useful stuff we have to statically
  # link.
  $(error Static builds are TODO.)
endif
libf.CLIENT.CPPFLAGS :=
sqlite3.c := $(firstword $(wildcard $(DIR.extsrc)/sqlite3-see*.c $(DIR.extsrc)/sqlite3.c))
ifeq (,$(sqlite3.c))
  sqlite3.o := $(DIR.extsrc)/sqlite3.o
  HAVE_OWN_SQLITE := 0
  libf.CLIENT.LDFLAGS += -lsqlite3
  libf.CLIENT.STATIC.LDFLAGS += -lsqlite3
else
  HAVE_OWN_SQLITE := 1
  sqlite3.o := $(sqlite3.c:.c=.o)
  $(sqlite3.o): CFLAGS:=$(filter-out -Werror,$(filter-out @CC_FLAG_C99@,$(CFLAGS)))
  $(sqlite3.o): CXXFLAGS:=$(filter-out -Werror,$(CXXFLAGS))
  libf.CPPFLAGS += -I$(DIR.extsrc)
  libf.CLIENT.CPPFLAGS += -I$(DIR.extsrc)
endif
#$(error libf.CPPFLAGS = $(libf.CPPFLAGS))
$(sqlite3.o): CPPFLAGS+=-UDEBUG -DNDEBUG -DWHAT \
              -DSQLITE_DQS=0 \
              -DSQLITE_THREADSAFE=0 \
              -DSQLITE_DEFAULT_MEMSTATUS=0 \
              -DSQLITE_DEFAULT_WAL_SYNCHRONOUS=1 \
              -DSQLITE_LIKE_DOESNT_MATCH_BLOBS \
              -DSQLITE_OMIT_DECLTYPE \
              -DSQLITE_OMIT_PROGRESS_CALLBACK \
              -DSQLITE_OMIT_SHARED_CACHE \
              -DSQLITE_OMIT_DEPRECATED \
              -DSQLITE_OMIT_LOAD_EXTENSION \
              -DSQLITE_MAX_EXPR_DEPTH=0 \
              -DSQLITE_ENABLE_LOCKING_STYLE=0 \
              -DSQLITE_DEFAULT_FILE_FORMAT=4 \
              -DSQLITE_ENABLE_EXPLAIN_COMMENTS \
              -DSQLITE_ENABLE_DBSTAT_VTAB \
              -DSQLITE_ENABLE_FTS5 \
              -DSQLITE_ENABLE_STMTVTAB \
              -DSQLITE_HAVE_ZLIB \
              -DSQLITE_INTROSPECTION_PRAGMAS \
              -DSQLITE_ENABLE_DBPAGE_VTAB \
              -DSQLITE_TRUSTED_SCHEMA=0


# libf.SRC = all source files for the core library. Any .h files in
# this list are purely internal, not part of the API.
libf.SRC := $(patsubst %,$(DIR.src)/%, \
	xdirent.h \
	fsl.c \
	annotate.c \
	appendf.c \
	auth.c \
	bag.c \
	buffer.c \
	cache.c \
	checkin.c \
	checkout.c \
	cli.c \
	content.c \
	config.c \
	cx.c \
	db.c \
	deck.c \
	delta.c \
	dibu.c \
	diff.c \
	encode.c \
	event.c \
	foci.c \
	fs.c \
	forum.c \
	glob.c \
	io.c \
	leaf.c \
	list.c \
	lookslike.c \
	md5.c \
	merge.c \
	merge3.c \
	popen.c \
	pq.c \
	repo.c \
	schema.c \
	search.c \
	sha1.c \
	sha3.c \
	strftime.c \
	tag.c \
	ticket.c \
	udf.c \
	utf8.c \
	vfile.c \
	vpath.c \
	wiki.c \
	zip.c)

libf.OBJ := $(patsubst %.c,%.o,$(filter-out %.h,$(libf.SRC)))

########################################################################
# Calls (CALL.FILE2C,$1,$2) then modifies libf.SRC and friends to add
# $1.c/.o.
define CALL.libf.FILE2C
$(call CALL.FILE2C,$(1),$(2))
libf.SRC += $(1).c
libf.OBJ += $(1).o
endef
# Generate src/XYZ_cstr.c from $(DIR.sql)/XYZ.* ...
#
# Copies of these generated (and seldom-changing) files are checked in
# to the repo, which is why we don't add these to the [DIST]CLEAN.libf
# list.
$(eval $(call CALL.libf.FILE2C,$(DIR.src)/difftk_cstr,$(DIR.src)/difftk.tcl))
$(eval $(call CALL.libf.FILE2C,$(DIR.src)/schema_config_cstr,$(DIR.sql)/config.sql))
$(eval $(call CALL.libf.FILE2C,$(DIR.src)/schema_repo1_cstr,$(DIR.sql)/repo-static.sql))
$(eval $(call CALL.libf.FILE2C,$(DIR.src)/schema_repo2_cstr,$(DIR.sql)/repo-transient.sql))
$(eval $(call CALL.libf.FILE2C,$(DIR.src)/schema_ckout_cstr,$(DIR.sql)/checkout.sql))
$(eval $(call CALL.libf.FILE2C,$(DIR.src)/schema_ticket_cstr,$(DIR.sql)/ticket.sql))
$(eval $(call CALL.libf.FILE2C,$(DIR.src)/schema_ticket_reports_cstr,$(DIR.sql)/ticket-reports.sql))
$(eval $(call CALL.libf.FILE2C,$(DIR.src)/schema_forum_cstr,$(DIR.sql)/forum.sql))

ifeq (1,$(HAVE_OWN_SQLITE))
  libf.SRC += $(sqlite3.c)
  libf.OBJ += $(sqlite3.o)
else
  libf.EXTRA_LIBS += -lsqlite3
endif
CLEAN.libf += $(libf.OBJ)

$(eval $(call CALL.ADD_C_DEPS,libf,$(libf.SRC)))
$(libf.OBJ): CPPFLAGS+=$(libf.CPPFLAGS)

libfossil.DLL.OBJECTS := $(libf.OBJ)
libfossil.DLL.FLAGS := $(libf.EXTRA_LIBS) $(LDFLAGS_RPATH)
# Maintenance note: SH_LINKRPATH is implicitly provided by autosetup
libfossil.LIB.OBJECTS := $(libfossil.DLL.OBJECTS)
libfossil: libfossil.LIB
########################################################################
# Shared lib
ifeq (1,@LIBFOSSIL_SHARED@)
$(eval $(call ShakeNMake.CALL.RULES.DLLS,libfossil))
#CLEAN.libf += $(libfossil.DLL)
libf: libfossil.DLL
$(libfossil.DLL): $(libfossil.DLL.OBJECTS)
ShakeNMake.install.dlls += $(libfossil.DLL)
endif

# Static lib
ifeq (1,$(LIBFOSSIL_STATIC))
$(eval $(call ShakeNMake.CALL.RULES.LIBS,libfossil))
libf: libfossil.LIB
$(libfossil.LIB): $(libfossil.LIB.OBJECTS)
#CLEAN.libf += $(libfossil.LIB)
ShakeNMake.install.libs += $(libfossil.LIB)
endif

########################################################################
# $(libfossil.library) is intended to be used as a dependency for
# clients which link to -lfossil. It will be either the DLL or LIB file
# for the library. Reminder: we cannot use $(wildcard) here because
# this string is, on the first build, eval'd before libfossil is
# compiled.
libfossil.library := $(word 1,$(libfossil.DLL) $(libfossil.LIB))

# /libfossil library
########################################################################

########################################################################
# f-apps
all: f-apps
f-apps:
$(call ShakeNMake.CALL.CLEAN-SET,f-apps)

# Binaries which might get installed...
f-apps.1 := $(patsubst %,$(DIR.f-apps)/%,\
  f-acat \
  f-add \
  f-adiff \
  f-annotate \
  f-aparse \
  f-ci \
  f-ciwoco \
  f-co \
  f-config \
  f-delta \
  f-extract \
  f-ls \
  f-merge \
  f-new \
  f-open \
  f-parseparty \
  f-query \
  f-rebuild \
  f-rename \
  f-repostat \
  f-resolve \
  f-revert \
  f-rm \
  f-status \
  f-tag \
  f-timeline \
  f-update \
  f-vdiff \
  f-wiki \
  f-zip)

# Test/non-installed binaries...
f-apps.2 := $(patsubst %,$(DIR.f-apps)/%,\
  f-event \
  f-sanity \
  f-sizeof \
  f-_scratchpad \
  f-import-blob \
  f-_template \
  f-test-canonical-name \
  f-test-ckout-db-search \
  f-test-ckout-has-changes \
  f-test-cidiff \
  f-test-ciwoco \
  f-test-diff-builder \
  f-test-filename-preferred-case \
  f-test-line-diff \
  f-test-merge3 \
  f-test-reserved-name-check)

f-apps.list := $(f-apps.1) $(f-apps.2)

ifeq (,$(CC.PROFILE_FLAG))
  f-apps.ADDED_LIBF_STATIC := 0
else
  f-apps.ADDED_LIBF_STATIC := 1
endif
ifeq (0,$(f-apps.ADDED_LIBF_STATIC))
  f-apps.LDFLAGS += $(libf.CLIENT.LDFLAGS)
else
  f-apps.LDFLAGS += $(libf.CLIENT.STATIC.LDFLAGS)
endif

########################################################################
# Optional curses-specific bits...
ifneq (,$(LDFLAGS_CURSES))
  $(DIR.f-apps)/diff-builder-ncu.o: CFLAGS+=$(CFLAGS_CURSES)
  ftcb := $(DIR.f-apps)/f-test-custom-builder
  f-apps.2 += $(ftcb)
  $(ftcb).BIN.FLAGS += $(LDFLAGS_CURSES)
  $(ftcb).BIN.OBJECTS += $(DIR.f-apps)/fsl-ncurses.o
  $(ftcb).o: CFLAGS+=$(CFLAGS_CURSES)

  $(DIR.f-apps)/f-vdiff.BIN.FLAGS += $(LDFLAGS_CURSES)
  $(DIR.f-apps)/fsl-ncurses.o: CFLAGS+=$(CFLAGS_CURSES)
  $(DIR.f-apps)/f-vdiff.BIN.OBJECTS += $(DIR.f-apps)/fsl-ncurses.o
  $(DIR.f-apps)/f-vdiff.o: CFLAGS+=$(CFLAGS_CURSES)
  $(DIR.f-apps)/f-vdiff.o: CPPFLAGS+=-DHAS_NCURSES
endif
# /curses
########################################################################

f-apps.DEPS := $(libfossil.library)

########################################################################
# Sets up binary build rules for binary named $1. This only works
# for the basic test binaries which all have common compile/link
# bits. Assumes sources are in $1.c.
define CALL.f-app.BIN
  # $(1).bin := $$(DIR.f-apps)/$(1)
  $(1).BIN.OBJECTS += $(1).o
  $$($(1).BIN.OBJECTS): $$(fapps.MAKEFILE)
  $$($(1).BIN.OBJECTS): CPPFLAGS+=$$(libf.CLIENT.CPPFLAGS)
  $(1).BIN.FLAGS += $$(f-apps.LDFLAGS)
  $(call ShakeNMake.CALL.RULES.BIN,$(1))
  $$($(1).BIN): $$(f-apps.DEPS)
  f-apps: $$($(1).BIN)
  CLEAN.f-apps += $$($(1).BIN) $$($(1).BIN.OBJECTS)
endef

$(eval $(call CALL.ADD_C_DEPS,f-apps,$(wildcard $(DIR.f-apps)/*.c)))
$(foreach fbin,$(f-apps.1) $(f-apps.2),$(eval $(call CALL.f-app.BIN,$(fbin))))
ShakeNMake.install.bins += $(f-apps.1)
# /f-apps
########################################################################

########################################################################
# fnc
#
# To build fnc, we need the curses and pthread libraries.
# -lz is for libfossil
# -liconv is for libfossil on macOS
# -lutil is... ???
# -lm is for sqlite3
# -lbsd is needed on _some_ Linux systems
$(call ShakeNMake.CALL.CLEAN-SET,fnc)
CLEAN.fnc = $(wildcard $(DIR.fnc)/*.o $(DIR.fnc)/fnc)
BUILD_CLIENT_FNC := @BUILD_CLIENT_FNC@
ifneq ($(PLATFORM_UNAME),Haiku)
  FNC_LIBS = -lutil -lpthread
else
  FNC_LIBS = -lbsd -lz
endif
ifeq (1,$(BUILD_CLIENT_FNC))
  _fnc := $(DIR.fnc)/fnc
  # ^^^^ level of indirection needed to avoid placing the fnc binary in
  # the top-level dir.
  $(_fnc).BIN.OBJECTS := $(patsubst %.c,%.o,$(wildcard $(DIR.fnc)/*.c))
  $($(_fnc).BIN.OBJECTS): CPPFLAGS+=$(libf.CLIENT.CPPFLAGS)
  $($(_fnc).BIN.OBJECTS): CPPFLAGS+=$(CFLAGS_CURSES)
ifneq ($(PLATFORM_UNAME),Haiku)
  $($(_fnc).BIN.OBJECTS): CFLAGS+=@F_PIE@
endif
  $($(_fnc).BIN.OBJECTS): CPPFLAGS+= '-DFNC_VERSION=@FNC_VERSION@' \
    '-DFNC_HASH=@FNC_HASH@' '-DFNC_DATE=@FNC_DATE@'
  $($(_fnc).BIN.OBJECTS): $(MAKEFILE.top)
  $(_fnc).BIN.FLAGS := $(libf.CLIENT.LDFLAGS) \
    $(LDFLAGS_CURSES) $(LDFLAGS_LIBBSD) $(FNC_LIBS)
  $(_fnc).BIN.FLAGS += @LDFLAGS_ICONV@
  $(eval $(call ShakeNMake.CALL.RULES.BIN,$(_fnc)))
  CLEAN.fnc += $($(_fnc).BIN)
  $($(_fnc).BIN): $(libfossil.library)
  ShakeNMake.install.bins += $($(_fnc).BIN)
  ShakeNMake.install.man1 += $(DIR.fnc)/fnc.1
  fnc: libfossil.c
  fnc: $($(_fnc).BIN)
  all: fnc
endif
# ^^^ $(BUILD_CLIENT_FNC)
# /fnc
########################################################################

########################################################################
# Amalgamation
bin.make-amal := $(DIR.tools)/make-amalgamation.bash
amal.zip := libfossil-amalgamation.zip
amal.deps := $(bin.make-amal) auto.def $(MAKEFILE.top) \
  $(libf.SRC) $(wildcard $(DIR.include)/fossil-scm/*.h)
ifeq (1,$(ENABLE_CXX))
  amal.c++.flags := -c++
  amal: libfossil++.cpp
else
  amal: libfossil.c
endif
amal-zip:
	$(SHELL) $(bin.make-amal) -zip $(amal.c++.flags)
amal-uv:
	$(SHELL) $(bin.make-amal) -zip -uv $(amal.c++.flags)
libfossil.c libfossil++.cpp:
	$(SHELL) $(bin.make-amal) -nc $(amal.c++.flags)
ifeq (,$(wildcard .fslckout))
  amal: amal-zip
else
  amal: amal-uv
endif
$(call ShakeNMake.CALL.CLEAN-SET,amal)
DISTCLEAN.amal += libfossil.c libfossil.h libfossil-config.h libfossil-amalgamation.zip
#
########################################################################

########################################################################
# C++ bindings
ENABLE_CXX := @ENABLE_CXX@
ifeq (1,$(ENABLE_CXX))
CXXFLAGS += @F_PIC@ -Wall -Werror
DIR.cpp := $(DIR.bindings)/cpp
libf++.SRC := $(patsubst %,$(DIR.cpp)/%,\
  Context.cpp \
  Db.cpp \
  Deck.cpp \
  Exception.cpp \
  Fossil.cpp \
  OStream.cpp)
libf++.H := $(DIR.include)/libfossil.hpp
libf++.OBJ := $(patsubst %.cpp,%.o,$(libf++.SRC))
$(call ShakeNMake.CALL.CLEAN-SET,libf++)
DISTCLEAN.libf++ += libfossil++.hpp libfossil++.cpp
$(eval $(call CALL.ADD_C_DEPS,libf++,$(libf++.SRC) $(libf++.H)))

# TODO? honor $(LIBFOSSIL_STATIC) and $(LIBFOSSIL_SHARED)
libf++.DLL.OBJECTS := $(libf++.OBJ)
libf++.DLL.FLAGS := $(libf.CLIENT.LDFLAGS)
$(eval $(call ShakeNMake.CALL.RULES.DLLS,libf++))
$(libf++.DLL): $(libfossil.library)
$(libf++.OBJ): CPPFLAGS+=-I$(DIR.extsrc)

libf++.tester.BIN.COMPILER := $(CXX)
libf++.tester.BIN.OBJECTS := $(DIR.cpp)/test.cpp
libf++.tester.BIN.FLAGS := -I$(DIR.include) $(libf.CLIENT.LDFLAGS) $(libf.CLIENT.CPPFLAGS)
$(eval $(call ShakeNMake.CALL.RULES.BIN,libf++.tester))
$(libf++.tester.BIN): $(libf++.DLL)

libf++: $(libf++.DLL) $(libf++.tester.BIN)
all: libf++
endif
# ^^^ $(ENABLE_CXX)
# /C++ bindings
########################################################################

########################################################################
# compile_commands.json
ifeq ($(MAKE_COMPILATION_DB),yes)
all: compile_commands.json
compile_commands.json:
	@$(RM) $@
	@{ echo -n '['; cat $(compdb_dir)/*.o.json | tr '\n' ' ' | sed -e 's/, $$//'; echo ']'; } > $@
	@echo "Generated $@"
endif
# /compile_commands.json
########################################################################

reconfig:
	@AUTOREMAKE@
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<