aruu

[MIRROR] Actual replacement for Busybox | suckless
git clone https://git.daat.foo/aruu.git
Log | Files | Refs | README | LICENSE

ninqu.rules (35953B)


      1 ; each generated file has one rule and one target, so parallel
      2 ; generators never write through another target's side effects
      3 
      4 (rule CONFIG_SET
      5   (out "scripts/mk/config.set")
      6   (dep "build.cfg" "scripts/genconfig.sh")
      7   (exec sh scripts/genconfig.sh config-set))
      8 
      9 (rule CONFIG_KV
     10   (out "scripts/mk/config.kv")
     11   (dep "build.cfg" "scripts/genconfig.sh")
     12   (exec sh scripts/genconfig.sh config-kv))
     13 
     14 (rule NOFORK_LIST_H
     15   (out "shared/libutil/nofork_list.h")
     16   (dep "build.cfg" "scripts/genconfig.sh")
     17   (exec sh scripts/genconfig.sh nofork-list-h))
     18 
     19 (rule FEATURES_H
     20   (out "scripts/mk/features.h")
     21   (dep "build.cfg" "scripts/genconfig.sh")
     22   (exec sh scripts/genconfig.sh features-h))
     23 
     24 (set-file "scripts/mk/config.set")
     25 
     26 ; static libraries: compile every .c in each lib dir then AR
     27 ;
     28 (rule LIBUTF_OBJ
     29   (glob "shared/libutf/*.c")
     30   (dep $(MATCH) FEATURES_H)
     31   (out "$(STEM).o")
     32   (exec $(CC) $(CPPFLAGS) -Ishared/libutf $(CFLAGS) -c -o $(OUT) $(MATCH)))
     33 
     34   (rule LIBUTF
     35   (dep LIBUTF_OBJ)
     36   (out "shared/libutf/libutf.a")
     37   (description "utf-8 and rune handling, linked into every aruu tool")
     38   (feature core-lib)
     39   (exec $(AR) $(ARFLAGS) $(OUT) $(IN)))
     40 
     41   ; a file of one system (net_linux.c, passwd_obsd.c) keeps its code under
     42   ; that system's #if, so every file is compiled everywhere and the others
     43   ; come out empty
     44   (rule LIBUTIL_OBJ
     45   (glob "shared/libutil/*.c")
     46   (dep $(MATCH) "shared/accounts.h" "shared/diskutil.h" "shared/filesystem.h" "shared/net.h" "shared/passwd.h"
     47        "shared/proc.h" "shared/reboot.h" "shared/session.h" "shared/sysinfo.h"
     48        "shared/timer.h" "shared/util.h" "shared/kmap.h" FEATURES_H)
     49   (after NOFORK_LIST_H)
     50   (out "$(STEM).o")
     51   (exec $(CC) $(CPPFLAGS_LIBUTIL) -Ishared -Ishared/libutil $(CFLAGS) -c -o $(OUT) $(MATCH)))
     52 
     53   (rule LIBUTIL
     54   (dep LIBUTIL_OBJ)
     55   (out "shared/libutil/libutil.a")
     56   (description "allocation, error reporting, and string helpers shared by every tool")
     57   (feature core-lib)
     58   (exec $(AR) $(ARFLAGS) $(OUT) $(IN)))
     59 
     60   (rule LIBREDLINE_OBJ
     61   (glob "shared/libredline/*.c")
     62   (dep $(MATCH) FEATURES_H)
     63   (out "$(STEM).o")
     64   (exec $(CC) $(CPPFLAGS) -Ishared/libredline $(CFLAGS) -c -o $(OUT) $(MATCH)))
     65 
     66   (rule LIBREDLINE
     67   (dep LIBREDLINE_OBJ)
     68   (out "shared/libredline/libredline.a")
     69   (description "line editing used by sh and any other interactive tool")
     70   (feature core-lib)
     71   (exec $(AR) $(ARFLAGS) $(OUT) $(IN)))
     72 
     73   (rule LIBBLAKE3_OBJ
     74   (glob "shared/libblake3/*.c")
     75   (dep $(MATCH) FEATURES_H)
     76   (out "$(STEM).o")
     77   (exec $(CC) $(CPPFLAGS) -Ishared/libblake3 $(CFLAGS) -c -o $(OUT) $(MATCH)))
     78 
     79   (rule LIBBLAKE3
     80   (dep LIBBLAKE3_OBJ)
     81   (out "shared/libblake3/libblake3.a")
     82   (description "the BLAKE3 hash algorithm, linked into b3sum, not embedded in it")
     83   (feature core-lib)
     84   (exec $(AR) $(ARFLAGS) $(OUT) $(IN)))
     85 
     86   (rule LIBDISK_OBJ
     87   (glob "shared/libdisk/*.c")
     88   (skip "label_test.c" "plan_test.c")
     89   (dep $(MATCH) FEATURES_H)
     90   (out "$(STEM).o")
     91   (exec $(CC) $(CPPFLAGS) -Ishared -Ishared/libdisk $(CFLAGS) -c -o $(OUT) $(MATCH)))
     92 
     93   (rule LIBDISK
     94   (dep LIBDISK_OBJ)
     95   (out "shared/libdisk/libdisk.a")
     96   (description "partition tables: the GPT and MBR as a list of partitions, for fdisk and for a partitioner")
     97   (feature core-lib)
     98   (exec $(AR) $(ARFLAGS) $(OUT) $(IN)))
     99 
    100 
    101   ; file(1) magic: tests read from file's own databases. self contained
    102   ; (c99 and posix, none of aruu's headers) because the same sources are
    103   ; copied verbatim into other MICE components that tell types by bytes
    104   (rule LIBMAGIC_OBJ
    105   (glob "shared/libmagic/*.c")
    106   (dep $(MATCH) "shared/libmagic/magic.h" "shared/libmagic/mgint.h")
    107   (out "$(STEM).o")
    108   (exec $(CC) $(CPPFLAGS) -Ishared/libmagic $(CFLAGS) -c -o $(OUT) $(MATCH)))
    109 
    110   (rule LIBMAGIC
    111   (dep LIBMAGIC_OBJ)
    112   (out "shared/libmagic/libmagic.a")
    113   (description "the file(1) magic engine, linked into file, not embedded in it")
    114   (feature core-lib)
    115   (exec $(AR) $(ARFLAGS) $(OUT) $(IN)))
    116 
    117   (group lib LIBUTF LIBUTIL LIBREDLINE LIBBLAKE3 LIBDISK LIBMAGIC)
    118 
    119   ; perfile: every *.c directly inside one of these dirs becomes its
    120   ; own binary of the same name, individually gated by
    121   ; build_<category>_<ident> (lowercase, hyphens and dots turned to
    122   ; underscores, see the $(IDENT) comment above BOX_OBJ below for why)
    123   ; (skip) excludes files that belong to a multi-file tool below instead
    124   ;
    125   ; -lcrypt and -lresolv used to be blanket LDLIBS entries, linked into
    126   ; every single utility whether it called crypt(3)/resolver functions
    127   ; or not. tracing real callers of shared/libutil/passwd.c's pw_check/
    128   ; pw_gensalt (not just direct crypt() calls) turns up exactly four:
    129   ; passwd, mkpasswd, login, su need -lcrypt; host needs -lresolv
    130   ; narrowing this here, not just for tidiness, is what makes aruu
    131   ; buildable on a host whose libc ships a static libresolv/libm but no
    132   ; static libcrypt. b3sum is the one EXTRA_BIN file with its own extra
    133   ; library dependency for a different reason: BLAKE3 used to be
    134   ; implemented inline in b3sum.c itself, which meant anything else
    135   ; that wanted the same algorithm (ports/pkgtools/libpkg, for hashing
    136   ; package archives) had no real library to link against and carried
    137   ; its own separate copy instead, with no way to notice the two had
    138   ; drifted until one of them turned out to have a bug the other one
    139   ; didn't. shared/libblake3 exists so there is exactly one copy
    140   (map EXTRA_LIBS
    141   (diff "-lm")
    142   (wget $(LDLIBS_TLS))
    143   (passwd "-lcrypt")
    144   (mkpasswd "-lcrypt")
    145   (login "-lcrypt")
    146   (su "-lcrypt")
    147   (usermod "-lcrypt")
    148   (host "-lresolv")
    149   (b3sum "-Lshared/libblake3 -lblake3")
    150   (file "shared/libmagic/libmagic.a"))
    151 
    152   ; every .c file in a category builds into its own binary. (PERFILE)
    153   ; only EXTRA_AFTER differs cuz POSIX waits for GETCONF_H, the rest pass ""
    154   ; cmd/posix/bc.c overrides this with its own yacc-based rule, so no need for
    155   ; PERFILE to have that as a special case
    156   ;
    157   (template PERFILE (NAME CATEGORY DESC EXTRA_AFTER)
    158   (rule $(NAME)
    159     (glob "cmd/$(CATEGORY)/*.c")
    160   (gate build_$(CATEGORY)_$(IDENT))
    161   ; compiled and linked in one step, so the header that every compile
    162   ; -includes is order-only: as a dep it would land in $(IN) and be
    163   ; passed to the linker. its path still makes a change rebuild
    164   (dep $(MATCH) LIBDISK LIBUTIL LIBUTF LIBBLAKE3 LIBMAGIC)
    165   (after "scripts/mk/features.h" $(EXTRA_AFTER))
    166   (out $(STEM))
    167   (description $(DESC))
    168   (feature perfile)
    169   (exec $(CC) $(CPPFLAGS) $(CFLAGS) -o $(OUT) $(IN) $(LDFLAGS) $(LDLIBS) $(EXTRA_LIBS:$(BASESTEM)))))
    170 
    171   (use PERFILE POSIX_BIN posix "one POSIX2024 utility per source file under cmd/posix" GETCONF_H)
    172   (use PERFILE LINUX_BIN linux "linux-only utility, one source file per binary under cmd/linux" "")
    173   (use PERFILE NET_BIN net "networking utility, one source file per binary under cmd/net" "")
    174   (use PERFILE XSI_BIN xsi "xsi-specified utility, one source file per binary under cmd/xsi" "")
    175   (use PERFILE PSEUDO_BIN pseudo "common but undefined utility, one source file per binary under cmd/pseudo" "")
    176   (use PERFILE EXTRA_BIN extra "extra utility outside POSIX/XSI scope, one source file per binary under cmd/extra" "")
    177 
    178   (group posix lib POSIX_BIN POSIX_BC POSIX_AWK POSIX_SH POSIX_MAKE)
    179   (group linux lib LINUX_BIN)
    180   (group net lib NET_BIN)
    181   (group xsi lib XSI_BIN)
    182   (group pseudo lib PSEUDO_BIN)
    183   (group extra lib EXTRA_BIN EXTRA_YAP EXTRA_FSCK_FAT EXTRA_FSCK_EXT4)
    184 
    185   ; codegen: generate sources consumed by the build rules below. ungated
    186   ; ones always run. conditional ones use (req) so they only run when
    187   ; their inputs exists in this checkout
    188   ;
    189   (rule GETCONF_H
    190   (gate build_posix_getconf)
    191   (out "cmd/posix/getconf.h")
    192   (dep "scripts/getconf.sh")
    193   (exec sh scripts/genconfig.sh getconf))
    194 
    195   (rule POSIX_BC_C
    196   (gate build_posix_bc)
    197   (req "cmd/posix/bc.y")
    198   (out "cmd/posix/bc.c")
    199   (dep "cmd/posix/bc.y")
    200   (exec sh scripts/genconfig.sh bc))
    201 
    202   (rule POSIX_AWK_C
    203   (gate build_posix_awk)
    204   (out "cmd/posix/awk/awkgram.tab.c")
    205   (dep "cmd/posix/awk/awkgram.y")
    206   (exec sh scripts/genconfig.sh awk))
    207 
    208   (rule POSIX_SH_C
    209   (gate build_posix_sh)
    210   (out "cmd/posix/sh/syntax.c")
    211   (dep "cmd/posix/sh/mksyntax.c" "cmd/posix/sh/mknodes.c" "cmd/posix/sh/mkbuiltins" "cmd/posix/sh/mktokens")
    212   (exec sh scripts/genconfig.sh sh))
    213 
    214   (rule DEVCONF
    215   (req "cmd/dev/configure")
    216   (out "cmd/dev/config.h")
    217   (dep "cmd/dev/configure")
    218   (phony)
    219   (exec sh cmd/dev/configure --target=$(MICE_TARGET_TRIPLE) --sysroot=$(MICE_TARGET_SYSROOT)))
    220 
    221   (group codegen GETCONF_H POSIX_BC_C POSIX_AWK_C POSIX_SH_C DEVCONF)
    222 
    223   ; multi: one binary from all .c files in one or more dirs (minus skip)
    224   ; codegen must run first so generated sources are present before these
    225   ; globs collect them
    226   ;
    227   (rule POSIX_BC_OBJ
    228   (glob "cmd/posix/bc.c")
    229   (gate build_posix_bc)
    230   (dep $(MATCH) FEATURES_H)
    231   (after POSIX_BC_C)
    232   (out "$(STEM).o")
    233   (exec $(CC) $(CPPFLAGS) $(CFLAGS) -c -o $(OUT) $(MATCH)))
    234 
    235   (rule POSIX_BC
    236   (gate build_posix_bc)
    237   (member posix bc)
    238   (dep POSIX_BC_OBJ LIBUTIL LIBUTF)
    239   (out "cmd/posix/bc")
    240   (exec $(CC) -o $(OUT) $(IN) $(LDFLAGS) $(LDLIBS) -lm))
    241 
    242   (rule POSIX_AWK_OBJ
    243   (glob "cmd/posix/awk/*.c")
    244   (gate build_posix_awk)
    245   (skip "maketab.c")
    246   (dep $(MATCH) FEATURES_H)
    247   (after POSIX_AWK_C)
    248   (out "$(STEM).o")
    249   (exec $(CC) $(CPPFLAGS) -Icmd/posix/awk $(CFLAGS) -c -o $(OUT) $(MATCH)))
    250 
    251   (rule POSIX_AWK
    252   (gate build_posix_awk)
    253   (member posix awk)
    254   (dep POSIX_AWK_OBJ LIBUTIL LIBUTF)
    255   (out "cmd/posix/awk/awk")
    256   (exec $(CC) -o $(OUT) $(IN) $(LDFLAGS) $(LDLIBS) -lm))
    257 
    258   (rule POSIX_SH_OBJ
    259   (glob "cmd/posix/sh/*.c")
    260   (gate build_posix_sh)
    261   (skip "mknodes.c" "mksyntax.c")
    262   (dep $(MATCH) FEATURES_H)
    263   (after POSIX_SH_C)
    264   (out "$(STEM).o")
    265   (exec $(CC) $(CPPFLAGS) -DSHELL -Icmd/posix/sh $(CFLAGS) -c -o $(OUT) $(MATCH)))
    266 
    267   (rule POSIX_SH
    268   (gate build_posix_sh)
    269   (member posix sh)
    270   (dep POSIX_SH_OBJ LIBUTIL LIBUTF LIBREDLINE)
    271   (out "cmd/posix/sh/sh")
    272   (exec $(CC) -o $(OUT) $(IN) $(LDFLAGS) $(LDLIBS)))
    273 
    274   (rule POSIX_MAKE_OBJ
    275   (glob "cmd/posix/make/*.c")
    276   (gate build_posix_make)
    277   (dep $(MATCH) FEATURES_H)
    278   (out "$(STEM).o")
    279   (exec $(CC) $(CPPFLAGS) $(CFLAGS) -c -o $(OUT) $(MATCH)))
    280 
    281   (rule POSIX_MAKE
    282   (gate build_posix_make)
    283   (member posix make)
    284   (dep POSIX_MAKE_OBJ LIBUTIL LIBUTF)
    285   (out "cmd/posix/make/make")
    286   (exec $(CC) -o $(OUT) $(IN) $(LDFLAGS) $(LDLIBS)))
    287 
    288   (rule EXTRA_YAP_OBJ
    289   (glob "cmd/extra/yap/*.c")
    290   (gate build_extra_yap)
    291   (dep $(MATCH) FEATURES_H)
    292   (out "$(STEM).o")
    293   (exec $(CC) $(CPPFLAGS) $(CFLAGS) -c -o $(OUT) $(MATCH)))
    294 
    295   (rule EXTRA_YAP
    296   (gate build_extra_yap)
    297   (member extra yap)
    298   (dep EXTRA_YAP_OBJ LIBUTIL LIBUTF)
    299   (out "cmd/extra/yap/yap")
    300   (exec $(CC) -o $(OUT) $(IN) $(LDFLAGS) $(LDLIBS) -ltinfo))
    301 
    302   (template FSCK (RULE TOOL KEY FLAGS HEADERS)
    303     (rule $(RULE)_OBJ
    304       (glob "cmd/extra/$(TOOL)/*.c")
    305       (gate build_extra_$(KEY))
    306       (dep $(MATCH) FEATURES_H "glob:cmd/extra/$(TOOL)/**/*.h" $(HEADERS))
    307       (out "$(STEM).o")
    308       (exec $(CC) $(CPPFLAGS) -U_POSIX_C_SOURCE -D_DEFAULT_SOURCE -Icmd/extra/$(TOOL) $(FLAGS) $(CFLAGS) -c -o $(OUT) $(MATCH)))
    309 
    310     (rule $(RULE)
    311       (gate build_extra_$(KEY))
    312       (member extra $(TOOL))
    313       (dep $(RULE)_OBJ LIBUTIL)
    314       (out "cmd/extra/$(TOOL)/$(TOOL)")
    315       (exec $(CC) -o $(OUT) $(IN) $(LDFLAGS) $(LDLIBS)))
    316 
    317     (rule $(RULE)_BOX
    318       (gate build_extra_$(KEY))
    319       (dep $(RULE)_OBJ)
    320       (out ".box/cmd/extra/$(TOOL).o")
    321       (shell "$(LD) -r -o $(OUT) $(IN) && $(OBJCOPY) --redefine-sym main=$(KEY)_main $(OUT) && $(OBJCOPY) --keep-global-symbol=$(KEY)_main $(OUT)")
    322       (group box)))
    323 
    324   (use FSCK EXTRA_FSCK_FAT fsck.fat fsck_fat "-includecmd/extra/fsck.fat/freebsd-compat.h" "shared/queue.h")
    325   (use FSCK EXTRA_FSCK_EXT4 fsck.ext4 fsck_ext4 "-includecmd/extra/fsck.ext4/compat.h" "shared/diskutil.h")
    326 
    327   ; (member GROUP ALIAS) gives a rule a qualified user-facing name
    328   ; (e.g. posix/bc) while keeping its internal name (POSIX_BC) for deps,
    329   ; gates, and other references
    330   ;
    331 
    332   ; dev: the aruu toolchain. ar/as/ld are standalone and cc
    333   ; shares one object pool linked into three frontends
    334   ;
    335   (rule AR_OBJ
    336   (glob "cmd/dev/ar/*.c")
    337   (gate build_dev_ar)
    338   (skip "tinyar.c")
    339   (after DEVCONF)
    340   (dep $(MATCH) FEATURES_H)
    341   (out "$(STEM).o")
    342   (exec $(CC) $(CPPFLAGS) -Icmd/dev/ar $(CFLAGS) -c -o $(OUT) $(MATCH)))
    343 
    344   (rule AR
    345   (gate build_dev_ar)
    346   (dep AR_OBJ LIBUTIL LIBUTF)
    347   ; static: these tools run inside whatever rootfs they target via
    348   ; nac, not just the host that built them, and never need the
    349   ; project-wide LDLIBS default (openssl, unused by any of them)
    350   (out "cmd/dev/ar/ar")
    351   (exec $(CC) -static -o $(OUT) $(IN) $(LDFLAGS)))
    352 
    353   (rule XELF_OBJ
    354   (glob "cmd/dev/xelf/*.c")
    355   (gate build_dev_xelf)
    356   (after DEVCONF)
    357   (dep $(MATCH) FEATURES_H)
    358   (out "$(STEM).o")
    359   (exec $(CC) $(CPPFLAGS) -Icmd/dev/xelf $(CFLAGS) -c -o $(OUT) $(MATCH)))
    360 
    361   (rule XELF
    362   (gate build_dev_xelf)
    363   (dep XELF_OBJ LIBUTIL LIBUTF)
    364   (out "cmd/dev/xelf/xelf")
    365   (exec $(CC) -static -o $(OUT) $(IN) $(LDFLAGS)))
    366 
    367   (rule TCUTIL_OBJ
    368   (glob "shared/libtcutil/*.c" "shared/libtcutil/elf/*.c" "shared/libtcutil/ar/*.c")
    369   (gate build_dev_cc)
    370   (after DEVCONF)
    371   (dep $(MATCH) FEATURES_H)
    372   (out "$(STEM).o")
    373   (exec $(CC) $(CPPFLAGS) -Ishared/libtcutil -Ishared/libtcutil/elf -Ishared/libtcutil/ar -Icmd/dev $(CFLAGS) -c -o $(OUT) $(MATCH)))
    374 
    375   (rule AS_OBJ
    376   (glob "cmd/dev/as/*.c" "cmd/dev/as/arch/x64/*.c")
    377   (gate build_dev_cc)
    378   (after DEVCONF)
    379   (dep $(MATCH) FEATURES_H)
    380   (out "$(STEM).o")
    381   (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)))
    382 
    383   (rule AS
    384   (gate build_dev_cc)
    385   (dep AS_OBJ TCUTIL_OBJ LIBUTIL LIBUTF)
    386   (out "cmd/dev/as/as")
    387   (exec $(CC) -static -o $(OUT) $(IN) $(LDFLAGS)))
    388 
    389   (rule LD_OBJ
    390   (glob "cmd/dev/ld/*.c" "cmd/dev/ld/arch/*/*.c")
    391   (gate build_dev_ld)
    392   (after DEVCONF)
    393   (dep $(MATCH) FEATURES_H)
    394   (out "$(STEM).o")
    395   (exec $(CC) $(CPPFLAGS) -Icmd/dev/ld $(CFLAGS) -c -o $(OUT) $(MATCH)))
    396 
    397   (rule LD
    398   (gate build_dev_ld)
    399   (dep LD_OBJ LIBUTIL LIBUTF)
    400   (out "cmd/dev/ld/ld")
    401   (exec $(CC) -static -o $(OUT) $(IN) $(LDFLAGS)))
    402 
    403   ; CCPOOL_OBJ globs the whole directory. the entry points below use
    404   ; literal globs, so the override excludes them automatically
    405   (rule CCPOOL_OBJ
    406   (glob "cmd/dev/cc/*.c")
    407   (gate build_dev_cc)
    408   (after DEVCONF)
    409   (dep $(MATCH) FEATURES_H)
    410   (out "$(STEM).o")
    411   (exec $(CC) $(CPPFLAGS) -Icmd/dev/cc $(CFLAGS) -c -o $(OUT) $(MATCH)))
    412 
    413   (rule CC1_OBJ
    414   (glob "cmd/dev/cc/cc1.c")
    415   (gate build_dev_cc)
    416   (after DEVCONF)
    417   (dep $(MATCH) FEATURES_H)
    418   (out "$(STEM).o")
    419   (exec $(CC) $(CPPFLAGS) -Icmd/dev/cc $(CFLAGS) -c -o $(OUT) $(MATCH)))
    420 
    421   ; util.c is its own rule, not folded into CCPOOL_OBJ's wildcard or
    422   ; CCDRV_OBJ's own glob: cc1, cpp, and cc (the driver) all call its
    423   ; helpers (fatal, xmalloc, arrayadd, ...), but only cc has its own
    424   ; main(), so driver.c cannot be a shared link input the other two
    425   ; binaries pull in too
    426   (rule UTIL_OBJ
    427   (glob "cmd/dev/cc/util.c")
    428   (gate build_dev_cc)
    429   (after DEVCONF)
    430   (dep $(MATCH) FEATURES_H)
    431   (out "$(STEM).o")
    432   (exec $(CC) $(CPPFLAGS) -Icmd/dev/cc $(CFLAGS) -c -o $(OUT) $(MATCH)))
    433 
    434   (rule CC1
    435   (gate build_dev_cc)
    436   (dep CC1_OBJ CCPOOL_OBJ UTIL_OBJ LIBUTIL LIBUTF)
    437   (out "cmd/dev/cc/cc1")
    438   (exec $(CC) -static -o $(OUT) $(IN) $(LDFLAGS)))
    439 
    440   (rule CPP_OBJ
    441   (glob "cmd/dev/cc/cpp.c")
    442   (gate build_dev_cc)
    443   (after DEVCONF)
    444   (dep $(MATCH) FEATURES_H)
    445   (out "$(STEM).o")
    446   (exec $(CC) $(CPPFLAGS) -Icmd/dev/cc $(CFLAGS) -c -o $(OUT) $(MATCH)))
    447 
    448   (rule CPP
    449   (gate build_dev_cc)
    450   (dep CPP_OBJ CCPOOL_OBJ UTIL_OBJ LIBUTIL LIBUTF)
    451   (out "cmd/dev/cc/cpp")
    452   (exec $(CC) -static -o $(OUT) $(IN) $(LDFLAGS)))
    453 
    454   ; driver.c's own quoted #include "config.h" needs cmd/dev/config.h
    455   ; (DEVCONF's own output), not shared/config.h, MICE's unrelated
    456   ; project-wide one that $(CPPFLAGS)'s own -Ishared would otherwise
    457   ; win on: -Icmd/dev goes first, ahead of $(CPPFLAGS), so it wins the
    458   ; search. (after DEVCONF) orders the generation itself first, or
    459   ; parallel execution can compile driver.c before config.h exists
    460   (rule CCDRV_OBJ
    461   (glob "cmd/dev/cc/driver.c")
    462   (gate build_dev_cc)
    463   (dep $(MATCH) FEATURES_H)
    464   (after DEVCONF)
    465   (out "$(STEM).o")
    466   (exec $(CC) -Icmd/dev $(CPPFLAGS) -Icmd/dev/cc $(CFLAGS) -c -o $(OUT) $(MATCH)))
    467 
    468   (rule CCDRV
    469   (gate build_dev_cc)
    470   (dep CCDRV_OBJ UTIL_OBJ LIBUTIL LIBUTF)
    471   (out "cmd/dev/cc/cc")
    472   (exec $(CC) -static -o $(OUT) $(IN) $(LDFLAGS)))
    473 
    474   ; ninqu is multiple translation units sharing globals (rules, insts,
    475   ; and so on), unlike the single-file tools BOX_OBJ handles: combine
    476   ; its objects first, like POSIX_BC_BOX/POSIX_AWK_BOX/POSIX_SH_BOX/
    477   ; POSIX_MAKE_BOX/EXTRA_YAP_BOX do for their own multi-file tools, so
    478   ; --keep-global-symbol only strips main across the combined object
    479   ; instead of hiding every cross-file global before linking even
    480   ; happens. it is still not reentrant, so it stays out of NOFORK_LIST
    481   ;
    482   (rule NINQU_BOX_OBJ
    483   (glob "cmd/dev/ninqu/*.c")
    484   (gate build_dev_ninqu)
    485   (dep $(MATCH) FEATURES_H)
    486   (after LIBUTIL LIBUTF LIBREDLINE NOFORK_LIST_H GETCONF_H)
    487   (out ".box/parts/$(STEM).o")
    488   (exec $(CC) $(CPPFLAGS) $(CFLAGS) -c -o $(OUT) $(MATCH)))
    489 
    490   (rule NINQU_BOX
    491   (gate build_dev_ninqu)
    492   (dep NINQU_BOX_OBJ)
    493   (out ".box/cmd/dev/ninqu.o")
    494   (description "ninqu's objects combined into one relocatable object, main renamed for the box dispatch table")
    495   (shell "$(LD) -r -o $(OUT) $(IN) && $(OBJCOPY) --redefine-sym main=ninqu_main $(OUT) && $(OBJCOPY) --keep-global-symbol=ninqu_main $(OUT)")
    496   (group box))
    497 
    498   (group dev lib DEVCONF AR XELF AS LD CC1 CPP CCDRV)
    499 
    500   ; man pages: build mdoc and text pages from ?man-marked sources
    501   ;
    502   (rule MKMAN
    503   (dir "scripts/mkman")
    504   (dep "glob:scripts/mkman/*.go")
    505   (out "scripts/mkman/mkman")
    506   (exec go build -o mkman .))
    507 
    508   (rule MAN_MDOC
    509   (glob "cmd/**/*.c")
    510   (mark "?man")
    511   (dep CONFIG_KV (after MKMAN))
    512   (out "man/man$(SEC_OF:$(DIR))/$(BASESTEM).$(SEC_OF:$(DIR))")
    513   (exec scripts/mkman/mkman -fmt mdoc -config scripts/mk/config.kv $(MATCH))
    514   (redirect))
    515 
    516   (rule MAN_TXT
    517   (glob "cmd/**/*.c")
    518   (mark "?man")
    519   (dep CONFIG_KV (after MKMAN))
    520   (out "man/man$(SEC_OF:$(DIR))/$(BASESTEM).$(SEC_OF:$(DIR)).txt")
    521   (exec scripts/mkman/mkman -fmt txt -config scripts/mk/config.kv $(MATCH))
    522   (redirect))
    523 
    524   (map SEC_OF
    525   (cmd/posix 1)
    526   (cmd/posix/make 1)
    527   (cmd/linux 8)
    528   (cmd/net 8)
    529   (cmd/xsi 1)
    530   (cmd/pseudo 1)
    531   (cmd/extra 1)
    532   (cmd/extra/fsck.fat 1)
    533   (cmd/dev 1))
    534 
    535   (group man MAN_MDOC MAN_TXT)
    536 
    537   (rule CLEAN
    538   (phony)
    539   (shell "
    540   printf ' CLEAN object files\n'
    541   find shared cmd -name '*.o' -exec rm -f {} +
    542 
    543   printf ' CLEAN static libraries\n'
    544   find shared -name '*.a' -exec rm -f {} +
    545 
    546   printf ' CLEAN compiled binaries\n'
    547   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 {} +
    548 
    549   sh scripts/genconfig.sh clean
    550   rm -f scripts/mk/config.mk scripts/mk/config.kv scripts/mk/rules.mk shared/libutil/nofork_list.h
    551 
    552   printf ' CLEAN build tools\n'
    553   rm -f scripts/mkman/mkman
    554 
    555   printf ' CLEAN dev artifacts\n'
    556   rm -f cmd/dev/cc/cc1 cmd/dev/cc/cpp cmd/dev/as/as cmd/dev/ld/ld cmd/dev/ar/ar
    557   rm -f shared/libaruuelf.so
    558   rm -f cmd/dev/config.h cmd/dev/cc/config.h cmd/dev/version.h
    559 
    560   printf ' CLEAN misc\n'
    561   rm -rf man/man1 man/man8
    562   rm -rf aruu-box .box
    563   rm -rf .ninja_log .ninja_deps
    564 
    565   printf ' CLEAN done\n'
    566   "))
    567 
    568   (group clean CLEAN)
    569 
    570   ; install every built executable and generated man page, plus
    571   ; shared/libutil itself as a real linkable library: other MICE
    572   ; components (ports/pkgtools, nac) should link against this, not carry
    573   ; their own copy of ealloc/eprintf/wexec/etc alongside it
    574   (rule INSTALL
    575   (phony)
    576   (after ALL_BINS LIBUTIL MAN_MDOC MAN_TXT)
    577   (shell "
    578   [ -n \"${DESTDIR:-}\" ] || { printf 'install requires DESTDIR\n' >&2; exit 1; }
    579     case \"$(PREFIX)\" in /usr|/usr/*|usr|usr/*) printf 'ARUU cannot install into usr\n' >&2; exit 1 ;; esac
    580     case \"$DESTDIR\" in /usr|/usr/*) printf 'ARUU cannot install into usr\n' >&2; exit 1 ;; esac
    581   d=\"$DESTDIR$(PREFIX)\"
    582   m=\"$DESTDIR$(MANPREFIX)\"
    583   mkdir -p \"$d/bin\" \"$m/man1\" \"$m/man8\" \"$d/lib\" \"$d/include/aruu\"
    584 
    585   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
    586   name=${bin##*/}
    587       printf '  INSTALL %s/bin/%s\n' '$(PREFIX)' \"$name\"
    588       cp \"$bin\" \"$d/bin/$name\"
    589       chmod 755 \"$d/bin/$name\"
    590     done
    591     # they run as root for whoever runs them (see SETUID_BIN)
    592     for name in su passwd; do
    593       [ ! -f \"$d/bin/$name\" ] || chmod 4755 \"$d/bin/$name\"
    594     done
    595 
    596     find man/man1 man/man8 -type f -name '*.[18]' 2>/dev/null | while read -r f; do
    597       sec=${f%/*}; sec=${sec##*/}
    598       name=${f##*/}
    599       cp \"$f\" \"$m/$sec/$name\"
    600     done
    601 
    602     # the keyboard layouts kmap reads, kept as they were written once
    603     printf '  INSTALL %s/share/kmap\n' '$(PREFIX)'
    604     mkdir -p \"$d/share\"
    605     cp -R share/kmap \"$d/share/kmap\"
    606 
    607     if [ -x cmd/extra/fsck.fat/fsck.fat ]; then
    608       ln -sf fsck.fat \"$d/bin/fsck.vfat\"
    609     fi
    610     for name in fsck.fat fsck.ext4; do
    611       if [ -x \"cmd/extra/$name/$name\" ]; then
    612         mkdir -p \"$d/share/licenses/aruu\"
    613         cp \"cmd/extra/$name/NOTICE\" \"$d/share/licenses/aruu/$name\"
    614       fi
    615     done
    616 
    617     printf '  INSTALL %s/lib/libaruu.a\n' '$(PREFIX)'
    618     cp shared/libutil/libutil.a \"$d/lib/libaruu.a\"
    619     chmod 644 \"$d/lib/libaruu.a\"
    620     for h in shared/util.h shared/wexec.h shared/arg.h shared/compat.h \
    621         shared/filesystem.h shared/net.h shared/sysinfo.h; do
    622       printf '  INSTALL %s/include/aruu/%s\n' '$(PREFIX)' \"${h##*/}\"
    623       cp \"$h\" \"$d/include/aruu/${h##*/}\"
    624       chmod 644 \"$d/include/aruu/${h##*/}\"
    625     done
    626   "))
    627 
    628 (group install INSTALL)
    629 
    630 ; same body as INSTALL, minus the dev (compiler toolchain) category:
    631 ; what a MICE port needs to put a shell and coreutils on a rootfs,
    632 ; not a hard dependency on the separate, not-yet-portable dev build
    633 (rule INSTALL_BASE
    634   (phony)
    635   (after POSIX_BIN LINUX_BIN NET_BIN XSI_BIN PSEUDO_BIN EXTRA_BIN
    636          POSIX_BC POSIX_AWK POSIX_SH POSIX_MAKE EXTRA_YAP EXTRA_FSCK_FAT EXTRA_FSCK_EXT4
    637          LIBUTIL MAN_MDOC MAN_TXT)
    638   (shell "
    639     [ -n \"${DESTDIR:-}\" ] || { printf 'install-base requires DESTDIR\n' >&2; exit 1; }
    640   case \"$(PREFIX)\" in /usr|/usr/*|usr|usr/*) printf 'ARUU cannot install into usr\n' >&2; exit 1 ;; esac
    641   case \"$DESTDIR\" in /usr|/usr/*) printf 'ARUU cannot install into usr\n' >&2; exit 1 ;; esac
    642     d=\"$DESTDIR$(PREFIX)\"
    643     m=\"$DESTDIR$(MANPREFIX)\"
    644     mkdir -p \"$d/bin\" \"$m/man1\" \"$m/man8\" \"$d/lib\" \"$d/include/aruu\"
    645 
    646     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
    647   name=${bin##*/}
    648       printf '  INSTALL %s/bin/%s\n' '$(PREFIX)' \"$name\"
    649       cp \"$bin\" \"$d/bin/$name\"
    650       chmod 755 \"$d/bin/$name\"
    651     done
    652     # they run as root for whoever runs them (see SETUID_BIN)
    653     for name in su passwd; do
    654       [ ! -f \"$d/bin/$name\" ] || chmod 4755 \"$d/bin/$name\"
    655     done
    656 
    657     find man/man1 man/man8 -type f -name '*.[18]' 2>/dev/null | while read -r f; do
    658       sec=${f%/*}; sec=${sec##*/}
    659       name=${f##*/}
    660       cp \"$f\" \"$m/$sec/$name\"
    661     done
    662 
    663     # the keyboard layouts kmap reads, kept as they were written once
    664     printf '  INSTALL %s/share/kmap\n' '$(PREFIX)'
    665     mkdir -p \"$d/share\"
    666     cp -R share/kmap \"$d/share/kmap\"
    667 
    668     if [ -x cmd/extra/fsck.fat/fsck.fat ]; then
    669       ln -sf fsck.fat \"$d/bin/fsck.vfat\"
    670     fi
    671     for name in fsck.fat fsck.ext4; do
    672       if [ -x \"cmd/extra/$name/$name\" ]; then
    673         mkdir -p \"$d/share/licenses/aruu\"
    674         cp \"cmd/extra/$name/NOTICE\" \"$d/share/licenses/aruu/$name\"
    675       fi
    676     done
    677 
    678     printf '  INSTALL %s/lib/libaruu.a\n' '$(PREFIX)'
    679     cp shared/libutil/libutil.a \"$d/lib/libaruu.a\"
    680     chmod 644 \"$d/lib/libaruu.a\"
    681     for h in shared/util.h shared/wexec.h shared/arg.h shared/compat.h \
    682         shared/filesystem.h shared/net.h shared/sysinfo.h; do
    683       printf '  INSTALL %s/include/aruu/%s\n' '$(PREFIX)' \"${h##*/}\"
    684       cp \"$h\" \"$d/include/aruu/${h##*/}\"
    685       chmod 644 \"$d/include/aruu/${h##*/}\"
    686     done
    687   "))
    688 
    689 (group install-base INSTALL_BASE)
    690 
    691 ; remove exactly what install would have copied
    692 (rule REMOVE
    693   (phony)
    694   (shell "
    695     [ -n \"${DESTDIR:-}\" ] || { printf 'remove requires DESTDIR\n' >&2; exit 1; }
    696     case \"$(PREFIX)\" in /usr|/usr/*|usr|usr/*) printf 'ARUU cannot remove from usr\n' >&2; exit 1 ;; esac
    697     case \"$DESTDIR\" in /usr|/usr/*) printf 'ARUU cannot remove from usr\n' >&2; exit 1 ;; esac
    698     d=\"$DESTDIR$(PREFIX)\"
    699     m=\"$DESTDIR$(MANPREFIX)\"
    700     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
    701       name=${bin##*/}
    702       printf '  REMOVE %s/bin/%s\n' '$(PREFIX)' \"$name\"
    703       rm -f \"$d/bin/$name\"
    704     done
    705 
    706     find man/man1 man/man8 -type f -name '*.[18]' 2>/dev/null | while read -r f; do
    707       sec=${f%/*}; sec=${sec##*/}
    708       name=${f##*/}
    709       printf '  REMOVE %s/%s/%s\n' '$(MANPREFIX)' \"$sec\" \"$name\"
    710       rm -f \"$m/$sec/$name\"
    711     done
    712 
    713     if [ \"`readlink \"$d/bin/fsck.vfat\"`\" = fsck.fat ]; then
    714       rm -f \"$d/bin/fsck.vfat\"
    715     fi
    716     rm -f \"$d/share/licenses/aruu/fsck.fat\"
    717     rm -f \"$d/share/licenses/aruu/fsck.ext4\"
    718 
    719     printf '  REMOVE %s/lib/libaruu.a\n' '$(PREFIX)'
    720     rm -f \"$d/lib/libaruu.a\"
    721     for h in util.h wexec.h arg.h compat.h filesystem.h net.h sysinfo.h; do
    722       printf '  REMOVE %s/include/aruu/%s\n' '$(PREFIX)' \"$h\"
    723       rm -f \"$d/include/aruu/$h\"
    724     done
    725     rmdir \"$d/include/aruu\" 2>/dev/null || :
    726   "))
    727 
    728 (group remove REMOVE)
    729 (group uninstall REMOVE)
    730 
    731 (rule FMT
    732   (phony)
    733   (shell "
    734     printf '  FMT cmd and shared (skipping dir tools)\n'
    735     find cmd shared -type f \( -name '*.c' -o -name '*.h' \) \
    736       ! -path 'cmd/posix/awk/*' \
    737       ! -path 'cmd/posix/sh/*' \
    738       ! -path 'cmd/posix/make/*' \
    739       ! -path 'cmd/extra/yap/*' \
    740       ! -path 'cmd/extra/fsck.fat/*' \
    741       ! -path 'cmd/extra/fsck.ext4/*' \
    742   ! -path 'cmd/posix/bc.c' \
    743   -print | xargs -r clang-format -i
    744   "))
    745 
    746   (rule FMT_ALL
    747   (phony)
    748   (shell "
    749   printf ' FMT cmd and shared (including dir tools)\n'
    750   find cmd shared -type f \( -name '*.c' -o -name '*.h' \) -print \
    751   | xargs -r clang-format -i
    752   "))
    753 
    754   (group fmt FMT)
    755   (group fmt-all FMT_ALL)
    756 
    757   ; box: one executable containing every enabled tool, dispatched through
    758   ; a table. a single-file tool just gets its main renamed by BOX_OBJ
    759   ; multi-file tools (POSIX_BC, POSIX_AWK, POSIX_SH, POSIX_MAKE, EXTRA_YAP)
    760   ; go through a partial link (ld -r) first, merging their objects into
    761   ; one before main gets renamed and helper symbols hidden. replaces
    762   ; scripts/mkbox
    763   ;
    764   ; object files live under .box/, mirroring the cmd/ layout
    765   ;
    766   ; ninqu determines which tools enter the box using the gate on BOX_OBJ
    767   ; BOX_DISPATCH reads the object paths passed on argv rather than consulting
    768   ; build.cfg or config.set directly
    769   ;
    770 
    771   ; CATEGORY_OF maps a directory path to its category name, matching the toggles
    772   ; in build.cfg. since BOX_OBJ globs multiple directories, its gate evaluates the
    773   ; category dynamically based on the match directory
    774   ;
    775   ; gates evaluate $(IDENT) instead of $(BASESTEM) because toggle names must be
    776   ; valid shell variables. genconfig.sh replaces hyphens and periods with
    777   ; underscores, and $(IDENT) applies the same normalization so they match
    778   ;
    779   (map CATEGORY_OF
    780   (cmd/posix posix)
    781   (cmd/linux linux)
    782   (cmd/net net)
    783   (cmd/pseudo pseudo)
    784   (cmd/xsi xsi)
    785   (cmd/extra extra))
    786 
    787   ; tool basestems match their c symbols using a shell transform (tr '.-' '__'
    788   ; and appending _main) in both the objcopy step and in genbox.sh. a static map
    789   ; is unnecessary because no current tools require custom overrides, and
    790   ; genbox.sh only receives paths via argv
    791   ;
    792 
    793   ; the match directory picks the gate and output path, so one rule covers
    794   ; all six categories. bc.c inside cmd/posix is excluded automatically by
    795   ; the literal-glob override mechanism
    796   ;
    797   (rule BOX_OBJ
    798   (glob "cmd/posix/*.c" "cmd/linux/*.c" "cmd/net/*.c" "cmd/pseudo/*.c"
    799         "cmd/xsi/*.c" "cmd/extra/*.c")
    800   (skip "su.c" "passwd.c")
    801   (gate build_$(CATEGORY_OF:$(DIR))_$(IDENT))
    802   (dep $(MATCH) FEATURES_H)
    803   (after LIBUTIL LIBUTF LIBREDLINE NOFORK_LIST_H GETCONF_H)
    804   (out ".box/$(DIR)/$(BASESTEM).o")
    805   (description "one object per enabled tool, main renamed for the box dispatch table")
    806   (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)")
    807   (group box))
    808 
    809   ; POSIX_BC, POSIX_AWK, POSIX_SH, POSIX_MAKE, and EXTRA_YAP cant go through
    810   ; the single-file objcopy step, their global helper symbols would collide
    811   ; once linked into one binary. a partial link (ld -r) resolves those
    812   ; internal references first, then main gets renamed and the rest hidden
    813   ;
    814   ; combined objects use the layout .box/cmd/<category>/<tool>.o so genbox.sh
    815   ; can parse them without structural modifications
    816   ;
    817   (rule POSIX_BC_BOX_OBJ
    818   (glob "cmd/posix/bc.c")
    819   (gate build_posix_bc)
    820   (dep $(MATCH) FEATURES_H)
    821   (after POSIX_BC_C)
    822   (out ".box/parts/$(STEM).o")
    823   (exec $(CC) $(CPPFLAGS) $(CFLAGS) -c -o $(OUT) $(MATCH)))
    824 
    825   (rule POSIX_BC_BOX
    826   (gate build_posix_bc)
    827   (dep POSIX_BC_BOX_OBJ)
    828   (out ".box/cmd/posix/bc.o")
    829   (description "bc's objects combined into one relocatable object, main renamed for the box dispatch table")
    830   (shell "$(LD) -r -o $(OUT) $(IN) && $(OBJCOPY) --redefine-sym main=bc_main $(OUT) && $(OBJCOPY) --keep-global-symbol=bc_main $(OUT)")
    831   (group box))
    832 
    833   (rule POSIX_AWK_BOX_OBJ
    834   (glob "cmd/posix/awk/*.c")
    835   (gate build_posix_awk)
    836   (skip "maketab.c")
    837   (dep $(MATCH) FEATURES_H)
    838   (after POSIX_AWK_C)
    839   (out ".box/parts/$(STEM).o")
    840   (exec $(CC) $(CPPFLAGS) -Icmd/posix/awk $(CFLAGS) -c -o $(OUT) $(MATCH)))
    841 
    842   (rule POSIX_AWK_BOX
    843   (gate build_posix_awk)
    844   (dep POSIX_AWK_BOX_OBJ)
    845   (out ".box/cmd/posix/awk.o")
    846   (description "awk's objects combined into one relocatable object, main renamed for the box dispatch table")
    847   (shell "$(LD) -r -o $(OUT) $(IN) && $(OBJCOPY) --redefine-sym main=awk_main $(OUT) && $(OBJCOPY) --keep-global-symbol=awk_main $(OUT)")
    848   (group box))
    849 
    850   (rule POSIX_SH_BOX_OBJ
    851   (glob "cmd/posix/sh/*.c")
    852   (gate build_posix_sh)
    853   (skip "mknodes.c" "mksyntax.c")
    854   (dep $(MATCH) FEATURES_H)
    855   (after POSIX_SH_C)
    856   (out ".box/parts/$(STEM).o")
    857   (exec $(CC) $(CPPFLAGS) -DSHELL -Icmd/posix/sh $(CFLAGS) -c -o $(OUT) $(MATCH)))
    858 
    859   (rule POSIX_SH_BOX
    860   (gate build_posix_sh)
    861   (dep POSIX_SH_BOX_OBJ)
    862   (out ".box/cmd/posix/sh.o")
    863   (description "sh's objects combined into one relocatable object, main renamed for the box dispatch table")
    864   (shell "$(LD) -r -o $(OUT) $(IN) && $(OBJCOPY) --redefine-sym main=sh_main $(OUT) && $(OBJCOPY) --keep-global-symbol=sh_main $(OUT)")
    865   (group box))
    866 
    867   (rule POSIX_MAKE_BOX_OBJ
    868   (glob "cmd/posix/make/*.c")
    869   (gate build_posix_make)
    870   (dep $(MATCH) FEATURES_H)
    871   (out ".box/parts/$(STEM).o")
    872   (exec $(CC) $(CPPFLAGS) $(CFLAGS) -c -o $(OUT) $(MATCH)))
    873 
    874   (rule POSIX_MAKE_BOX
    875   (gate build_posix_make)
    876   (dep POSIX_MAKE_BOX_OBJ)
    877   (out ".box/cmd/posix/make.o")
    878   (description "make's objects combined into one relocatable object, main renamed for the box dispatch table")
    879   (shell "$(LD) -r -o $(OUT) $(IN) && $(OBJCOPY) --redefine-sym main=make_main $(OUT) && $(OBJCOPY) --keep-global-symbol=make_main $(OUT)")
    880   (group box))
    881 
    882   (rule EXTRA_YAP_BOX_OBJ
    883   (glob "cmd/extra/yap/*.c")
    884   (gate build_extra_yap)
    885   (dep $(MATCH) FEATURES_H)
    886   (out ".box/parts/$(STEM).o")
    887   (exec $(CC) $(CPPFLAGS) $(CFLAGS) -c -o $(OUT) $(MATCH)))
    888 
    889   (rule EXTRA_YAP_BOX
    890   (gate build_extra_yap)
    891   (dep EXTRA_YAP_BOX_OBJ)
    892   (out ".box/cmd/extra/yap.o")
    893   (description "yap's objects combined into one relocatable object, main renamed for the box dispatch table")
    894   (shell "$(LD) -r -o $(OUT) $(IN) && $(OBJCOPY) --redefine-sym main=yap_main $(OUT) && $(OBJCOPY) --keep-global-symbol=yap_main $(OUT)")
    895   (group box))
    896 
    897   ; genbox.sh relies on arguments passed by ninqu, where each argument matches
    898   ; an output from BOX_OBJ or a custom box rule. the script derives categories
    899   ; and tool names directly from these paths and outputs the dispatch code
    900   ;
    901   ; a tool that runs as root for whoever runs it (setuid: su, and passwd,
    902   ; which writes the shadow file) is never part of the box, which would
    903   ; make every tool in it setuid. each is a binary of its own under
    904   ; setuid/, which install makes setuid root
    905   ;
    906   (rule SETUID_BIN
    907   (glob "cmd/xsi/su.c" "cmd/xsi/passwd.c")
    908   (gate build_xsi_$(IDENT))
    909   (dep $(MATCH) LIBDISK LIBUTIL LIBUTF LIBBLAKE3 LIBMAGIC)
    910   (after "scripts/mk/features.h")
    911   (out "setuid/$(BASESTEM)")
    912   (description "a tool that runs as root for whoever runs it, kept out of the box")
    913   (exec $(CC) $(CPPFLAGS) $(CFLAGS) -o $(OUT) $(IN) $(LDFLAGS) $(LDLIBS) $(EXTRA_LIBS:$(BASESTEM)))
    914   (group box))
    915 
    916   (rule BOX_DISPATCH
    917   (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)
    918   (out ".box/aruu-box.c")
    919   (description "dispatch table and main() for aruu-box, generated from the enabled tool list")
    920   (exec sh $(IN))
    921   (redirect)
    922   (group box))
    923 
    924   ; libm is linked unconditionally because bc requires it, and unused library
    925   ; references are safe. modern toolchains omit unreferenced archive components
    926   ; yap requires terminfo, which is an optional system dependency. linking it
    927   ; unconditionally breaks builds on systems without ncurses-dev when yap is
    928   ; disabled. genconfig.sh exports BOX_EXTRA_LIBS as "-ltinfo" or an empty string
    929   ; based on whether yap is enabled
    930   ;
    931   ; libblake3 is the same story as libm: b3sum needs it, EXTRA_LIBS only
    932   ; applies to PERFILE's own standalone link line, box has no per-tool
    933   ; equivalent, so LIBBLAKE3 goes in BOX's own dep list unconditionally
    934   ; instead, same as LIBUTIL/LIBUTF/LIBREDLINE
    935   ;
    936   (rule BOX
    937   (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)
    938   (out "aruu-box")
    939   (description "single multi-call binary, one dispatch table for every enabled tool")
    940   (shell "$(CC) $(CPPFLAGS) $(CFLAGS) -o $(OUT) $(IN) $(LDFLAGS) $(LDLIBS) $(LDLIBS_TLS) $(BOX_EXTRA_LIBS)")
    941   (group box))
    942 
    943   (group box BOX SETUID_BIN)
    944 
    945   ; -------------------------------------------------------------------
    946   ; top level. (group all) contains every build target except clean
    947   ; and box. box is separate because it produces a different binary
    948   ; with different .o files, and mixing it with standalone builds
    949   ; would cause confusion. clean is never in all because it removes
    950   ; what all builds
    951   ; -------------------------------------------------------------------
    952 
    953   (rule ALL_BINS
    954   (phony)
    955   (after LIBUTIL LIBUTF LIBREDLINE
    956   POSIX_BIN LINUX_BIN NET_BIN XSI_BIN
    957   PSEUDO_BIN EXTRA_BIN
    958   POSIX_BC POSIX_AWK POSIX_SH POSIX_MAKE EXTRA_YAP EXTRA_FSCK_FAT EXTRA_FSCK_EXT4
    959   AR XELF AS LD CC1 CPP CCDRV)
    960   (exec true))
    961 
    962   (group all ALL_BINS)
    963 
    964   (group default all)
    965 
    966   ; meta-targets: apply an override, then build a normal target under
    967   ; it. invoke as `ninqu META.TARGET` (`ninqu debug.posix`) or bare
    968   ; `ninqu META` to apply the override and build (group default)
    969   ;
    970   (meta debug
    971   (set CFLAGS "$(CFLAGS) -g -O0"))
    972 
    973   (meta release
    974   (set CFLAGS "$(CFLAGS) -O2 -DNDEBUG"))