summarylogtreecommitdiffstats
path: root/prepare
blob: 8f20ba3eef676cfef9291a270e1b0ad70cfa1b6e (plain)
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
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
#!/bin/bash

ver54=109
ver57=19
ver58=18
ver59=16
ver510=27
ver511=11
ver512=rc6

_cpuschedselector() {
  msg2 "Which CPU sched variant do you want to build/install? Select \"CFS\" (linux kernel's default) if unsure."
  select CPUSCHED in "${_CPUSCHEDARRAY[@]}"
  do
    case $CPUSCHED in
      "CFS")
        echo "_cpusched=\"cfs\"" > "${_path}"/cpuschedset
        ;;
      "PDS")
        echo "_cpusched=\"pds\"" > "${_path}"/cpuschedset
        ;;
      "MuQSS")
        echo "_cpusched=\"MuQSS\"" > "${_path}"/cpuschedset
        ;;
      "BMQ")
        echo "_cpusched=\"bmq\"" > "${_path}"/cpuschedset
        ;;
      "Project C / PDS")
        echo "_cpusched=\"pds\"" > "${_path}"/cpuschedset
        ;;
      "Project C / BMQ")
        echo "_cpusched=\"bmq\"" > "${_path}"/cpuschedset
        ;;
      "Undead PDS (TkG)")
        echo "_cpusched=\"upds\"" > "${_path}"/cpuschedset
        ;;
      *)
    esac
    break
  done
}

_tkg_initscript() {

  # Default to Arch
  if [ -z "$_distro" ] || [ "$_ispkgbuild" = "true" ]; then
    msg2 "Defaulting to Archlinux target\n"
    _distro="Arch"
  fi

  # create build dir early
    _path="${_where}"

  # _basever, _basekernel and _sub are saved to the file "versel"
  # then this file is sourced at the end of these so these vars are accessible
  # to the rest of the script
  if [ -z "$_version" ] && [ ! -e "$_path"/versel ]; then
    case $_VERSEL in
          *)
          echo "_basever=510" > "$_path"/versel
          echo "_basekernel=5.10" >> "$_path"/versel
          echo "_sub=${ver510}" >> "$_path"/versel
          ;;
    esac
  elif [ -n "$_version" ];then
      case "$_version" in
		"5.10")
		echo "_basever=510" > "$_path"/versel
		echo "_basekernel=5.10" >> "$_path"/versel
		echo "_sub=${ver510}" >> "$_path"/versel
		;;
		*)
		error "There is something wrong with your kernel version selection, exiting..."
		exit 1
	esac
  fi

  # source versel early if present
  if [ -e "${_path}"/versel ]; then
    source "${_path}"/versel
  fi

  if [ -z "$_OPTIPROFILE" ] && [ ! -e "$_path"/cpuschedset ]; then
    # Prompt about optimized configurations. Available variable values will overwrite customization.cfg/external config ones.
    plain "Do you want to use a predefined optimized profile?"
    read -rp "`echo $'  > 1.Custom\n    2.Ryzen Desktop (Performance)\n    3.Other Desktop (Performance)\nchoice[1-3?]: '`" _OPTIPROFILE;
  fi
  if [ "$_OPTIPROFILE" = "2" ]; then
    source "${_path}"/ryzen-desktop-profile.cfg && msg2 "Ryzen Desktop (Performance) profile will be used." && msg2 ""
  elif [ "$_OPTIPROFILE" = "3" ]; then
    source "${_path}"/generic-desktop-profile.cfg && msg2 "Generic Desktop (Performance) profile will be used." && msg2 ""
  fi

  # source cpuschedset early if present
  if [ -e "${_path}"/cpuschedset ]; then
    source "${_path}"/cpuschedset
  fi

  # source compilerset early if present
  if [ -e "${_path}"/compilerset ]; then
    source "${_path}"/compilerset
  fi

  # CPU SCHED selector
  if [ "$_basever" = "54" ] || [ "$_basever" = "57" ]; then
    _CPUSCHEDARRAY=("PDS" "MuQSS" "BMQ" "CFS")
    _CPUSCHEDVARARRAY=("pds" "muqss" "MuQSS" "bmq" "cfs")
  elif [ "$_basever" = "58" ]; then
    _CPUSCHEDARRAY=("Undead PDS (TkG)" "Project C / PDS" "Project C / BMQ" "CFS")
    _CPUSCHEDVARARRAY=("upds" "pds" "bmq" "cfs")
  elif [ "$_basever" = "59" ] || [ "$_basever" = "510" ]; then
    _CPUSCHEDARRAY=("Undead PDS (TkG)" "Project C / PDS" "Project C / BMQ" "MuQSS" "CFS")
    _CPUSCHEDVARARRAY=("upds" "pds" "bmq" "muqss" "MuQSS" "cfs")
  elif [ "$_basever" = "511" ]; then
    _CPUSCHEDARRAY=("Undead PDS (TkG)" "Project C / PDS" "Project C / BMQ" "MuQSS" "CFS")
    _CPUSCHEDVARARRAY=("upds" "pds" "bmq" "muqss" "MuQSS" "cfs")
  else
    _CPUSCHEDARRAY=("CFS")
    _CPUSCHEDVARARRAY=("cfs")
  fi

  if [ -z "$_cpusched" ] && [ ! -e "${_path}"/cpuschedset ]; then
    _cpuschedselector
  elif [[ ${_CPUSCHEDVARARRAY[*]} =~ "$_cpusched" ]]; then
    if ( [ "$_cpusched" = "muqss" ] || [ "$_cpusched" = "MuQSS" ] ); then
      echo "_cpusched=\"MuQSS\"" > "${_path}"/cpuschedset
    else
      echo "_cpusched=\"$_cpusched\"" > "${_path}"/cpuschedset
    fi
  else
    if ! [[ ${_CPUSCHEDVARARRAY[*]} =~ "$_cpusched" ]]; then
      warning "Your cpusched selection ( $_cpusched ) is not available for the selected kernel version."
      if [ "$_nofallback" = "true" ]; then
        warning "Since _nofallback is enabled, let's exit..."
        exit 1
      else
        warning "Please select another:"
        _cpuschedselector
      fi
    fi
  fi

  if [ -n "$_custom_pkgbase" ]; then
    echo "_custom_pkgbase=\"${_custom_pkgbase}\"" >> "${_path}"/cpuschedset
  fi

  case $_compileroptlevel in
	"2")
	_compileropt="-O3"
	;;
	"3")
	_compileropt="-Os"
	;;
	*)
	_compileropt="-O2"
	;;
  esac

# Compiler selector
  if [ -z "$_compiler" ] && [ ! -e "${_path}"/compilerset ]; then
    plain "Which compiler do you want to use?"
    read -rp "`echo $'  > 1.GCC (recommended)\n    2.Clang/LLVM\nchoice[1-2?]: '`" _CONDITION_CMPLR;
    if [ "$_CONDITION_CMPLR" = "2" ];then
      echo "_compiler_name=\"-llvm\"" > ${_path}/compilerset
      echo "llvm_opt=\"LLVM=1\"" >> ${_path}/compilerset
    else
      echo "_compiler_name=" >> ${_path}/compilerset
    fi
  elif [ "$_compiler" = "llvm" ]; then
      echo "_compiler_name=\"-llvm\"" > ${_path}/compilerset
      echo "llvm_opt=\"LLVM=1\"" >> ${_path}/compilerset
  elif [ "$_compiler" = "gcc" ]; then
      echo "_compiler_name=" >> ${_path}/compilerset
  else
    if [ "$_nofallback" != "true" ] && [ ! -e "${_path}"/compilerset ] && [ "$_compiler" != "llvm" ]; then
      warning "Something is wrong with your compiler selection. Do you want to fallback to GCC (default)?"
      read -rp "`echo $'    > N/y : '`" _fallback;
    fi
    if [[ "$_fallback" =~ [yY] ]] || [ "$_nofallback" = "true" ]; then
      echo "_compiler_name=" >> "${_path}"/compilerset
    fi
    if [ ! -e "${_path}"/compilerset ]; then
      error "Exiting..."
      exit 1
    fi
  fi

  source "${_path}"/cpuschedset
  source "${_path}"/compilerset
  source "${_path}"/versel
}

