forked from umake/make
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
7275 lines (6397 loc) · 285 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
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
#!/usr/bin/make -f
# Ultimate Makefile
########################################################################
# Copyright 2015 RCF #
# #
# Licensed under the Apache License, Version 2.0 (the "License"); #
# you may not use this file except in compliance with the License. #
# You may obtain a copy of the License at #
# #
# http://www.apache.org/licenses/LICENSE-2.0 #
# #
# Unless required by applicable law or agreed to in writing, software #
# distributed under the License is distributed on an "AS IS" BASIS, #
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or #
# implied. #
# See the License for the specific language governing permissions and #
# limitations under the License. #
########################################################################
# Make version
ifneq ($(firstword $(shell $(firstword $(MAKE)) --version)),GNU)
$(error "Ultimate Makefile requires GNU Make. Please install it.")
endif
# Default goal
.DEFAULT_GOAL := all
#//////////////////////////////////////////////////////////////////////#
#%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%#
#''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''#
# USER CONFIGURATION #
#......................................................................#
#%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%#
#\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\#
########################################################################
## PROGRAM ##
########################################################################
# Project setting
PROJECT := Default
VERSION := 0.1.0
# Package info
AUXFILES :=
MAINTAINER_NAME := Your Name
MAINTAINER_MAIL := [email protected]
COPYRIGHT := $(MAINTAINER_NAME)
SYNOPSIS := default short synopsis
DESCRIPTION := default long description
# Debian package
DEB_PROJECT := default
DEB_PRIORITY := optional
# Program settings
BIN :=
SBIN :=
LIBEXEC :=
TESTBIN :=
BENCHBIN :=
ARLIB :=
SHRLIB :=
# Documentation settings
LICENSE := LICENSE
NOTICE := NOTICE
CONTRIBUTORS := CONTRIBUTORS
DOXYFILE := Doxyfile
# Dependencies
GIT_DEPENDENCY :=
WEB_DEPENDENCY :=
# Project namespace (C/C++)
STD_NAMESPACE :=
########################################################################
## COMPILATION FLAGS ##
########################################################################
# Preprocessor options
CPPFLAGS :=
# Assembly/C/C++/Fortran options
ASFLAGS := -f elf32
CFLAGS :=
CXXFLAGS := -std=c++11
FFLAGS := -ffree-form -cpp
# Library options
ARFLAGS := -rc
SHRFLAGS := -fPIC
# Program options
LEXFLAGS :=
YACCFLAGS :=
ESQLFLAGS :=
GCOVFLAGS :=
LCOVFLAGS := -q --rc lcov_branch_coverage=1
PROFFLAGS :=
FINDFLAGS := -type d -print 2> /dev/null
SCRIPTFLAGS := /dev/null -efc
CTAGSFLAGS :=
ETAGSFLAGS :=
MAKEFLAGS += --no-print-directory
# Analysis lint options
CALFLAGS := --quiet --enable=style
FALFLAGS :=
CXXALFLAGS := --quiet --enable=style
# Style l options
CSLFLAGS :=
FSLFLAGS :=
CXXSLFLAGS :=
# Coverage options
CPPCOVFLAGS :=
CCOVFLAGS := --coverage
FCOVFLAGS := --coverage
CXXCOVFLAGS := --coverage
# Profile options
CPPPROFFLAGS :=
CPROFFLAGS := -pg
FPROFFLAGS := -pg
CXXPROFFLAGS := -pg
########################################################################
## LINKER FLAGS ##
########################################################################
# Assembly/C/C++/Fortran options
LDFLAGS :=
LDC :=
LDF := -lgfortran
LDCXX :=
LDTEST :=
LDBENCH :=
# Library options
LDSHR := -shared
# Program options
LDLEX :=
LDYACC :=
LDESQL :=
# Coverage options
LDCOV := --coverage
# Profile options
LDPROF := -pg
########################################################################
## PATHS ##
########################################################################
# Assembly/C/C++/Fortran paths for include dirs
ASLIBS :=
CLIBS :=
CXXLIBS :=
FLIBS :=
# Program paths for include dirs
LEXLIBS :=
YACCLIBS :=
ESQLLIBS :=
# Linker paths for library dirs
LDLIBS :=
########################################################################
## RUNTIME ##
########################################################################
# Binaries
EXEC_ENV :=
EXEC_ARGS :=
# Tests
TEST_ENV :=
TEST_ARGS :=
# Benchmarks
BENC_HENV :=
BENC_HARGS :=
########################################################################
## DIRECTORIES ##
########################################################################
# Local directories
ifndef SINGLE_DIR
SRCDIR := src
DEPDIR := dep
INCDIR := include
DOCDIR := doc
DEBDIR := debian
OBJDIR := build
COVDIR := coverage
LIBDIR := lib
EXTDIR := external
SRPDIR := script
IMGDIR := img
BINDIR := bin
SBINDIR := sbin
EXECDIR := libexec
DISTDIR := dist
CONFDIR := conf
PROFDIR := profile
DATADIR := data
MAKEDIR := make
DESTDIR :=
TESTDIR := test
BENCHDIR := benchmark
LOCALEDIR := locale
else
$(foreach var,\
SRCDIR DEPDIR INCDIR OBJDIR COVDIR LIBDIR EXTDIR SRPDIR \
IMGDIR BINDIR SBINDIR DISTDIR CONFDIR PROFDIR DATADIR \
MAKEDIR TESTDIR BENCHDIR LOCALEDIR,\
$(eval $(var) := .)\
)
endif
# System directories
SYSINCDIR := /include /usr/include /usr/local/include
SYSLIBDIR := /lib /usr/lib /usr/local/lib \
/lib32 /usr/lib32 /usr/local/lib32 \
/lib64 /usr/lib64 /usr/local/lib64
SYSBINDIR := /bin /usr/bin /usr/local/bin
SYSSBINDIR := /sbin /usr/sbin /usr/local/sbin
SYSEXECDIR := /libexec /usr/libexec /usr/local/libexec
########################################################################
## EXTENSIONS ##
########################################################################
# Assembly extensions
ASMEXT := .asm .S
# Header extensions
HEXT := .h
HFEXT := .mod .MOD
HXXEXT := .H .hh .hpp .HPP .hxx .h++ .ih
# Source extensions
CEXT := .c
FEXT := .f .f77 .f90 .f95 .for .fpp .F .FOR .FPP
CXXEXT := .cc .cxx .cpp .c++ .C .CPP
INLEXT := .ii .ixx .ipp .i++ .inl
# Library extensions
LIBEXT := .a .so .dll .dylib
AREXT := .a
SHREXT := .so
# Parser/Lexer extensions
LEXEXT := .l
LEXXEXT := .ll .lpp
YACCEXT := .y
YAXXEXT := .yy .ypp
# Embedded SQL extensions
ESQLEXT := .pgc .pc
# Dependence extensions
DEPEXT := .d
EXTEXT := .dy
SYSEXT := .dep
# Coverage extensions
COVEXT := .gcno .gcda
# Profile extensions
PROFEXT := .out
# Report extension
REPEXT := .info
# Binary extensions
OBJEXT := .o
BINEXT :=
# Documentation extensions
TEXIEXT := .texi
INFOEXT := .info
HTMLEXT := .html
DVIEXT := .dvi
PDFEXT := .pdf
PSEXT := .ps
# Script extensions
SRPEXT := .ahk .applescript .bat .bash .cmd .coffee .erb .hta \
.itcl .js .lua .m .php .pl .pm .py .pyc .pyo .r .rb \
.scpt .scptd .sh .tcl .vbs
# Image extensions
IMGEXT := .ai .ani .anim .apng .art .bmp .bpg .bsave .cal .cdf .cdr \
.cgm .ciff .cin .cpc .cpt .cur .djvu .dng .dpx .dxf .ecw \
.emf .eps .eva .exr .fits .flic .fpx .gerber .gif .hdri \
.hevc .hvif .icer .icns .ico .ics .iges .ilbm .jbig .jbig2 \
.jng .jp2 .jpeg .jpeg .jpeg-hdr .logluv .miff .mng .nrrd \
.pam .pbm .pcx .pdf .pgf .pgm .pgml .pict .pictor .png \
.pnm .ppm .ps .psb .psd .psp .qtvr .ras .rbe .sgi .svg .swf \
.tga .tiff .tiff .vml .wbmp .webp .wmf .xaml .xar .xbm .xcf \
.xpm .xr .xwd
# Data extensions
DATAEXT := .asc .bak .bin .bk .cfg .conf .cnf .css .csv .dat \
.diff .dsk .htm .html .json .log .ltsv .raw .sql \
.temp .tmp .tsv .txt .xml .yaml .yml
# I18n extensions
POTEXT := .pot
POEXT := .po
MOEXT := .mo
# Prefixes
LIBPREF := lib cyg
ARPREF := lib
SHRPREF := lib
# Suffixes
TESTSUF := Test
BENCHSUF := Bench
########################################################################
## PROGRAMS ##
########################################################################
# Compilation
AR := ar
AS := nasm
CC := gcc
FC := gfortran
CXX := g++
RANLIB := ranlib
# Include configuration file for compiler if exists
-include .compiler.mk compiler.mk Compiler.mk
# Installation
INSTALL := install
INSTALL_DATA := $(INSTALL)
INSTALL_PROGRAM := $(INSTALL) -m 644
# File manipulation
CP := cp -a
MV := mv
RM := rm -f
LN := ln -s
TAR := tar -cvf
ZIP := zip
GZIP := gzip
BZIP2 := bzip2
MKDIR := mkdir -p
RMDIR := rm -rf
FIND := find
SCRIPT := script -q
# Parser and Lexer
LEX := flex
LEXCXX := flexc++
YACC := bison
YACCCXX := bisonc++
# Analysis lint
CALINT = cppcheck --enable=all $(addprefix -i,$(extdir))
FALINT :=
CXXALINT = $(CALINT)
# Syntax lint
CSLINT :=
FSLINT :=
CXXSLINT = cpplint --extensions=$(subst .,,$(strip \
$(subst $(space),$(comma),$(strip \
$(cxxext) $(hxxext) $(inlext)))))
# Coverage
GCOV := gcov
LCOV := lcov
# Profiler
PROF := gprof
# Embedded SQL
ESQL := ecpg
# Tags
CTAGS := ctags
ETAGS := etags
# Documentation
DOXYGEN := doxygen
MAKEINFO := makeinfo
INSTALL_INFO := install-info
TEXI2HTML := makeinfo --no-split --html
TEXI2DVI := texi2dvi
TEXI2PDF := texi2pdf
TEXI2PS := texi2dvi --ps
# Native Language Support
XGETTEXT := xgettext
MSGINIT := msginit --no-translator
MSGMERGE := msgmerge
MSGFMT := msgfmt -c
NLSREQINC := libintl.h
# Packages (Debian)
DEBUILD := debuild -us -uc
DCH = dch --create -v $(deb_version) \
--package $(deb_project)
# Remote
CURL := curl -o
GIT := git
# Make
MAKE += -f $(firstword $(MAKEFILE_LIST))
########################################################################
# INSTALLATION #
########################################################################
### PREFIXES
# * prefix: Default prefix for variables below
# * exec_prefix: Prefix for machine-specific files (bins and libs)
prefix := /usr/local
exec_prefix := $(prefix)
### EXECUTABLES AND LIBRARIES
# * bindir: Programs that user can run
# * sbindir: Runnable by shell, useful by sysadmins
# * libexecdir: Executables for being run only by other programs
# * libdir Object and libraries of object code
install_dirs := bindir sbindir libexecdir libdir
bindir := $(exec_prefix)/bin
sbindir := $(exec_prefix)/sbin
libexecdir := $(exec_prefix)/libexec
libdir := $(exec_prefix)/lib
### DATA PREFIXES
# * datarootdir: Read-only machine-independent files (docs and data)
# * datadir: Read-only machine-independent files (data, no docs)
# * sysconfdir: Read-only single-machine files (as server configs)
# * localstatedir: Exec-modifiable single-machine single-exec files
# * runstatedir: Exec-modifiable single-machine run-persistent files
install_dirs += datarootdir datadir sysconfdir
install_dirs += sharedstatedir localstatedir runstatedir
datarootdir := $(prefix)/share
datadir := $(datarootdir)
sysconfdir := $(prefix)/etc
sharedstatedir := $(prefix)/com
localstatedir := $(prefix)/var
runstatedir := $(localstatedir)/run
### HEADER FILES
# * includedir: Includable (header) files for use by GCC
# * oldincludedir: Includable (header) files for GCC and other compilers
install_dirs += includedir oldincludedir
includedir := $(prefix)/include
oldincludedir := /usr/include
### DOCUMENTATION FILES
# * infodir: Doc directory for info files
# * docdir: Doc directory for files other than info
# * htmldir: Doc directory for HTML files (with subdir for locale)
# * dvidir: Doc directory for DVI files (with subdir for locale)
# * pdfdir: Doc directory for PDF files (with subdir for locale)
# * psdir: Doc directory for PS files (with subdir for locale)
install_dirs += docdir infodir htmldir dvidir pdfdir psdir
docdir := $(datarootdir)/doc/$(PROJECT)/$(VERSION)
infodir := $(datarootdir)/info
htmldir := $(docdir)
dvidir := $(docdir)
pdfdir := $(docdir)
psdir := $(docdir)
### MAN FILES
# * mandir: Manual main directory
# * manXdir: Manual section X (X from 1 to 7)
install_dirs += mandir man1dir man2dir man3dir
install_dirs += man4dir man5dir man6dir man7dir
mandir := $(datarootdir)/man
man1dir := $(mandir)/man1
man2dir := $(mandir)/man2
man3dir := $(mandir)/man3
man4dir := $(mandir)/man4
man5dir := $(mandir)/man5
man6dir := $(mandir)/man6
man7dir := $(mandir)/man7
### OTHERS
# * lispdir: Emacs Lisp files in this package
# * localedir: Locale-specific message catalogs for the package
install_dirs += lispdir localedir
lispdir := $(datarootdir)/emacs/site-lisp
localedir := $(datarootdir)/locale
#//////////////////////////////////////////////////////////////////////#
#----------------------------------------------------------------------#
# PLATFORM-SPECIFIC DEFINITIONS #
#----------------------------------------------------------------------#
#\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\#
# The default definitions presented above area all set to work in a
# standard Linux environment. Here we present changes required for
# the code to work in different OSs.
ifeq ($(or $(shell which uname 2>/dev/null),empty),empty) # exists 'uname'
$(warning "Platform-specific support unavailable: 'uname' required")
else # exists 'uname'
# Information extracted by uname
# ================================
# uname_S: Kernel name
# uname_M: Machine hardware name
# uname_O: Operating System
# uname_R: Kernel release
# uname_P: Processor type (or 'unknown')
# uname_V: Kernel version
override uname_S := $(shell sh -c 'uname -s 2>/dev/null || echo not')
override uname_M := $(shell sh -c 'uname -m 2>/dev/null || echo not')
override uname_O := $(shell sh -c 'uname -o 2>/dev/null || echo not')
override uname_R := $(shell sh -c 'uname -r 2>/dev/null || echo not')
override uname_P := $(shell sh -c 'uname -p 2>/dev/null || echo not')
override uname_V := $(shell sh -c 'uname -v 2>/dev/null || echo not')
PLAT_KERNEL ?= $(uname_S)
PLAT_ARCH ?= $(uname_M)
PLAT_OS ?= $(uname_O)
PLAT_RELEASE ?= $(uname_R)
PLAT_PROC ?= $(uname_P)
PLAT_VERSION ?= $(uname_V)
# Platform specific flags
# =========================
ifeq ($(PLAT_KERNEL),Darwin) # OSX Family
SHREXT := .dylib
SHRFLAGS := -fno-common
LDSHR := -dynamiclib -undefined dynamic_lookup
SCRIPTFLAGS := -t0 /dev/null
define SCRIPTQUOTE
"
endef
endif
ifeq ($(PLAT_OS),Cygwin) # Windows with Cygwin
SHREXT := .dll
SHRPREF := cyg
SHRFLAGS :=
LDSHR = -shared \
-Wl,--out-implib,$@$(arext) \
-Wl,--export-all-symbols \
-Wl,--enable-auto-import \
-Wl,--enable-auto-image-base
endif
ifeq ($(PLAT_OS),Msys) # Windows with MSYS2
SHREXT := .dll
SHRFLAGS :=
LDSHR = -shared \
-Wl,--out-implib,$@$(arext) \
-Wl,--export-all-symbols \
-Wl,--enable-auto-import \
-Wl,--enable-auto-image-base
endif
# Include additional platform specific changes
-include $(PLAT_KERNEL).$(PLAT_ARCH).mk
-include $(PLAT_KERNEL).$(PLAT_ARCH).$(PLAT_RELEASE).mk
endif # exists 'uname'
#//////////////////////////////////////////////////////////////////////#
#%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%#
#''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''#
# USER CONFIGURATIONS #
#......................................................................#
#%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%#
#\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\#
#//////////////////////////////////////////////////////////////////////#
#----------------------------------------------------------------------#
# AUTOMATIC FLAGS #
#----------------------------------------------------------------------#
#\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\#
ifndef COVERAGE
COVERAGE := $(if $(filter %coverage %clean,$(MAKECMDGOALS)),T)
endif
ifndef PROFILE
PROFILE := $(if $(filter %profile %clean,$(MAKECMDGOALS)),T)
endif
ifndef DEPLOY
DEPLOY := $(if $(filter deploy,$(MAKECMDGOALS)),T)
endif
export COVERAGE PROFILE DEPLOY
#//////////////////////////////////////////////////////////////////////#
#----------------------------------------------------------------------#
# CONFIGURATION FILES #
#----------------------------------------------------------------------#
#\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\#
# Include configuration file if exists
-include .version.mk
-include .config.mk config.mk Config.mk
#//////////////////////////////////////////////////////////////////////#
#----------------------------------------------------------------------#
# FLAG-SPECIFIC POST PROCESSMENT #
#----------------------------------------------------------------------#
#\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\#
# Coverage
# ==========
# Changes needed to deal with coverage compilation.
# 1) Preprocess compilation flags to add coverage compiler options
# and remove automatic optimizations (flags -On, n > 0)
# 2) Preprocess linker flags to add coverage linker options
#------------------------------------------------------------------[ ]
ifndef DEPLOY
ifdef COVERAGE
#------------------------------------------------------------------[ 1 ]
$(foreach p,CPP AS C F CXX,\
$(eval override $pFLAGS := $(strip \
$(patsubst -O%,,$($pFLAGS) $($pCOVFLAGS) ))))
#------------------------------------------------------------------[ 2 ]
override LDFLAGS += $(LDCOV)
#------------------------------------------------------------------[ ]
endif # ifdef COVERAGE
endif # ifndef DEPLOY
# Profile
# =========
# Changes needed to deal with profile compilation.
# 1) Preprocess compilation flags to add profile options
# 2) Preprocess linker flags to add profile linker options
#------------------------------------------------------------------[ ]
ifndef DEPLOY
ifdef PROFILE
#------------------------------------------------------------------[ 1 ]
$(foreach p,CPP AS C F CXX,\
$(eval override $pFLAGS := $(strip $($pFLAGS) $($pPROFFLAGS) )))
#------------------------------------------------------------------[ 2 ]
override LDFLAGS += $(LDPROF)
#------------------------------------------------------------------[ ]
endif # ifdef PROFILE
endif # ifndef DEPLOY
# Deploy
# ========
# Changes needed to deal with deploy compilation.
# 1) Preprocess compilation flags to add deploy proprocessor options
#------------------------------------------------------------------[ ]
ifdef DEPLOY
#------------------------------------------------------------------[ 1 ]
override CPPFLAGS += -DNDEBUG
#------------------------------------------------------------------[ ]
endif # ifdef DEPLOY
#//////////////////////////////////////////////////////////////////////#
#%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%#
#''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''#
# MAKEFILE CONFIGURATIONS #
#......................................................................#
#%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%#
#\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\#
# Remote path
MAKERAWREMOTE := \
https://raw.githubusercontent.com/umake/make/master/Makefile
# Git remote path
MAKEGITREMOTE := \
https://github.com/umake/make.git
# Make current directory
MAKECURRENTDIR := \
$(patsubst %/,%,$(dir $(abspath $(firstword $(MAKEFILE_LIST)))))
# Define the shell to be used
SHELL = /bin/sh
#//////////////////////////////////////////////////////////////////////#
#%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%#
#''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''#
# COMPILE-TIME LIBRARY #
#......................................................................#
#%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%#
#\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\#
########################################################################
## DEFINITIONS ##
########################################################################
T := 1
comma := ,
empty :=
space := $(empty) $(empty)
tab := $(empty) $(empty)
define squote
'
endef
define dquote
"
endef
define newline
endef
lparentheses := (
rparentheses := )
n0 :=
n1 := 1
n2 := 1 1
n3 := 1 1 1
n4 := 1 1 1 1
n5 := 1 1 1 1 1
n6 := 1 1 1 1 1 1
n7 := 1 1 1 1 1 1 1
n8 := 1 1 1 1 1 1 1 1
n9 := 1 1 1 1 1 1 1 1 1
########################################################################
## FUNCTIONS ##
########################################################################
# Basic variable functions
# ==========================
# 1) is-empty: Returns not empty if a variable is empty
# 2) not-empty: Returns not empty if a variable is not empty
define is-empty
$(strip $(if $(strip $1),,T))
endef
define not-empty
$(strip $(if $(strip $1),T))
endef
# Logic functions
# =================
# 1) not: Returns empty if arg is not empty, and not empty otherwise
# 2) eq: Returns not empty if $1 == $2, and empty otherwise
# 3) ne: Returns not empty if $1 != $2, and empty otherwise
define not
$(strip $(if $1,,T))
endef
define eq
$(strip $(if $(or $(strip $1),$(strip $2)),\
$(if $(filter $(subst $(space),,$1),$(subst $(space),,$2)),T),T))
endef
define ne
$(strip $(call not,$(call eq,$1,$2)))
endef
# Set functions
# ===============
# 1) union: Returns union of 2 lists
# 2) intersection: Returns intersection of 2 lists
define union
$1 $(foreach e,$2,$(if $(filter $e,$1),,$e))
endef
define intersection
$(foreach e,$1,$(filter $e,$2))
endef
# List manipulation functions
# =============================
# 1) car: Gets first element of a list
# 2) cdr: Gets all but firs element of a list
# 3) rcar: Gets last element of a list
# 4) rcdr: Gets all but last element of a list
# 5) invert: Inverts a list
define car
$(strip $(firstword $(strip $1)))
endef
define cdr
$(strip $(wordlist 2,$(words $(strip $1)),$(strip $1)))
endef
define rcar
$(strip $(lastword $(strip $1)))
endef
define rcdr
$(if $(strip $1),$(strip $(patsubst %.word,%,\
$(patsubst %.word.last,,$(strip $(addsuffix .word,$1)).last))))
endef
define invert
$(if $(strip $1),\
$(call invert,$(wordlist 2,$(words $1),$1))) $(firstword $1)
endef
# Numeric classification functions
# ==================================
# 1) is-numeric: Returns not empty if $1 matches [0-9]*
# 2) is-positive: Returns not empty if $1 matches -[0-9]*
# 3) is-negative: Returns not empty if $1 matches +?[0-9]*
# 4) is-integer: Returns not empty if $1 matches [+-]?[0-9]*
# 5) is-decimal: Returns not empty if $1 matches [+-]?[1-9]?[0-9]*
define rm-number
$(strip $(subst 0,,$(subst 1,,$(subst 2,,$(subst 3,,$(subst 4,,\
$(subst 5,,$(subst 6,,$(subst 7,,$(subst 8,,$(subst 9,,\
$(strip $1))))))))))))
endef
define is-numeric
$(if $(call rm-number,$1),,T)
endef
define is-negative
$(if $(and $(call is-numeric,$1),$(filter -%,$1)),T)
endef
define is-positive
$(call not,$(call is-negative,$(patsubst +%,%,$1)))
endef
define is-integer
$(if $(and $(call is-numeric,$1),$(strip \
$(or $(call is-positive,$1),$(call is-negative,$1))\
)),T)
endef
define is-decimal
$(if $(and $(call not,$(filter 0%,$1)),$(call is-integer,$1)),T)
endef
# Numeric comparison functions
# ==============================
# 1) gt: Returns not empty if $1 is greater than $2
# 2) lt: Returns not empty if $1 is less than $2
# 3) ge: Returns not empty if $1 is greater or equal than $2
# 4) le: Returns not empty if $1 is less or equal than $2
define cmp-factory
lt_$(word 1,$(subst -, ,$1))_$(word 2,$(subst -, ,$1)) := T
gt_$(word 2,$(subst -, ,$1))_$(word 1,$(subst -, ,$1)) := T
endef
$(foreach p,\
0-1 0-2 0-3 0-4 0-5 0-6 0-7 0-8 0-9 1-2 1-3 1-4 1-5 1-6 1-7 1-8 \
1-9 2-3 2-4 2-5 2-6 2-7 2-8 2-9 3-4 3-5 3-6 3-7 3-8 3-9 4-5 4-6 \
4-7 4-8 4-9 5-6 5-7 5-8 5-9 6-7 6-8 6-9 7-8 7-9 8-9, \
$(eval $(call cmp-factory,$p)))
define expand
$(subst 0,0 ,$(subst 1,1 ,$(subst 2,2 ,$(subst 3,3 ,$(subst 4,4 ,\
$(subst 5,5 ,$(subst 6,6 ,$(subst 7,7 ,$(subst 8,8 ,$(subst 9,9 ,$1)\
)))))))))
endef
define gt_impl
$(if $(strip $1),$(if $(strip $2),\
$(if $(gt_$(call car,$1)_$(call car,$2)),T,\
$(call gt_impl,$(call cdr,$1),$(call cdr,$2))),T))
endef
define gt
$(strip $(if \
$(call eq,$(words $(call expand,$1)),$(words $(call expand,$2))),\
$(call gt_impl,\
$(call invert,$(call expand,$1)), \
$(call invert,$(call expand,$2))), \
$(call gt_impl,\
$(call invert,$(call expand,$(words $1))), \
$(call invert,$(call expand,$(words $2)))) \
))
endef
define ge
$(or $(call eq,$1,$2),$(call gt,$1,$2))
endef
define lt
$(if $(call eq,$(call ge,$1,$2),T),,T)
endef
define le
$(or $(call eq,$1,$2),$(call lt,$1,$2))
endef
# Arithmetic functions
# ======================
# 1) oppose: Returns -$1 if $1 >= 0, or $1 otherwise
# 2) add: Returns sum of $1 and $2
# 3) increment: Returns sum of $1 with 1
define oppose
$(if $(call is-negative,$1),$(patsubst -%,%,$1),-$1)
endef
define add_impl
$(if $(strip $1 $2 $3),\
$(foreach n,$(words $(n$(or $(call rcar,$1),0)) \
$(n$(or $(call rcar,$2),0)) \
$(n$(or $(call rcar,$3),0))),\
$(if $(call eq,1,$(words $(call expand,$n))),\
$n $(call add_impl,$(call rcdr,$1),$(call rcdr,$2)),\
$(lastword $(call expand,$n)) $(call add_impl,\
$(call rcdr,$1),$(call rcdr,$2),\
$(firstword $(call expand,$n)))\
)))
endef
define add
$(strip $(subst $(space),,$(call invert,\
$(call add_impl,$(call expand,$1),$(call expand,$2)))))
endef
define increment
$(call add,$1,1)
endef
# Lexical functions
# ===================
# 1) lc: Returns $1 with lowercase letters only
# 2) uc: Returns $1 with uppercase letters only
# 2) camel-to-snake-case: Convert $1 from CamelCase to snake_case
# 2) snake-to-camel-case: Convert $1 from snake_case to CamelCase
define lc
$(strip $(subst A,a,$(subst B,b,$(subst C,c,$(subst D,d,$(subst E,e,\
$(subst F,f,$(subst G,g,$(subst H,h,$(subst I,i,$(subst J,j,\
$(subst K,k,$(subst L,l,$(subst M,m,$(subst N,n,$(subst O,o,\
$(subst P,p,$(subst Q,q,$(subst R,r,$(subst S,s,$(subst T,t,\
$(subst U,u,$(subst V,v,$(subst W,w,$(subst X,x,$(subst Y,y,\
$(subst Z,z,$(strip $1))))))))))))))))))))))))))))
endef
define uc
$(strip $(subst a,A,$(subst b,B,$(subst c,C,$(subst d,D,$(subst e,E,\
$(subst f,F,$(subst g,G,$(subst h,H,$(subst i,I,$(subst j,J,\
$(subst k,K,$(subst l,L,$(subst m,M,$(subst n,N,$(subst o,O,\
$(subst p,P,$(subst q,Q,$(subst r,R,$(subst s,S,$(subst t,T,\
$(subst u,U,$(subst v,V,$(subst w,W,$(subst x,X,$(subst y,Y,\
$(subst z,Z,$(strip $1))))))))))))))))))))))))))))
endef
define camel-to-snake-case
$(strip $(patsubst _%,%,\
$(subst A,_a,$(subst B,_b,$(subst C,_c,$(subst D,_d,$(subst E,_e,\
$(subst F,_f,$(subst G,_g,$(subst H,_h,$(subst I,_i,$(subst J,_j,\
$(subst K,_k,$(subst L,_l,$(subst M,_m,$(subst N,_n,$(subst O,_o,\
$(subst P,_p,$(subst Q,_q,$(subst R,_r,$(subst S,_s,$(subst T,_t,\
$(subst U,_u,$(subst V,_v,$(subst W,_w,$(subst X,_x,$(subst Y,_y,\
$(subst Z,_z,$(strip $1)))))))))))))))))))))))))))))
endef
define snake-to-camel-case
$(strip $(patsubst _%,%,\
$(subst _a,A,$(subst _b,B,$(subst _c,C,$(subst _d,D,$(subst _e,E,\
$(subst _f,F,$(subst _g,G,$(subst _h,H,$(subst _i,I,$(subst _j,J,\
$(subst _k,K,$(subst _l,L,$(subst _m,M,$(subst _n,N,$(subst _o,O,\
$(subst _p,P,$(subst _q,Q,$(subst _r,R,$(subst _s,S,$(subst _t,T,\
$(subst _u,U,$(subst _v,V,$(subst _w,W,$(subst _x,X,$(subst _y,Y,\
$(subst _z,Z,$(strip $1)))))))))))))))))))))))))))))
endef
# Lexical comparison functions
# ==============================
# 1) lexical-eq: Returns not empty if $1 is equal to $2
# 2) lexical-ne: Returns not empty if $1 is not equal to $2
# 3) lexical-gt: Returns not empty if $1 is greater than $2
# 4) lexical-lt: Returns not empty if $1 is less than $2
# 5) lexical-ge: Returns not empty if $1 is greater or equal than $2
# 6) lexical-le: Returns not empty if $1 is less or equal than $2
define lexical-eq
$(call eq,$1,$2)
endef
define lexical-ne
$(call ne,$1,$2)
endef
define lexical-gt