Codebase list fish / upstream/2.6.0 Makefile.in
upstream/2.6.0

Tree @upstream/2.6.0 (Download .tar.gz)

Makefile.in @upstream/2.6.0raw · history · blame

   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
 652
 653
 654
 655
 656
 657
 658
 659
 660
 661
 662
 663
 664
 665
 666
 667
 668
 669
 670
 671
 672
 673
 674
 675
 676
 677
 678
 679
 680
 681
 682
 683
 684
 685
 686
 687
 688
 689
 690
 691
 692
 693
 694
 695
 696
 697
 698
 699
 700
 701
 702
 703
 704
 705
 706
 707
 708
 709
 710
 711
 712
 713
 714
 715
 716
 717
 718
 719
 720
 721
 722
 723
 724
 725
 726
 727
 728
 729
 730
 731
 732
 733
 734
 735
 736
 737
 738
 739
 740
 741
 742
 743
 744
 745
 746
 747
 748
 749
 750
 751
 752
 753
 754
 755
 756
 757
 758
 759
 760
 761
 762
 763
 764
 765
 766
 767
 768
 769
 770
 771
 772
 773
 774
 775
 776
 777
 778
 779
 780
 781
 782
 783
 784
 785
 786
 787
 788
 789
 790
 791
 792
 793
 794
 795
 796
 797
 798
 799
 800
 801
 802
 803
 804
 805
 806
 807
 808
 809
 810
 811
 812
 813
 814
 815
 816
 817
 818
 819
 820
 821
 822
 823
 824
 825
 826
 827
 828
 829
 830
 831
 832
 833
 834
 835
 836
 837
 838
 839
 840
 841
 842
 843
 844
 845
 846
 847
 848
 849
 850
 851
 852
 853
 854
 855
 856
 857
 858
 859
 860
 861
 862
 863
 864
 865
 866
 867
 868
 869
 870
 871
 872
 873
 874
 875
 876
 877
 878
 879
 880
 881
 882
 883
 884
 885
 886
 887
 888
 889
 890
 891
 892
 893
 894
 895
 896
 897
 898
 899
 900
 901
 902
 903
 904
 905
 906
 907
 908
 909
 910
 911
 912
 913
 914
 915
 916
 917
 918
 919
 920
 921
 922
 923
 924
 925
 926
 927
 928
 929
 930
 931
 932
 933
 934
 935
 936
 937
 938
 939
 940
 941
 942
 943
 944
 945
 946
 947
 948
 949
 950
 951
 952
 953
 954
 955
 956
 957
 958
 959
 960
 961
 962
 963
 964
 965
 966
 967
 968
 969
 970
 971
 972
 973
 974
 975
 976
 977
 978
 979
 980
 981
 982
 983
 984
 985
 986
 987
 988
 989
 990
 991
 992
 993
 994
 995
 996
 997
 998
 999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
# Copyright (C) 2005-2006 Axel Liljencrantz
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License version 2 as
# published by the Free Software Foundation.
#
# 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, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA
#

#
# @configure_input@
#

#
# Makefile for the fish shell. Can build fish and associated
# applications, install them, and recalculate dependencies.
#

# Verbosity
# make V=1 causes a noisy make, V=0 is silent/quiet. If one uses (lower case v)
# $v  as a substitute for @, it will be replaced with an empty string for the
# default (V=1) case and replaced with @ in the V=0 case. You can use a bare @
# for things that should almost never print.
V := 0

#
# Used by docdir
#
PACKAGE_TARNAME := @PACKAGE_TARNAME@

# The default: /bin/sh
# Fish won't work.
SHELL := @SHELL@

# Programs
#
CXX := @CXX@
INSTALL := @INSTALL@
LN_S := @LN_S@
SED := @SED@
MKDIR_P := @MKDIR_P@
AWK := @AWK@
GREP := @GREP@
FGREP := @FGREP@

#
# Installation directories
#
prefix = @prefix@
exec_prefix = @exec_prefix@
datarootdir = @datarootdir@
datadir = @datadir@
bindir = @bindir@
mandir = @mandir@
sysconfdir = @sysconfdir@
docdir = @docdir@
localedir = @localedir@
extra_completionsdir = @extra_completionsdir@
extra_functionsdir = @extra_functionsdir@
extra_confdir = @extra_confdir@

#
# pcre2
#
PCRE2_WIDTH = @WCHAR_T_BITS@
PCRE2_DIR = pcre2-10.22
PCRE2_LIBDIR = $(PCRE2_DIR)/.libs
PCRE2_LIB = $(PCRE2_LIBDIR)/libpcre2-$(PCRE2_WIDTH).a
PCRE2_H = $(PCRE2_DIR)/src/pcre2.h
EXTRA_PCRE2 = @EXTRA_PCRE2@

#
# Various flags
#
CXXFLAGS = @CXXFLAGS@ $(EXTRA_CXXFLAGS)
CPPFLAGS = -DLOCALEDIR=\"$(localedir)\" -DPREFIX=L\"$(prefix)\" -DDATADIR=L\"$(datadir)\" -DSYSCONFDIR=L\"$(sysconfdir)\" -DBINDIR=L\"$(bindir)\" -DDOCDIR=L\"$(docdir)\" -iquote. -iquote./src/
LDFLAGS = @LDFLAGS@
LIBS = @LIBS@
LDFLAGS_FISH = ${LDFLAGS} @LDFLAGS_FISH@

#
# Set to 1 if we have gettext
#
HAVE_GETTEXT=@HAVE_GETTEXT@

#
# Set to 1 if we have doxygen
#
HAVE_DOXYGEN=@HAVE_DOXYGEN@

#
# All objects that the system needs to build fish, except fish.o
#
FISH_OBJS := obj/autoload.o obj/builtin.o obj/builtin_commandline.o \
	obj/builtin_complete.o obj/builtin_jobs.o obj/builtin_printf.o \
	obj/builtin_set.o obj/builtin_set_color.o obj/builtin_string.o \
	obj/builtin_test.o obj/builtin_ulimit.o obj/color.o obj/common.o \
	obj/complete.o obj/env.o obj/env_universal_common.o obj/event.o \
	obj/exec.o obj/expand.o obj/fallback.o obj/fish_version.o \
	obj/function.o obj/highlight.o obj/history.o obj/input.o \
	obj/input_common.o obj/intern.o obj/io.o obj/iothread.o obj/kill.o \
	obj/output.o obj/pager.o obj/parse_execution.o \
	obj/parse_productions.o obj/parse_tree.o obj/parse_util.o \
	obj/parser.o obj/parser_keywords.o obj/path.o obj/postfork.o \
	obj/proc.o obj/reader.o obj/sanity.o obj/screen.o obj/signal.o \
	obj/tokenizer.o obj/utf8.o obj/util.o obj/wcstringutil.o \
	obj/wgetopt.o obj/wildcard.o obj/wutil.o

FISH_INDENT_OBJS := obj/fish_indent.o obj/print_help.o $(FISH_OBJS)

FISH_KEYREAD_OBJS := obj/fish_key_reader.o obj/print_help.o $(FISH_OBJS)


#
# All objects that the system needs to build fish_tests
#
FISH_TESTS_OBJS := $(FISH_OBJS) obj/fish_tests.o

#
# All of the sources that produce object files
# (that is, are not themselves #included in other source files)
#
FISH_ALL_OBJS := $(sort $(FISH_OBJS) $(FISH_INDENT_OBJS) $(FISH_TESTS_OBJS) $(FISH_KEYREAD_OBJS) obj/fish.o)

#
# Files containing user documentation
#

#
# These files are the source files, they contain a few @FOO@-style substitutions
# Note that this order defines the order that they appear in the documentation
#
HDR_FILES_SRC := doc_src/index.hdr.in doc_src/tutorial.hdr doc_src/design.hdr doc_src/license.hdr doc_src/commands.hdr.in doc_src/faq.hdr

#
# These are the generated result files
#
HDR_FILES := $(HDR_FILES_SRC:.hdr.in=.hdr)

# Use a pattern rule so that Make knows to only issue one invocation
# per http://www.gnu.org/software/make/manual/make.html#Pattern-Intro

