Repository navigation
Expand file tree
/
Copy pathninqu.rules
More file actions
980 lines (856 loc) · 35.3 KB
/
Copy pathninqu.rules
File metadata and controls
980 lines (856 loc) · 35.3 KB
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
; each generated file has one rule and one target, so parallel
; generators never write through another target's side effects
(rule CONFIG_SET
(out "scripts/mk/config.set")
(dep "build.cfg" "scripts/genconfig.sh")
(exec sh scripts/genconfig.sh config-set))
(rule CONFIG_KV
(out "scripts/mk/config.kv")
(dep "build.cfg" "scripts/genconfig.sh")
(exec sh scripts/genconfig.sh config-kv))
(rule NOFORK_LIST_H
(out "shared/libutil/nofork_list.h")
(dep "build.cfg" "scripts/genconfig.sh")
(exec sh scripts/genconfig.sh nofork-list-h))
(rule FEATURES_H
(out "scripts/mk/features.h")
(dep "build.cfg" "scripts/genconfig.sh")
(exec sh scripts/genconfig.sh features-h))
(set-file "scripts/mk/config.set")
; static libraries: compile every .c in each lib dir then AR
;
(rule LIBUTF_OBJ
(glob "shared/libutf/*.c")
(dep $(MATCH) FEATURES_H)
(out "$(STEM).o")
(exec $(CC) $(CPPFLAGS) -Ishared/libutf $(CFLAGS) -c -o $(OUT) $(MATCH)))
(rule LIBUTF
(dep LIBUTF_OBJ)
(out "shared/libutf/libutf.a")
(description "utf-8 and rune handling, linked into every aruu tool")
(feature core-lib)
(exec $(AR) $(ARFLAGS) $(OUT) $(IN)))
; a file of one system (net_linux.c, passwd_obsd.c) keeps its code under
; that system's #if, so every file is compiled everywhere and the others
; come out empty
(rule LIBUTIL_OBJ
(glob "shared/libutil/*.c")
(dep $(MATCH) "shared/accounts.h" "shared/diskutil.h" "shared/filesystem.h" "shared/net.h" "shared/passwd.h"
"shared/proc.h" "shared/reboot.h" "shared/session.h" "shared/sysinfo.h"
"shared/timer.h" "shared/util.h" "shared/kmap.h" FEATURES_H)
(after NOFORK_LIST_H)
(out "$(STEM).o")
(exec $(CC) $(CPPFLAGS_LIBUTIL) -Ishared -Ishared/libutil $(CFLAGS) -c -o $(OUT) $(MATCH)))
(rule LIBUTIL
(dep LIBUTIL_OBJ)
(out "shared/libutil/libutil.a")
(description "allocation, error reporting, and string helpers shared by every tool")
(feature core-lib)
(exec $(AR) $(ARFLAGS) $(OUT) $(IN)))
(rule LIBREDLINE_OBJ
(glob "shared/libredline/*.c")
(dep $(MATCH) FEATURES_H)
(out "$(STEM).o")
(exec $(CC) $(CPPFLAGS) -Ishared/libredline $(CFLAGS) -c -o $(OUT) $(MATCH)))
(rule LIBREDLINE
(dep LIBREDLINE_OBJ)
(out "shared/libredline/libredline.a")
(description "line editing used by sh and any other interactive tool")
(feature core-lib)
(exec $(AR) $(ARFLAGS) $(OUT) $(IN)))
(rule LIBBLAKE3_OBJ
(glob "shared/libblake3/*.c")
(dep $(MATCH) FEATURES_H)
(out "$(STEM).o")
(exec $(CC) $(CPPFLAGS) -Ishared/libblake3 $(CFLAGS) -c -o $(OUT) $(MATCH)))
(rule LIBBLAKE3
(dep LIBBLAKE3_OBJ)
(out "shared/libblake3/libblake3.a")
(description "the BLAKE3 hash algorithm, linked into b3sum, not embedded in it")
(feature core-lib)
(exec $(AR) $(ARFLAGS) $(OUT) $(IN)))
(rule LIBDISK_OBJ
(glob "shared/libdisk/*.c")
(skip "label_test.c" "plan_test.c")
(dep $(MATCH) FEATURES_H)
(out "$(STEM).o")
(exec $(CC) $(CPPFLAGS) -Ishared -Ishared/libdisk $(CFLAGS) -c -o $(OUT) $(MATCH)))
(rule LIBDISK
(dep LIBDISK_OBJ)
(out "shared/libdisk/libdisk.a")
(description "partition tables: the GPT and MBR as a list of partitions, for fdisk and for a partitioner")
(feature core-lib)
(exec $(AR) $(ARFLAGS) $(OUT) $(IN)))
; file(1) magic: tests read from file's own databases. self contained
; (c99 and posix, none of aruu's headers) because the same sources are
; copied verbatim into other MICE components that tell types by bytes
(rule LIBMAGIC_OBJ
(glob "shared/libmagic/*.c")
(dep $(MATCH) "shared/libmagic/magic.h" "shared/libmagic/mgint.h")
(out "$(STEM).o")
(exec $(CC) $(CPPFLAGS) -Ishared/libmagic $(CFLAGS) -c -o $(OUT) $(MATCH)))
(rule LIBMAGIC
(dep LIBMAGIC_OBJ)
(out "shared/libmagic/libmagic.a")
(description "the file(1) magic engine, linked into file, not embedded in it")
(feature core-lib)
(exec $(AR) $(ARFLAGS) $(OUT) $(IN)))
(group lib LIBUTF LIBUTIL LIBREDLINE LIBBLAKE3 LIBDISK LIBMAGIC)
; perfile: every *.c directly inside one of these dirs becomes its
; own binary of the same name, individually gated by
; build_<category>_<ident> (lowercase, hyphens and dots turned to
; underscores, see the $(IDENT) comment above BOX_OBJ below for why)
; (skip) excludes files that belong to a multi-file tool below instead
;
; -lcrypt and -lresolv used to be blanket LDLIBS entries, linked into
; every single utility whether it called crypt(3)/resolver functions
; or not. tracing real callers of shared/libutil/passwd.c's pw_check/
; pw_gensalt (not just direct crypt() calls) turns up exactly four:
; passwd, mkpasswd, login, su need -lcrypt; host needs -lresolv
; narrowing this here, not just for tidiness, is what makes aruu
; buildable on a host whose libc ships a static libresolv/libm but no
; static libcrypt. b3sum is the one EXTRA_BIN file with its own extra
; library dependency for a different reason: BLAKE3 used to be
; implemented inline in b3sum.c itself, which meant anything else
; that wanted the same algorithm (ports/pkgtools/libpkg, for hashing
; package archives) had no real library to link against and carried
; its own separate copy instead, with no way to notice the two had
; drifted until one of them turned out to have a bug the other one
; didn't. shared/libblake3 exists so there is exactly one copy
(map EXTRA_LIBS
(diff "-lm")
(wget $(LDLIBS_TLS))
(passwd "-lcrypt")
(mkpasswd "-lcrypt")
(login "-lcrypt")
(su "-lcrypt")
(usermod "-lcrypt")
(host "-lresolv")
(b3sum "-Lshared/libblake3 -lblake3")
(file "shared/libmagic/libmagic.a"))
; every .c file in a category builds into its own binary. (PERFILE)
; only EXTRA_AFTER differs cuz POSIX waits for GETCONF_H, the rest pass ""
; cmd/posix/bc.c overrides this with its own yacc-based rule, so no need for
; PERFILE to have that as a special case
;
(template PERFILE (NAME CATEGORY DESC EXTRA_AFTER)
(rule $(NAME)
(glob "cmd/$(CATEGORY)/*.c")
(gate build_$(CATEGORY)_$(IDENT))
; compiled and linked in one step, so the header that every compile
; -includes is order-only: as a dep it would land in $(IN) and be
; passed to the linker. its path still makes a change rebuild
(dep $(MATCH) LIBDISK LIBUTIL LIBUTF LIBBLAKE3 LIBMAGIC)
(after "scripts/mk/features.h" $(EXTRA_AFTER))
(out $(STEM))
(description $(DESC))
(feature perfile)
(exec $(CC) $(CPPFLAGS) $(CFLAGS) -o $(OUT) $(IN) $(LDFLAGS) $(LDLIBS) $(EXTRA_LIBS:$(BASESTEM)))))
(use PERFILE POSIX_BIN posix "one POSIX2024 utility per source file under cmd/posix" GETCONF_H)
(use PERFILE LINUX_BIN linux "linux-only utility, one source file per binary under cmd/linux" "")
(use PERFILE NET_BIN net "networking utility, one source file per binary under cmd/net" "")
(use PERFILE XSI_BIN xsi "xsi-specified utility, one source file per binary under cmd/xsi" "")
(use PERFILE PSEUDO_BIN pseudo "common but undefined utility, one source file per binary under cmd/pseudo" "")
(use PERFILE EXTRA_BIN extra "extra utility outside POSIX/XSI scope, one source file per binary under cmd/extra" "")
(group posix lib POSIX_BIN POSIX_BC POSIX_AWK POSIX_SH POSIX_MAKE)
(group linux lib LINUX_BIN)
(group net lib NET_BIN)
(group xsi lib XSI_BIN)
(group pseudo lib PSEUDO_BIN)
(group extra lib EXTRA_BIN EXTRA_YAP EXTRA_FSCK_FAT EXTRA_FSCK_EXT4)
; codegen: generate sources consumed by the build rules below. ungated
; ones always run. conditional ones use (req) so they only run when
; their inputs exists in this checkout
;
(rule GETCONF_H
(gate build_posix_getconf)
(out "cmd/posix/getconf.h")
(dep "scripts/getconf.sh")
(exec sh scripts/genconfig.sh getconf))
(rule POSIX_BC_C
(gate build_posix_bc)
(req "cmd/posix/bc.y")
(out "cmd/posix/bc.c")
(dep "cmd/posix/bc.y")
(exec sh scripts/genconfig.sh bc))
(rule POSIX_AWK_C
(gate build_posix_awk)
(out "cmd/posix/awk/awkgram.tab.c")
(dep "cmd/posix/awk/awkgram.y")
(exec sh scripts/genconfig.sh awk))
(rule POSIX_SH_C
(gate build_posix_sh)
(out "cmd/posix/sh/syntax.c")
(dep "cmd/posix/sh/mksyntax.c" "cmd/posix/sh/mknodes.c" "cmd/posix/sh/mkbuiltins" "cmd/posix/sh/mktokens")
(exec sh scripts/genconfig.sh sh))
(rule DEVCONF
(req "cmd/dev/configure")
(out "cmd/dev/config.h")
(dep "cmd/dev/configure")
(phony)
(exec sh cmd/dev/configure --target=$(MICE_TARGET_TRIPLE) --sysroot=$(MICE_TARGET_SYSROOT)))
(group codegen GETCONF_H POSIX_BC_C POSIX_AWK_C POSIX_SH_C DEVCONF)
; multi: one binary from all .c files in one or more dirs (minus skip)
; codegen must run first so generated sources are present before these
; globs collect them
;
(rule POSIX_BC_OBJ
(glob "cmd/posix/bc.c")
(gate build_posix_bc)
(dep $(MATCH) FEATURES_H)
(after POSIX_BC_C)
(out "$(STEM).o")
(exec $(CC) $(CPPFLAGS) $(CFLAGS) -c -o $(OUT) $(MATCH)))
(rule POSIX_BC
(gate build_posix_bc)
(member posix bc)
(dep POSIX_BC_OBJ LIBUTIL LIBUTF)
(out "cmd/posix/bc")
(exec $(CC) -o $(OUT) $(IN) $(LDFLAGS) $(LDLIBS) -lm))
(rule POSIX_AWK_OBJ
(glob "cmd/posix/awk/*.c")
(gate build_posix_awk)
(skip "maketab.c")
(dep $(MATCH) FEATURES_H)
(after POSIX_AWK_C)
(out "$(STEM).o")
(exec $(CC) $(CPPFLAGS) -Icmd/posix/awk $(CFLAGS) -c -o $(OUT) $(MATCH)))
(rule POSIX_AWK
(gate build_posix_awk)
(member posix awk)
(dep POSIX_AWK_OBJ LIBUTIL LIBUTF)
(out "cmd/posix/awk/awk")
(exec $(CC) -o $(OUT) $(IN) $(LDFLAGS) $(LDLIBS) -lm))
(rule POSIX_SH_OBJ
(glob "cmd/posix/sh/*.c")
(gate build_posix_sh)
(skip "mknodes.c" "mksyntax.c")
(dep $(MATCH) FEATURES_H)
(after POSIX_SH_C)
(out "$(STEM).o")
(exec $(CC) $(CPPFLAGS) -DSHELL -Icmd/posix/sh $(CFLAGS) -c -o $(OUT) $(MATCH)))
(rule POSIX_SH
(gate build_posix_sh)
(member posix sh)
(dep POSIX_SH_OBJ LIBUTIL LIBUTF LIBREDLINE)
(out "cmd/posix/sh/sh")
(exec $(CC) -o $(OUT) $(IN) $(LDFLAGS) $(LDLIBS)))
(rule POSIX_MAKE_OBJ
(glob "cmd/posix/make/*.c")
(gate build_posix_make)
(dep $(MATCH) FEATURES_H)
(out "$(STEM).o")
(exec $(CC) $(CPPFLAGS) $(CFLAGS) -c -o $(OUT) $(MATCH)))
(rule POSIX_MAKE
(gate build_posix_make)
(member posix make)
(dep POSIX_MAKE_OBJ LIBUTIL LIBUTF)
(out "cmd/posix/make/make")
(exec $(CC) -o $(OUT) $(IN) $(LDFLAGS) $(LDLIBS)))
(rule EXTRA_YAP_OBJ
(glob "cmd/extra/yap/*.c")
(gate build_extra_yap)
(dep $(MATCH) FEATURES_H)
(out "$(STEM).o")
(exec $(CC) $(CPPFLAGS) $(CFLAGS) -c -o $(OUT) $(MATCH)))
(rule EXTRA_YAP
(gate build_extra_yap)
(member extra yap)
(dep EXTRA_YAP_OBJ LIBUTIL LIBUTF)
(out "cmd/extra/yap/yap")
(exec $(CC) -o $(OUT) $(IN) $(LDFLAGS) $(LDLIBS) -ltinfo))
(template FSCK (RULE TOOL KEY FLAGS HEADERS)
(rule $(RULE)_OBJ
(glob "cmd/extra/$(TOOL)/*.c")
(gate build_extra_$(KEY))
(dep $(MATCH) FEATURES_H "glob:cmd/extra/$(TOOL)/**/*.h" $(HEADERS))
(out "$(STEM).o")
(exec $(CC) $(CPPFLAGS) -U_POSIX_C_SOURCE -D_DEFAULT_SOURCE -Icmd/extra/$(TOOL) $(FLAGS) $(CFLAGS) -c -o $(OUT) $(MATCH)))
(rule $(RULE)
(gate build_extra_$(KEY))
(member extra $(TOOL))
(dep $(RULE)_OBJ LIBUTIL)
(out "cmd/extra/$(TOOL)/$(TOOL)")
(exec $(CC) -o $(OUT) $(IN) $(LDFLAGS) $(LDLIBS)))
(rule $(RULE)_BOX
(gate build_extra_$(KEY))
(dep $(RULE)_OBJ)
(out ".box/cmd/extra/$(TOOL).o")
(shell "$(LD) -r -o $(OUT) $(IN) && $(OBJCOPY) --redefine-sym main=$(KEY)_main $(OUT) && $(OBJCOPY) --keep-global-symbol=$(KEY)_main $(OUT)")
(group box)))
(use FSCK EXTRA_FSCK_FAT fsck.fat fsck_fat "-includecmd/extra/fsck.fat/freebsd-compat.h" "shared/queue.h")
(use FSCK EXTRA_FSCK_EXT4 fsck.ext4 fsck_ext4 "-includecmd/extra/fsck.ext4/compat.h" "shared/diskutil.h")
; (member GROUP ALIAS) gives a rule a qualified user-facing name
; (e.g. posix/bc) while keeping its internal name (POSIX_BC) for deps,
; gates, and other references
;
; dev: the aruu toolchain. ar/as/ld are standalone and cc
; shares one object pool linked into three frontends
;
(rule AR_OBJ
(glob "cmd/dev/ar/*.c")
(gate build_dev_ar)
(skip "tinyar.c")
(after DEVCONF)
(dep $(MATCH) FEATURES_H)
(out "$(STEM).o")
(exec $(CC) $(CPPFLAGS) -Icmd/dev/ar $(CFLAGS) -c -o $(OUT) $(MATCH)))
(rule AR
(gate build_dev_ar)
(dep AR_OBJ LIBUTIL LIBUTF)
; static: these tools run inside whatever rootfs they target via
; nac, not just the host that built them, and never need the
; project-wide LDLIBS default (openssl, unused by any of them)
(out "cmd/dev/ar/ar")
(exec $(CC) -static -o $(OUT) $(IN) $(LDFLAGS)))
(rule XELF_OBJ
(glob "cmd/dev/xelf/*.c")
(gate build_dev_xelf)
(after DEVCONF)
(dep $(MATCH) FEATURES_H)
(out "$(STEM).o")
(exec $(CC) $(CPPFLAGS) -Icmd/dev/xelf $(CFLAGS) -c -o $(OUT) $(MATCH)))
(rule XELF
(gate build_dev_xelf)
(dep XELF_OBJ LIBUTIL LIBUTF)
(out "cmd/dev/xelf/xelf")
(exec $(CC) -static -o $(OUT) $(IN) $(LDFLAGS)))
(rule TCUTIL_OBJ
(glob "shared/libtcutil/*.c" "shared/libtcutil/elf/*.c" "shared/libtcutil/ar/*.c")
(gate build_dev_cc)
(after DEVCONF)
(dep $(MATCH) FEATURES_H)
(out "$(STEM).o")
(exec $(CC) $(CPPFLAGS) -Ishared/libtcutil -Ishared/libtcutil/elf -Ishared/libtcutil/ar -Icmd/dev $(CFLAGS) -c -o $(OUT) $(MATCH)))
(rule AS_OBJ
(glob "cmd/dev/as/*.c" "cmd/dev/as/arch/x64/*.c")
(gate build_dev_cc)
(after DEVCONF)
(dep $(MATCH) FEATURES_H)
(out "$(STEM).o")
(exec $(CC) $(CPPFLAGS) -Ishared/libtcutil -Ishared/libtcutil/elf -Ishared/libtcutil/ar -Icmd/dev -Icmd/dev/as -Icmd/dev/as/arch/x64 -Ishared $(CFLAGS) -c -o $(OUT) $(MATCH)))
(rule AS
(gate build_dev_cc)
(dep AS_OBJ TCUTIL_OBJ LIBUTIL LIBUTF)
(out "cmd/dev/as/as")
(exec $(CC) -static -o $(OUT) $(IN) $(LDFLAGS)))
(rule LD_OBJ
(glob "cmd/dev/ld/*.c" "cmd/dev/ld/arch/*/*.c")
(gate build_dev_ld)
(after DEVCONF)
(dep $(MATCH) FEATURES_H)
(out "$(STEM).o")
(exec $(CC) $(CPPFLAGS) -Icmd/dev/ld $(CFLAGS) -c -o $(OUT) $(MATCH)))
(rule LD
(gate build_dev_ld)
(dep LD_OBJ LIBUTIL LIBUTF)
(out "cmd/dev/ld/ld")
(exec $(CC) -static -o $(OUT) $(IN) $(LDFLAGS)))
; CCPOOL_OBJ globs the whole directory. the entry points below use
; literal globs, so the override excludes them automatically
(rule CCPOOL_OBJ
(glob "cmd/dev/cc/*.c")
(gate build_dev_cc)
(after DEVCONF)
(dep $(MATCH) FEATURES_H)
(out "$(STEM).o")
(exec $(CC) $(CPPFLAGS) -Icmd/dev/cc $(CFLAGS) -c -o $(OUT) $(MATCH)))
(rule CC1_OBJ
(glob "cmd/dev/cc/cc1.c")
(gate build_dev_cc)
(after DEVCONF)
(dep $(MATCH) FEATURES_H)
(out "$(STEM).o")
(exec $(CC) $(CPPFLAGS) -Icmd/dev/cc $(CFLAGS) -c -o $(OUT) $(MATCH)))
; util.c is its own rule, not folded into CCPOOL_OBJ's wildcard or
; CCDRV_OBJ's own glob: cc1, cpp, and cc (the driver) all call its
; helpers (fatal, xmalloc, arrayadd, ...), but only cc has its own
; main(), so driver.c cannot be a shared link input the other two
; binaries pull in too
(rule UTIL_OBJ
(glob "cmd/dev/cc/util.c")
(gate build_dev_cc)
(after DEVCONF)
(dep $(MATCH) FEATURES_H)
(out "$(STEM).o")
(exec $(CC) $(CPPFLAGS) -Icmd/dev/cc $(CFLAGS) -c -o $(OUT) $(MATCH)))
(rule CC1
(gate build_dev_cc)
(dep CC1_OBJ CCPOOL_OBJ UTIL_OBJ LIBUTIL LIBUTF)
(out "cmd/dev/cc/cc1")
(exec $(CC) -static -o $(OUT) $(IN) $(LDFLAGS)))
(rule CPP_OBJ
(glob "cmd/dev/cc/cpp.c")
(gate build_dev_cc)
(after DEVCONF)
(dep $(MATCH) FEATURES_H)
(out "$(STEM).o")
(exec $(CC) $(CPPFLAGS) -Icmd/dev/cc $(CFLAGS) -c -o $(OUT) $(MATCH)))
(rule CPP
(gate build_dev_cc)
(dep CPP_OBJ CCPOOL_OBJ UTIL_OBJ LIBUTIL LIBUTF)
(out "cmd/dev/cc/cpp")
(exec $(CC) -static -o $(OUT) $(IN) $(LDFLAGS)))
; driver.c's own quoted #include "config.h" needs cmd/dev/config.h
; (DEVCONF's own output), not shared/config.h, MICE's unrelated
; project-wide one that $(CPPFLAGS)'s own -Ishared would otherwise
; win on: -Icmd/dev goes first, ahead of $(CPPFLAGS), so it wins the
; search. (after DEVCONF) orders the generation itself first, or
; parallel execution can compile driver.c before config.h exists
(rule CCDRV_OBJ
(glob "cmd/dev/cc/driver.c")
(gate build_dev_cc)
(dep $(MATCH) FEATURES_H)
(after DEVCONF)
(out "$(STEM).o")
(exec $(CC) -Icmd/dev $(CPPFLAGS) -Icmd/dev/cc $(CFLAGS) -c -o $(OUT) $(MATCH)))
(rule CCDRV
(gate build_dev_cc)
(dep CCDRV_OBJ UTIL_OBJ LIBUTIL LIBUTF)
(out "cmd/dev/cc/cc")
(exec $(CC) -static -o $(OUT) $(IN) $(LDFLAGS)))
; ninqu is multiple translation units sharing globals (rules, insts,
; and so on), unlike the single-file tools BOX_OBJ handles: combine
; its objects first, like POSIX_BC_BOX/POSIX_AWK_BOX/POSIX_SH_BOX/
; POSIX_MAKE_BOX/EXTRA_YAP_BOX do for their own multi-file tools, so
; --keep-global-symbol only strips main across the combined object
; instead of hiding every cross-file global before linking even
; happens. it is still not reentrant, so it stays out of NOFORK_LIST
;
(rule NINQU_BOX_OBJ
(glob "cmd/dev/ninqu/*.c")
(gate build_dev_ninqu)
(dep $(MATCH) FEATURES_H)
(after LIBUTIL LIBUTF LIBREDLINE NOFORK_LIST_H GETCONF_H)
(out ".box/parts/$(STEM).o")
(exec $(CC) $(CPPFLAGS) $(CFLAGS) -c -o $(OUT) $(MATCH)))
(rule NINQU_BOX
(gate build_dev_ninqu)
(dep NINQU_BOX_OBJ)
(out ".box/cmd/dev/ninqu.o")
(description "ninqu's objects combined into one relocatable object, main renamed for the box dispatch table")
(shell "$(LD) -r -o $(OUT) $(IN) && $(OBJCOPY) --redefine-sym main=ninqu_main $(OUT) && $(OBJCOPY) --keep-global-symbol=ninqu_main $(OUT)")
(group box))
(group dev lib DEVCONF AR XELF AS LD CC1 CPP CCDRV)
; man pages: build mdoc and text pages from ?man-marked sources
;
(rule MKMAN
(dir "scripts/mkman")
(dep "glob:scripts/mkman/*.go")
(out "scripts/mkman/mkman")
(exec go build -o mkman .))
(rule MAN_MDOC
(glob "cmd/**/*.c")
(mark "?man")
(dep CONFIG_KV (after MKMAN))
(out "man/man$(SEC_OF:$(DIR))/$(BASESTEM).$(SEC_OF:$(DIR))")
(exec scripts/mkman/mkman -fmt mdoc -config scripts/mk/config.kv $(MATCH))
(redirect))
(rule MAN_TXT
(glob "cmd/**/*.c")
(mark "?man")
(dep CONFIG_KV (after MKMAN))
(out "man/man$(SEC_OF:$(DIR))/$(BASESTEM).$(SEC_OF:$(DIR)).txt")
(exec scripts/mkman/mkman -fmt txt -config scripts/mk/config.kv $(MATCH))
(redirect))
(map SEC_OF
(cmd/posix 1)
(cmd/posix/make 1)
(cmd/linux 8)
(cmd/net 8)
(cmd/xsi 1)
(cmd/pseudo 1)
(cmd/extra 1)
(cmd/extra/fsck.fat 1)
(cmd/dev 1))
(group man MAN_MDOC MAN_TXT)
(rule CLEAN
(phony)
(shell "
printf ' CLEAN object files\n'
find shared cmd -name '*.o' -exec rm -f {} +
printf ' CLEAN static libraries\n'
find shared -name '*.a' -exec rm -f {} +
printf ' CLEAN compiled binaries\n'
find cmd -type f '(' ! -name '*.*' -o -name 'mkfs.fat' -o -name 'mkfs.ext4' -o -name 'fsck.fat' -o -name 'fsck.ext4' ')' -perm -100 -exec rm -f {} +
sh scripts/genconfig.sh clean
rm -f scripts/mk/config.mk scripts/mk/config.kv scripts/mk/rules.mk shared/libutil/nofork_list.h
printf ' CLEAN build tools\n'
rm -f scripts/mkman/mkman
printf ' CLEAN dev artifacts\n'
rm -f cmd/dev/cc/cc1 cmd/dev/cc/cpp cmd/dev/as/as cmd/dev/ld/ld cmd/dev/ar/ar
rm -f shared/libaruuelf.so
rm -f cmd/dev/config.h cmd/dev/cc/config.h cmd/dev/version.h
printf ' CLEAN misc\n'
rm -rf man/man1 man/man8
rm -rf aruu-box .box
rm -rf .ninja_log .ninja_deps
printf ' CLEAN done\n'
"))
(group clean CLEAN)
; install every built executable and generated man page, plus
; shared/libutil itself as a real linkable library: other MICE
; components (ports/pkgtools, nac) should link against this, not carry
; their own copy of ealloc/eprintf/wexec/etc alongside it
(rule INSTALL
(phony)
(after ALL_BINS LIBUTIL MAN_MDOC MAN_TXT)
(shell "
[ -n \"${DESTDIR:-}\" ] || { printf 'install requires DESTDIR\n' >&2; exit 1; }
case \"$(PREFIX)\" in /usr|/usr/*|usr|usr/*) printf 'ARUU cannot install into usr\n' >&2; exit 1 ;; esac
case \"$DESTDIR\" in /usr|/usr/*) printf 'ARUU cannot install into usr\n' >&2; exit 1 ;; esac
d=\"$DESTDIR$(PREFIX)\"
m=\"$DESTDIR$(MANPREFIX)\"
mkdir -p \"$d/bin\" \"$m/man1\" \"$m/man8\" \"$d/lib\" \"$d/include/aruu\"
find cmd -type f '(' ! -name '*.*' -o -name 'mkfs.fat' -o -name 'mkfs.ext4' -o -name 'fsck.fat' -o -name 'fsck.ext4' ')' -perm -100 | while read -r bin; do
name=${bin##*/}
printf ' INSTALL %s/bin/%s\n' '$(PREFIX)' \"$name\"
cp \"$bin\" \"$d/bin/$name\"
chmod 755 \"$d/bin/$name\"
done
# they run as root for whoever runs them (see SETUID_BIN)
for name in su passwd; do
[ ! -f \"$d/bin/$name\" ] || chmod 4755 \"$d/bin/$name\"
done
find man/man1 man/man8 -type f -name '*.[18]' 2>/dev/null | while read -r f; do
sec=${f%/*}; sec=${sec##*/}
name=${f##*/}
cp \"$f\" \"$m/$sec/$name\"
done
# the keyboard layouts kmap reads, kept as they were written once
printf ' INSTALL %s/share/kmap\n' '$(PREFIX)'
mkdir -p \"$d/share\"
cp -R share/kmap \"$d/share/kmap\"
# what file knows files by
mkdir -p \"$d/share/misc\"
cp -R share/magic \"$d/share/misc/magic\"
if [ -x cmd/extra/fsck.fat/fsck.fat ]; then
ln -sf fsck.fat \"$d/bin/fsck.vfat\"
fi
for name in fsck.fat fsck.ext4; do
if [ -x \"cmd/extra/$name/$name\" ]; then
mkdir -p \"$d/share/licenses/aruu\"
cp \"cmd/extra/$name/NOTICE\" \"$d/share/licenses/aruu/$name\"
fi
done
printf ' INSTALL %s/lib/libaruu.a\n' '$(PREFIX)'
cp shared/libutil/libutil.a \"$d/lib/libaruu.a\"
chmod 644 \"$d/lib/libaruu.a\"
for h in shared/util.h shared/wexec.h shared/arg.h shared/compat.h \
shared/filesystem.h shared/net.h shared/sysinfo.h; do
printf ' INSTALL %s/include/aruu/%s\n' '$(PREFIX)' \"${h##*/}\"
cp \"$h\" \"$d/include/aruu/${h##*/}\"
chmod 644 \"$d/include/aruu/${h##*/}\"
done
"))
(group install INSTALL)
; same body as INSTALL, minus the dev (compiler toolchain) category:
; what a MICE port needs to put a shell and coreutils on a rootfs,
; not a hard dependency on the separate, not-yet-portable dev build
(rule INSTALL_BASE
(phony)
(after POSIX_BIN LINUX_BIN NET_BIN XSI_BIN PSEUDO_BIN EXTRA_BIN
POSIX_BC POSIX_AWK POSIX_SH POSIX_MAKE EXTRA_YAP EXTRA_FSCK_FAT EXTRA_FSCK_EXT4
LIBUTIL MAN_MDOC MAN_TXT)
(shell "
[ -n \"${DESTDIR:-}\" ] || { printf 'install-base requires DESTDIR\n' >&2; exit 1; }
case \"$(PREFIX)\" in /usr|/usr/*|usr|usr/*) printf 'ARUU cannot install into usr\n' >&2; exit 1 ;; esac
case \"$DESTDIR\" in /usr|/usr/*) printf 'ARUU cannot install into usr\n' >&2; exit 1 ;; esac
d=\"$DESTDIR$(PREFIX)\"
m=\"$DESTDIR$(MANPREFIX)\"
mkdir -p \"$d/bin\" \"$m/man1\" \"$m/man8\" \"$d/lib\" \"$d/include/aruu\"
find cmd -type f '(' ! -name '*.*' -o -name 'mkfs.fat' -o -name 'mkfs.ext4' -o -name 'fsck.fat' -o -name 'fsck.ext4' ')' -perm -100 ! -path 'cmd/dev/*' | while read -r bin; do
name=${bin##*/}
printf ' INSTALL %s/bin/%s\n' '$(PREFIX)' \"$name\"
cp \"$bin\" \"$d/bin/$name\"
chmod 755 \"$d/bin/$name\"
done
# they run as root for whoever runs them (see SETUID_BIN)
for name in su passwd; do
[ ! -f \"$d/bin/$name\" ] || chmod 4755 \"$d/bin/$name\"
done
find man/man1 man/man8 -type f -name '*.[18]' 2>/dev/null | while read -r f; do
sec=${f%/*}; sec=${sec##*/}
name=${f##*/}
cp \"$f\" \"$m/$sec/$name\"
done
# the keyboard layouts kmap reads, kept as they were written once
printf ' INSTALL %s/share/kmap\n' '$(PREFIX)'
mkdir -p \"$d/share\"
cp -R share/kmap \"$d/share/kmap\"
# what file knows files by
mkdir -p \"$d/share/misc\"
cp -R share/magic \"$d/share/misc/magic\"
if [ -x cmd/extra/fsck.fat/fsck.fat ]; then
ln -sf fsck.fat \"$d/bin/fsck.vfat\"
fi
for name in fsck.fat fsck.ext4; do
if [ -x \"cmd/extra/$name/$name\" ]; then
mkdir -p \"$d/share/licenses/aruu\"
cp \"cmd/extra/$name/NOTICE\" \"$d/share/licenses/aruu/$name\"
fi
done
printf ' INSTALL %s/lib/libaruu.a\n' '$(PREFIX)'
cp shared/libutil/libutil.a \"$d/lib/libaruu.a\"
chmod 644 \"$d/lib/libaruu.a\"
for h in shared/util.h shared/wexec.h shared/arg.h shared/compat.h \
shared/filesystem.h shared/net.h shared/sysinfo.h; do
printf ' INSTALL %s/include/aruu/%s\n' '$(PREFIX)' \"${h##*/}\"
cp \"$h\" \"$d/include/aruu/${h##*/}\"
chmod 644 \"$d/include/aruu/${h##*/}\"
done
"))
(group install-base INSTALL_BASE)
; remove exactly what install would have copied
(rule REMOVE
(phony)
(shell "
[ -n \"${DESTDIR:-}\" ] || { printf 'remove requires DESTDIR\n' >&2; exit 1; }
case \"$(PREFIX)\" in /usr|/usr/*|usr|usr/*) printf 'ARUU cannot remove from usr\n' >&2; exit 1 ;; esac
case \"$DESTDIR\" in /usr|/usr/*) printf 'ARUU cannot remove from usr\n' >&2; exit 1 ;; esac
d=\"$DESTDIR$(PREFIX)\"
m=\"$DESTDIR$(MANPREFIX)\"
find cmd -type f '(' ! -name '*.*' -o -name 'mkfs.fat' -o -name 'mkfs.ext4' -o -name 'fsck.fat' -o -name 'fsck.ext4' ')' -perm -100 | while read -r bin; do
name=${bin##*/}
printf ' REMOVE %s/bin/%s\n' '$(PREFIX)' \"$name\"
rm -f \"$d/bin/$name\"
done
find man/man1 man/man8 -type f -name '*.[18]' 2>/dev/null | while read -r f; do
sec=${f%/*}; sec=${sec##*/}
name=${f##*/}
printf ' REMOVE %s/%s/%s\n' '$(MANPREFIX)' \"$sec\" \"$name\"
rm -f \"$m/$sec/$name\"
done
if [ \"`readlink \"$d/bin/fsck.vfat\"`\" = fsck.fat ]; then
rm -f \"$d/bin/fsck.vfat\"
fi
rm -f \"$d/share/licenses/aruu/fsck.fat\"
rm -f \"$d/share/licenses/aruu/fsck.ext4\"
printf ' REMOVE %s/lib/libaruu.a\n' '$(PREFIX)'
rm -f \"$d/lib/libaruu.a\"
for h in util.h wexec.h arg.h compat.h filesystem.h net.h sysinfo.h; do
printf ' REMOVE %s/include/aruu/%s\n' '$(PREFIX)' \"$h\"
rm -f \"$d/include/aruu/$h\"
done
rmdir \"$d/include/aruu\" 2>/dev/null || :
"))
(group remove REMOVE)
(group uninstall REMOVE)
(rule FMT
(phony)
(shell "
printf ' FMT cmd and shared (skipping dir tools)\n'
find cmd shared -type f \( -name '*.c' -o -name '*.h' \) \
! -path 'cmd/posix/awk/*' \
! -path 'cmd/posix/sh/*' \
! -path 'cmd/posix/make/*' \
! -path 'cmd/extra/yap/*' \
! -path 'cmd/extra/fsck.fat/*' \
! -path 'cmd/extra/fsck.ext4/*' \
! -path 'cmd/posix/bc.c' \
-print | xargs -r clang-format -i
"))
(rule FMT_ALL
(phony)
(shell "
printf ' FMT cmd and shared (including dir tools)\n'
find cmd shared -type f \( -name '*.c' -o -name '*.h' \) -print \
| xargs -r clang-format -i
"))
(group fmt FMT)
(group fmt-all FMT_ALL)
; box: one executable containing every enabled tool, dispatched through
; a table. a single-file tool just gets its main renamed by BOX_OBJ
; multi-file tools (POSIX_BC, POSIX_AWK, POSIX_SH, POSIX_MAKE, EXTRA_YAP)
; go through a partial link (ld -r) first, merging their objects into
; one before main gets renamed and helper symbols hidden. replaces
; scripts/mkbox
;
; object files live under .box/, mirroring the cmd/ layout
;
; ninqu determines which tools enter the box using the gate on BOX_OBJ
; BOX_DISPATCH reads the object paths passed on argv rather than consulting
; build.cfg or config.set directly
;
; CATEGORY_OF maps a directory path to its category name, matching the toggles
; in build.cfg. since BOX_OBJ globs multiple directories, its gate evaluates the
; category dynamically based on the match directory
;
; gates evaluate $(IDENT) instead of $(BASESTEM) because toggle names must be
; valid shell variables. genconfig.sh replaces hyphens and periods with
; underscores, and $(IDENT) applies the same normalization so they match
;
(map CATEGORY_OF
(cmd/posix posix)
(cmd/linux linux)
(cmd/net net)
(cmd/pseudo pseudo)
(cmd/xsi xsi)
(cmd/extra extra))
; tool basestems match their c symbols using a shell transform (tr '.-' '__'
; and appending _main) in both the objcopy step and in genbox.sh. a static map
; is unnecessary because no current tools require custom overrides, and
; genbox.sh only receives paths via argv
;
; the match directory picks the gate and output path, so one rule covers
; all six categories. bc.c inside cmd/posix is excluded automatically by
; the literal-glob override mechanism
;
(rule BOX_OBJ
(glob "cmd/posix/*.c" "cmd/linux/*.c" "cmd/net/*.c" "cmd/pseudo/*.c"
"cmd/xsi/*.c" "cmd/extra/*.c")
(skip "su.c" "passwd.c")
(gate build_$(CATEGORY_OF:$(DIR))_$(IDENT))
(dep $(MATCH) FEATURES_H)
(after LIBUTIL LIBUTF LIBREDLINE NOFORK_LIST_H GETCONF_H)
(out ".box/$(DIR)/$(BASESTEM).o")
(description "one object per enabled tool, main renamed for the box dispatch table")
(shell "$(CC) $(CPPFLAGS) $(CFLAGS) -c -o $(OUT) $(MATCH) && sym=`echo $(BASESTEM) | tr '.-' '__'`_main && $(OBJCOPY) --redefine-sym main=$sym $(OUT) && $(OBJCOPY) --keep-global-symbol=$sym $(OUT)")
(group box))
; POSIX_BC, POSIX_AWK, POSIX_SH, POSIX_MAKE, and EXTRA_YAP cant go through
; the single-file objcopy step, their global helper symbols would collide
; once linked into one binary. a partial link (ld -r) resolves those
; internal references first, then main gets renamed and the rest hidden
;
; combined objects use the layout .box/cmd/<category>/<tool>.o so genbox.sh
; can parse them without structural modifications
;
(rule POSIX_BC_BOX_OBJ
(glob "cmd/posix/bc.c")
(gate build_posix_bc)
(dep $(MATCH) FEATURES_H)
(after POSIX_BC_C)
(out ".box/parts/$(STEM).o")
(exec $(CC) $(CPPFLAGS) $(CFLAGS) -c -o $(OUT) $(MATCH)))
(rule POSIX_BC_BOX
(gate build_posix_bc)
(dep POSIX_BC_BOX_OBJ)
(out ".box/cmd/posix/bc.o")
(description "bc's objects combined into one relocatable object, main renamed for the box dispatch table")
(shell "$(LD) -r -o $(OUT) $(IN) && $(OBJCOPY) --redefine-sym main=bc_main $(OUT) && $(OBJCOPY) --keep-global-symbol=bc_main $(OUT)")
(group box))
(rule POSIX_AWK_BOX_OBJ
(glob "cmd/posix/awk/*.c")
(gate build_posix_awk)
(skip "maketab.c")
(dep $(MATCH) FEATURES_H)
(after POSIX_AWK_C)
(out ".box/parts/$(STEM).o")
(exec $(CC) $(CPPFLAGS) -Icmd/posix/awk $(CFLAGS) -c -o $(OUT) $(MATCH)))
(rule POSIX_AWK_BOX
(gate build_posix_awk)
(dep POSIX_AWK_BOX_OBJ)
(out ".box/cmd/posix/awk.o")
(description "awk's objects combined into one relocatable object, main renamed for the box dispatch table")
(shell "$(LD) -r -o $(OUT) $(IN) && $(OBJCOPY) --redefine-sym main=awk_main $(OUT) && $(OBJCOPY) --keep-global-symbol=awk_main $(OUT)")
(group box))
(rule POSIX_SH_BOX_OBJ
(glob "cmd/posix/sh/*.c")
(gate build_posix_sh)
(skip "mknodes.c" "mksyntax.c")
(dep $(MATCH) FEATURES_H)
(after POSIX_SH_C)
(out ".box/parts/$(STEM).o")
(exec $(CC) $(CPPFLAGS) -DSHELL -Icmd/posix/sh $(CFLAGS) -c -o $(OUT) $(MATCH)))
(rule POSIX_SH_BOX
(gate build_posix_sh)
(dep POSIX_SH_BOX_OBJ)
(out ".box/cmd/posix/sh.o")
(description "sh's objects combined into one relocatable object, main renamed for the box dispatch table")
(shell "$(LD) -r -o $(OUT) $(IN) && $(OBJCOPY) --redefine-sym main=sh_main $(OUT) && $(OBJCOPY) --keep-global-symbol=sh_main $(OUT)")
(group box))
(rule POSIX_MAKE_BOX_OBJ
(glob "cmd/posix/make/*.c")
(gate build_posix_make)
(dep $(MATCH) FEATURES_H)
(out ".box/parts/$(STEM).o")
(exec $(CC) $(CPPFLAGS) $(CFLAGS) -c -o $(OUT) $(MATCH)))
(rule POSIX_MAKE_BOX
(gate build_posix_make)
(dep POSIX_MAKE_BOX_OBJ)
(out ".box/cmd/posix/make.o")
(description "make's objects combined into one relocatable object, main renamed for the box dispatch table")
(shell "$(LD) -r -o $(OUT) $(IN) && $(OBJCOPY) --redefine-sym main=make_main $(OUT) && $(OBJCOPY) --keep-global-symbol=make_main $(OUT)")
(group box))
(rule EXTRA_YAP_BOX_OBJ
(glob "cmd/extra/yap/*.c")
(gate build_extra_yap)
(dep $(MATCH) FEATURES_H)
(out ".box/parts/$(STEM).o")
(exec $(CC) $(CPPFLAGS) $(CFLAGS) -c -o $(OUT) $(MATCH)))
(rule EXTRA_YAP_BOX
(gate build_extra_yap)
(dep EXTRA_YAP_BOX_OBJ)
(out ".box/cmd/extra/yap.o")
(description "yap's objects combined into one relocatable object, main renamed for the box dispatch table")
(shell "$(LD) -r -o $(OUT) $(IN) && $(OBJCOPY) --redefine-sym main=yap_main $(OUT) && $(OBJCOPY) --keep-global-symbol=yap_main $(OUT)")
(group box))
; genbox.sh relies on arguments passed by ninqu, where each argument matches
; an output from BOX_OBJ or a custom box rule. the script derives categories
; and tool names directly from these paths and outputs the dispatch code
;
; a tool that runs as root for whoever runs it (setuid: su, and passwd,
; which writes the shadow file) is never part of the box, which would
; make every tool in it setuid. each is a binary of its own under
; setuid/, which install makes setuid root
;
(rule SETUID_BIN
(glob "cmd/xsi/su.c" "cmd/xsi/passwd.c")
(gate build_xsi_$(IDENT))
(dep $(MATCH) LIBDISK LIBUTIL LIBUTF LIBBLAKE3 LIBMAGIC)
(after "scripts/mk/features.h")
(out "setuid/$(BASESTEM)")
(description "a tool that runs as root for whoever runs it, kept out of the box")
(exec $(CC) $(CPPFLAGS) $(CFLAGS) -o $(OUT) $(IN) $(LDFLAGS) $(LDLIBS) $(EXTRA_LIBS:$(BASESTEM)))
(group box))
(rule BOX_DISPATCH
(dep "scripts/genbox.sh" BOX_OBJ POSIX_BC_BOX POSIX_AWK_BOX POSIX_SH_BOX POSIX_MAKE_BOX EXTRA_YAP_BOX EXTRA_FSCK_FAT_BOX EXTRA_FSCK_EXT4_BOX NINQU_BOX)
(out ".box/aruu-box.c")
(description "dispatch table and main() for aruu-box, generated from the enabled tool list")
(exec sh $(IN))
(redirect)
(group box))
; libm is linked unconditionally because bc requires it, and unused library
; references are safe. modern toolchains omit unreferenced archive components
; yap requires terminfo, which is an optional system dependency. linking it
; unconditionally breaks builds on systems without ncurses-dev when yap is
; disabled. genconfig.sh exports BOX_EXTRA_LIBS as "-ltinfo" or an empty string
; based on whether yap is enabled
;
; libblake3 is the same story as libm: b3sum needs it, EXTRA_LIBS only
; applies to PERFILE's own standalone link line, box has no per-tool
; equivalent, so LIBBLAKE3 goes in BOX's own dep list unconditionally
; instead, same as LIBUTIL/LIBUTF/LIBREDLINE
;
(rule BOX
(dep BOX_DISPATCH BOX_OBJ POSIX_BC_BOX POSIX_AWK_BOX POSIX_SH_BOX POSIX_MAKE_BOX EXTRA_YAP_BOX EXTRA_FSCK_FAT_BOX EXTRA_FSCK_EXT4_BOX NINQU_BOX LIBDISK LIBUTIL LIBUTF LIBREDLINE LIBBLAKE3 LIBMAGIC)
(out "aruu-box")
(description "single multi-call binary, one dispatch table for every enabled tool")
(shell "$(CC) $(CPPFLAGS) $(CFLAGS) -o $(OUT) $(IN) $(LDFLAGS) $(LDLIBS) $(LDLIBS_TLS) $(BOX_EXTRA_LIBS)")
(group box))
(group box BOX SETUID_BIN)
; -------------------------------------------------------------------
; top level. (group all) contains every build target except clean
; and box. box is separate because it produces a different binary
; with different .o files, and mixing it with standalone builds
; would cause confusion. clean is never in all because it removes
; what all builds
; -------------------------------------------------------------------
(rule ALL_BINS
(phony)
(after LIBUTIL LIBUTF LIBREDLINE
POSIX_BIN LINUX_BIN NET_BIN XSI_BIN
PSEUDO_BIN EXTRA_BIN
POSIX_BC POSIX_AWK POSIX_SH POSIX_MAKE EXTRA_YAP EXTRA_FSCK_FAT EXTRA_FSCK_EXT4
AR XELF AS LD CC1 CPP CCDRV)
(exec true))
(group all ALL_BINS)
(group default all)
; meta-targets: apply an override, then build a normal target under
; it. invoke as `ninqu META.TARGET` (`ninqu debug.posix`) or bare
; `ninqu META` to apply the override and build (group default)
;
(meta debug
(set CFLAGS "$(CFLAGS) -g -O0"))
(meta release
(set CFLAGS "$(CFLAGS) -O2 -DNDEBUG"))