user_patcher() {
    for _f in "$_where"/*."${_userpatch_ext}patch" "$_where"/*."${_userpatch_ext}revert"; do
      [ -e "${_f}" ] || continue
      warning "Found userpatch file ${f##*/} in the PKGBUILD directory."
      warning "Userpatches must now be placed in version-specific subdirectories (linux${_basever}-tkg-userpatches for this kernel version)."
      warning "The patch will not be applied."
      break
    done

	# To patch the user because all your base are belong to us
	local _patches=("$_where"/*."${_userpatch_ext}revert")
	if [ ${#_patches[@]} -ge 2 ] || [ -e "${_patches}" ]; then
	  if [ "$_user_patches_no_confirm" != "true" ]; then
	    msg2 "Found ${#_patches[@]} 'to revert' userpatches for ${_userpatch_target}:"
	    printf '%s\n' "${_patches[@]}"
	    read -rp "Do you want to install it/them? - Be careful with that ;)"$'\n> N/y : ' _CONDITION;
	  fi
	  if [[ "$_CONDITION" =~ [yY] ]] || [ "$_user_patches_no_confirm" = "true" ]; then
	    for _f in "${_patches[@]}"; do
	      if [ -e "${_f}" ]; then
	        msg2 "######################################################"
	        msg2 ""
	        msg2 "Reverting your own ${_userpatch_target} patch ${_f}"
	        msg2 ""
	        msg2 "######################################################"
	        patch -Np1 -R < "${_f}"
	        echo "Reverted your own patch ${_f}" >> "$_where"/last_build_config.log
	      fi
	    done
	  fi
	fi

	_patches=("$_where"/*."${_userpatch_ext}patch")
	if [ ${#_patches[@]} -ge 2 ] || [ -e "${_patches}" ]; then
	  if [ "$_user_patches_no_confirm" != "true" ]; then
	    msg2 "Found ${#_patches[@]} userpatches for ${_userpatch_target}:"
	    printf '%s\n' "${_patches[@]}"
	    read -rp "Do you want to install it/them? - Be careful with that ;)"$'\n> N/y : ' _CONDITION;
	  fi
	  if [[ "$_CONDITION" =~ [yY] ]] || [ "$_user_patches_no_confirm" = "true" ]; then
	    for _f in "${_patches[@]}"; do
	      if [ -e "${_f}" ]; then
	        msg2 "######################################################"
	        msg2 ""
	        msg2 "Applying your own ${_userpatch_target} patch ${_f}"
	        msg2 ""
	        msg2 "######################################################"
	        patch -Np1 < "${_f}"
	        echo "Applied your own patch ${_f}" >> "$_where"/last_build_config.log
	      fi
	    done
	  fi
	fi
}

_tkg_patcher() {
  if [ -e "$tkgpatch" ]; then
    echo -e "### Applying ${tkgpatch##*/}... ###" >> "$_where"/prepare.log
    patch -Np1 -i "$tkgpatch" >> "$_where"/prepare.log || error "An error was encountered applying patches. It was logged to the prepare.log file."
    echo -e "\n" >> "$_where"/prepare.log
  else
    msg2 "Patch either not found, not available for this kernel version or not needed. Skipping..."
  fi
}