#
# Files containing documentation for external commands.
#
HELP_SRC := $(wildcard doc_src/*.txt)

#
# HTML includes needed for HTML help
#
HTML_SRC := doc_src/user_doc.header.html doc_src/user_doc.footer.html doc_src/user_doc.css

#
# Files in the test directory
#
TEST_IN := $(wildcard tests/test*.in)

#
# Files in ./share/completions/
#
COMPLETIONS_DIR_FILES := $(wildcard share/completions/*.fish) share/completions/..fish

#
# Files in ./share/functions/
#
FUNCTIONS_DIR_FILES := $(wildcard share/functions/*.fish)

#
# Programs to install
#
PROGRAMS := fish fish_indent fish_key_reader

#
# Manual pages to install
#
MANUALS := $(addsuffix .1, $(addprefix share/man/man1/, $(PROGRAMS)))
HELP_MANPAGES = $(wildcard share/man/man1/*.1)

# Determine which man pages we don't want to install
# On OS X, don't install a man page for open, since we defeat fish's open
# function on OS X.
# This is also done in build_tools/build_documentation.sh, but because the
# tarball includes this page, we need to skip it in the Makefile too (see
# https://github.com/fish-shell/fish-shell/issues/2561).
ifeq ($(shell uname), Darwin)
	CONDEMNED_PAGES := open.1
	HELP_MANPAGES = $(filter-out share/man/man1/open.1, $(wildcard share/man/man1/*.1))
endif

#
# All translation message catalogs, filter files based on LINGUAS.
#
TRANSLATIONS_SRC := $(wildcard po/*.po)
ifeq ($(HAVE_GETTEXT), 1)
	TRANSLATIONS := $(TRANSLATIONS_SRC:.po=.gmo)
ifdef LINGUAS
	TRANSLATIONS_ALL := $(TRANSLATIONS)
	TRANSLATIONS_WANTED = $(patsubst %,po/%.gmo,$(LINGUAS))
	TRANSLATIONS = $(filter $(TRANSLATIONS_WANTED),$(TRANSLATIONS_ALL))
endif
else
	TRANSLATIONS :=
endif

#
# If Doxygen is not available, don't attempt to build the documentation
#
ifeq ($(HAVE_DOXYGEN), 1)
  user_doc=doc
  share_man=share/man
else
  user_doc=
  share_man=
endif


t_co:=$(shell tput colors || echo '')  2> /dev/null
green  := $(shell ( tput setaf 2 || tput AF 2 ) 2> /dev/null )
yellow := $(shell ( tput setaf 3 || tput AF 3 ) 2> /dev/null )
cyan := $(shell ( tput setaf 6 || tput AF 6 ) 2> /dev/null )
red := $(shell ( tput setaf 1 || tput AF 1 ) 2> /dev/null )
bo := $(shell ( tput bold || tput md ) 2> /dev/null )
# * Italic: Rarely defined -  it's common for it to work despite
# 		terminfo entries and isn't known to cause any recent > 256-color terminals
# 		to explode. If terminfo says a terminal supports 256 colors - it's fancy enough
# 		and won't have trouble the escape.
ifeq ($(t_co), 256)
	em := $(shell ( tput sitm || tput ZH || echo "\\033[3m" ) 2> /dev/null )
# * Half-bright/faint 'dim' mode - rarely works - rarely in terminfo when it does
#   but it's cool. Use it with one of the basic colors to get a fainter version
#   of it. We use this to shade the output from any reconfigures we trigger.
	dim := $(shell ( tput dim || tput mh || [ $(TERM_PROGRAM) = Apple_Terminal ] && echo "\\033[2m") 2> /dev/null )
else
	em := $(shell ( tput sitm || tput ZH ) 2> /dev/null )
	dim := $(shell ( tput dim || tput mh) 2> /dev/null )
endif

sgr0 := $(shell ( tput sgr0 || tput me) 2> /dev/null )

#
# A target that shows VAR='$(VAR)' (properly escaped)
# Cool trick: `make show-$var` (e.g. make show-HAVE_DOXYGEN) to quickly see what $var is.
#
show-%:
	@echo "  $* = $(em)$(cyan)'$(subst ',''',$($*))'$(sgr0)" ||:
#
# Make everything needed for installing fish
#
all: show-CXX show-CXXFLAGS $(PROGRAMS) $(user_doc) $(share_man) $(TRANSLATIONS) fish.pc share/__fish_build_paths.fish
ifneq (,$(findstring install,$(MAKECMDGOALS)))
# Fish has been built, but if the goal was 'install', we aren't done yet and this output isnt't desirable
	@echo "$(green)fish has now been built.$(sgr0)"
	@echo "Run $(yellow)$(notdir $(MAKE)) install$(sgr0) to install fish.$(sgr0)"
endif
.PHONY: all

#
# Pull version information
#
FISH-BUILD-VERSION-FILE: FORCE | show-FISH_BUILD_VERSION
	$v build_tools/git_version_gen.sh 2> /dev/null
-include FISH-BUILD-VERSION-FILE
CPPFLAGS += -DFISH_BUILD_VERSION=\"$(FISH_BUILD_VERSION)\"
.PHONY: FORCE
obj/fish_version.o: FISH-BUILD-VERSION-FILE

#
# These dependencies make sure that autoconf and configure are run
# when the source code for the build configuration has changed.
#
configure: configure.ac
	@echo "Rechecking config.status; rerunning ./configure if necessary...$(dim)"
	$v ./config.status --recheck
	@echo "$(sgr0)"

Makefile: Makefile.in configure
	@echo "Checking config.status...$(dim)"
	$v ./config.status
	@echo "$(sgr0)"

#
# Build fish with some debug flags specified. This is GCC specific,
# and should only be used when debugging fish.
#
prof: EXTRA_CXXFLAGS += -pg
prof: LDFLAGS += -pg
prof: all
.PHONY: prof

#
# User documentation, describing the features of the fish shell.
#
# Depend on the sources (*.hdr.in) and manually make the intermediate *.hdr
# and doc.h files if needed. The sed command deletes everything including and
# after the first -, for simpler version numbers. Cleans up the user_doc/html
# directory once Doxygen is done.
#
doc: $(HDR_FILES_SRC) Doxyfile.user $(HTML_SRC) $(HELP_SRC) doc.h $(HDR_FILES) lexicon_filter
	@echo "  doxygen  $(em)user_doc$(sgr0)"
	$v (cat Doxyfile.user; echo INPUT_FILTER=./lexicon_filter; echo PROJECT_NUMBER=$(FISH_BUILD_VERSION) | $(SED) "s/-.*//") | doxygen - && touch user_doc
	$v rm -f $(wildcard $(addprefix ./user_doc/html/,arrow*.png bc_s.png bdwn.png closed.png doc.png folder*.png ftv2*.png nav*.png open.png splitbar.png sync_*.png tab*.* doxygen.* dynsections.js jquery.js pages.html))

#
# PDF version of the source code documentation.
#
doc/refman.pdf: doc
	@echo "  MAKE     $(em)doc/latex$(sgr0)"
	$v cd doc/latex
	$v $(MAKE) V=$(V)
	$v mv refman.pdf ..

#
# Prep the environment for running the unit tests. When specifying DESTDIR on
# the command line (e.g., `make DESTDIR=/usr/local/`) you must have previously
# installed fish using the same prefix; e.g., `./configure --prefix=/usr/local`
# followed by `make install`.
#
test-prep: show-DESTDIR show-LN_S show-FISH_VERSION
	$v rm -rf test
	$v $(MKDIR_P) test/data test/home test/temp
ifdef DESTDIR
	$v $(LN_S) $(DESTDIR) test/root
else
	$v $(MKDIR_P) test/root
endif
.PHONY: test-prep

#
# The test target runs both the low level code tests and the high level script
# tests.
#
# Note that doing `make DESTDIR=/some/path/ test` overrides this assignment.
#
test: DESTDIR = $(PWD)/test/root/
test: prefix = .
test: test-prep install-force test_low_level test_high_level
	$v rm -f /tmp/file_truncation_test.txt /tmp/tee_test.txt /tmp/fish_foo.txt
	$v rm -rf /tmp/is_potential_path_test
.PHONY: test

#
# We want the various tests to run serially so their output doesn't mix
# We can do that by adding ordering dependencies based on what goals are being used.
#
test_goals := test_low_level test_fishscript test_interactive

#
# The following variables define targets that depend on the tests. If any more targets
# are added that depend, directly or indirectly, on tests, they need to be recorded here.
#
test_test_deps = test_low_level $(test_high_level_test_deps)
test_high_level_test_deps = test_fishscript test_interactive

active_test_goals = $(filter $(test_goals),$(foreach a,$(or $(MAKECMDGOALS),$(.DEFAULT_GOAL)),$(a) $($(a)_test_deps)))
filter_up_to = $(eval b:=1)$(foreach a,$(2),$(and $(b),$(if $(subst $(1),,$(a)),$(a),$(eval b:=))))

# The values for XDG_DATA_HOME and XDG_CONFIG_HOME mimic those from tests/test_util.fish.
test_low_level: fish_tests $(call filter_up_to,test_low_level,$(active_test_goals))
	$v rm -rf test/data test/home
	$(MKDIR_P) test/data test/home
	env XDG_DATA_HOME=test/data XDG_CONFIG_HOME=test/home ./fish_tests
.PHONY: test_low_level

test_high_level: DESTDIR = $(PWD)/test/root/
test_high_level: prefix = .
test_high_level: test-prep install-force test_fishscript test_interactive
.PHONY: test_high_level

test_fishscript: $(call filter_up_to,test_fishscript,$(active_test_goals))
	cd tests; ../test/root/bin/fish test.fish
.PHONY: test_fishscript

test_interactive: $(call filter_up_to,test_interactive,$(active_test_goals))
	cd tests; ../test/root/bin/fish interactive.fish
.PHONY: test_interactive

#
# commands.hdr collects documentation on all commands, functions and
# builtins
#
doc_src/commands.hdr:$(HELP_SRC) doc_src/commands.hdr.in |
	@echo "  CAT AWK  $(em)$@$(sgr0)"
	$v rm -f command_list.tmp command_list_toc.tmp $@
	$v for i in $(sort $(HELP_SRC)); do \
		echo "<hr>" >>command_list.tmp; \
		cat $$i >>command_list.tmp; \
		echo >>command_list.tmp; \
		echo >>command_list.tmp; \
		NAME=`basename $$i .txt`; \
		echo '- <a href="#'$$NAME'">'$$NAME'</a>' >> command_list_toc.tmp; \
		echo "Back to <a href='index.html#toc-commands'>command index</a>". >>command_list.tmp; \
	done
	$v mv command_list.tmp command_list.txt
	$v mv command_list_toc.tmp command_list_toc.txt
	$v cat $@.in | $(AWK) '{if ($$0 ~ /@command_list_toc@/) { system("cat command_list_toc.txt"); } else if ($$0 ~ /@command_list@/){ system("cat command_list.txt");} else{ print $$0;}}' >$@

toc.txt: $(HDR_FILES:index.hdr=index.hdr.in) | show-SED
	@echo "  SED      $(em)$@$(sgr0)"
	$v rm -f toc.tmp $@
# Ugly hack to set the toc initial title for the main page
	$v echo '- <a href="index.html" id="toc-index">fish shell documentation - $(FISH_BUILD_VERSION)</a>' > toc.tmp
# The first sed command captures the page name, followed by the description
# The second sed command captures the command name \1 and the description \2, but only up to a dash
# This is to reduce the size of the TOC in the command listing on the main page
	$v for i in $(HDR_FILES:index.hdr=index.hdr.in); do\
		NAME=`basename $$i .hdr`; \
		NAME=`basename $$NAME .hdr.in`; \
		$(SED) <$$i >>toc.tmp -n \
		-e 's,.*\\page *\([^ ]*\) *\(.*\)$$,- <a href="'$$NAME'.html" id="toc-'$$NAME'">\2</a>,p' \
		-e 's,.*\\section *\([^ ]*\) *\([^-]*\)\(.*\)$$,  - <a href="'$$NAME'.html#\1">\2</a>,p'; \
	done
	$v mv toc.tmp $@

doc_src/index.hdr: toc.txt doc_src/index.hdr.in | show-AWK
	@echo "  AWK CAT  $(em)$@$(sgr0)"
	$v cat $@.in | $(AWK) '{if ($$0 ~ /@toc@/){ system("cat toc.txt");} else{ print $$0;}}' >$@

#
# To enable the lexicon filter, we first need to be aware of what fish
# considers to be a command, function, or external binary. We use
# command_list_toc.txt for the base commands. Scan the share/functions
# directory for other functions, some of which are mentioned in the docs, and
# use /share/completions to find a good selection of binaries. Additionally,
# colour defaults from __fish_config_interactive to set the docs colours when
# used in a 'cli' style context.
#
lexicon.txt: doc_src/commands.hdr $(FUNCTIONS_DIR_FILES) $(COMPLETIONS_DIR_FILES) share/functions/__fish_config_interactive.fish | show-SED show-FGREP
	$v rm -f lexicon.tmp lexicon_catalog.tmp lexicon_catalog.txt $@
# Scan sources for commands/functions/binaries/colours. If GNU sed was portable, this could be much smarter.
	@echo "  SEDFGREP $(em)$@$(sgr0)"
	$v $(SED) <command_list_toc.txt >>lexicon.tmp -n \
		-e "s|^.*>\([a-z][a-z_]*\)</a>|'\1'|w lexicon_catalog.tmp" \
		-e "s|'\(.*\)'|bltn \1|p"; mv lexicon_catalog.tmp lexicon_catalog.txt
	$v printf "%s\n" $(COMPLETIONS_DIR_FILES) | $(SED) -n \
		-e "s|[^ ]*/\([a-z][a-z_-]*\).fish|'\1'|p" | $(FGREP) -vx -f lexicon_catalog.txt | $(SED) >>lexicon.tmp -n \
		-e 'w lexicon_catalog.tmp' \
		-e "s|'\(.*\)'|cmnd \1|p"; cat lexicon_catalog.tmp >> lexicon_catalog.txt;
	$v printf "%s\n" $(FUNCTIONS_DIR_FILES) | $(SED) -n \
		-e "s|[^ ]*/\([a-z][a-z_-]*\).fish|'\1'|p" | $(FGREP) -vx -f lexicon_catalog.txt | $(SED) >>lexicon.tmp -n \
		-e 'w lexicon_catalog.tmp' \
		-e "s|'\(.*\)'|func \1|p";
	$v $(SED) <share/functions/__fish_config_interactive.fish >>lexicon.tmp -n  \
		-e '/set_default/s/.*\(fish_[a-z][a-z_]*\).*$$/clrv \1/p'; \
	    $(SED) <lexicon_filter.in >>lexicon.tmp -n \
		-e '/^#.!#/s/^#.!# \(.... [a-z][a-z_]*\)/\1/p';
	$v mv lexicon.tmp lexicon.txt; rm -f lexicon_catalog.tmp lexicon_catalog.txt;

#
# Compile Doxygen Input Filter from the lexicon. This is an executable sed
# script as Doxygen opens it via popen()(3) Input (doc.h) is piped through and
# matching words inside /fish../endfish blocks are marked up, contextually,
# with custom Doxygen commands in the form of @word_type{content}. These are
# trapped by ALIASES in the various Doxyfiles, allowing the content to be
# transformed depending on output type (HTML, man page, developer docs). In
# HTML, a style context can be applied through the /fish{style} block and
# providing suitable CSS in user_doc.css.in
#
lexicon_filter: lexicon.txt lexicon_filter.in | show-SED
	$v rm -f $@.tmp $@
	@echo "  SED      $(em)$@.tmp$(sgr0)"
# Set the shebang as sed can reside in multiple places.
	$v $(SED) <$@.in >$@.tmp -e 's|@sed@|'$(SED)'|'
# Scan through the lexicon, transforming each line to something useful to Doxygen.
	$v if echo x | $(SED) "/[[:<:]]x/d" 2>/dev/null; then \
		WORDBL='[[:<:]]'; WORDBR='[[:>:]]'; \
	else \
		WORDBL='\\<'; WORDBR='\\>'; \
	fi; $(SED) <lexicon.txt >>$@.tmp -n -e "s|^\([a-z][a-z][a-z][a-z]\) \([a-z_-]*\)$$|s,$$WORDBL\2$$WORDBR,@\1{\2},g|p" -e '$$G;s/.*\n/b tidy/p';
	$v mv $@.tmp $@; test -x $@ || chmod a+x $@;


#
# doc.h is a compilation of the various snipptes of text used both for
# the user documentation and for internal help functions into a single
# file that can be parsed by Doxygen to generate the user
# documentation.
#
doc.h: $(HDR_FILES)
	@echo " HDR_FILES $(em)$@$(sgr0)"
	$v cat $(HDR_FILES) >$@

#
# This rule creates complete doxygen headers from each of the various
# snipptes of text used both for the user documentation and for
# internal help functions, that can be parsed to Doxygen to generate
# the internal help function text.
#
%.doxygen:%.txt
	@echo "  cat *     $(em)$@$(sgr0)"
	$v echo  "/** \page " `basename $*` >$@;
	$v cat $*.txt >>$@;
	$v echo "*/" >>$@

#
# Depend on Makefile because I don't see a better way of rebuilding
# if any of the paths change.
#
%: %.in Makefile FISH-BUILD-VERSION-FILE | show-prefix show-sysconfdir show-docdir show-extra_completionsdir show-extra_functionsdir show-extra_confdir show-prefix show-FISH_BUILD_VERSION
	@echo "  SED      $(em)$@$(sgr0)"

	$v $(SED) <$< >$@ \
		-e "s,@sysconfdir\@,$(sysconfdir),g" \
		-e "s,@datadir\@,$(datadir),g" \
		-e "s,@docdir\@,$(docdir),g" \
		-e "s,@extra_completionsdir\@,$(extra_completionsdir),g" \
		-e "s,@extra_functionsdir\@,$(extra_functionsdir),g" \
		-e "s,@extra_confdir\@,$(extra_confdir),g" \
		-e "s|@configure_input\@|$@, generated from $@.in by the Makefile. DO NOT MANUALLY EDIT THIS FILE!|g" \
		-e "s,@prefix\@,$(prefix),g" \
		-e "s,@fish_build_version\@,$(FISH_BUILD_VERSION),g" \


#
# Compile translation files to binary format
#
%.gmo:
	@echo "  msgfmt   $(em)$@$(sgr0)"
	$v msgfmt -o $@ $*.po

#
# Update existing po file or copy messages.pot
#
%.po:messages.pot
	@echo "  msgmerge $(em)$@$(sgr0)"
	$v if test -f $*.po; then \
		msgmerge -U --backup=existing $*.po messages.pot;\
	else \
		cp messages.pot $*.po;\
	fi

#
# Create a template translation object
#
messages.pot: $(wildcard src/*.cpp src/*.h share/completions/*.fish share/functions/*.fish)
	@echo "  xgettext $(em)$@$(sgr0)"
	xgettext -k_ -kN_ $(wildcard src/*.cpp src/*.h) -o messages.pot
	$v xgettext -j -k_ -kN_ -k--description -LShell --from-code=UTF-8 $(wildcard share/completions/*.fish share/functions/*.fish) share/fish.config -o messages.pot

ifdef EXTRA_PCRE2
src/builtin_string.cpp: $(PCRE2_H)
endif

#
# Generate the internal help functions by making doxygen create
# man-pages. The convertion path looks like this:
#
#   .txt file
#       ||
#     (make)
#       ||
#       \/
#  .doxygen file
#       ||
#    (doxygen)
#       ||
#       \/
#    roff file
#       ||
# (__fish_print_help)
#       ||
#       \/
#   formated text
#   with escape
#    sequences
#
#
# There ought to be something simpler.
#
share/man: $(HELP_SRC) lexicon_filter | show-FISH_BUILD_VERSION show-SED
	-$v $(MKDIR_P) share/man
	@echo "  doxygen  $(em)$@$(sgr0)"
	$v touch share/man
	-$v rm -Rf share/man/man1
	$v echo "$(dim)" && PROJECT_NUMBER=`echo $(FISH_BUILD_VERSION) \
		| $(SED) "s/-.*//"` INPUT_FILTER=./lexicon_filter build_tools/build_documentation.sh Doxyfile.help ./doc_src ./share;

#
# The build rules for installing/uninstalling fish
#

check-legacy-binaries:
	@echo "Checking for legacy binaries..."
	$v KR_LOC=$(prefix)/bin/key_reader;\
	if test -x "$$KR_LOC" && env TERM=dumb "$$KR_LOC" cr | grep -q 26; then\
		echo "$(red)A key_reader binary was found. You might want to remove this, and use 'fish_key_reader':";\
		echo "    '$$KR_LOC'$(sgr0)";\
	fi;
	$v SEQLOC=$(prefix)/bin/seq;\
	if test -f "$$SEQLOC" && grep -q '\(^#!/.*/fish\|^#!/usr/bin/env fish\)' "$$SEQLOC"; then\
		echo "$(red)An outdated seq from a previous fish install was found. You should remove it with:";\
		echo "    rm '$$SEQLOC'$(sgr0)";\
	fi;
	$v SETCOLOR_LOC=$(prefix)/bin/set_color;\
	if test -x "$$SETCOLOR_LOC" && $$SETCOLOR_LOC -v 2>&1 >/dev/null | grep -q "^set_color, version "; then\
		echo "$(red)An outdated set_color from a previous fish install was found. You should remove it with:";\
		echo "    rm '$$SETCOLOR_LOC'$(sgr0)";\
	fi;
	$v MIMEDB_LOC=$(prefix)/bin/mimedb;\
	if test -x "$$MIMEDB_LOC" && $$MIMEDB_LOC --version 2>&1 | grep -q "^mimedb, version "; then\
		echo "$(red)An outdated mimedb binary from a previous fish install was found. You should remove it with:";\
		echo "    rm '$$MIMEDB_LOC'$(sgr0)";\
	fi;
	$v FISHD_LOC=$(prefix)/bin/fishd;\
	if test -x "$$FISHD_LOC" && $$FISHD_LOC --version 2>&1 | grep -q "^fishd: fishd, version "; then\
		echo "$(red)An outdated fishd binary from a previous fish install was found. You should remove it with:";\
		echo "    rm '$$FISHD_LOC'$(sgr0)";\
	fi;
	$v true;
.PHONY: check-legacy-binaries

install: all install-force | check-legacy-binaries
	@echo
	@echo "$(bo)fish is now installed on your system.$(sgr0)"
	@echo "To run fish, type $(bo)$(green)fish$(sgr0) in your terminal."
	@echo "$(T_YELLOW)Even if you are already in fish, you should now start a new fish session.$(sgr0)"
	@echo
	@if type chsh >/dev/null 2>&1; then \
		echo To use fish as your login shell:; \
		grep -q -- "$(DESTDIR)$(bindir)/fish" /etc/shells || echo  \* add the line \'$(DESTDIR)$(bindir)/fish\' to the file \'/etc/shells\'; \
		echo "  * run $(yellow)chsh -s $(DESTDIR)$(bindir)/fish$(sgr0)"; \
		echo; \
	fi;
	@if type chcon >/dev/null 2>&1; then \
		echo If you have SELinux enabled, you may need to manually update the security policy:; \
		echo \* use the command \'chcon -t shell_exec_t $(DESTDIR)$(bindir)/fish\'.; \
		echo; \
	fi;
	@echo "To set your colors, run $(green)$(bo)fish_config$(sgr0)"
	@echo "To scan your man pages for completions, run $(green)$(bo)fish_update_completions$(sgr0)"
	@echo "To accept autosuggestions (in $(dim)grey$(sgr0)) as you type, hit $(bo)ctrl-F$(sgr0) or right arrow key."
	@echo
	@echo "$(bo)Have fun! <><$(sgr0)"
.PHONY: install

#
# Xcode install
#
xcode-install:
	rm -Rf /tmp/fish_build
	xcrun xcodebuild install DSTROOT=/tmp/fish_build
	ditto /tmp/fish_build
.PHONY: xcode-install

#
# Actually do the installation. These '||true', '||:' lines are to prevent installs
# from failing for (e.g.) missing man pages or extra_dirs outside the
# writeable prefix.
#
install-force: all install-translations | show-datadir show-sysconfdir show-extra_completionsdir show-extra_functionsdir show-extra_confdir show-mandir
	$v $(INSTALL) -m 755 -d $(DESTDIR)$(bindir)
	$v for i in $(PROGRAMS); do\
		$(INSTALL) -m 755 $$i $(DESTDIR)$(bindir);\
		echo " Installing $(bo)$$i$(sgr0)";\
		true ;\
	done;
	@echo "Creating sysconfdir tree"
	$v $(INSTALL) -m 755 -d $(DESTDIR)$(sysconfdir)/fish
	$v $(INSTALL) -m 755 -d $(DESTDIR)$(sysconfdir)/fish/conf.d
	$v $(INSTALL) -m 644 etc/config.fish $(DESTDIR)$(sysconfdir)/fish/
	@echo "Creating datadir tree"
	$v $(INSTALL) -m 755 -d $(DESTDIR)$(datadir)/fish
	$v $(INSTALL) -m 755 -d $(DESTDIR)$(datadir)/fish/completions
	$v $(INSTALL) -m 755 -d $(DESTDIR)$(datadir)/fish/functions
	$v $(INSTALL) -m 755 -d $(DESTDIR)$(datadir)/fish/groff
	$v $(INSTALL) -m 755 -d $(DESTDIR)$(datadir)/fish/man/man1
	$v $(INSTALL) -m 755 -d $(DESTDIR)$(datadir)/fish/tools
	$v $(INSTALL) -m 755 -d $(DESTDIR)$(datadir)/fish/tools/web_config
	$v $(INSTALL) -m 755 -d $(DESTDIR)$(datadir)/fish/tools/web_config/js
	$v $(INSTALL) -m 755 -d $(DESTDIR)$(datadir)/fish/tools/web_config/partials
	$v $(INSTALL) -m 755 -d $(DESTDIR)$(datadir)/fish/tools/web_config/sample_prompts
	$v $(INSTALL) -m 644 share/config.fish $(DESTDIR)$(datadir)/fish/
	$v $(INSTALL) -m 644 share/__fish_build_paths.fish    $(DESTDIR)$(datadir)/fish/
	$v $(INSTALL) -m 755 -d $(DESTDIR)$(datadir)/pkgconfig
	@echo "Creating placeholder vendor/'extra_' directories"
	$v $(INSTALL) -m 755 -d $(DESTDIR)$(extra_completionsdir) ||:
	$v $(INSTALL) -m 755 -d $(DESTDIR)$(extra_functionsdir) ||:
	$v $(INSTALL) -m 755 -d $(DESTDIR)$(extra_confdir) ||:
	@echo "Installing pkgconfig file"
	$v $(INSTALL) -m 644 fish.pc $(DESTDIR)$(datadir)/pkgconfig
	@echo "Installing the $(bo)fish completion library$(sgr0)...";
	$v $(INSTALL) -m 644 $(COMPLETIONS_DIR_FILES:%='%') $(DESTDIR)$(datadir)/fish/completions/
	@echo "Installing $(bo)fish functions$(sgr0)";
	$v $(INSTALL) -m 644 $(FUNCTIONS_DIR_FILES:%='%') $(DESTDIR)$(datadir)/fish/functions/
	@echo "Installing $(bo)man pages$(sgr0)";
	$v $(INSTALL) -m 644 share/groff/* $(DESTDIR)$(datadir)/fish/groff/
	$v test -z "$(wildcard share/man/man1/*.1)" || $(INSTALL) -m 644 $(filter-out $(addprefix share/man/man1/, $(CONDEMNED_PAGES)), $(wildcard share/man/man1/*.1)) $(DESTDIR)$(datadir)/fish/man/man1/
	@echo "Installing helper tools";
	$v $(INSTALL) -m 755 share/tools/*.py $(DESTDIR)$(datadir)/fish/tools/
	$v $(INSTALL) -m 644 share/tools/web_config/*.* $(DESTDIR)$(datadir)/fish/tools/web_config/
	$v $(INSTALL) -m 644 share/tools/web_config/js/*.* $(DESTDIR)$(datadir)/fish/tools/web_config/js/
	$v $(INSTALL) -m 644 share/tools/web_config/partials/* $(DESTDIR)$(datadir)/fish/tools/web_config/partials/
	$v $(INSTALL) -m 644 share/tools/web_config/sample_prompts/*.fish $(DESTDIR)$(datadir)/fish/tools/web_config/sample_prompts/
	$v $(INSTALL) -m 755 share/tools/web_config/*.py $(DESTDIR)$(datadir)/fish/tools/web_config/
	@echo "Installing online user documentation";
	$v $(INSTALL) -m 755 -d $(DESTDIR)$(docdir)
	$v for i in user_doc/html/* CHANGELOG.md; do \
		if test -f $$i; then \
			$(INSTALL) -m 644 $$i $(DESTDIR)$(docdir); \
		fi; \
	done;
	@echo "Installing more man pages";
	$v $(INSTALL) -m 755 -d $(DESTDIR)$(mandir)/man1;
	$v for i in $(MANUALS); do \
		$(INSTALL) -m 644 $$i $(DESTDIR)$(mandir)/man1/; \
		true; \
	done;
.PHONY: install-force

#
# Uninstall this fish version
#
uninstall: uninstall-translations | show-prefix show-bindir show-sysconfdir show-datadir show-docdir show-mandir
	@echo
	@echo "$(bo)$(yellow)Uninstalling fish$(sgr0) from configured \$$prefix: $(bo)$(prefix)$(sgr0)"
	@echo
	@echo "Deleting programs: [ $(bo)$(PROGRAMS)$(sgr0) ] in $(em)$(bindir)$(sgr0)"
	-$v for i in $(PROGRAMS); do \
		rm -f $(DESTDIR)$(bindir)/$$i; \
	done;
	@echo "Deleting configuration: $(bo)$(DESTDIR)$(sysconfdir)/fish/*$(sgr0)"
	-$v rm -rf $(DESTDIR)$(sysconfdir)/fish
	@echo
	@echo "In 5 seconds, $(red)all data$(sgr0) (includes functions, completions, tools) in"
	@echo $$"\t$(bo)$(DESTDIR)$(datadir)/fish$(sgr0) will be deleted!"
	@echo
	@echo $$"If you put things there, $(red)stop now!$(sgr0) $(bo)\\c"
	@echo $$"$(bo)5$(sgr0) \\c"
	@sleep 1
	@echo $$"$(bo)4$(sgr0) \\c"
	@sleep 1
	@echo $$"$(bo)3$(sgr0) \\c"
	@sleep 1
	@echo $$"$(bo)2$(sgr0) \\c"
	@sleep 1
	@echo $$"$(bo)1$(sgr0) \\c"
	@sleep 1
	@echo ...
	@sleep 2
	@echo "... deleting $(bo)$(DESTDIR)$(datadir)/fish/*$(sgr0)"
	-$v if test -d $(DESTDIR)$(datadir)/fish; then \
		rm -rf $(DESTDIR)$(datadir)/fish; \
	fi
	@echo
	@echo "Deleting documentation: $(bo)$(DESTDIR)$(docdir)/*$(sgr0)"
	-$v if test -d $(DESTDIR)$(docdir); then \
		rm -rf $(DESTDIR)$(docdir);\
	fi
	@echo
	@echo "Deleting pkgconfig file: $(bo)$(DESTDIR)$(datadir)/pkgconfig/fish.pc$(sgr0)"
	-$v if test -f $(DESTDIR)$(datadir)/pkgconfig/fish.pc; then \
		rm -f $(DESTDIR)$(datadir)/pkgconfig/fish.pc;\
	fi
	@echo
	@echo $$"Deleting \\c"
	@echo "[ $(bo)"$(basename $(MANUALS))$(sgr0) $$"] in \\c"
	@echo "$(em)$(mandir)/man1$(sgr0)"
	-$v for i in $(MANUALS); do \
		rm -rf "$(DESTDIR)$(mandir)/man1/"$$$(basename $i)$$$(wildcard .*);
	done;
	@echo
	@echo "$(green)Fish (likely) unintalled$(sgr0)"
	@echo
	@echo "$(bo)./configure --prefix=$(sgr0) to uninstall fish from a different prefix"
.PHONY: uninstall

install-translations: $(TRANSLATIONS) | show-HAVE_GETTEXT
ifeq ($(HAVE_GETTEXT), 1)
	@echo "Installing translations..."
	$v for i in $(TRANSLATIONS); do \
		$(INSTALL) -m 755 -d $(DESTDIR)$(localedir)/`basename $$i .gmo`/LC_MESSAGES; \
		$(INSTALL) -m 644 $$i $(DESTDIR)$(localedir)/`basename $$i .gmo`/LC_MESSAGES/fish.mo; \
	done
endif
.PHONY: install-translations

uninstall-translations: show-DESTDIR show-localedir
	$v rm -f $(DESTDIR)$(localedir)/*/LC_MESSAGES/fish.mo
.PHONY: uninstall-translations

#
# The build rules for all the commands
#

#
# How basic files get compiled
#
obj/%.o: src/%.cpp | show-CXX show-CXXFLAGS show-CPPFLAGS obj
	@echo "  CXX      $(em)$@$(sgr0)"
	$v $(CXX) $(CPPFLAGS) $(CXXFLAGS) -c $< -o $@

#
# obj directory
#
obj: | show-MKDIR_P
	@echo "  MKDIR_P   $(em)$@$(sgr0)"
	$v $(MKDIR_P) obj

#
# Build the fish program.
#
fish: obj/fish.o $(FISH_OBJS) $(EXTRA_PCRE2)
	@echo "  CXX LD   $(em)$@$(sgr0)"
	$v $(CXX) $(CPPFLAGS) $(CXXFLAGS) $(LDFLAGS_FISH) $(FISH_OBJS) obj/fish.o $(LIBS) -o $@

$(PCRE2_LIB): $(PCRE2_H)
	@echo "  MAKE     $(em)$@$(sgr0)"
	$v $(MAKE) V=$(V) -C $(PCRE2_DIR) libpcre2-$(PCRE2_WIDTH).la

$(PCRE2_H):
	@echo "  autoconf $(em)$@$(sgr0)"
	$v (cd $(PCRE2_DIR) && ./config.status)

#
# Build the fish_tests program.
#
fish_tests: $(FISH_TESTS_OBJS) $(EXTRA_PCRE2)
	@echo "  CXX LD   $(em)$@$(sgr0)"
	$v $(CXX) $(CXXFLAGS) $(LDFLAGS_FISH) $(FISH_TESTS_OBJS) $(LIBS) -o $@

#
# Build the fish_indent program.
#
fish_indent: $(FISH_INDENT_OBJS) $(EXTRA_PCRE2)
	@echo "  CXX LD   $(em)$@$(sgr0)"
	$v $(CXX) $(CXXFLAGS) $(LDFLAGS) $(FISH_INDENT_OBJS) $(LIBS) -o $@

#
# Build the fish_key_reader program to show input from the terminal.
#
fish_key_reader: $(FISH_KEYREAD_OBJS) $(EXTRA_PCRE2)
	@echo "  CXX LD   $(em)$@$(sgr0)"
	$v $(CXX) $(CXXFLAGS) $(LDFLAGS_FISH) $^ $(LIBS) -o $@

#
# Update dependencies
# Unfortunately makedepend cannot handle source files in one directory
# and object files in another. So we have to cons up a fake directory
# tree and run it there. Note that some .cpp files do not result in
# objects because they are #include'd directly. In that case we need to
# leave them in the 'header' directory, so they get picked up by the
# dependencies. So we put everything in the header directory and move out
# exactly the files that result in objects, leaving the #include'd files
# behind.
#
depend: | show-MKDIR_P
	@echo "  CXX LD   $(em)$@$(sgr0)"
	$v $(MKDIR_P) /tmp/fish_make_depend/src
	# This is ran only once in a blue moon - full verbosity so we are reminded what it does.
	cp $(wildcard src/*.cpp src/*.h) /tmp/fish_make_depend/src
	cp config.h /tmp/fish_make_depend/
	mv $(subst obj/,/tmp/fish_make_depend/src/,$(FISH_ALL_OBJS:.o=.cpp)) /tmp/fish_make_depend/
	cd /tmp/fish_make_depend && makedepend -f$(CURDIR)/Makefile.in -pobj/ -Y -Isrc *.cpp
	rm -Rf /tmp/fish_make_depend
	$v ./config.status
.PHONY: depend

#
# Lint the code. This only deals with C++
# TODO - why not have the Makefile run lint.fish on actual files itself (generate a report target?)
#
lint:
	$v build_tools/lint.fish "$(CXX)" $(CXXFLAGS) $(CPPFLAGS)
lint-all:
	$v build_tools/lint.fish "$(CXX)" --all $(CXXFLAGS) $(CPPFLAGS)
.PHONY: lint lint-all

#
# Run the code through the style refomatter. This handles both C++ files and
# fish scripts (*.fish).
#
style:
	$v build_tools/style.fish
style-all:
	$v build_tools/style.fish --all
.PHONY: style style-all

#
# Restore the source tree to the state right after extracting a tarball.
#
distclean: clean
	$v test ! -f $(PCRE2_DIR)/Makefile || \
	  $(MAKE) V=$(V) -C $(PCRE2_DIR) distclean ||:
	$v rm -rf config.status config.log config.h Makefile autom4te.cache aclocal.m4
.PHONY: distclean

#
# Remove everything built by the Makefile, but not things that are created by
# the configure script.
#
# Don't delete the docs unless we have Doxygen installed We provide pre-built
# docs in the tarball, and if they get deleted we won't be able to regenerate
# them.
#
clean:
	@echo "$(bo)Removing everything built by the Makefile...$(sgr0)"
# PCRE's make clean has a few slightly annoying exceptions to the V= rule. If V=0
# send all output to /dev/null - unless there's an error, in which case run it again not silenced.
ifeq ($(V), 0 )
	@test ! -f $(PCRE2_DIR)/Makefile || \
	  $(MAKE) -C $(PCRE2_DIR) clean ||:
else
	@test ! -f $(PCRE2_DIR)/Makefile || \
	  $(MAKE) -s -C $(PCRE2_DIR) clean > /dev/null || \
	  $(MAKE) -s -C $(PCRE2_DIR) clean ||:
endif
	$v rm -f obj/*.o *.o doc.h doc.tmp
	$v rm -f doc_src/*.doxygen doc_src/*.cpp doc_src/*.o doc_src/commands.hdr
	$v rm -f tests/tmp.err tests/tmp.out tests/tmp.status tests/foo.txt
	$v rm -f $(PROGRAMS) fish_tests fish_key_reader
	$v rm -f command_list.txt command_list_toc.txt toc.txt
	$v rm -f doc_src/index.hdr doc_src/commands.hdr
	$v rm -f lexicon_filter lexicon.txt lexicon.log
	$v rm -f compile_commands.json xcodebuild.log
	$v rm -f FISH-BUILD-VERSION-FILE fish.pc share/__fish_build_paths.fish
	$v if test "$(HAVE_DOXYGEN)" = 1; then \
		rm -rf doc user_doc share/man; \
	fi
	$v rm -f po/*.gmo
	$v rm -rf obj build test
.PHONY: clean

# For silent build
# These rules need to stay at the end - $v won't work after this.
# if V=0:
#   $v cmd ⇒ @cmd
V0 := @
# if V=1
#   $v cmd ⇒ cmd
V1 :=
v = $(V$(V))

# DO NOT DELETE THIS LINE -- make depend depends on it.

obj/autoload.o: config.h src/autoload.h src/common.h src/fallback.h
obj/autoload.o: src/signal.h src/lru.h src/env.h src/exec.h src/wutil.h
obj/builtin.o: config.h src/builtin.h src/common.h src/fallback.h
obj/builtin.o: src/signal.h src/builtin_commandline.h src/builtin_complete.h
obj/builtin.o: src/builtin_jobs.h src/builtin_printf.h src/builtin_set.h
obj/builtin.o: src/builtin_set_color.h src/builtin_string.h
obj/builtin.o: src/builtin_test.h src/builtin_ulimit.h src/complete.h
obj/builtin.o: src/env.h src/event.h src/exec.h src/expand.h
obj/builtin.o: src/parse_constants.h src/function.h src/highlight.h
obj/builtin.o: src/color.h src/history.h src/wutil.h src/input.h src/intern.h
obj/builtin.o: src/io.h src/parse_util.h src/tokenizer.h src/parser.h
obj/builtin.o: src/parse_tree.h src/proc.h src/parser_keywords.h src/path.h
obj/builtin.o: src/reader.h src/wcstringutil.h src/wgetopt.h
obj/builtin_commandline.o: config.h src/builtin.h src/common.h src/fallback.h
obj/builtin_commandline.o: src/signal.h src/input.h src/env.h src/io.h
obj/builtin_commandline.o: src/parse_util.h src/parse_constants.h
obj/builtin_commandline.o: src/tokenizer.h src/proc.h src/parse_tree.h
obj/builtin_commandline.o: src/reader.h src/complete.h src/highlight.h
obj/builtin_commandline.o: src/color.h src/util.h src/wgetopt.h src/wutil.h
obj/builtin_complete.o: config.h src/builtin.h src/common.h src/fallback.h
obj/builtin_complete.o: src/signal.h src/complete.h src/env.h src/io.h
obj/builtin_complete.o: src/parse_constants.h src/parse_util.h
obj/builtin_complete.o: src/tokenizer.h src/parser.h src/event.h src/expand.h
obj/builtin_complete.o: src/parse_tree.h src/proc.h src/reader.h
obj/builtin_complete.o: src/highlight.h src/color.h src/wgetopt.h src/wutil.h
obj/builtin_jobs.o: config.h src/builtin.h src/common.h src/fallback.h
obj/builtin_jobs.o: src/signal.h src/io.h src/proc.h src/parse_tree.h
obj/builtin_jobs.o: src/parse_constants.h src/tokenizer.h src/wgetopt.h
obj/builtin_jobs.o: src/wutil.h
obj/builtin_printf.o: config.h src/builtin.h src/common.h src/fallback.h
obj/builtin_printf.o: src/signal.h src/io.h src/proc.h src/parse_tree.h
obj/builtin_printf.o: src/parse_constants.h src/tokenizer.h src/wutil.h
obj/builtin_set.o: config.h src/builtin.h src/common.h src/fallback.h
obj/builtin_set.o: src/signal.h src/env.h src/expand.h src/parse_constants.h
obj/builtin_set.o: src/io.h src/proc.h src/parse_tree.h src/tokenizer.h
obj/builtin_set.o: src/wgetopt.h src/wutil.h
obj/builtin_set_color.o: config.h src/builtin.h src/common.h src/env.h src/fallback.h
obj/builtin_set_color.o: src/signal.h src/color.h src/io.h src/output.h
obj/builtin_set_color.o: src/proc.h src/parse_tree.h src/parse_constants.h
obj/builtin_set_color.o: src/tokenizer.h src/wgetopt.h src/wutil.h
obj/builtin_string.o: config.h src/builtin.h src/common.h src/fallback.h
obj/builtin_string.o: src/signal.h src/io.h src/parse_util.h
obj/builtin_string.o: src/parse_constants.h src/tokenizer.h src/wgetopt.h
obj/builtin_string.o: src/wildcard.h src/complete.h src/expand.h src/wutil.h
obj/builtin_test.o: config.h src/builtin.h src/common.h src/fallback.h
obj/builtin_test.o: src/signal.h src/io.h src/proc.h src/parse_tree.h
obj/builtin_test.o: src/parse_constants.h src/tokenizer.h src/wutil.h
obj/builtin_ulimit.o: config.h src/builtin.h src/common.h src/fallback.h
obj/builtin_ulimit.o: src/signal.h src/io.h src/util.h src/wgetopt.h
obj/builtin_ulimit.o: src/wutil.h
obj/color.o: config.h src/color.h src/common.h src/fallback.h src/signal.h
obj/common.o: config.h src/signal.h src/common.h src/fallback.h src/expand.h
obj/common.o: src/parse_constants.h src/wildcard.h src/complete.h src/wutil.h
obj/complete.o: config.h src/autoload.h src/common.h src/fallback.h
obj/complete.o: src/signal.h src/lru.h src/builtin.h src/complete.h src/env.h
obj/complete.o: src/exec.h src/expand.h src/parse_constants.h src/function.h
obj/complete.o: src/event.h src/iothread.h src/parse_tree.h src/tokenizer.h
obj/complete.o: src/parse_util.h src/parser.h src/proc.h src/io.h src/path.h
obj/complete.o: src/util.h src/wildcard.h src/wutil.h
obj/env.o: config.h src/common.h src/fallback.h src/signal.h src/env.h
obj/env.o: src/env_universal_common.h src/wutil.h src/event.h src/expand.h
obj/env.o: src/parse_constants.h src/fish_version.h src/history.h src/input.h
obj/env.o: src/input_common.h src/path.h src/proc.h src/io.h src/parse_tree.h
obj/env.o: src/tokenizer.h src/reader.h src/complete.h src/highlight.h
obj/env.o: src/color.h src/sanity.h
obj/env_universal_common.o: config.h src/common.h src/fallback.h src/signal.h
obj/env_universal_common.o: src/env.h src/env_universal_common.h src/wutil.h
obj/env_universal_common.o: src/utf8.h src/util.h
obj/event.o: config.h src/signal.h src/common.h src/fallback.h src/event.h
obj/event.o: src/input_common.h src/io.h src/parser.h src/expand.h
obj/event.o: src/parse_constants.h src/parse_tree.h src/tokenizer.h
obj/event.o: src/proc.h src/wutil.h
obj/exec.o: config.h src/signal.h src/builtin.h src/common.h src/fallback.h
obj/exec.o: src/env.h src/exec.h src/function.h src/event.h src/io.h
obj/exec.o: src/parse_tree.h src/parse_constants.h src/tokenizer.h
obj/exec.o: src/parser.h src/expand.h src/proc.h src/postfork.h src/reader.h
obj/exec.o: src/complete.h src/highlight.h src/color.h src/wutil.h
obj/expand.o: config.h src/common.h src/fallback.h src/signal.h
obj/expand.o: src/complete.h src/env.h src/exec.h src/expand.h
obj/expand.o: src/parse_constants.h src/iothread.h src/parse_util.h
obj/expand.o: src/tokenizer.h src/path.h src/proc.h src/io.h src/parse_tree.h
obj/expand.o: src/util.h src/wildcard.h src/wutil.h
obj/fallback.o: config.h src/signal.h src/common.h src/fallback.h src/util.h
obj/fish.o: config.h src/builtin.h src/common.h src/fallback.h src/signal.h
obj/fish.o: src/env.h src/event.h src/expand.h src/parse_constants.h
obj/fish.o: src/fish_version.h src/function.h src/history.h src/wutil.h
obj/fish.o: src/input.h src/io.h src/parser.h src/parse_tree.h
obj/fish.o: src/tokenizer.h src/proc.h src/path.h src/reader.h src/complete.h
obj/fish.o: src/highlight.h src/color.h
obj/fish_indent.o: config.h src/color.h src/common.h src/fallback.h
obj/fish_indent.o: src/signal.h src/env.h src/fish_version.h src/highlight.h
obj/fish_indent.o: src/input.h src/output.h src/parse_constants.h
obj/fish_indent.o: src/parse_tree.h src/tokenizer.h src/print_help.h
obj/fish_indent.o: src/wutil.h
obj/fish_key_reader.o: config.h src/signal.h src/common.h src/fallback.h
obj/fish_key_reader.o: src/env.h src/input.h src/input_common.h
obj/fish_key_reader.o: src/print_help.h src/proc.h src/io.h src/parse_tree.h
obj/fish_key_reader.o: src/parse_constants.h src/tokenizer.h src/reader.h
obj/fish_key_reader.o: src/complete.h src/highlight.h src/color.h src/wutil.h
obj/fish_tests.o: config.h src/signal.h src/builtin.h src/common.h
obj/fish_tests.o: src/fallback.h src/color.h src/complete.h src/env.h
obj/fish_tests.o: src/env_universal_common.h src/wutil.h src/event.h
obj/fish_tests.o: src/expand.h src/parse_constants.h src/function.h
obj/fish_tests.o: src/highlight.h src/history.h src/input.h
obj/fish_tests.o: src/input_common.h src/io.h src/iothread.h src/lru.h
obj/fish_tests.o: src/pager.h src/reader.h src/screen.h src/parse_tree.h
obj/fish_tests.o: src/tokenizer.h src/parse_util.h src/parser.h src/proc.h
obj/fish_tests.o: src/path.h src/utf8.h src/wcstringutil.h src/wildcard.h
obj/fish_version.o: src/fish_version.h
obj/function.o: config.h src/autoload.h src/common.h src/fallback.h
obj/function.o: src/signal.h src/lru.h src/env.h src/event.h src/function.h
obj/function.o: src/intern.h src/parser_keywords.h src/reader.h
obj/function.o: src/complete.h src/highlight.h src/color.h
obj/function.o: src/parse_constants.h src/wutil.h
obj/highlight.o: config.h src/builtin.h src/common.h src/fallback.h
obj/highlight.o: src/signal.h src/color.h src/env.h src/expand.h
obj/highlight.o: src/parse_constants.h src/function.h src/event.h
obj/highlight.o: src/highlight.h src/history.h src/wutil.h src/output.h
obj/highlight.o: src/parse_tree.h src/tokenizer.h src/parse_util.h src/path.h
obj/highlight.o: src/wildcard.h src/complete.h
obj/history.o: config.h src/common.h src/fallback.h src/signal.h src/env.h
obj/history.o: src/history.h src/wutil.h src/io.h src/iothread.h src/lru.h
obj/history.o: src/parse_constants.h src/parse_tree.h src/tokenizer.h
obj/history.o: src/path.h src/reader.h src/complete.h src/highlight.h
obj/history.o: src/color.h
obj/input.o: config.h src/common.h src/fallback.h src/signal.h src/env.h
obj/input.o: src/event.h src/input.h src/input_common.h src/io.h src/output.h
obj/input.o: src/color.h src/parser.h src/expand.h src/parse_constants.h
obj/input.o: src/parse_tree.h src/tokenizer.h src/proc.h src/reader.h
obj/input.o: src/complete.h src/highlight.h src/wutil.h
obj/input_common.o: config.h src/common.h src/fallback.h src/signal.h
obj/input_common.o: src/env.h src/env_universal_common.h src/wutil.h
obj/input_common.o: src/input_common.h src/iothread.h src/util.h
obj/intern.o: config.h src/common.h src/fallback.h src/signal.h src/intern.h
obj/io.o: config.h src/common.h src/fallback.h src/signal.h src/exec.h
obj/io.o: src/io.h src/wutil.h
obj/iothread.o: config.h src/signal.h src/common.h src/fallback.h
obj/iothread.o: src/iothread.h
obj/kill.o: config.h src/common.h src/fallback.h src/signal.h
obj/output.o: config.h src/color.h src/common.h src/fallback.h src/signal.h
obj/output.o: src/env.h src/output.h src/wutil.h
obj/pager.o: config.h src/common.h src/fallback.h src/signal.h src/complete.h
obj/pager.o: src/highlight.h src/color.h src/env.h src/pager.h src/reader.h
obj/pager.o: src/parse_constants.h src/screen.h src/util.h src/wutil.h
obj/parse_execution.o: config.h src/builtin.h src/common.h src/fallback.h
obj/parse_execution.o: src/signal.h src/complete.h src/env.h src/event.h
obj/parse_execution.o: src/exec.h src/expand.h src/parse_constants.h
obj/parse_execution.o: src/function.h src/io.h src/parse_execution.h
obj/parse_execution.o: src/parse_tree.h src/tokenizer.h src/proc.h
obj/parse_execution.o: src/parse_util.h src/parser.h src/path.h src/reader.h
obj/parse_execution.o: src/highlight.h src/color.h src/util.h src/wildcard.h
obj/parse_execution.o: src/wutil.h
obj/parse_productions.o: config.h src/common.h src/fallback.h src/signal.h
obj/parse_productions.o: src/parse_constants.h src/parse_productions.h
obj/parse_productions.o: src/parse_tree.h src/tokenizer.h
obj/parse_tree.o: config.h src/common.h src/fallback.h src/signal.h
obj/parse_tree.o: src/parse_constants.h src/parse_productions.h
obj/parse_tree.o: src/parse_tree.h src/tokenizer.h src/proc.h src/io.h
obj/parse_tree.o: src/wutil.h
obj/parse_util.o: config.h src/builtin.h src/common.h src/fallback.h
obj/parse_util.o: src/signal.h src/expand.h src/parse_constants.h
obj/parse_util.o: src/parse_tree.h src/tokenizer.h src/parse_util.h
obj/parse_util.o: src/util.h src/wildcard.h src/complete.h src/wutil.h
obj/parser.o: config.h src/common.h src/fallback.h src/signal.h src/env.h
obj/parser.o: src/event.h src/expand.h src/parse_constants.h src/function.h
obj/parser.o: src/intern.h src/parse_execution.h src/io.h src/parse_tree.h
obj/parser.o: src/tokenizer.h src/proc.h src/parse_util.h src/parser.h
obj/parser.o: src/reader.h src/complete.h src/highlight.h src/color.h
obj/parser.o: src/sanity.h src/wutil.h
obj/parser_keywords.o: config.h src/common.h src/fallback.h src/signal.h
obj/parser_keywords.o: src/parser_keywords.h
obj/path.o: config.h src/common.h src/fallback.h src/signal.h src/env.h
obj/path.o: src/expand.h src/parse_constants.h src/path.h src/wutil.h
obj/postfork.o: config.h src/signal.h src/common.h src/fallback.h src/exec.h
obj/postfork.o: src/io.h src/iothread.h src/postfork.h src/proc.h
obj/postfork.o: src/parse_tree.h src/parse_constants.h src/tokenizer.h
obj/postfork.o: src/wutil.h
obj/print_help.o: config.h src/common.h src/fallback.h src/signal.h
obj/print_help.o: src/print_help.h
obj/proc.o: config.h src/signal.h src/common.h src/fallback.h src/event.h
obj/proc.o: src/io.h src/output.h src/color.h src/parse_tree.h
obj/proc.o: src/parse_constants.h src/tokenizer.h src/parser.h src/expand.h
obj/proc.o: src/proc.h src/reader.h src/complete.h src/highlight.h src/env.h
obj/proc.o: src/sanity.h src/util.h src/wutil.h
obj/reader.o: config.h src/signal.h src/color.h src/common.h src/fallback.h
obj/reader.o: src/complete.h src/env.h src/event.h src/exec.h src/expand.h
obj/reader.o: src/parse_constants.h src/function.h src/highlight.h
obj/reader.o: src/history.h src/wutil.h src/input.h src/input_common.h
obj/reader.o: src/intern.h src/io.h src/iothread.h src/kill.h src/output.h
obj/reader.o: src/pager.h src/reader.h src/screen.h src/parse_tree.h
obj/reader.o: src/tokenizer.h src/parse_util.h src/parser.h src/proc.h
obj/reader.o: src/sanity.h src/util.h
obj/sanity.o: config.h src/common.h src/fallback.h src/signal.h src/history.h
obj/sanity.o: src/wutil.h src/kill.h src/proc.h src/io.h src/parse_tree.h
obj/sanity.o: src/parse_constants.h src/tokenizer.h src/reader.h
obj/sanity.o: src/complete.h src/highlight.h src/color.h src/env.h
obj/sanity.o: src/sanity.h
obj/screen.o: config.h src/common.h src/fallback.h src/signal.h
obj/screen.o: src/highlight.h src/color.h src/env.h src/output.h src/pager.h
obj/screen.o: src/complete.h src/reader.h src/parse_constants.h src/screen.h
obj/screen.o: src/util.h
obj/signal.o: config.h src/signal.h src/common.h src/fallback.h src/event.h
obj/signal.o: src/proc.h src/io.h src/parse_tree.h src/parse_constants.h
obj/signal.o: src/tokenizer.h src/reader.h src/complete.h src/highlight.h
obj/signal.o: src/color.h src/env.h src/wutil.h
obj/tokenizer.o: config.h src/common.h src/fallback.h src/signal.h
obj/tokenizer.o: src/tokenizer.h src/wutil.h
obj/utf8.o: config.h src/common.h src/fallback.h src/signal.h src/utf8.h
obj/util.o: config.h src/common.h src/fallback.h src/signal.h src/util.h
obj/util.o: src/wutil.h
obj/wcstringutil.o: config.h src/common.h src/fallback.h src/signal.h
obj/wcstringutil.o: src/wcstringutil.h
obj/wgetopt.o: config.h src/common.h src/fallback.h src/signal.h
obj/wgetopt.o: src/wgetopt.h src/wutil.h
obj/wildcard.o: config.h src/common.h src/fallback.h src/signal.h
obj/wildcard.o: src/complete.h src/expand.h src/parse_constants.h
obj/wildcard.o: src/reader.h src/highlight.h src/color.h src/env.h
obj/wildcard.o: src/wildcard.h src/wutil.h
obj/wutil.o: config.h src/common.h src/fallback.h src/signal.h src/wutil.h