-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathEnjin.mk
1337 lines (1175 loc) · 41.3 KB
/
Enjin.mk
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 --no-print-directory --jobs=1 --environment-overrides -f
# Copyright (c) 2023 The Go-Enjin Authors
#
# 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.
#: uncomment to echo instead of execute
#CMD=echo
ENJIN_MK_VERSION := v0.2.15
#
#: phony make targets
#
.PHONY: audit audit-% be-update build build-dev-run check clean locales
.PHONY: con-% dev dist-clean help help-gopkgs local
.PHONY: profile.cpu profile.mem release release-dev-run run stop tidy unlocal
.PHONY: yarn-% _audit _enjenv _golang _nodejs
.PHONY: _check_make_target _clean _enjenv_bin
.PHONY: _enjenv_present _env_run_vars _golang_nancy_installed
.PHONY: _has_feature _is_nodejs_tag
.PHONY: _make_go_local _make_go_unlocal
.PHONY: _run _upx_build
.PHONY: _validate_extra_pkgs _yarn_run _yarn_run_script
.PHONY: _yarn_tag_install
.PHONY: list-make-targets
#
#: global make settings
#
SHELL := /bin/bash
#
#: global enjin settings
#
ifeq ($(origin APP_NAME),undefined)
APP_NAME := $(shell basename `pwd`)
endif
APP_SUMMARY ?= Go-Enjin
ENV_PREFIX ?= BE
APP_PREFIX ?= ${USER}
UNTAGGED_VERSION ?= v0.0.0
LISTEN ?=
PORT ?= 3334
DEBUG ?= ${BE_DEBUG}
STRICT ?= false
DOMAIN ?=
THEMES_PATH ?= themes
CONTENT_PATH ?= content
BE_CONSOLE_KEYS ?=
DEFAULT_CONSOLE_KEY ?=
#
#: enjin locale settings
#
ifndef SRC_LANG
SRC_LANG := en
endif
ifndef LANGUAGES
LANGUAGES := en
endif
ifeq ($(filter en,$(LANGUAGES)),)
LANGUAGES += en
endif
ifeq (${MAKE_LOCALES},true)
MAKE_THEME_LOCALES := true
MAKE_SOURCE_LOCALES := true
MAKE_CONTENT_LOCALES := true
else
MAKE_THEME_LOCALES ?= false
MAKE_SOURCE_LOCALES ?= false
MAKE_CONTENT_LOCALES ?= false
endif
CONTENT_LOCALES_PATH ?= ./locales-content
#
#: custom go.mod locals and be-update targets
#
GOPKG_KEYS ?=
# Basic Enjin Theme
BUILT_IN_GOPKG_KEYS += _BASIC_THEME
_BASIC_THEME_LABEL := Go-Enjin basic theme
_BASIC_THEME_GO_PACKAGE ?= github.com/go-enjin/basic-enjin-theme
_BASIC_THEME_LOCAL_PATH ?= ../basic-enjin-theme
# Default Enjin Theme
BUILT_IN_GOPKG_KEYS += _DEFAULT_THEME
_DEFAULT_THEME_LABEL := Go-Enjin default theme
_DEFAULT_THEME_GO_PACKAGE ?= github.com/go-enjin/default-enjin-theme
_DEFAULT_THEME_LOCAL_PATH ?= ../default-enjin-theme
# Semantic Enjin Theme
BUILT_IN_GOPKG_KEYS += _SEMANTIC_THEME
_SEMANTIC_THEME_LABEL := Go-Enjin semantic theme
_SEMANTIC_THEME_GO_PACKAGE ?= github.com/go-enjin/semantic-enjin-theme
_SEMANTIC_THEME_LOCAL_PATH ?= ../semantic-enjin-theme
# Go-Enjin fork of gotext package (beta enjin tags only)
BUILT_IN_GOPKG_KEYS += _GOTEXT
_GOTEXT_LABEL := Go-Enjin fork of golang.org/x/text
_GOTEXT_GO_PACKAGE ?= github.com/go-enjin/golang-org-x-text
_GOTEXT_LOCAL_PATH ?= ../golang-org-x-text
_GOTEXT_LATEST_VER ?= v0.12.1-enjin.1
# Go-Enjin fork of text scanner package
BUILT_IN_GOPKG_KEYS += _TEXT_SCANNER
_TEXT_SCANNER_LABEL := Go-Enjin fork of text/scanner
_TEXT_SCANNER_GO_PACKAGE ?= github.com/go-enjin/go-stdlib-text-scanner
_TEXT_SCANNER_LOCAL_PATH ?= ../go-stdlib-text-scanner
# Go-Enjin fork of times package
BUILT_IN_GOPKG_KEYS += _TIMES
_TIMES_LABEL := Go-Enjin fork of github.com/djherbis/times
_TIMES_GO_PACKAGE ?= github.com/go-enjin/github-com-djherbis-times
_TIMES_LOCAL_PATH ?= ../github-com-djherbis-times
# Go-Enjin fork of auth api
BUILT_IN_GOPKG_KEYS += _PKGZ_AUTH
_PKGZ_AUTH_LABEL := Go-Enjin fork of github.com/pkgz/auth
_PKGZ_AUTH_GO_PACKAGE ?= github.com/go-enjin/github-com-pkgz-auth
_PKGZ_AUTH_LOCAL_PATH ?= ../github-com-pkgz-auth
# Go-Enjin fork of atlas-gonnect package
BUILT_IN_GOPKG_KEYS += _ATLAS_GONNECT
_ATLAS_GONNECT_LABEL := Go-Enjin fork of github.com/craftamap/atlas-gonnect
_ATLAS_GONNECT_GO_PACKAGE ?= github.com/go-enjin/github-com-craftamap-atlas-gonnect
_ATLAS_GONNECT_LOCAL_PATH ?= ../github-com-craftamap-atlas-gonnect
# Go-Enjin sass output feature
BUILT_IN_GOPKG_KEYS += _SASS_OUTPUTS
_SASS_OUTPUTS_LABEL := Go-Enjin SASS outputs feature
_SASS_OUTPUTS_GO_PACKAGE ?= github.com/go-enjin/features-outputs-sass
_SASS_OUTPUTS_LOCAL_PATH ?= ../features-outputs-sass
# Go-Enjin gonnectian feature
BUILT_IN_GOPKG_KEYS += _GONNECTIAN
_GONNECTIAN_LABEL := Go-Enjin Atlassian Connect feature
_GONNECTIAN_GO_PACKAGE ?= github.com/go-enjin/features-gonnectian
_GONNECTIAN_LOCAL_PATH ?= ../features-gonnectian
# Go-Enjin gonnectian console feature
BUILT_IN_GOPKG_KEYS += _GONNECTIAN_CONSOLE
_GONNECTIAN_CONSOLE_LABEL := Go-Enjin Atlassian Connect console feature
_GONNECTIAN_CONSOLE_GO_PACKAGE ?= github.com/go-enjin/features-consoles-gonnectian
_GONNECTIAN_CONSOLE_LOCAL_PATH ?= ../features-consoles-gonnectian
# Go-Enjin starter apt site
BUILT_IN_GOPKG_KEYS += _STARTER_APT
_STARTER_APT_LABEL := Go-Enjin starter APT (debian packaging) site
_STARTER_APT_GO_PACKAGE ?= github.com/go-enjin/starter-apt-enjin
_STARTER_APT_LOCAL_PATH ?= ../starter-apt-enjin
# Go-Curses CDK
BUILT_IN_GOPKG_KEYS += _CDK
_CDK_LABEL := Go-Curses Development Kit
_CDK_GO_PACKAGE ?= github.com/go-curses/cdk
_CDK_LOCAL_PATH ?= ../../go-curses/cdk
# Go-Curses CTK
BUILT_IN_GOPKG_KEYS += _CTK
_CTK_LABEL := Go-Curses Tool Kit
_CTK_GO_PACKAGE ?= github.com/go-curses/ctk
_CTK_LOCAL_PATH ?= ../../go-curses/ctk
#
#: global go-enjin settings
#
GO_ENJIN_PKG ?= github.com/go-enjin/be
BE_PATH ?= ../be
BE_LOCAL_PATH ?= ${BE_PATH}
BE_DEBUG ?= false
DENY_DURATION ?= 86400
DLV_PORT ?= 2345
DLV_DEBUG ?=
DLV_BIN := $(shell which dlv)
#
#: global enjin build settings
#
BUILD_TAGS ?=
BUILD_ARGV ?=
BUILD_LDFLAGS ?=
DEV_BUILD_TAGS ?= ${BUILD_TAGS}
DEV_BUILD_ARGV ?=
DEV_BUILD_GCFLAGS ?=
CLEAN ?= ${APP_NAME} cpu.pprof mem.pprof
DIST_CLEAN ?=
EXTRA_CLEAN ?=
EXTRA_BUILD_TARGET_DEPS ?=
GOLANG ?= 1.21.0
GO_MOD ?= 1021
NODEJS ?=
RELEASE_BUILD ?= false
PRE_RELEASE_BUILD ?= false
#
#: enjin preset helpers
#
PRESET_TAGS ?=
ifeq (${ADD_TAGS_ESSENTIALS},true)
PRESET_TAGS += requests_deny
PRESET_TAGS += htmlify
PRESET_TAGS += header_proxy
PRESET_TAGS += page_query
PRESET_TAGS += page_status
PRESET_TAGS += page_partials
PRESET_TAGS += page_funcmaps
PRESET_TAGS += srv_pages
PRESET_TAGS += srv_listener_httpd
endif
ifeq (${ADD_TAGS_DEFAULTS},true)
PRESET_TAGS += requests_deny
PRESET_TAGS += user_base_htenv
PRESET_TAGS += user_auth_basic
PRESET_TAGS += htmlify
PRESET_TAGS += header_proxy
PRESET_TAGS += page_query
PRESET_TAGS += page_status
PRESET_TAGS += page_partials
PRESET_TAGS += page_funcmaps
PRESET_TAGS += page_permalink
PRESET_TAGS += srv_pages
PRESET_TAGS += srv_listener_httpd
endif
ifneq (${PRESET_TAGS},)
BUILD_TAGS += ${PRESET_TAGS}
DEV_BUILD_TAGS += ${PRESET_TAGS}
endif
#
#: global internal settings
#
_INTERNAL_BUILD_LOG_ := /dev/null
#_INTERNAL_BUILD_LOG_ := ./build.log
HEROKU_BIN := $(shell which heroku)
ENJENV_PKG ?= github.com/go-enjin/enjenv/cmd/enjenv@latest
ENJENV_DIR_NAME ?= .enjenv
ENJENV_DIR ?= ${ENJENV_DIR_NAME}
PROFILE_PATH ?= .
RUN_ARGV ?=
#
#: dynamically defined global variables and functions
#
ifeq ($(origin ENJENV_BIN),undefined)
ENJENV_BIN:=$(shell which enjenv)
endif
ifeq ($(origin ENJENV_EXE),undefined)
ENJENV_EXE:=$(shell \
echo "ENJENV_EXE" >> ${_INTERNAL_BUILD_LOG_}; \
if [ "${ENJENV_BIN}" != "" -a -x "${ENJENV_BIN}" ]; then \
echo "${ENJENV_BIN}"; \
else \
if [ -x "${PWD}/.enjenv.bin" ]; then \
echo "${PWD}/.enjenv.bin"; \
elif [ -d "${PWD}/.bin" -a -x "${PWD}/.bin/enjenv" ]; then \
echo "${PWD}/.bin/enjenv"; \
else \
echo "ERROR"; \
fi; \
fi)
endif
ifeq ($(origin ENJENV_PATH),undefined)
ENJENV_PATH := $(shell \
echo "_enjenv_path" >> ${_INTERNAL_BUILD_LOG_}; \
if [ -x "${ENJENV_EXE}" ]; then \
${ENJENV_EXE}; \
elif [ -d "${PWD}/${ENJENV_DIR}" ]; then \
echo "${PWD}/${ENJENV_DIR}"; \
fi)
endif
ifeq ($(origin VERSION),undefined)
VERSION := $(shell \
echo "_be_version" >> ${_INTERNAL_BUILD_LOG_}; \
if [ -x "${ENJENV_EXE}" ]; then \
${ENJENV_EXE} git-tag --untagged ${UNTAGGED_VERSION}; \
fi)
endif
ifeq ($(origin RELEASE),undefined)
RELEASE := $(shell \
echo "_be_release" >> ${_INTERNAL_BUILD_LOG_}; \
if [ -x "${ENJENV_EXE}" ]; then \
${ENJENV_EXE} rel-ver; \
fi)
endif
_MAKE_TARGETS := $($(MAKE) list-make-targets 2>/dev/null)
_ALL_FEATURES_PRESENT := $(shell ${ENJENV_EXE} features list 2>/dev/null)
_LIST_PACKAGE_JSON := $(shell \
echo "_list_package_json" >> ${_INTERNAL_BUILD_LOG_}; \
ls */package.json 2> /dev/null)
_LIST_NODE_PATHS := $(shell \
echo "_list_node_paths" >> ${_INTERNAL_BUILD_LOG_}; \
ls */package.json 2> /dev/null | while read P; do \
dirname $${P}; \
done)
_ENJENV_PRESENT := $(shell \
echo "_enjenv_present" >> ${_INTERNAL_BUILD_LOG_}; \
if [ -n "${ENJENV_EXE}" -a -x "${ENJENV_EXE}" ]; then \
echo "present"; \
fi)
_GO_PRESENT := $(shell \
echo "_go_present" >> ${_INTERNAL_BUILD_LOG_}; \
if [ -n "$(call _has_feature,go)" ]; then \
echo "present"; \
fi)
_YARN_PRESENT := $(shell \
echo "_yarn_present" >> ${_INTERNAL_BUILD_LOG_}; \
if [ -n "$(call _has_feature,yarn)" ]; then \
echo "present"; \
fi)
_DEPS_PRESENT := $(shell \
echo "_deps_present" >> ${_INTERNAL_BUILD_LOG_}; \
if [ \
"${_ENJENV_PRESENT}" == "present" \
-a "${_GO_PRESENT}" == "present" \
-a "${_YARN_PRESENT}" == "present" \
]; then \
echo "deps-present"; \
fi)
_BUILD_ARGS = $(shell \
echo "_build_args" >> ${_INTERNAL_BUILD_LOG_}; \
if [ "${RELEASE_BUILD}" == "true" ]; then \
echo " --optimize"; \
fi)
_BUILD_ARGV = $(shell \
echo "_build_argv" >> ${_INTERNAL_BUILD_LOG_}; \
if [ "${RELEASE_BUILD}" == "true" -o "${PRE_RELEASE_BUILD}" == "true" ]; then \
echo "${BUILD_ARGV}"; \
else \
echo "${DEV_BUILD_ARGV}"; \
fi)
_EXTRA_LDFLAGS := $(shell \
if [ "${RELEASE_BUILD}" == true ]; then \
echo "${BUILD_LDFLAGS}"; \
else \
echo "${DEV_BUILD_LDFLAGS}"; \
fi)
_EXTRA_GCFLAGS := $(shell \
if [ "${RELEASE_BUILD}" == true ]; then \
echo "${BUILD_GCFLAGS}"; \
else \
echo "${DEV_BUILD_GCFLAGS}"; \
fi)
_BUILD_TAGS = $(shell \
echo "_build_tags" >> ${_INTERNAL_BUILD_LOG_}; \
if [ "${RELEASE_BUILD}" == "true" -o "${PRE_RELEASE_BUILD}" == "true" ]; then \
if [ "${BUILD_TAGS}" != "" ]; then \
tags=`echo "${BUILD_TAGS}" | perl -pe 's!\s+!,!msg;s!,$$!!;'`; \
echo "-tags $${tags}"; \
fi; \
elif [ "${DEV_BUILD_TAGS}" != "" ]; then \
tags=`echo "${DEV_BUILD_TAGS}" | perl -pe 's!\s+!,!msg;s!,$$!!;'`; \
echo "-tags $${tags}"; \
fi)
define _check_make_target
echo "_check_make_target $(1)" >> ${_INTERNAL_BUILD_LOG_}; \
if echo "${_MAKE_TARGETS}" | egrep -q "^$(1)\$"; then \
echo "false"; \
else \
echo "true"; \
fi
endef
define _clean
echo "_clean $(1)" >> ${_INTERNAL_BUILD_LOG_}; \
for thing in $(1); do \
if [ -d "$${thing}" ]; then \
rm -rf "$${thing}" && \
echo "removed: \"$${thing}\" (recursively)"; \
elif [ -f "$${thing}" ]; then \
rm -f "$${thing}" && \
echo "removed: \"$${thing}\""; \
fi; \
done
endef
define _upx_build
if [ -n "$(1)" ]; then \
echo "_upx_build" >> ${_INTERNAL_BUILD_LOG_}; \
if [ -x /usr/bin/upx ]; then \
echo -n "# packing: $(1) - "; \
du -hs "$(1)" | awk '{print $$1}'; \
/usr/bin/upx -qq -7 --no-color --no-progress "$(1)"; \
echo -n "# packed: $(1) - "; \
du -hs "$(1)" | awk '{print $$1}'; \
sha256sum "$(1)"; \
else \
echo "# upx command not found, skipping binary packing stage"; \
fi; \
fi
endef
define _validate_extra_pkgs
$(if ${GOPKG_KEYS},$(foreach key,${GOPKG_KEYS},$(shell \
if [ \
-z "$($(key)_GO_PACKAGE)" \
-o -z "$($(key)_LOCAL_PATH)" \
-o ! -d "$($(key)_LOCAL_PATH)" \
]; then \
echo "echo \"# $(key)_GO_PACKAGE and/or $(key)_LOCAL_PATH not found\"; false;"; \
fi \
)))
endef
define _make_go_local
echo "_make_go_local $(1) $(2)" >> ${_INTERNAL_BUILD_LOG_}; \
echo "# go.mod local: $(1)"; \
${CMD} ${ENJENV_EXE} go-local "$(1)" "$(2)"
endef
define _make_go_unlocal
echo "_make_go_unlocal $(1)" >> ${_INTERNAL_BUILD_LOG_}; \
echo "# go.mod unlocal $(1)"; \
${CMD} ${ENJENV_EXE} go-unlocal "$(1)"
endef
define _make_extra_pkgs
$(if ${GOPKG_KEYS},$(foreach key,${GOPKG_KEYS},$($(key)_GO_PACKAGE)@$(if $($(key)_LATEST_VER),$($(key)_LATEST_VER),latest)))
endef
define _make_console_names
$(if ${BE_CONSOLE_KEYS},$(foreach key,${BE_CONSOLE_KEYS},$(shell echo "$($(key)_CONSOLE_NAME)")))
endef
define _first_console_name
$(shell \
for name in $(call _make_console_names); do \
echo "$${name}"; \
break; \
done)
endef
define _default_console_name
$(shell \
if [ -n "${DEFAULT_CONSOLE_KEY}" ]; then \
echo "$($(DEFAULT_CONSOLE_KEY)_CONSOLE_NAME)"; \
elif [ -n "${BE_CONSOLE_KEYS}" ]; then \
echo "$(call _first_console_name)"; \
fi)
endef
define _has_feature
$(shell \
if [ -n "$(1)" -a "$(1)" != "yarn--" -a "$(1)" != "yarn---install" ]; then \
for feature in ${_ALL_FEATURES_PRESENT}; do \
if [ "$${feature}" == "$(1)" ]; then \
echo "_has_feature $(1) (found)" >> ${_INTERNAL_BUILD_LOG_}; \
echo "$${feature}"; \
break; \
else \
echo "_has_feature $(1) (is not $${feature})" >> ${_INTERNAL_BUILD_LOG_}; \
fi; \
done; \
fi)
endef
define _env_run_vars
${ENV_PREFIX}_DEBUG="${DEBUG}" \
${ENV_PREFIX}_LISTEN="${LISTEN}" \
${ENV_PREFIX}_PORT="${PORT}" \
${ENV_PREFIX}_PREFIX="${APP_PREFIX}" \
${ENV_PREFIX}_STRICT="${STRICT}" \
${ENV_PREFIX}_DOMAIN="${DOMAIN}" \
${ENV_PREFIX}_DENY_DURATION="${DENY_DURATION}"
endef
ifdef override_env_run_vars
define _get_run_vars
$(call override_env_run_vars)
endef
else
define _get_run_vars
$(call _env_run_vars)
endef
endif
define _is_nodejs_tag
echo "_is_nodejs_tag $(1)" >> ${_INTERNAL_BUILD_LOG_}; \
if [ "$(1)" != "" -a -d "$(1)" ]; then \
if [ ! -f "$(1)/package.json" ]; then \
echo "# $(1)/package.json not found"; \
false; \
fi; \
else \
echo "# \"$(1)/package.json\" not found"; \
false; \
fi
endef
define _yarn_tag_install
if [ -n "$(1)" ]; then \
echo "_yarn_tag_install $(1)" >> ${_INTERNAL_BUILD_LOG_}; \
if ( ${ENJENV_EXE} features has yarn-$(1)--install 2>&1 ) > /dev/null; then \
${CMD} ${ENJENV_EXE} yarn-$(1)--install; \
fi; \
fi
endef
define _yarn_run
if [ -n "$(1)" -a -n "$(2)" ]; then \
echo "_yarn_run $(1) $(2)" >> ${_INTERNAL_BUILD_LOG_}; \
if [ "${HAS_YARN}" == "true" ]; then \
cd $(1) > /dev/null; \
${CMD} ${ENJENV_EXE} yarn -- $(2) 2> /dev/null || true; \
cd - > /dev/null; \
else \
echo "# yarn feature not found"; \
false; \
fi; \
fi
endef
define _yarn_run_script
if [ -n "$(1)" -a -n "$(2)" ]; then \
echo "_yarn_run_script $(1) $(2)" >> ${_INTERNAL_BUILD_LOG_}; \
if ( ${ENJENV_EXE} features has yarn-$(1)-$(2) 2>&1 ) > /dev/null; then \
${CMD} ${ENJENV_EXE} yarn-$(1)-$(2); \
else \
echo "# yarn-$(1)-$(2) script not found"; \
false; \
fi; \
fi
endef
define _golang_nancy_installed
echo "_golang_nancy_installed" >> ${_INTERNAL_BUILD_LOG_}; \
if [ -n "$(call _has_feature,golang--setup-nancy)" ]; then \
${CMD} ${ENJENV_EXE} golang setup-nancy || false; \
fi
endef
define _source_activate_run
if [ -f "${ENJENV_PATH}/activate" ]; then \
source "${ENJENV_PATH}/activate" 2>/dev/null \
&& ${CMD} ${1} ${2} ${3} ${4} ${5} ${6} ${7} ${8} ${9}; \
else \
echo "# missing ${ENJENV_PATH}/activate"; \
fi
endef
define _run_checks
if [ ! -x "${APP_NAME}" ]; then \
echo "${APP_NAME} not found or not executable"; \
false; \
fi;
endef
ifdef override_run_checks
define _get_run_checks
$(call override_run_checks)
endef
else
define _get_run_checks
$(call _run_checks)
endef
endif
define _run
$(call _get_run_checks) \
if [ "${DLV_DEBUG}" == "true" -a -n "${DLV_BIN}" ]; then \
echo "# delving ${APP_NAME} ${RUN_ARGV}"; \
${CMD} $(call _get_run_vars) \
${DLV_BIN} --listen=:${DLV_PORT} --headless=true --api-version=2 --accept-multiclient \
exec -- ./${APP_NAME} ${RUN_ARGV}; \
else \
echo "# running ${APP_NAME} ${RUN_ARGV}"; \
${CMD} $(call _get_run_vars) ./${APP_NAME} ${RUN_ARGV}; \
fi
endef
define is_defined
$(if $(strip $($1)),true,false)
endef
define _find_pid_tree
`\
function _all_children { \
for cid in $$(ps -o pid= --ppid "$${1}"); \
do \
echo $$(_all_children "$${cid}"); \
echo "$${cid}"; \
done; \
}; \
function _up_to_first_make { \
for ppid in $$(ps -o ppid= -p "$${1}"); \
do \
NAME="$$(ps -o command= -p "$${ppid}" | awk '{print $$1 $$2}')"; \
if echo "$${NAME}" | egrep -q '^(/.*/bash-c|/.*/make.*|make.*)$$'; then \
echo "$${ppid}"; \
echo $$(_up_to_first_make "$${ppid}"); \
fi; \
done; \
}; \
FOUND=""; \
for pid in $$(_all_children "$(1)") $(1) $$(_up_to_first_make "$(1)") \
; \
do \
if [ -z "$${FOUND}" ]; then \
FOUND="$${pid}"; \
else \
FOUND="$${FOUND} $${pid}"; \
fi; \
done; \
echo "$${FOUND}" \
`
endef
define _prune_null_locales
if [ -d "$(1)" ]; then \
if [ -f "$(1)/en/out.gotext.json" ]; then \
if grep -q '"messages": null' "$(1)/en/out.gotext.json"; then \
echo "# $(1) translation messages not found, cleaning up"; \
rm -rfv "$(1)"; \
fi; \
fi; \
fi
endef
list-make-targets:
@LC_ALL=C \
$(MAKE) -pRrq -f $(firstword $(MAKEFILE_LIST)) : 2>/dev/null \
| awk -v RS= -F: '/(^|\n)# Files(\n|$$)/,/(^|\n)# Finished Make data base/ {if ($$1 !~ "^[#.]") {print $$1}}' \
| sort \
| egrep -v -e '^[^[:alnum:]]' -e '^$@$$' \
| egrep -v '\-\%$$'
@$(shell \
if [ -n "${ENJENV_EXE}" -a -x "${ENJENV_EXE}" ]; then \
_ENJENV_HELP=$$(${ENJENV_EXE} features list); \
_FOUND=""; \
if echo "$${_ENJENV_HELP}" | egrep -q '^go-audit$$'; then \
for tag in ${_LIST_NODE_PATHS}; do \
echo "echo \"audit-$${tag}\";"; \
done; \
fi; \
for tag in ${_LIST_NODE_PATHS}; do \
for script in `echo "$${_ENJENV_HELP}" | grep yarn-$${tag}- | awk '{print $$1}'`; do \
echo "echo \"$${script}\";"; \
_FOUND="$${_FOUND};$${script}"; \
done; \
done; \
if [ -z "$${_FOUND}" ]; then \
for tag in ${_LIST_NODE_PATHS}; do \
echo "echo \"yarn-$${tag}-install\";"; \
done; \
fi; \
fi)
#
#: actual make targets
#
help:
@echo "${APP_NAME} - ${APP_SUMMARY}"
@echo
@echo "version: ${VERSION}"
@echo "release: ${RELEASE}"
@echo
@echo "usage: make <target> [targets...]"
@echo
@echo "Cleanup Targets:"
@echo " clean remove built binary"
@echo " dist-clean clean and purge local .bin ${ENJENV_DIR}"
@echo
@echo "Compile Targets:"
@echo " build build a debug-able version of ${APP_NAME}"
@echo " release build a release version of ${APP_NAME}"
@echo
@echo "Runtime Targets:"
@echo " dev set DEBUG mode and run ./${APP_NAME}"
ifneq (${DLV_BIN},)
@echo " dlv same as 'dev' ran with headless dlv (port ${DLV_PORT})"
endif
@echo " run execute ./${APP_NAME}"
@echo " stop interrupt running ${APP_NAME}"
@echo
@echo "Aesthetic Targets:"
@echo " build-dev-run make build dev with colourized output"
ifneq (${DLV_BIN},)
@echo " build-dlv-run make build dlv with colourized output"
endif
@echo
@echo "#############################################################"
@echo
@echo "Profiling Targets:"
@echo " profile.cpu make build dev with cpu profiling"
@echo " profile.mem make build dev with mem profiling"
@echo
@echo " note: use 'make stop' from another terminal to end profiling"
ifneq (${_DEPS_PRESENT},)
@echo
@echo "#############################################################"
@echo
@echo "Auditing Targets:"
endif
ifneq (${_GO_PRESENT},)
@echo " audit runs enjenv go-audit-report"
endif
ifneq (${_LIST_PACKAGE_JSON},)
@$(shell \
for tag in ${_LIST_NODE_PATHS}; do \
echo "echo \" audit-$${tag} runs enjenv $${tag}-audit-report\""; \
done)
endif
ifneq (${HEROKU_BIN},)
@echo
@echo "#############################################################"
@echo
@echo "Heroku Targets:"
@echo " heroku-tail wrapper for: heroku logs --tail"
@echo " heroku-push wrapper for: git push ${HEROKU_GIT_REMOTE} ${HEROKU_SRC_BRANCH}:${HEROKU_DST_BRANCH}"
@echo
@echo " Configure heroku-push"
@echo " HEROKU_GIT_REMOTE=${HEROKU_GIT_REMOTE}"
@echo " HEROKU_SRC_REMOTE=${HEROKU_SRC_BRANCH}"
@echo " HEROKU_DST_REMOTE=${HEROKU_DST_BRANCH}"
endif
ifneq (${_LIST_PACKAGE_JSON},)
@echo
@echo "#############################################################"
@echo
@echo "There are nodejs package.json files present in this project"
@echo "and enjenv has convenient wrappers for a number of extra"
@echo "targets that Enjin.mk provides. These follow a simple naming"
@echo "convention: yarn-<dir>-<script-name> where when targetted"
@echo "with make, will run 'yarn <script-name>' in <dir> for you."
@echo
@echo "Yarn Targets:"
@$(shell \
if [ -n "${ENJENV_EXE}" -a -x "${ENJENV_EXE}" ]; then \
_ENJENV_HELP=$$(${ENJENV_EXE} features list); \
_FOUND=""; \
for tag in ${_LIST_NODE_PATHS}; do \
for script in `echo "$${_ENJENV_HELP}" | grep yarn-$${tag}- | awk '{print $$1}'`; do \
echo "echo \" $${script}\";"; \
_FOUND="$${_FOUND};$${script}"; \
done; \
done; \
if [ -z "$${_FOUND}" ]; then \
for tag in ${_LIST_NODE_PATHS}; do \
echo "echo \" yarn-$${tag}-install\";"; \
done; \
fi; \
fi)
@echo
endif
ifneq (${BE_CONSOLE_KEYS},)
@echo
@echo "#############################################################"
@echo
@echo "Console Targets:"
@echo -e " list-consoles\t\t# (list all console targets)"
@echo -e " console\t\t# (run default/first console)"
@$(if ${BE_CONSOLE_KEYS},$(foreach key,${BE_CONSOLE_KEYS},$(shell \
_NAME_="$($(key)_CONSOLE_NAME)"; \
_DESC_="$($(key)_CONSOLE_DESC)"; \
[ -z "$${_DESC_}" ] && _DESC_="(description not found)"; \
echo "echo -e \" con-$${_NAME_}\t# ($${_DESC_})\""; \
)))
endif
@echo
@echo "#############################################################"
@echo
@echo "Helper Targets:"
@echo " help this screen of output"
@echo " tidy run go mod tidy"
@echo " local go mod -replace for ${GO_ENJIN_PKG}"
@echo " unlocal go mod -dropreplace for ${GO_ENJIN_PKG}"
@echo " be-update go clean and get ${GO_ENJIN_PKG}"
ifeq (${DLV_BIN},)
@echo " install-dlv run go install github.com/go-delve/delve@latest"
endif
@echo " help-gopkgs prints a table of built-in GOPKG_KEYS values"
@echo
@echo "#############################################################"
@echo
@echo "This is a Go-Enjin project which depends upon enjenv to"
@echo "manage the Golang and Nodejs SDKs and build this Enjin."
@echo
@echo "Go-Enjin projects use make as their build system and in"
@echo "particular, they include Enjin.mk (which is where this"
@echo "help screen lives)."
@echo
@echo "Enjin.mk will ensure that any dependencies that are not"
@echo "already present, will be included just before they're"
@echo "actually needed. For your information, these are summarized"
@echo "into two categories, the managed ones Enjin.mk will handle"
@echo "and the assumptions are up to the developer(s) managing this"
@echo "project."
@echo
@echo "Managed Dependencies:"
@echo " enjenv the Go-Enjin environment utility"
@echo " nancy for auditing go code using Sonatype nancy"
@echo " nodejs enjenv managed nodejs environment"
@echo " yarn preferred nodejs package manager"
@echo
@echo "Assumed Dependencies:"
@echo " os linux or darwin"
@echo " arch arm64 or amd64"
@echo " make GNU make is installed"
@echo " coreutils GNU coreutils is installed"
@echo
@echo "Enjin.mk Version: ${ENJIN_MK_VERSION}"
help-gopkgs:
@echo "#############################################################"
@echo
@echo "GOPKG_KEYS is a Makfile setting to configure the local,"
@echo "unlocal and be-update build targets."
@echo
@echo "Example GOPKG_KEYS Makefile settings:"
@echo
@echo "GOPKG_KEYS += EXAMPLE"
@echo "EXAMPLE_LABEL := A custom label for a package"
@echo "EXAMPLE_GO_PACKAGE := example.com/custom/package"
@echo "EXAMPLE_LOCAL_PATH := ../path/to/package"
@echo
@echo "The built-in settings simplify the inclusion of common"
@echo "packages used during enjin development. Simply include"
@echo "one or more of the built-in keys and if necessary specify"
@echo "the path to the local git checkout of the given package."
@echo
@echo "Note that all of the options start with an underscore. This"
@echo "is only used to differentiate between custom settings and the"
@echo "built-in ones."
@echo
@echo "Built-in key options:"
@echo
@echo -e "$(foreach key,${BUILT_IN_GOPKG_KEYS},\n$(key);$($(key)_LABEL))" \
| column --table --table-noheadings --separator=";"
_enjenv:
@if [ -z "${ENJENV_EXE}" -o ! -x "${ENJENV_EXE}" ]; then \
echo "# critical error: enjenv not found"; \
false; \
fi
_golang: _enjenv
@if [ -z "$(call _has_feature,golang--build)" ]; then \
if [ "${GOLANG}" != "" ]; then \
${CMD} ${ENJENV_EXE} golang init --golang "${GOLANG}"; \
else \
${CMD} ${ENJENV_EXE} golang init; \
fi; \
${CMD} ${ENJENV_EXE} write-scripts; \
$(call _source_activate_run,${ENJENV_EXE},golang,setup-nancy); \
elif [ ! -f "${ENJENV_PATH}/activate" ]; then \
${CMD} ${ENJENV_EXE} write-scripts; \
else \
echo "# golang present"; \
fi
_nodejs: _enjenv
@if [ -z "$(call _has_feature,yarn)" ]; then \
if [ "${NODEJS}" != "" ]; then \
${CMD} ${ENJENV_EXE} nodejs init --nodejs "${NODEJS}"; \
else \
${CMD} ${ENJENV_EXE} nodejs init; \
fi; \
${CMD} ${ENJENV_EXE} write-scripts; \
else \
echo "# nodejs present"; \
fi
setup-golang: _golang
@echo "# setup-golang complete"
setup-yarn: _nodejs
@echo "# setup-yarn complete"
setup: setup-golang setup-yarn
tidy: _golang
@if [ ${GO_MOD} -le 1017 ]; then \
echo "# go mod tidy -go=1.16 && go mod tidy -go=1.17"; \
$(call _source_activate_run,go,mod,tidy,-go=1.16); \
$(call _source_activate_run,go,mod,tidy,-go=1.17); \
else \
echo "# go mod tidy"; \
$(call _source_activate_run,go,mod,tidy); \
fi
local: _golang
@`echo "_make_extra_locals" >> ${_INTERNAL_BUILD_LOG_}`
@$(call _validate_extra_pkgs)
@$(if ${GOPKG_KEYS},$(foreach key,${GOPKG_KEYS},$(call _make_go_local,$($(key)_GO_PACKAGE),$($(key)_LOCAL_PATH));))
@$(call _make_go_local,${GO_ENJIN_PKG},${BE_LOCAL_PATH})
unlocal: _golang
@`echo "_make_extra_unlocals" >> ${_INTERNAL_BUILD_LOG_}`
@$(call _validate_extra_pkgs)
@$(if ${GOPKG_KEYS},$(foreach key,${GOPKG_KEYS},$(call _make_go_unlocal,$($(key)_GO_PACKAGE));))
@$(call _make_go_unlocal,${GO_ENJIN_PKG})
be-update: export GOPROXY=direct
be-update: PKG_LIST = ${GO_ENJIN_PKG}@latest $(call _make_extra_pkgs)
be-update: _golang
@$(call _validate_extra_pkgs)
@echo "# go get ${PKG_LIST}"
@$(call _source_activate_run,go,get,${_BUILD_TAGS},${PKG_LIST})
clean:
ifdef override_clean
@$(call override_clean)
else
@$(call _clean,${CLEAN})
@$(call _clean,${EXTRA_CLEAN})
endif
dist-clean: clean
ifdef override_dist_clean
@$(call override_dist_clean)
else
@if [ -d "./${ENJENV_DIR}" ]; then \
ENJENV_PATH="${PWD}/${ENJENV_DIR}" \
${CMD} ${ENJENV_EXE} clean --force; \
fi
@$(call _clean,${DIST_CLEAN})
endif
build: export BE_APP_NAME=${APP_NAME}
build: export BE_SUMMARY=${APP_SUMMARY}
build: export BE_ENV_PREFIX=${ENV_PREFIX}
build: export BE_VERSION=${VERSION}
build: export BE_RELEASE=${RELEASE}
build: export ENJENV_GO_LDFLAGS=${_EXTRA_LDFLAGS}
build: export ENJENV_GO_GCFLAGS=${_EXTRA_GCFLAGS}
build: _golang ${EXTRA_BUILD_TARGET_DEPS}
ifdef pre_build
@$(call pre_build)
endif
ifdef override_build
@$(call override_build)