_tkg_srcprep() {

  if [ "${_distro}" = "Arch" ]; then
    
    echo "-$pkgrel-tkg-${_cpusched}${_compiler_name}" > localversion.10-pkgrel
    echo -e "Version tail set to \"-$pkgrel-tkg-${_cpusched}${_compiler_name}\"\n" > "$_where"/prepare.log
    echo "" > localversion.20-pkgname

    # add upstream patch
    if [ "$_sub" != "0" ] && [[ "$_sub" != rc* ]]; then
      msg2 "Patching from $_basekernel to $pkgver"
      if [ ! -e "$srcdir/patch-${pkgver}" ]; then
        if [ -e "$srcdir/patch-${pkgver}.xz" ]; then
          xz -dk "$(readlink -f "$srcdir/patch-${pkgver}.xz")" --stdout > "$srcdir/patch-${pkgver}"
        else
          ( cd "$_where" && xz -dk patch-${pkgver}.xz && mv "$_where"/patch-${pkgver} "$srcdir"/ )
        fi
      fi
      tkgpatch="$srcdir/patch-${pkgver}" && _tkg_patcher
    fi

    # ARCH Patches
    if [ "${_configfile}" = "config_hardened.x86_64" ] && [ "${_cpusched}" = "cfs" ]; then
      msg2 "Using linux hardened patchset"
      tkgpatch="$srcdir/0012-linux-hardened.patch" && _tkg_patcher
    else
      tkgpatch="$srcdir/0001-add-sysctl-to-disallow-unprivileged-CLONE_NEWUSER-by.patch" && _tkg_patcher
    fi
  fi

  # graysky's cpu opts - https://github.com/graysky2/kernel_gcc_patch
  
  msg2 "Applying graysky's cpu opts patch"
  if [ "${_distro}" = "Arch" ]; then
    tkgpatch="$srcdir/more-uarches-for-kernel-${opt_ver}.patch" && _tkg_patcher
  elif [ "${_distro}" = "Void" ]; then
    tkgpatch="${wrksrc}/more-uarches-for-kernel-${opt_ver}.patch" && _tkg_patcher
  else
    tkgpatch="$srcdir/more-uarches-for-kernel-${opt_ver}.patch" && _tkg_patcher
  fi

  msg2 "Applying graysky's cpu opts patch (legacy)"
  if [ "${_distro}" = "Arch" ]; then
    tkgpatch="$srcdir/enable_additional_cpu_optimizations_for_gcc_v10.1%2B_kernel_v${opt_ver}.patch" && _tkg_patcher
  elif [ "${_distro}" = "Void" ]; then
    tkgpatch="${wrksrc}/enable_additional_cpu_optimizations_for_gcc_v10.1+_kernel_v${opt_ver}.patch" && _tkg_patcher
  else
    tkgpatch="$srcdir/enable_additional_cpu_optimizations_for_gcc_v10.1+_kernel_v${opt_ver}+.patch" && _tkg_patcher
  fi

  # TkG
  msg2 "Applying clear linux patches"
  tkgpatch="$srcdir/0002-clear-patches.patch" && _tkg_patcher

  msg2 "Applying glitched base patch"
  tkgpatch="$srcdir/0003-glitched-base.patch" && _tkg_patcher

  if [ -z $_misc_adds ]; then
    plain "Enable misc additions ? They may contain temporary fixes pending upstream, or some other changes that can break on non-Arch distros."
    read -rp "`echo $'    > [Y]/n : '`" _interactive_misc_adds;
    if [ "$_interactive_misc_adds" != "n" ] && [ "$_interactive_misc_adds" != "N" ]; then
      _misc_adds="true"
    fi
  fi

  if [ "$_misc_adds" = "true" ]; then
    msg2 "Applying misc additions patch"
    tkgpatch="$srcdir/0012-misc-additions.patch" && _tkg_patcher
  fi

  # prjc/bmq patch rev
  if [ "$_basever" = "58" ] || [ "$_basever" = "57" ]; then
    rev=3
  elif [ "$_basever" = "59" ]; then
    rev=3
  elif [ "$_basever" = "510" ]; then
    rev=2
  else
    rev=0
  fi

  if [ "${_cpusched}" = "MuQSS" ]; then
    # MuQSS
    msg2 "Applying MuQSS base patch"
    tkgpatch="$srcdir/0004-${_basekernel}-ck1.patch" && _tkg_patcher

    if [ "${_aggressive_ondemand}" = "true" ]; then
      msg2 "Applying MuQSS agressive ondemand governor patch"
      tkgpatch="$srcdir/0004-glitched-ondemand-muqss.patch" && _tkg_patcher
    fi

    msg2 "Applying Glitched MuQSS patch"
    tkgpatch="$srcdir/0004-glitched-muqss.patch" && _tkg_patcher

  elif [ "${_cpusched}" = "upds" ] || [ "${_cpusched}" = "pds" ]; then
    # upds naming quirk
    if [ "${_cpusched}" = "upds" ];then
      # is it dead or alive
      doa="-undead"
    fi

    # PDS-mq
    msg2 "Applying PDS base patch"
    if [ "${_cpusched}" = "upds" ] || ( [ "$_basever" = "54" ] || [ "$_basever" = "57" ] && [ "${_cpusched}" = "pds" ] ); then
      tkgpatch="$srcdir/0005-v${_basekernel}_undead-pds099o.patch" && _tkg_patcher
      if [ "${_aggressive_ondemand}" = "true" ]; then
        msg2 "Applying PDS agressive ondemand governor patch"
        tkgpatch="$srcdir/0005${doa}-glitched-ondemand-pds.patch" && _tkg_patcher
      fi
    else
      tkgpatch="$srcdir/0009-prjc_v${_basekernel}-r${rev}.patch" && _tkg_patcher
      if [ "${_aggressive_ondemand}" = "true" ]; then
        msg2 "Applying prjc PDS/BMQ agressive ondemand governor patch"
        tkgpatch="$srcdir/0009-glitched-ondemand-bmq.patch" && _tkg_patcher
      fi
    fi

    msg2 "Applying Glitched PDS patch"
    tkgpatch="$srcdir/0005${doa}-glitched-pds.patch" && _tkg_patcher

  elif [ "${_cpusched}" = "bmq" ]; then
    # Project C / BMQ
    msg2 "Applying Project C / BMQ base patch"
    if [ "$_basever" != "54" ]; then
      tkgpatch="$srcdir/0009-prjc_v${_basekernel}-r${rev}.patch" && _tkg_patcher
    else
      tkgpatch="$srcdir/0009-bmq_v5.4-r2.patch" && _tkg_patcher
    fi

    if [ "${_aggressive_ondemand}" = "true" ] && [ "$_basever" != "54" ]; then
      msg2 "Applying BMQ agressive ondemand governor patch"
      tkgpatch="$srcdir/0009-glitched-ondemand-bmq.patch" && _tkg_patcher
    fi

    msg2 "Applying Glitched BMQ patch"
    tkgpatch="$srcdir/0009-glitched-bmq.patch" && _tkg_patcher

  elif [ "${_cpusched}" = "cfs" ]; then
    msg2 "Applying Glitched CFS patch"
    tkgpatch="$srcdir/0003-glitched-cfs.patch" && _tkg_patcher
  fi

  if [ "$_distro" = "Void" ] && [[ "$_sub" = rc* ]]; then
    cd ${wrksrc}/linux-${_rc_kern_ver}
  elif [ "$_distro" = "Void" ] && [[ "$_sub" != rc* ]]; then
    cd ${wrksrc}/linux-${_kern_ver}
  fi

  
  if [ -z "${_configfile}" ]; then    
    if [ "${_distro}" = "Arch" ] || [ "$_distro" = "Void" ]; then
      cat "${srcdir}"/config.x86_64 > ./.config
    else
      if [ -f /boot/config-`uname -r` ];then
        msg2 "Using /boot/config-`uname -r` as config file"
        cp /boot/config-`uname -r` .config
      elif [ -f /proc/config.gz ];then
        msg2 "Using /proc/config.gz as config file"
        zcat --verbose /proc/config.gz > .config
      else
        msg2 "Current kernel config not found! Falling back to default..."
      fi
    fi
  else
    cat "${srcdir}/${_configfile}" > ./.config
  fi

  # Set some -tkg defaults
  echo "# CONFIG_DYNAMIC_FAULT is not set" >> ./.config
  sed -i -e 's/CONFIG_DEFAULT_FQ_CODEL=y/# CONFIG_DEFAULT_FQ_CODEL is not set/' ./.config
  echo "CONFIG_DEFAULT_CAKE=y" >> ./.config
  if [ "$_basever" = "54" ]; then
    echo "CONFIG_TP_SMAPI=m" >> ./.config
    echo "CONFIG_RAID6_USE_PREFER_GEN=y" >> ./.config
  fi
  if [ "$_basever" = "54" ] || [ "$_basever" = "59" ]; then
    sed -i -e 's/CONFIG_RCU_BOOST_DELAY=500/CONFIG_RCU_BOOST_DELAY=0/' ./.config
  fi
  echo "# CONFIG_NTP_PPS is not set" >> ./.config
  sed -i -e 's/CONFIG_CRYPTO_LZ4=m/CONFIG_CRYPTO_LZ4=y/' ./.config
  sed -i -e 's/CONFIG_CRYPTO_LZ4HC=m/CONFIG_CRYPTO_LZ4HC=y/' ./.config
  sed -i -e 's/CONFIG_LZ4_COMPRESS=m/CONFIG_LZ4_COMPRESS=y/' ./.config
  sed -i -e 's/CONFIG_LZ4HC_COMPRESS=m/CONFIG_LZ4HC_COMPRESS=y/' ./.config
  sed -i -e 's/CONFIG_ZSWAP_COMPRESSOR_DEFAULT_LZO=y/# CONFIG_ZSWAP_COMPRESSOR_DEFAULT_LZO is not set/' ./.config
  sed -i -e 's/# CONFIG_ZSWAP_COMPRESSOR_DEFAULT_LZ4 is not set/CONFIG_ZSWAP_COMPRESSOR_DEFAULT_LZ4=y/' ./.config
  sed -i -e 's/CONFIG_ZSWAP_COMPRESSOR_DEFAULT="lzo"/CONFIG_ZSWAP_COMPRESSOR_DEFAULT="lz4"/' ./.config
  sed -i -e 's/# CONFIG_CMDLINE_BOOL is not set/CONFIG_CMDLINE_BOOL=y/' ./.config
  if [ "$_futex2" = "true" ]; then
    sed -i -e 's/# CONFIG_EXPERT is not set/CONFIG_EXPERT=y/' ./.config
    echo -e "# CONFIG_DEBUG_RSEQ is not set\n
# CONFIG_PC104 is not set\n
# CONFIG_SLUB_MEMCG_SYSFS_ON is not set\n
# CONFIG_SLOB is not set\n
# CONFIG_PROCESSOR_SELECT is not set\n
# CONFIG_SUSPEND_SKIP_SYNC is not set\n
# CONFIG_DPM_WATCHDOG is not set\n
# CONFIG_ACPI_REDUCED_HARDWARE_ONLY is not set\n
# CONFIG_PCI_CNB20LE_QUIRK is not set\n
# CONFIG_ISA_BUS is not set\n
CONFIG_KVM_WERROR=y\n
# CONFIG_GCC_PLUGIN_CYC_COMPLEXITY is not set\n
# CONFIG_CFG80211_CERTIFICATION_ONUS is not set\n
# CONFIG_PCIE_BUS_TUNE_OFF is not set\n
CONFIG_PCIE_BUS_DEFAULT=y\n
# CONFIG_PCIE_BUS_SAFE is not set\n
# CONFIG_PCIE_BUS_PERFORMANCE is not set\n
# CONFIG_PCIE_BUS_PEER2PEER is not set\n
# CONFIG_PATA_PLATFORM is not set\n
# CONFIG_TTY_PRINTK is not set\n
# CONFIG_GPIO_SYSFS is not set\n
# CONFIG_VIDEO_TDA1997X is not set\n
# CONFIG_VIDEO_TLV320AIC23B is not set\n
# CONFIG_VIDEO_ADV7180 is not set\n
# CONFIG_VIDEO_ADV7183 is not set\n
# CONFIG_VIDEO_ADV7604 is not set\n
# CONFIG_VIDEO_ADV7842 is not set\n
# CONFIG_VIDEO_BT819 is not set\n
# CONFIG_VIDEO_BT856 is not set\n
# CONFIG_VIDEO_BT866 is not set\n
# CONFIG_VIDEO_KS0127 is not set\n
# CONFIG_VIDEO_ML86V7667 is not set\n
# CONFIG_VIDEO_SAA7110 is not set\n
# CONFIG_VIDEO_TC358743 is not set\n
# CONFIG_VIDEO_TVP514X is not set\n
# CONFIG_VIDEO_TVP7002 is not set\n
# CONFIG_VIDEO_TW9910 is not set\n
# CONFIG_VIDEO_VPX3220 is not set\n
# CONFIG_VIDEO_SAA7185 is not set\n
# CONFIG_VIDEO_ADV7170 is not set\n
# CONFIG_VIDEO_ADV7175 is not set\n
# CONFIG_VIDEO_ADV7343 is not set\n
# CONFIG_VIDEO_ADV7393 is not set\n
# CONFIG_VIDEO_ADV7511 is not set\n
# CONFIG_VIDEO_AD9389B is not set\n
# CONFIG_VIDEO_AK881X is not set\n
# CONFIG_VIDEO_THS8200 is not set\n
# CONFIG_VIDEO_THS7303 is not set\n
# CONFIG_VIDEO_I2C is not set\n
# CONFIG_VIDEO_ST_MIPID02 is not set\n
# CONFIG_VIDEO_GS1662 is not set\n
# CONFIG_MEDIA_TUNER_MSI001 is not set\n
# CONFIG_DVB_S5H1432 is not set\n
# CONFIG_DVB_DIB9000 is not set\n
# CONFIG_DVB_CXD2880 is not set\n
# CONFIG_DVB_MN88443X is not set\n
# CONFIG_DVB_LNBH29 is not set\n
# CONFIG_DVB_LGS8GL5 is not set\n
# CONFIG_DRM_DEBUG_DP_MST_TOPOLOGY_REFS is not set\n
# CONFIG_DRM_FBDEV_LEAK_PHYS_SMEM is not set\n
# CONFIG_DRM_I915_WERROR is not set\n
# CONFIG_DRM_I915_DEBUG is not set\n
# CONFIG_DRM_I915_DEBUG_MMIO is not set\n
# CONFIG_DRM_I915_SW_FENCE_DEBUG_OBJECTS is not set\n
# CONFIG_DRM_I915_SW_FENCE_CHECK_DAG is not set\n
# CONFIG_DRM_I915_DEBUG_GUC is not set\n
# CONFIG_DRM_I915_SELFTEST is not set\n
# CONFIG_DRM_I915_LOW_LEVEL_TRACEPOINTS is not set\n
# CONFIG_DRM_I915_DEBUG_VBLANK_EVADE is not set\n
# CONFIG_DRM_I915_DEBUG_RUNTIME_PM is not set\n
# CONFIG_FB_INTEL is not set\n
# CONFIG_SND_SOC_SOF_DEVELOPER_SUPPORT is not set\n
# CONFIG_USB_KBD is not set\n
# CONFIG_USB_MOUSE is not set\n
# CONFIG_USB_OTG_DISABLE_EXTERNAL_HUB is not set\n
# CONFIG_HARDENED_USERCOPY_PAGESPAN is not set\n
CONFIG_PAHOLE_HAS_SPLIT_BTF=y\n
CONFIG_DEBUG_INFO_BTF_MODULES=y\n
# CONFIG_DEBUG_FORCE_FUNCTION_ALIGN_32B is not set\n
# CONFIG_WIRELESS_WDS is not set\n
# CONFIG_UNWINDER_GUESS is not set" >> ./.config
  fi
  echo "CONFIG_CMDLINE=\"${_custom_commandline}\"" >> ./.config
  echo "# CONFIG_CMDLINE_OVERRIDE is not set" >> ./.config
  echo "# CONFIG_X86_P6_NOP is not set" >> ./.config
  #echo "# CONFIG_CPU_FREQ_DEFAULT_GOV_PERFORMANCE is not set" >> ./.config
  echo "# CONFIG_CPU_FREQ_DEFAULT_GOV_ONDEMAND is not set" >> ./.config
  echo "# CONFIG_CPU_FREQ_DEFAULT_GOV_CONSERVATIVE is not set" >> ./.config

  # openrgb
  echo "CONFIG_I2C_NCT6775=m" >> ./.config

  # ccache fix
  if [ "$_noccache" != "true" ]; then
    if { [ "$_distro" = "Arch" ] && pacman -Qq ccache &> /dev/null; } || { [ "$_distro" = "Ubuntu" ] && dpkg -l ccache > /dev/null; }\
	    || { [ "$_distro" = "Void" ] && xbps-query -s ccache > /dev/null; } ; then
      sed -i -e 's/CONFIG_GCC_PLUGINS=y/# CONFIG_GCC_PLUGINS is not set/' ./.config
    fi
  fi

  if [ "$_compiler_name" = "-llvm" ]; then
    echo 'CONFIG_KCSAN=n' >> ./.config
    if [ "$_basever" != "54" ] && [ "$_basever" != "57" ] && [ "$_basever" != "58" ]; then
      echo 'CONFIG_INIT_STACK_ALL_PATTERN=n' >> ./.config
    else
      echo 'CONFIG_INIT_STACK_ALL=n' >> ./.config
    fi
    sed -i -e 's/# CONFIG_INIT_ON_FREE_DEFAULT_ON is not set/CONFIG_INIT_ON_FREE_DEFAULT_ON=y/' ./.config
    sed -i -e 's/CONFIG_INIT_STACK_NONE=y/CONFIG_INIT_STACK_NONE=n/' ./.config
    echo "CONFIG_INIT_STACK_ALL_ZERO=y" >> ./.config
  fi

  if [ "$_font_autoselect" != "false" ]; then
    sed -i -e 's/CONFIG_FONT_TER16x32=y/# CONFIG_FONT_TER16x32 is not set\nCONFIG_FONT_AUTOSELECT=y/' ./.config
  fi

  # cpu opt

  if [ -n "$_processor_opt" ] && [[ "$_processor_opt" != native* ]]; then
    echo "# CONFIG_MNATIVE is not set" >> ./.config
    echo "# CONFIG_MNATIVE_AMD is not set" >> ./.config
    echo "# CONFIG_MNATIVE_INTEL is not set" >> ./.config
  fi

  if [ -n "$_processor_opt" ] && [[ "$_processor_opt" != generic* ]]; then
    sed -i -e 's/CONFIG_GENERIC_CPU=y/# CONFIG_GENERIC_CPU is not set/' ./.config
    echo "# CONFIG_GENERIC_CPU2 is not set" >> ./.config
    echo "# CONFIG_GENERIC_CPU3 is not set" >> ./.config
    echo "# CONFIG_GENERIC_CPU4 is not set" >> ./.config
  elif [ -n "$_processor_opt" ] && [ "$_processor_opt" = "genericv2" ]; then
    sed -i -e 's/CONFIG_GENERIC_CPU=y/# CONFIG_GENERIC_CPU is not set/' ./.config
    echo "CONFIG_GENERIC_CPU2=y" >> ./.config
    echo "# CONFIG_GENERIC_CPU3 is not set" >> ./.config
    echo "# CONFIG_GENERIC_CPU4 is not set" >> ./.config
  elif [ -n "$_processor_opt" ] && [ "$_processor_opt" = "genericv3" ]; then
    sed -i -e 's/CONFIG_GENERIC_CPU=y/# CONFIG_GENERIC_CPU is not set/' ./.config
    echo "# CONFIG_GENERIC_CPU2 is not set" >> ./.config
    echo "CONFIG_GENERIC_CPU3=y" >> ./.config
    echo "# CONFIG_GENERIC_CPU4 is not set" >> ./.config
  elif [ -n "$_processor_opt" ] && [ "$_processor_opt" = "genericv4" ]; then
    sed -i -e 's/CONFIG_GENERIC_CPU=y/# CONFIG_GENERIC_CPU is not set/' ./.config
    echo "# CONFIG_GENERIC_CPU2 is not set" >> ./.config
    echo "# CONFIG_GENERIC_CPU3 is not set" >> ./.config
    echo "CONFIG_GENERIC_CPU4=y" >> ./.config
  else
    echo "# CONFIG_GENERIC_CPU2 is not set" >> ./.config
    echo "# CONFIG_GENERIC_CPU3 is not set" >> ./.config
    echo "# CONFIG_GENERIC_CPU4 is not set" >> ./.config
  fi

  _cpu_marchs=("k8" "k8sse3" "k10" "barcelona" "bobcat" "jaguar" "bulldozer" "piledriver")
  _cpu_marchs+=("steamroller" "excavator" "zen" "zen2" "zen3" "mpsc" "atom" "core2" "nehalem" "westmere")
  _cpu_marchs+=("silvermont" "sandybridge" "ivybridge" "haswell" "broadwell" "skylake")
  _cpu_marchs+=("skylakex" "cannonlake" "icelake" "goldmont" "goldmontplus" "cascadelake")
  _cpu_marchs+=("cooperlake" "tigerlake" "native" "native_amd" "native_intel")

  if [ ! -z "$_processor_opt" ]; then # Don't populate when the config variable is empty
    for _march in "${_cpu_marchs[@]}"
    do
      _march_upper=`echo ${_march} | tr '[:lower:]' '[:upper:]'`
      if [ "$_processor_opt" = "$_march" ]; then
        echo "CONFIG_M${_march_upper}=y/" >> ./.config
      else
        echo "# CONFIG_M${_march_upper} is not set" >> ./.config
      fi
    done
  fi

  # Disable some debugging
  if [ "${_debugdisable}" = "true" ]; then
    sed -i -e 's/CONFIG_SLUB_DEBUG=y/# CONFIG_SLUB_DEBUG is not set/' ./.config
    sed -i -e 's/CONFIG_PM_DEBUG=y/# CONFIG_PM_DEBUG is not set/' ./.config
    sed -i -e 's/CONFIG_PM_ADVANCED_DEBUG=y/# CONFIG_PM_ADVANCED_DEBUG is not set/' ./.config
    sed -i -e 's/CONFIG_PM_SLEEP_DEBUG=y/# CONFIG_PM_SLEEP_DEBUG is not set/' ./.config
    sed -i -e 's/CONFIG_ACPI_DEBUG=y/# CONFIG_ACPI_DEBUG is not set/' ./.config
    sed -i -e 's/CONFIG_SCHED_DEBUG=y/# CONFIG_SCHED_DEBUG is not set/' ./.config
    sed -i -e 's/CONFIG_LATENCYTOP=y/# CONFIG_LATENCYTOP is not set/' ./.config
    sed -i -e 's/CONFIG_DEBUG_PREEMPT=y/# CONFIG_DEBUG_PREEMPT is not set/' ./.config
  fi

  if [ "${_cpusched}" = "MuQSS" ]; then
    # MuQSS default config
    echo "CONFIG_SCHED_MUQSS=y" >> ./.config
  elif [ "${_cpusched}" = "pds" ]; then
    # PDS default config
    echo "CONFIG_SCHED_ALT=y" >> ./.config
    echo "CONFIG_SCHED_PDS=y" >> ./.config
    echo "# CONFIG_SCHED_BMQ is not set" >> ./.config
  elif [ "${_cpusched}" = "upds" ]; then
    # PDS default config
    echo "CONFIG_SCHED_PDS=y" >> ./.config
  elif [ "${_cpusched}" = "bmq" ]; then
    # BMQ default config
    echo "CONFIG_SCHED_ALT=y" >> ./.config
    echo "CONFIG_SCHED_BMQ=y" >> ./.config
    echo "# CONFIG_SCHED_PDS is not set" >> ./.config
  fi

  if [ "${_cpusched}" = "MuQSS" ] || [ "${_cpusched}" = "pds" ] || [ "${_cpusched}" = "bmq" ] || [ "${_cpusched}" = "upds" ]; then
    # Disable CFS
    sed -i -e 's/CONFIG_FAIR_GROUP_SCHED=y/# CONFIG_FAIR_GROUP_SCHED is not set/' ./.config
    sed -i -e 's/CONFIG_CFS_BANDWIDTH=y/# CONFIG_CFS_BANDWIDTH is not set/' ./.config
    # sched yield type
    if [ -n "$_sched_yield_type" ]; then
      CONDITION0="$_sched_yield_type"
    # in customization.cfg for linux59-tkg _sched_yield_type is set to 0
    elif [ "$_basever" = "59" ]; then
      CONDITION0="0"
    else
      plain ""
      plain "CPU sched_yield_type - Choose what sort of yield sched_yield will perform."
      plain ""
      plain "For PDS and MuQSS:"
      plain "0: No yield."
      plain "1: Yield only to better priority/deadline tasks."
      plain "2: Expire timeslice and recalculate deadline."
      plain ""
      plain "For BMQ (experimental) - No recommended value yet, so try for yourself x) :"
      plain "0: No yield."
      plain "1: Deboost and requeue task. (default)"
      plain "2: Set rq skip task."
      if [ "${_cpusched}" = "MuQSS" ]; then
        read -rp "`echo $'\n      0. Supposedly best option for gaming performance,\n         but might lead to stability issues on some (AMD) platforms when combined with MuQSS\n    > 1. Default and recommended option for MuQSS - could lead to stability issues on some (Intel) platforms\n      2. Can be a good option with low rr_interval on MuQSS\n    [0-2?]: '`" CONDITION0;
      else
        read -rp "`echo $'\n    > 0. Recommended option for gaming on PDS - "tkg" default\n      1. Default, but can lead to stability issues on some platforms\n      2. Can be a good option with low rr_interval on MuQSS\n    [0-2?]: '`" CONDITION0;
      fi
    fi
    if [ "${_cpusched}" = "upds" ] || ( [ "$_basever" = "54" ] || [ "$_basever" = "57" ] && [ "${_cpusched}" = "pds" ] ); then
      _sched="pds"
    elif [ "${_cpusched}" = "MuQSS" ] || ( [ "$_basever" != "54" ] && [ "$_cpusched" != "bmq" ] && [ "$_cpusched" != "pds" ] ) || ( [ "$_basever" = "54" ] && [ "$_cpusched" = "bmq" ] ); then
      _sched="${_cpusched}"
    else
      _sched="alt_core"
    fi
    if [ "$CONDITION0" = "0" ]; then
      sed -i -e 's/int sched_yield_type __read_mostly = 1;/int sched_yield_type __read_mostly = 0;/' ./kernel/sched/${_sched}.c
    elif [ "$CONDITION0" = "1" ]; then
      msg2 "Using default CPU sched yield type (1)"
    elif [ "$CONDITION0" = "2" ]; then
      sed -i -e 's/int sched_yield_type __read_mostly = 1;/int sched_yield_type __read_mostly = 2;/' ./kernel/sched/${_sched}.c
    else
      if [ "${_cpusched}" = "MuQSS" ]; then
        msg2 "Using default CPU sched yield type (1)"
      else
        sed -i -e 's/int sched_yield_type __read_mostly = 1;/int sched_yield_type __read_mostly = 0;/' ./kernel/sched/${_sched}.c
      fi
    fi
  fi

  # Round Robin interval
  if [ "${_cpusched}" = "MuQSS" ] || [ "${_cpusched}" = "pds" ] || [ "${_cpusched}" = "bmq" ] || [ "${_cpusched}" = "upds" ]; then
    if [ -n "$_rr_interval" ]; then
      CONDITION1="$_rr_interval"
    else
      plain ""
      plain "Round Robin interval is the longest duration two tasks with the same nice level will"
      plain "be delayed for. When CPU time is requested by a task, it receives a time slice equal"
      plain "to the rr_interval in addition to a virtual deadline. When using yield_type 2, a low"
      plain "value can help offset the disadvantages of rescheduling a process that has yielded."
      plain ""
      plain "MuQSS default: 6ms"
      plain "PDS default: 4ms"
      plain "BMQ default: 2ms"
      read -rp "`echo $'\n    > 0.Keep defaults\n      1.2ms\n      2.4ms\n      3.6ms\n      4.8ms\n    [0-4?]: '`" CONDITION1;
    fi
    if [ "$CONDITION1" = "1" ]; then
      msg2 "Using 2ms rr_interval"
      _rrvalue="2"
    elif [ "$CONDITION1" = "2" ]; then
      msg2 "Using 4ms rr_interval"
      _rrvalue="4"
    elif [ "$CONDITION1" = "3" ]; then
      msg2 "Using 6ms rr_interval"
      _rrvalue="6"
    elif [ "$CONDITION1" = "4" ]; then
      msg2 "Using 8ms rr_interval"
      _rrvalue="8"
    else
      msg2 "Using default rr_interval"
      _rrvalue="default"
    fi
    if [ "$_basever" != "54" ]; then
      if [ "$_rrvalue" != "default" ]; then
        if [ "${_cpusched}" = "MuQSS" ]; then
          sed -i -e "s/int rr_interval __read_mostly = 6;/int rr_interval __read_mostly = ${_rrvalue};/" ./kernel/sched/"${_cpusched}".c
	elif [ "${_cpusched}" = "upds" ]; then
	  sed -i -e "s/#define SCHED_DEFAULT_RR (4)/#define SCHED_DEFAULT_RR (${_rrvalue})/" ./kernel/sched/pds.c
        elif [ "${_cpusched}" = "bmq" ] || [ "${_cpusched}" = "pds" ]; then
          sed -i -e "s/u64 sched_timeslice_ns __read_mostly = (4 * 1000 * 1000);/u64 sched_timeslice_ns __read_mostly = (${_rrvalue} * 1000 * 1000);/" ./kernel/sched/${_sched}.c
        fi
        if [ "${_cpusched}" == "bmq" ]; then
          echo "CONFIG_SCHED_TIMESLICE=2" >> ./.config
        fi
      else
        if [ "${_cpusched}" = "bmq" ] || [ "${_cpusched}" = "pds" ]; then
          sed -i -e "s/u64 sched_timeslice_ns __read_mostly = (4 * 1000 * 1000);/u64 sched_timeslice_ns __read_mostly = (2 * 1000 * 1000);/" ./kernel/sched/${_sched}.c
        fi
      fi
    else
      if [ "$_rrvalue" != "default" ]; then
        if [ "${_cpusched}" == "MuQSS" ]; then
          sed -i -e "s/int rr_interval __read_mostly = 6;/int rr_interval __read_mostly = ${_rrvalue};/" ./kernel/sched/"${_cpusched}".c
        elif [ "${_cpusched}" == "pds" ]; then
          sed -i -e "s/#define SCHED_DEFAULT_RR (4)/#define SCHED_DEFAULT_RR (${_rrvalue})/" ./kernel/sched/"${_cpusched}".c
        elif [ "${_cpusched}" == "bmq" ]; then
          echo "CONFIG_SCHED_TIMESLICE=${_rrvalue}" >> ./.config
        fi
      else
        if [ "${_cpusched}" == "bmq" ]; then
          echo "CONFIG_SCHED_TIMESLICE=2" >> ./.config
        fi
      fi
    fi
  fi

  # zenify
  if [ "$_zenify" = "true" ]; then
    echo "CONFIG_ZENIFY=y" >> ./.config
  elif [ "$_zenify" = "false" ]; then
    echo "# CONFIG_ZENIFY is not set" >> ./.config
  fi

  # compiler optimization level
  if [ "$_compileroptlevel" = "1" ]; then
    if [ "$_basever" != "54" ]; then
      echo "# CONFIG_CC_OPTIMIZE_FOR_PERFORMANCE_O3 is not set" >> ./.config
    else
      echo "# CONFIG_CC_OPTIMIZE_HARDER is not set" >> ./.config
    fi
  elif [ "$_compileroptlevel" = "2" ]; then
    sed -i -e 's/CONFIG_CC_OPTIMIZE_FOR_PERFORMANCE=y/# CONFIG_CC_OPTIMIZE_FOR_PERFORMANCE is not set/' ./.config
    if [ "$_basever" != "54" ]; then
      echo "CONFIG_CC_OPTIMIZE_FOR_PERFORMANCE_O3=y" >> ./.config
    else
      echo "CONFIG_CC_OPTIMIZE_HARDER=y" >> ./.config
    fi
  elif [ "$_compileroptlevel" = "3" ]; then
    sed -i -e 's/CONFIG_CC_OPTIMIZE_FOR_PERFORMANCE=y/# CONFIG_CC_OPTIMIZE_FOR_PERFORMANCE is not set/' ./.config
    sed -i -e 's/# CONFIG_CC_OPTIMIZE_FOR_SIZE is not set/CONFIG_CC_OPTIMIZE_FOR_SIZE=y/' ./.config
    if [ "$_basever" != "54" ]; then
      echo "# CONFIG_CC_OPTIMIZE_FOR_PERFORMANCE_O3 is not set" >> ./.config
    else
      echo "# CONFIG_CC_OPTIMIZE_HARDER is not set" >> ./.config
    fi
  fi

  # irq threading
  if [ "$_irq_threading" = "true" ]; then
    echo "CONFIG_FORCE_IRQ_THREADING=y" >> ./.config
  elif [ "$_irq_threading" = "false" ]; then
    echo "# CONFIG_FORCE_IRQ_THREADING is not set" >> ./.config
  fi

  # smt nice
  if [ "$_smt_nice" = "true" ]; then
    echo "CONFIG_SMT_NICE=y" >> ./.config
  elif [ "$_smt_nice" = "false" ]; then
    echo "# CONFIG_SMT_NICE is not set" >> ./.config
  fi

  # random trust cpu
  if [ "$_random_trust_cpu" = "true" ]; then
    sed -i -e 's/# CONFIG_RANDOM_TRUST_CPU is not set/CONFIG_RANDOM_TRUST_CPU=y/' ./.config
  fi

  # rq sharing
  if [ "$_runqueue_sharing" = "none" ]; then
    echo -e "CONFIG_RQ_NONE=y\n# CONFIG_RQ_SMT is not set\n# CONFIG_RQ_MC is not set\n# CONFIG_RQ_MC_LLC is not set\n# CONFIG_RQ_SMP is not set\n# CONFIG_RQ_ALL is not set" >> ./.config
  elif [ -z "$_runqueue_sharing" ] || [ "$_runqueue_sharing" = "smt" ]; then
    echo -e "# CONFIG_RQ_NONE is not set\nCONFIG_RQ_SMT=y\n# CONFIG_RQ_MC is not set\n# CONFIG_RQ_MC_LLC is not set\n# CONFIG_RQ_SMP is not set\n# CONFIG_RQ_ALL is not set" >> ./.config
  elif [ "$_runqueue_sharing" = "mc" ]; then
    echo -e "# CONFIG_RQ_NONE is not set\n# CONFIG_RQ_SMT is not set\nCONFIG_RQ_MC=y\n# CONFIG_RQ_MC_LLC is not set\n# CONFIG_RQ_SMP is not set\n# CONFIG_RQ_ALL is not set" >> ./.config
  elif [ "$_runqueue_sharing" = "smp" ]; then
    echo -e "# CONFIG_RQ_NONE is not set\n# CONFIG_RQ_SMT is not set\n# CONFIG_RQ_MC is not set\n# CONFIG_RQ_MC_LLC is not set\nCONFIG_RQ_SMP=y\n# CONFIG_RQ_ALL is not set" >> ./.config
  elif [ "$_runqueue_sharing" = "all" ]; then
    echo -e "# CONFIG_RQ_NONE is not set\n# CONFIG_RQ_SMT is not set\n# CONFIG_RQ_MC is not set\n# CONFIG_RQ_MC_LLC is not set\n# CONFIG_RQ_SMP is not set\nCONFIG_RQ_ALL=y" >> ./.config
  elif [ "$_runqueue_sharing" = "mc-llc" ]; then
    echo -e "# CONFIG_RQ_NONE is not set\n# CONFIG_RQ_SMT is not set\n# CONFIG_RQ_MC is not set\nCONFIG_RQ_MC_LLC=y\n# CONFIG_RQ_SMP is not set\n# CONFIG_RQ_ALL is not set" >> ./.config
  fi

  # timer freq
  if [ -n "$_timer_freq" ] && [ "$_timer_freq" != "300" ]; then
    sed -i -e 's/CONFIG_HZ_300=y/# CONFIG_HZ_300 is not set/' ./.config
    sed -i -e 's/CONFIG_HZ_300_NODEF=y/# CONFIG_HZ_300_NODEF is not set/' ./.config
    if [ "$_timer_freq" = "1000" ]; then
      sed -i -e 's/# CONFIG_HZ_1000 is not set/CONFIG_HZ_1000=y/' ./.config
      sed -i -e 's/CONFIG_HZ=300/CONFIG_HZ=1000/' ./.config
      echo "# CONFIG_HZ_500 is not set" >> ./.config
      echo "# CONFIG_HZ_500_NODEF is not set" >> ./.config
      echo "# CONFIG_HZ_750 is not set" >> ./.config
      echo "# CONFIG_HZ_750_NODEF is not set" >> ./.config
      echo "CONFIG_HZ_1000_NODEF=y" >> ./.config
      echo "# CONFIG_HZ_250_NODEF is not set" >> ./.config
      echo "# CONFIG_HZ_300_NODEF is not set" >> ./.config
    elif [ "$_timer_freq" = "750" ]; then
      sed -i -e 's/CONFIG_HZ=300/CONFIG_HZ=750/' ./.config
      echo "# CONFIG_HZ_500 is not set" >> ./.config
      echo "# CONFIG_HZ_500_NODEF is not set" >> ./.config
      echo "CONFIG_HZ_750=y" >> ./.config
      echo "CONFIG_HZ_750_NODEF=y" >> ./.config
      echo "# CONFIG_HZ_1000_NODEF is not set" >> ./.config
      echo "# CONFIG_HZ_250_NODEF is not set" >> ./.config
      echo "# CONFIG_HZ_300_NODEF is not set" >> ./.config
    elif [ "$_timer_freq" = "500" ]; then
      sed -i -e 's/CONFIG_HZ=300/CONFIG_HZ=500/' ./.config
      echo "CONFIG_HZ_500=y" >> ./.config
      echo "CONFIG_HZ_500_NODEF=y" >> ./.config
      echo "# CONFIG_HZ_750 is not set" >> ./.config
      echo "# CONFIG_HZ_750_NODEF is not set" >> ./.config
      echo "# CONFIG_HZ_1000_NODEF is not set" >> ./.config
      echo "# CONFIG_HZ_250_NODEF is not set" >> ./.config
      echo "# CONFIG_HZ_300_NODEF is not set" >> ./.config
    elif [ "$_timer_freq" = "100" ]; then
      sed -i -e 's/CONFIG_HZ=300/CONFIG_HZ=100/' ./.config
      echo "# CONFIG_HZ_500 is not set" >> ./.config
      echo "# CONFIG_HZ_750 is not set" >> ./.config
      echo "# CONFIG_HZ_1000_NODEF is not set" >> ./.config
      echo "# CONFIG_HZ_750_NODEF is not set" >> ./.config
      echo "# CONFIG_HZ_500_NODEF is not set" >> ./.config
      echo "# CONFIG_HZ_250_NODEF is not set" >> ./.config
      echo "# CONFIG_HZ_300_NODEF is not set" >> ./.config
      echo "CONFIG_HZ_100=y" >> ./.config
      echo "CONFIG_HZ_100_NODEF=y" >> ./.config
    fi
  elif [ "${_cpusched}" = "MuQSS" ] && [ -z "$_timer_freq" ]; then
      sed -i -e 's/CONFIG_HZ=300/CONFIG_HZ=100/' ./.config
      echo "# CONFIG_HZ_500 is not set" >> ./.config
      echo "# CONFIG_HZ_750 is not set" >> ./.config
      echo "# CONFIG_HZ_1000_NODEF is not set" >> ./.config
      echo "# CONFIG_HZ_750_NODEF is not set" >> ./.config
      echo "# CONFIG_HZ_500_NODEF is not set" >> ./.config
      echo "# CONFIG_HZ_250_NODEF is not set" >> ./.config
      echo "# CONFIG_HZ_300_NODEF is not set" >> ./.config
      echo "CONFIG_HZ_100=y" >> ./.config
      echo "CONFIG_HZ_100_NODEF=y" >> ./.config
  else
    sed -i -e 's/CONFIG_HZ_300=y/# CONFIG_HZ_300 is not set/' ./.config
    sed -i -e 's/CONFIG_HZ_300_NODEF=y/# CONFIG_HZ_300_NODEF is not set/' ./.config
    sed -i -e 's/CONFIG_HZ=300/CONFIG_HZ=500/' ./.config
    echo "CONFIG_HZ_500=y" >> ./.config
    echo "CONFIG_HZ_500_NODEF=y" >> ./.config
    echo "# CONFIG_HZ_250_NODEF is not set" >> ./.config
    echo "# CONFIG_HZ_300_NODEF is not set" >> ./.config
  fi

  # default cpu gov
  if [ "$_default_cpu_gov" = "performance" ]; then
    sed -i -e 's/CONFIG_CPU_FREQ_DEFAULT_GOV_SCHEDUTIL=y/# CONFIG_CPU_FREQ_DEFAULT_GOV_SCHEDUTIL is not set/' ./.config
    sed -i -e 's/# CONFIG_CPU_FREQ_DEFAULT_GOV_PERFORMANCE is not set/CONFIG_CPU_FREQ_DEFAULT_GOV_PERFORMANCE=y/' ./.config
  elif [ "$_default_cpu_gov" = "ondemand" ]; then
    sed -i -e 's/CONFIG_CPU_FREQ_DEFAULT_GOV_SCHEDUTIL=y/# CONFIG_CPU_FREQ_DEFAULT_GOV_SCHEDUTIL is not set/' ./.config
    sed -i -e 's/# CONFIG_CPU_FREQ_DEFAULT_GOV_ONDEMAND is not set/CONFIG_CPU_FREQ_DEFAULT_GOV_ONDEMAND=y/' ./.config
    sed -i -e 's/CONFIG_CPU_FREQ_GOV_ONDEMAND=m/CONFIG_CPU_FREQ_GOV_ONDEMAND=y/' ./.config
  fi

  # ACPI_CPUFREQ disablement
  if [ "$_disable_acpi_cpufreq" = "true" ]; then
    sed -i -e 's/CONFIG_X86_ACPI_CPUFREQ=m/# CONFIG_X86_ACPI_CPUFREQ is not set/' ./.config
  fi

  # ftrace
  if [ -z "$_ftracedisable" ]; then
    plain ""
    plain "Disable FUNCTION_TRACER/GRAPH_TRACER? Lowers overhead but limits debugging"
    plain "and analyzing of kernel functions."
    read -rp "`echo $'    > N/y : '`" CONDITION2;
  fi
  if [[ "$CONDITION2" =~ [yY] ]] || [ "$_ftracedisable" = "true" ]; then
    sed -i -e 's/CONFIG_FUNCTION_TRACER=y/# CONFIG_FUNCTION_TRACER is not set/' ./.config
    sed -i -e 's/CONFIG_FUNCTION_GRAPH_TRACER=y/# CONFIG_FUNCTION_GRAPH_TRACER is not set/' ./.config
  fi

  # disable numa
  if [ -z "$_numadisable" ]; then
    plain ""
    plain "Disable NUMA? Lowers overhead, but breaks CUDA/NvEnc on Nvidia if disabled."
    plain "https://bbs.archlinux.org/viewtopic.php?id=239174"
    read -rp "`echo $'    > N/y : '`" CONDITION3;
  fi
  if [[ "$CONDITION3" =~ [yY] ]] || [ "$_numadisable" = "true" ]; then
    # disable NUMA since 99.9% of users do not have multiple CPUs but do have multiple cores in one CPU
    sed -i -e 's/CONFIG_NUMA=y/# CONFIG_NUMA is not set/' \
        -i -e '/CONFIG_AMD_NUMA=y/d' \
        -i -e '/CONFIG_X86_64_ACPI_NUMA=y/d' \
        -i -e '/CONFIG_NODES_SPAN_OTHER_NODES=y/d' \
        -i -e '/# CONFIG_NUMA_EMU is not set/d' \
        -i -e '/CONFIG_NODES_SHIFT=6/d' \
        -i -e '/CONFIG_NEED_MULTIPLE_NODES=y/d' \
        -i -e '/CONFIG_USE_PERCPU_NUMA_NODE_ID=y/d' \
        -i -e '/CONFIG_ACPI_NUMA=y/d' ./.config
  fi

  # tickless
  if [ -z "$_tickless" ]; then
    plain ""
    plain "Use CattaRappa mode (Tickless/Dynticks) ?"
    plain "Can give higher performances in many cases but lower consistency on some hardware."
    plain "Just tickless idle can perform better with some platforms (mostly AMD) or CPU schedulers (mostly MuQSS)."
    read -rp "`echo $'\n      0.No, use periodic ticks\n      1.Yes, full tickless baby!\n    > 2.Just tickless idle plz\n    [0-2?]: '`" CONDITION4;
  fi
  if [ "$CONDITION4" = "0" ] || [ "$_tickless" = "0" ]; then
    echo "# CONFIG_NO_HZ_FULL_NODEF is not set" >> ./.config
    sed -i -e 's/# CONFIG_HZ_PERIODIC is not set/CONFIG_HZ_PERIODIC=y/' ./.config
    sed -i -e 's/CONFIG_NO_HZ_IDLE=y/# CONFIG_NO_HZ_IDLE is not set/' ./.config
    sed -i -e 's/CONFIG_NO_HZ_FULL=y/# CONFIG_NO_HZ_FULL is not set/' ./.config
    sed -i -e 's/CONFIG_NO_HZ=y/# CONFIG_NO_HZ is not set/' ./.config
    sed -i -e 's/CONFIG_NO_HZ_COMMON=y/# CONFIG_NO_HZ_COMMON is not set/' ./.config
  elif [ "$CONDITION4" = "2" ] || [ "$_tickless" = "1" ]; then
    echo "CONFIG_NO_HZ_FULL_NODEF=y" >> ./.config
    sed -i -e 's/CONFIG_HZ_PERIODIC=y/# CONFIG_HZ_PERIODIC is not set/' ./.config
    sed -i -e 's/CONFIG_NO_HZ_IDLE=y/# CONFIG_NO_HZ_IDLE is not set/' ./.config
    sed -i -e 's/# CONFIG_NO_HZ_FULL is not set/CONFIG_NO_HZ_FULL=y/' ./.config
    sed -i -e 's/# CONFIG_NO_HZ is not set/CONFIG_NO_HZ=y/' ./.config
    sed -i -e 's/# CONFIG_NO_HZ_COMMON is not set/CONFIG_NO_HZ_COMMON=y/' ./.config
    echo "CONFIG_CONTEXT_TRACKING=y" >> ./.config
    echo "# CONFIG_CONTEXT_TRACKING_FORCE is not set" >> ./.config
  else
    echo "# CONFIG_NO_HZ_FULL_NODEF is not set" >> ./.config
    sed -i -e 's/CONFIG_HZ_PERIODIC=y/# CONFIG_HZ_PERIODIC is not set/' ./.config
    sed -i -e 's/# CONFIG_NO_HZ_IDLE is not set/CONFIG_NO_HZ_IDLE=y/' ./.config
    sed -i -e 's/CONFIG_NO_HZ_FULL=y/# CONFIG_NO_HZ_FULL is not set/' ./.config
    sed -i -e 's/# CONFIG_NO_HZ is not set/CONFIG_NO_HZ=y/' ./.config
    sed -i -e 's/# CONFIG_NO_HZ_COMMON is not set/CONFIG_NO_HZ_COMMON=y/' ./.config
  fi

  # voluntary preempt
  if [ "$_voluntary_preempt" = "true" ]; then
    sed -i -e 's/CONFIG_PREEMPT=y/# CONFIG_PREEMPT is not set/' ./.config
    sed -i -e 's/CONFIG_PREEMPT_LL=y/# CONFIG_PREEMPT_LL is not set/' ./.config
    sed -i -e 's/# CONFIG_PREEMPT_VOLUNTARY is not set/CONFIG_PREEMPT_VOLUNTARY=y/' ./.config
  fi

  # Open Firmware support
  if [ -z "$_OFenable" ]; then
    plain ""
    plain "Enable Device Tree and Open Firmware support?"
    read -rp "`echo $'    > N/y : '`" CONDITION6;
  fi
  if [[ "$CONDITION6" =~ [yY] ]] || [ "$_OFenable" = "true" ]; then
    sed -i -e 's/# CONFIG_OF is not set/CONFIG_OF=y/' ./.config
  fi

  # acs override
  if [ -z "$_acs_override" ]; then
    plain ""
    plain "Use ACS override patch?"
    plain "https://wiki.archlinux.org/index.php/PCI_passthrough_via_OVMF#Bypassing_the_IOMMU_groups_.28ACS_override_patch.29"
    read -rp "`echo $'    > N/y : '`" CONDITION7;
  fi
  if [[ "$CONDITION7" =~ [yY] ]] || [ "$_acs_override" = "true" ]; then
    msg2 "Patching ACS override"
    tkgpatch="$srcdir/0006-add-acs-overrides_iommu.patch" && _tkg_patcher
  fi

  # bcachefs
  if [ -z "$_bcachefs" ] && [ "$_basever" != "54" ]; then
     plain ""
     plain "Add Bcache filesystem support? You'll have to install bcachefs-tools-git from AUR for utilities."
     plain "https://bcachefs.org/"
     read -rp "`echo $'    > N/y : '`" CONDITION8;
  fi
  if [[ "$CONDITION8" =~ [yY] ]] || [ "$_bcachefs" = "true" ]; then
     msg2 "Patching Bcache filesystem support override"
     tkgpatch="$srcdir/0008-${_basekernel}-bcachefs.patch" && _tkg_patcher
     echo "CONFIG_BCACHEFS_FS=m" >> ./.config
     echo "CONFIG_BCACHEFS_QUOTA=y" >> ./.config
     echo "CONFIG_BCACHEFS_POSIX_ACL=y" >> ./.config
     echo "# CONFIG_BCACHEFS_DEBUG is not set" >> ./.config
     echo "# CONFIG_BCACHEFS_TESTS is not set" >> ./.config
     echo "# CONFIG_DEBUG_CLOSURES is not set" >> ./.config
  fi

  # fsync support
  if [ -z "$_fsync" ]; then
    plain ""
    plain "Enable support for fsync, an experimental replacement for esync in Valve Proton 4.11+"
    plain "https://steamcommunity.com/games/221410/announcements/detail/2957094910196249305"
    read -rp "`echo $'    > N/y : '`" CONDITION9;
  fi
  if [[ "$CONDITION9" =~ [yY] ]] || [ "$_fsync" = "true" ]; then
    msg2 "Patching Fsync support"
    tkgpatch="$srcdir/0007-v${_basekernel}-fsync.patch" && _tkg_patcher
  fi

  # futex2 support
  if [ -z "$_futex2" ]; then
    plain ""
    plain "Enable support for futex2, an experimental replacement for esync and fsync in Valve Proton 5.13 experimental"
    plain "Can be enabled alongside regular fsync patchset to have a fallback option"
    plain "https://gitlab.collabora.com/tonyk/linux/-/tree/futex2-dev"
    plain "https://github.com/ValveSoftware/Proton/issues/4568"
    read -rp "`echo $'    > N/y : '`" CONDITION10;
  fi
  if [[ "$CONDITION10" =~ [yY] ]] || [ "$_futex2" = "true" ]; then
    msg2 "Patching futex2 support"
    tkgpatch="$srcdir/0007-v${_basekernel}-futex2_interface.patch" && _tkg_patcher
    echo "CONFIG_FUTEX2=y" >> ./.config
  fi

  # winesync support
  if [ -z "$_winesync" ]; then
    plain ""
    plain "Enable support for winesync/fastsync, an experimental replacement for esync"
    plain "https://repo.or.cz/linux/zf.git/shortlog/refs/heads/winesync"
    warning "Alternatively, on Arch you can use the DKMS module which allows for using the feature on multiple kernels side by side: https://aur.archlinux.org/packages/winesync-dkms/"
    read -rp "`echo $'    > N/y : '`" CONDITION_winesync;
  fi
  if [[ "$CONDITION_winesync" =~ [yY] ]] || [ "$_winesync" = "true" ]; then
    msg2 "Patching winesync/fastsync support"
    tkgpatch="$srcdir/0007-v${_basekernel}-winesync.patch" && _tkg_patcher
    echo "CONFIG_WINESYNC=m" >> ./.config
    echo "KERNEL==\"winesync\", MODE=\"0644\"" > ../winesync.rules
    echo "winesync" > ../winesync.conf
  fi

 # Anbox modules
  if [ "$_basever" != "54" ]; then
    if [ -z "$_anbox" ]; then
      plain ""
      plain "Enable android modules for use with Anbox?"
      plain "https://github.com/anbox/anbox"
      read -rp "`echo $'    > N/y : '`" CONDITION12;
    fi
    if [[ "$CONDITION12" =~ [yY] ]] || [ "$_anbox" = "true" ]; then
      echo "CONFIG_ASHMEM=y" >> ./.config
      echo "CONFIG_ION=y" >> ./.config
      echo "CONFIG_ION_CMA_HEAP=y" >> ./.config
      echo "# CONFIG_ION_SYSTEM_HEAP is not set" >> ./.config
      echo "CONFIG_ANDROID=y" >> ./.config
      echo "CONFIG_ANDROID_BINDER_IPC=y" >> ./.config
      echo "CONFIG_ANDROID_BINDERFS=y" >>./.config
      echo 'CONFIG_ANDROID_BINDER_DEVICES="binder,hwbinder,vndbinder"' >>./.config
      echo "# CONFIG_ANDROID_BINDER_IPC_SELFTEST is not set" >> ./.config
      warning "Please make sure to read up on how to use this; https://github.com/Frogging-Family/linux-tkg#anbox-usage"
      if [[ "$CONDITION12" =~ [yY] ]]; then
        read -rp "Press enter to continue..."
      fi
    fi
  fi

  # Community patches
  if [ -n "$_community_patches" ]; then
    if [ ! -d "$_where/../community-patches" ]; then
      cd "$_where/.." && git clone https://github.com/Frogging-Family/community-patches.git && cd "${srcdir}/${_srcpath}"
    fi
    _community_patches=($_community_patches)
    mkdir -p "$_where"/linux"$_basever"-tkg-userpatches
    for _p in ${_community_patches[@]}; do
      ln -s "$_where"/../community-patches/linux"$_basever"-tkg/$_p "$_where"/linux"$_basever"-tkg-userpatches/$_p
    done
  fi

  # userpatches
  if [ "$_user_patches" = "true" ]; then
    _userpatch_target="linux-${_basekernel}"
    _userpatch_ext="my"
    user_patcher
  fi

  # Community patches removal
  for _p in ${_community_patches[@]}; do
    rm -f "$_where"/linux"$_basever"-tkg-userpatches/$_p
  done

  if [ "$_distro" = "Arch" ] || [ "$_distro" = "Void" ]; then
    # don't run depmod on 'make install'. We'll do this ourselves in packaging
    sed -i '2iexit 0' scripts/depmod.sh

    # get kernel version
    make prepare ${llvm_opt}
  fi

  # modprobed-db
  if [ -z "$_modprobeddb" ]; then
    plain ""
    plain "Use modprobed db to clean config from unneeded modules?"
    plain "Speeds up compilation considerably. Requires root."
    plain "https://wiki.archlinux.org/index.php/Modprobed-db"
    plain "!!!! Make sure to have a well populated db !!!!"
    read -rp "`echo $'    > N/y : '`" CONDITIONMPDB;
  fi
  if [[ "$CONDITIONMPDB" =~ [yY] ]] || [ "$_modprobeddb" = "true" ]; then
    if [ -f "$where"/"$_modprobeddb_db_path" ];then
      _modprobeddb_db_path="$where"/"$_modprobeddb_db_path"
    fi
    if [ ! -f $_modprobeddb_db_path ]; then
      msg2 "modprobed-db database not found"
      exit 1
    fi
    yes "" | make LSMOD=$_modprobeddb_db_path localmodconfig ${llvm_opt}
  fi

  if [ true = "$_config_fragments" ]; then
    local fragments=()
    mapfile -d '' -t fragments < <(find "$_where"/ -type f -name "*.myfrag" -print0)

    if [ true = "$_config_fragments_no_confirm" ]; then
      printf 'Using config fragment %s\n' "${fragments[@]#$_where/}"
    else
      for i in "${!fragments[@]}"; do
        while true; do
          read -r -p 'Found config fragment '"${fragments[$i]#$_where/}"', apply it? [y/N] ' CONDITIONMPDB
          CONDITIONMPDB="$(printf '%s' "$CONDITIONMPDB" | tr '[:upper:]' '[:lower:]')"
          case "$CONDITIONMPDB" in
            y|yes)
              break;;
            n|no|'')
              unset fragments[$i]
              break;;
            *)
              echo 'Please answer with yes or no'
          esac
        done
      done
    fi

    if [ 0 -lt "${#fragments[@]}" ]; then
      scripts/kconfig/merge_config.sh -m .config "${fragments[@]}"
    fi
  fi

  # menuconfig / nconfig
  if [ -z "$_menunconfig" ] && [ "$_distro" != "Void" ]; then
    plain ""
    plain "*Optional* For advanced users - Do you want to use make menuconfig or nconfig"
    plain "to configure the kernel before building it?"
    plain "If you do, make sure your terminal is currently"
    plain "at least 19 lines by 80 columns large or you'll get an error :D"
    read -rp "`echo $'    > 0. nope\n      1. menuconfig\n      2. nconfig\n      3. xconfig\n      choice[0-3?]: '`" CONDITIONMNC;
    _menunconfig="$CONDITIONMNC"
  fi
  if [ 1 = "$_menunconfig" ]; then
    cp .config .config.orig
    make menuconfig ${llvm_opt}
  elif [ 2 = "$_menunconfig" ]; then
    cp .config .config.orig
    make nconfig ${llvm_opt}
  elif [ 3 = "$_menunconfig" ]; then
    cp .config .config.orig
    make xconfig ${llvm_opt}
  else
    # rewrite configuration
    yes "" | make config ${llvm_opt} >/dev/null
  fi
  if [ 1 = "$_menunconfig" ] || [ 2 = "$_menunconfig" ] || [ 3 = "$_menunconfig" ]; then
    if [ -z "${_diffconfig}" ]; then
      while true; do
        read -r -p 'Generate a config fragment from your changes? [y/N] ' CONDITIONF
        CONDITIONF="$(printf '%s' "$CONDITIONF" | tr '[:upper:]' '[:lower:]')"
        case "$CONDITIONF" in
          y|yes)
            _diffconfig=true
            break;;
          n|no|'')
            _diffconfig=false
            break;;
          *)
            echo 'Please answer with yes or no'
        esac
      done
    fi
    if [ true = "$_diffconfig" ]; then
      if [ -z "$_diffconfig_name" ]; then
        IFS= read -r -p 'Filename for the config fragment [leave empty to not generate fragment]: ' _diffconfig_name
      fi
      if [ -z "$_diffconfig_name" ]; then
        echo 'No file name given, not generating config fragment.'
      else (
        prev_pwd="${PWD:-$(pwd)}"
        cd "$_where"
        "${prev_pwd}/scripts/diffconfig" -m "${prev_pwd}/.config.orig" "${prev_pwd}/.config" > "$_diffconfig_name"
      ) fi
    fi
    rm .config.orig
  fi

  if [ "$_distro" = "Arch" ]; then
    make -s kernelrelease > version
    msg2 "Prepared %s version %s" "$pkgbase" "$(<version)"
  fi

  # copy new config file back to the user's git folder for an eventual future use
  cp .config "${_where}"/kernelconfig.new
}

exit_cleanup() {
  # Remove state tracker
  rm -f "$_where"/cpuschedset
  rm -f "$_where"/compilerset
  rm -f "$_where"/versel

  # Community patches removal in case of failure
  for _p in ${_community_patches[@]}; do
    rm -f "$_where"/"$_p"
  done

  if [ "$_NUKR" = "true" ] && [ "$_where" != "$srcdir" ]; then
    rm -rf "$_where"/src/*
    # Double tap
    rm -rf "$srcdir"/linux-*
    rm -rf "$srcdir"/*.xz
    rm -rf "$srcdir"/*.patch
    rm -rf "$srcdir"/*-profile.cfg
    rm -rf "$srcdir"/*.rules
    rm -f "$srcdir"/config.x86_64
    rm -f "$srcdir"/customization.cfg

  elif [ "$_distro" == "Arch" ]; then
    rm -rf "$srcdir"/linux-${_basekernel}/Documentation/filesystems/aufs/*
    rm -f "$srcdir"/linux-${_basekernel}/Documentation/ABI/testing/*-aufs
    rm -rf "$srcdir"/linux-${_basekernel}/fs/aufs/*
    rm -f "$srcdir"/linux-${_basekernel}/include/uapi/linux/aufs*

    rm -f "$srcdir"/linux-${_basekernel}/mm/prfile.c

    rm -f "$srcdir"/linux-${_basekernel}/block/bfq*

    rm -rf "$srcdir"/linux-${_basekernel}/drivers/scsi/vhba/*

    rm -rf "$srcdir"/linux-${_basekernel}/fs/exfat/*
    rm -f "$srcdir"/linux-${_basekernel}/include/trace/events/fs.h

    rm -f "$srcdir"/linux-${_basekernel}/Documentation/scheduler/sched-PDS-mq.txt
    rm -f "$srcdir"/linux-${_basekernel}/include/linux/skip_list.h
    rm -f "$srcdir"/linux-${_basekernel}/kernel/sched/pds.c
    rm -f "$srcdir"/linux-${_basekernel}/kernel/sched/pds_sched.h

    rm -f "$srcdir"/linux-${_basekernel}/Documentation/scheduler/sched-BMQ.txt
    rm -f "$srcdir"/linux-${_basekernel}/kernel/sched/${_sched}.c
    rm -f "$srcdir"/linux-${_basekernel}/kernel/sched/sched/alt_debug.c
    rm -f "$srcdir"/linux-${_basekernel}/kernel/sched/alt_sched.h

    rm -f "$srcdir"/linux-${_basekernel}/Documentation/scheduler/sched-BFS.txt
    rm -f "$srcdir"/linux-${_basekernel}/Documentation/scheduler/sched-MuQSS.txt
    rm -rf "$srcdir"/linux-${_basekernel}/arch/blackfin/*
    rm -f "$srcdir"/linux-${_basekernel}/arch/powerpc/configs/c2k_defconfig
    rm -f "$srcdir"/linux-${_basekernel}/arch/score/configs/spct6600_defconfig
    rm -f "$srcdir"/linux-${_basekernel}/arch/tile/configs/tilegx_defconfig
    rm -f "$srcdir"/linux-${_basekernel}/arch/tile/configs/tilepro_defconfig
    rm -f "$srcdir"/linux-${_basekernel}/drivers/staging/lustre/lnet/lnet/lib-eq.c
    rm -f "$srcdir"/linux-${_basekernel}/kernel/sched/MuQSS*
    rm -f "$srcdir"/linux-${_basekernel}/kernel/skip_list.c

    rm -f "$srcdir"/linux-${_basekernel}/Documentation/vm/uksm.txt
    rm -f "$srcdir"/linux-${_basekernel}/include/linux/sradix-tree.h
    rm -f "$srcdir"/linux-${_basekernel}/include/linux/uksm.h
    rm -f "$srcdir"/linux-${_basekernel}/lib/sradix-tree.c
    rm -f "$srcdir"/linux-${_basekernel}/mm/uksm.c
  fi

  if [ "${_distro}" = "Arch" ]; then
    remove_deps || ( true && msg2 "remove_deps not found" )
  fi

  msg2 'exit cleanup done\n'
  if [ -n "$_runtime" ]; then
    msg2 "compilation time : \n$_runtime"
  fi
}