-
Notifications
You must be signed in to change notification settings - Fork 66
/
Makefile
1448 lines (1396 loc) · 66.2 KB
/
Makefile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
# Bedrock Linux Makefile
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# version 2 as published by the Free Software Foundation.
#
# Copyright (c) 2012-2024 Daniel Thau <danthau@bedrocklinux.org>
#
# This creates a script which can be used to install or update a Bedrock Linux
# system.
#
# First install the necessary build dependencies:
#
# - Standard UNIX utilities: grep, sed, awk, etc.
# - autoconf
# - autopoint
# - bison
# - fakeroot
# - gcc 4.9.1 or newer
# - git 1.8 or newer
# - gpg (optional)
# - gzip
# - libtool
# - make
# - meson 0.38 or newer
# - ninja-build
# - pkg-config
# - rsyn
# - rsync
# - udev (build-time only)
#
# Ensure you have internet access (to fetch upstream dependencies), then run:
#
# make GPGID=<gpg-id-with-which-to-sign>
#
# to build a signed install/update script or
#
# make SKIPSIGN=true
#
# to build an unsigned install/update script.
#
# To build for all supported architectures on a Bedrock Linux system, run:
#
# make release-build-environment
#
# as root to set up various build strata, and finally
#
# make GPGID=<gpg-id-with-which-to-sign> release
#
# This build system attempts to strike a balance between being overly dependent
# on the host system at the expense of portability, and maximizing portability
# at the expense of build time. Build tools such as gcc and meson are taken
# from the host system rather than recompiled. Upstream code which ends up
# within the output script is compiled from source.
#
# In order to ensure portability, the code base is compiled against musl. To
# do so easily, this uses the `musl-gcc` wrapper, which in turn means gcc is
# required. Effort to support other compilers, such a clang, should be made at
# some point in the future.
#
# Directory layout:
#
# - src/ contains Bedrock's own code, in contrast to upstream libraries.
# - src/slash-bedrock/ contains all files and directories which will populate
# the eventual install's /bedrock/ directory except binary executables which
# must be compiled.
# - src/installer/ contains the actual installer script. The build system will
# embed the eventual system files into the installation script.
# - Other src/ directories correspond to source for binary executables. These
# binaries will be included in the slash-bedrock structure embedded within the
# installation script.
# - vendor/ (initially absent) will contain upstream build dependencies. The
# build system will automatically fetch these and populate vendor/ accordingly.
# The build system will attempt to automatically get the latest stable version
# and may occasionally fail if an upstream component changes too drastically.
# This is purposeful; it will serve as a canary indicating developer attention
# is required and is preferable to distributing outdated upstream components
# which may contain security vulnerabilities.
# - vendor/*/.success_fetching_source files indicate that the given vendor
# component's files have been successfully acquired. This is used to properly
# handle interrupted downloads.
# - build/ (initially absent) will contain intermediate build output
# - build/<arch>/ separates build artifacts per-CPU-architecture which allows
# parallelized builds for different CPU architectures. See the "release"
# recipe.
# - build/<arch>/support/ will contain build-time support code and will not
# directly end up in the resulting install.
# - build/<arch>/bedrock/ will contain files which eventually end up in the
# installed system's /bedrock/ directory. This will be populated by
# src/slash-bedrock/ contents and the various src/ binaries.
# - build/<arch>/completed/ will contain files which indicate various build
# steps have been completed. These are for build steps that may produce many
# output files as an alternative to verbosely tracking each individual output
# file.
# - Makefile service as the build system.
# - `*.md` files service as documentation.
#
# Many dependencies have deep paths which may be awkward to type at a command
# line. For these, shorter recipe aliases are created.
#
# Where possible, recipes which acquire upstream source should attempt to get
# the latest stable version. This does risk the possibility that an upstream
# change breaks the build system, but this is preferable to acquiring outdated,
# insecure files. If the build system breaks, someone will be notified, while
# a missed security update may go unnoticed for a while.
#
# To format the code base, install:
#
# - shfmt (https://github.com/mvdan/sh)
# - indent (GNU)
#
# and run
#
# make format
#
# To run various static analysis tools against the code base, install
#
# - shellcheck
# - cppcheck
# - clang
# - gcc
# - scan-build (usually distributed with clang)
# - shfmt (https://github.com/mvdan/sh)
# - indent (GNU)
# - uthash
# - libfuse3
# - libcap
# - libattr
#
# and run
#
# make check
BEDROCK_VERSION=0.7.31beta2
CODENAME=Poki
ARCHITECTURE=$(shell ./detect_arch.sh | head -n1)
FILE_ARCH_NAME=$(shell ./detect_arch.sh | awk 'NR==2')
ARCH_BIT_DEPTH=$(shell ./detect_arch.sh | awk 'NR==3')
RELEASE=Bedrock Linux $(BEDROCK_VERSION) $(CODENAME)
INSTALLER=bedrock-linux-$(BEDROCK_VERSION)-$(ARCHITECTURE).sh
RELEASE_CFLAGS=-O2
ROOT=$(shell pwd)
BUILD=$(ROOT)/build/$(ARCHITECTURE)
SRC=$(BUILD)/src
VENDOR=$(BUILD)/vendor
SUPPORT=$(BUILD)/support
SLASHBR=$(BUILD)/bedrock
COMPLETED=$(BUILD)/completed
MUSLCC=$(SUPPORT)/bin/musl-gcc
INDENT_FLAGS=--linux-style --dont-line-up-parentheses \
--continuation-indentation8 --indent-label0 --case-indentation0 --line-length 120
WERROR_FLAGS=-Werror -Wall -Wextra -std=c99 -pedantic
all: $(INSTALLER)
remove_vendor_source:
rm -rf ./vendor
fetch_vendor_sources: \
vendor/busybox/.success_retrieving_source \
vendor/curl/.success_retrieving_source \
vendor/kmod/.success_retrieving_source \
vendor/libaio/.success_retrieving_source \
vendor/libattr/.success_retrieving_source \
vendor/libcap/.success_fetching_source \
vendor/libfuse/.success_fetching_source \
vendor/linux_headers/.success_fetching_source \
vendor/lvm2/.success_retrieving_source \
vendor/musl/.success_fetching_source \
vendor/netselect/.success_retrieving_source \
vendor/openssl/.success_retrieving_source \
vendor/uthash/.success_fetching_source \
vendor/util-linux/.success_fetching_source \
vendor/xz/.success_retrieving_source \
vendor/zlib/.success_retrieving_source \
vendor/zstd/.success_retrieving_source
clean:
rm -rf build/*
rm -f bedrock-linux-*-*.sh
#
# The build directory structure. This is a dependency of just about
# everything.
#
$(COMPLETED)/builddir:
# Support symlinking build into a tmpfs
if [ -h "$(ROOT)/build" ]; then \
mkdir -p $$(readlink $(ROOT)/build); \
fi; \
# build internal directory structure
mkdir -p $(BUILD) $(SRC) $(VENDOR)
mkdir -p $(SUPPORT)/include $(SUPPORT)/lib $(SUPPORT)/bin
# Some dependencies seem to require gtkdocize with no way to opt-out.
# Make a no-op one to fulfill the need.
printf '#!/bin/sh\nmkdir -p libkmod/docs\ntouch libkmod/docs/gtk-doc.make' > $(SUPPORT)/bin/gtkdocize
chmod a+rx $(SUPPORT)/bin/gtkdocize
# copy /bedrock into build structure
cp -r src/slash-bedrock/ $(SLASHBR)
# create bedrock-release
echo "$(RELEASE)" > $(SLASHBR)/etc/bedrock-release
# create os-release
sed -e "s,^VERSION=.*,VERSION=\"$(BEDROCK_VERSION) ($(CODENAME))\"," \
-e "s,^VERSION_ID=.*,VERSION_ID=\"$(BEDROCK_VERSION)\"," \
-e "s,^PRETTY_NAME=.*,PRETTY_NAME=\"$(RELEASE)\"," \
$(SLASHBR)/etc/os-release > $(SLASHBR)/etc/os-release-new
mv $(SLASHBR)/etc/os-release-new $(SLASHBR)/etc/os-release
# create release-specific bedrock.conf
mv $(SLASHBR)/etc/bedrock.conf $(SLASHBR)/etc/bedrock.conf-$(BEDROCK_VERSION)
# move world file to temporary position so it does not overwrite
# preexisting one during update
mv $(SLASHBR)/etc/world $(SLASHBR)/etc/.fresh-world
# git does not track empty directories. Ensure known required
# directories are created.
mkdir -p $(SLASHBR)/bin
mkdir -p $(SLASHBR)/etc
mkdir -p $(SLASHBR)/gnupg-keys
mkdir -p $(SLASHBR)/info
mkdir -p $(SLASHBR)/libexec
mkdir -p $(SLASHBR)/run
mkdir -p $(SLASHBR)/share/brl-fetch/distros
mkdir -p $(SLASHBR)/strata/bedrock
mkdir -p $(SLASHBR)/var
mkdir -p $(COMPLETED)
mkdir -p $(BUILD)/sbin/
# Most files going into the tarball exist in /bedrock, but Bedrock's
# /sbin/init is not one of them. Copy it separately.
cp src/init/init $(BUILD)/sbin/init
touch $(COMPLETED)/builddir
builddir: $(COMPLETED)/builddir
#
# Support libraries and tools. Populates $(SUPPORT)
#
vendor/linux_headers/.success_fetching_source:
rm -rf vendor/linux_headers
mkdir -p vendor/linux_headers
git clone --depth=1 'https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux-stable.git' vendor/linux_headers
touch vendor/linux_headers/.success_fetching_source
$(COMPLETED)/linux_headers: vendor/linux_headers/.success_fetching_source $(COMPLETED)/builddir
rm -rf $(VENDOR)/linux_headers/
mkdir -p $(VENDOR)/linux_headers
cd $(ROOT)/vendor/linux_headers/ && \
$(MAKE) headers_install INSTALL_HDR_PATH=$(SUPPORT) O=$(VENDOR)/linux_headers
touch $(COMPLETED)/linux_headers
linux_headers: $(COMPLETED)/linux_headers
vendor/musl/.success_fetching_source:
rm -rf vendor/musl
mkdir -p vendor/musl
git clone --depth=1 \
-b `git ls-remote --tags 'git://git.musl-libc.org/musl' | \
awk -F/ '{print $$NF}' | \
sed 's/^v//g' | \
grep '^[0-9.]*$$' | \
sort -t . -k1,1n -k2,2n -k3,3n -k4,4n -k5,5n | \
tail -n1 | \
sed 's/^/v/'` 'git://git.musl-libc.org/musl' \
vendor/musl
touch vendor/musl/.success_fetching_source
$(COMPLETED)/musl: vendor/musl/.success_fetching_source $(COMPLETED)/builddir $(COMPLETED)/linux_headers
rm -rf $(VENDOR)/musl
cp -r vendor/musl $(VENDOR)
cd $(VENDOR)/musl/ && \
./configure --prefix=$(SUPPORT) --enable-static --enable-gcc-wrapper --disable-shared && \
$(MAKE) && \
$(MAKE) install
if ! [ -e $(SUPPORT)/lib64 ]; then \
ln -fs lib $(SUPPORT)/lib64; \
fi
if ! [ -e $(SUPPORT)/sbin ]; then \
ln -fs bin $(SUPPORT)/sbin; \
fi
# gcc can get confused when using musl depending on -static/-pie setup,
# and so we need to enforce -static. meson apparently ignores CFLAGS
# et al when sanity testing a compiler, requiring another method to
# ensure meson tests the compiler with -static. Thus this hack: embed
# the -static flag into musl-gcc.
#
# i386 requires -latomic. If building i386, shove -latomic in here as well.
if [ "$(ARCHITECTURE)" = "i386" ]; then \
sed 's/ -specs/ -static -latomic -specs/' $(SUPPORT)/bin/musl-gcc > $(SUPPORT)/bin/musl-gcc-new; \
else \
sed 's/ -specs/ -static -specs/' $(SUPPORT)/bin/musl-gcc > $(SUPPORT)/bin/musl-gcc-new; \
fi
mv $(SUPPORT)/bin/musl-gcc-new $(SUPPORT)/bin/musl-gcc
chmod a+rx $(SUPPORT)/bin/musl-gcc
touch $(COMPLETED)/musl
musl: $(COMPLETED)/musl
vendor/libcap/.success_fetching_source:
rm -rf vendor/libcap
mkdir -p vendor/libcap
git clone --depth=1 \
-b `git ls-remote --tags 'https://git.kernel.org/pub/scm/libs/libcap/libcap.git/' | \
awk -F/ '{print $$NF}' | \
sed 's/^libcap-//g' | \
grep '^[0-9.]*$$' | \
grep '[.]' | \
sort -t . -k1,1n -k2,2n -k3,3n -k4,4n -k5,5n | \
tail -n1 | \
sed 's/^/libcap-/'` 'https://git.kernel.org/pub/scm/libs/libcap/libcap.git/' \
vendor/libcap
touch vendor/libcap/.success_fetching_source
$(COMPLETED)/libcap: vendor/libcap/.success_fetching_source $(COMPLETED)/builddir $(COMPLETED)/musl
rm -rf $(VENDOR)/libcap
cp -r vendor/libcap/ $(VENDOR)
mkdir -p $(SUPPORT)/include/sys
if ! [ -e $(SUPPORT)/include/sys/capability.h ]; then \
cp $(SUPPORT)/include/linux/capability.h $(SUPPORT)/include/sys/capability.h; \
fi
sed \
-e 's/^BUILD_GPERF.*/BUILD_GPERF=no/' $(VENDOR)/libcap/Make.Rules \
-e 's/^SHARED.*/SHARED=no/' $(VENDOR)/libcap/Make.Rules \
-e 's/^DYNAMIC.*/DYNAMIC=no/' $(VENDOR)/libcap/Make.Rules \
-e 's/^LIBCSTATIC.*/LIBCSTATIC=yes/' $(VENDOR)/libcap/Make.Rules \
> $(VENDOR)/libcap/Make.Rules-new
mv $(VENDOR)/libcap/Make.Rules-new $(VENDOR)/libcap/Make.Rules
cd $(VENDOR)/libcap/libcap && \
$(MAKE) BUILD_CC=$(MUSLCC) CC=$(MUSLCC) LD="$(MUSLCC) -Wl,-x -shared" lib=$(SUPPORT)/lib prefix=$(SUPPORT) BUILD_CFLAGS="$(CFLAGS) -static" SHARED=no DYNAMIC=no LIBCSTATIC=yes && \
$(MAKE) install-static RAISE_SETFCAP=no DESTDIR=$(SUPPORT) prefix=/ lib=lib SHARED=no DYNAMIC=no LIBCSTATIC=yes
cd $(VENDOR)/libcap/progs && \
$(MAKE) BUILD_CC=$(MUSLCC) CC=$(MUSLCC) LD="$(MUSLCC) -Wl,-x -shared" lib=$(SUPPORT)/lib prefix=$(SUPPORT) LDFLAGS=-static SHARED=no DYNAMIC=no LIBCSTATIC=yes && \
$(MAKE) install RAISE_SETFCAP=no DESTDIR=$(SUPPORT) prefix=/ lib=lib SHARED=no DYNAMIC=no LIBCSTATIC=yes
touch $(COMPLETED)/libcap
libcap: $(COMPLETED)/libcap
vendor/libfuse/.success_fetching_source:
rm -rf vendor/libfuse
mkdir -p vendor/libfuse
# More recent libfuse versions bumped up meson requirements which breaks build environment. Stick with 3.12.x for now.
git clone --depth=1 \
-b 'fuse-3.12.0' 'https://github.com/libfuse/libfuse.git' \
vendor/libfuse
touch vendor/libfuse/.success_fetching_source
$(COMPLETED)/libfuse: vendor/libfuse/.success_fetching_source $(COMPLETED)/builddir $(COMPLETED)/musl
rm -rf $(VENDOR)/libfuse
cp -r vendor/libfuse/ $(VENDOR)
mkdir -p $(VENDOR)/libfuse/build
# ln -s $(VENDOR)/libfuse/build/libfuse_config.h $(SUPPORT)/include/
# meson/ninja sometimes fails with
# ninja: error: unknown target 'lib/libfuse3.a'
# for no apparent reason. It seems to eventually take after multiple
# tries. Thus, retry a few times.
cd $(VENDOR)/libfuse/build && \
CC=$(MUSLCC) CFLAGS="$(CFLAGS) -static" meson && \
meson configure -D buildtype=release && \
meson configure -D default_library=static && \
meson configure -D strip=true && \
meson configure -D prefix=$(SUPPORT) && \
CC=$(MUSLCC) ninja lib/libfuse3.a || \
CC=$(MUSLCC) CFLAGS="$(CFLAGS) -static" meson && \
meson configure -D buildtype=release && \
meson configure -D default_library=static && \
meson configure -D strip=true && \
meson configure -D prefix=$(SUPPORT) && \
CC=$(MUSLCC) ninja lib/libfuse3.a || \
CC=$(MUSLCC) CFLAGS="$(CFLAGS) -static" meson && \
meson configure -D buildtype=release && \
meson configure -D default_library=static && \
meson configure -D strip=true && \
meson configure -D prefix=$(SUPPORT) && \
CC=$(MUSLCC) ninja lib/libfuse3.a || \
CC=$(MUSLCC) CFLAGS="$(CFLAGS) -static" meson && \
meson configure -D buildtype=release && \
meson configure -D default_library=static && \
meson configure -D strip=true && \
meson configure -D prefix=$(SUPPORT) && \
CC=$(MUSLCC) ninja lib/libfuse3.a || \
CC=$(MUSLCC) CFLAGS="$(CFLAGS) -static" meson && \
meson configure -D buildtype=release && \
meson configure -D default_library=static && \
meson configure -D strip=true && \
meson configure -D prefix=$(SUPPORT) && \
CC=$(MUSLCC) ninja lib/libfuse3.a
cp -r $(VENDOR)/libfuse/build/lib/* $(SUPPORT)/lib/
mkdir -p $(SUPPORT)/include/fuse3/
cp $(VENDOR)/libfuse/include/*.h $(SUPPORT)/include/fuse3/
touch $(COMPLETED)/libfuse
libfuse: $(COMPLETED)/libfuse
vendor/uthash/.success_fetching_source:
rm -rf vendor/uthash
mkdir -p vendor/uthash
git clone --depth=1 \
-b `git ls-remote --tags 'https://github.com/troydhanson/uthash.git' | \
awk -F/ '{print $$NF}' | \
sed 's/^v//g' | \
grep '^[0-9.]*$$' | \
sort -t . -k1,1n -k2,2n -k3,3n -k4,4n -k5,5n | \
tail -n1 | \
sed 's/^/v/'` 'https://github.com/troydhanson/uthash.git' \
vendor/uthash
touch vendor/uthash/.success_fetching_source
$(COMPLETED)/uthash: vendor/uthash/.success_fetching_source $(COMPLETED)/builddir
rm -rf $(VENDOR)/uthash
cp -r vendor/uthash/ $(VENDOR)
cp -r $(VENDOR)/uthash/src/*.h $(SUPPORT)/include/
touch $(COMPLETED)/uthash
uthash: $(COMPLETED)/uthash
vendor/libaio/.success_retrieving_source:
rm -rf vendor/libaio/
mkdir -p vendor/libaio
git clone --depth=1 \
-b `git ls-remote --tags 'https://pagure.io/libaio.git' | \
awk -F/ '{print $$NF}' | \
sed 's/^libaio-//g' | \
grep '^[0-9.]*$$' | \
sort -t . -k1,1n -k2,2n -k3,3n -k4,4n -k5,5n | \
tail -n1 | \
sed 's/^/libaio-/'` 'https://pagure.io/libaio.git' \
vendor/libaio
touch vendor/libaio/.success_retrieving_source
$(COMPLETED)/libaio: vendor/libaio/.success_retrieving_source $(COMPLETED)/builddir $(COMPLETED)/musl
rm -rf $(VENDOR)/libaio
cp -r vendor/libaio $(VENDOR)
cp $(VENDOR)/libaio/src/libaio.h $(SUPPORT)/include
cd $(VENDOR)/libaio && $(MAKE) CC=$(MUSLCC)
cp $(VENDOR)/libaio/src/libaio.a $(SUPPORT)/lib
cp $(VENDOR)/libaio/src/libaio.so.1.0.2 $(SUPPORT)/lib/libaio.so
touch $(COMPLETED)/libaio
libaio: $(COMPLETED)/libaio
vendor/util-linux/.success_fetching_source:
rm -rf vendor/util-linux
mkdir -p vendor/util-linux
git clone --depth=1 \
-b `git ls-remote --tags 'https://git.kernel.org/pub/scm/utils/util-linux/util-linux.git' | \
awk -F/ '{print $$NF}' | \
sed 's/^v//g' | \
grep '^[0-9.]*$$' | \
sort -t . -k1,1n -k2,2n -k3,3n -k4,4n -k5,5n | \
tail -n1 | \
sed 's/^/v/'` 'https://git.kernel.org/pub/scm/utils/util-linux/util-linux.git' \
vendor/util-linux
touch vendor/util-linux/.success_fetching_source
$(COMPLETED)/util-linux: vendor/util-linux/.success_fetching_source $(COMPLETED)/builddir $(COMPLETED)/musl
rm -rf $(VENDOR)/util-linux
cp -r vendor/util-linux $(VENDOR)
cd $(VENDOR)/util-linux && ./autogen.sh && \
CC=$(MUSLCC) CFLAGS="-I$(SUPPORT)/include -L$(SUPPORT)/lib" ./configure --enable-static=yes --disable-all-programs --enable-libblkid --enable-libuuid && \
$(MAKE) CC=$(MUSLCC) CFLAGS="-I$(SUPPORT)/include -L$(SUPPORT)/lib"
cp $(VENDOR)/util-linux/.libs/libblkid.* $(SUPPORT)/lib || true
cp $(VENDOR)/util-linux/.libs/libuuid.* $(SUPPORT)/lib || true
touch $(COMPLETED)/util-linux
util-linux: $(COMPLETED)/util-linux
vendor/openssl/.success_retrieving_source:
rm -rf vendor/openssl
mkdir -p vendor/openssl
git clone --depth=1 \
-b `git ls-remote --tags 'https://github.com/openssl/openssl.git' | \
awk -F/ '{print $$NF}' | \
grep '^OpenSSL_1_1_[0-9a-z]*$$' | \
sort -t '_' -k1,1n -k2,2n -k3,3n -k4,4n -k5,5n | \
tail -n1` 'https://github.com/openssl/openssl.git' \
vendor/openssl
touch vendor/openssl/.success_retrieving_source
$(COMPLETED)/openssl: vendor/openssl/.success_retrieving_source $(COMPLETED)/builddir $(COMPLETED)/musl
rm -rf $(VENDOR)/openssl
cp -r vendor/openssl $(VENDOR)
cd $(VENDOR)/openssl && \
if [ "$(ARCHITECTURE)" = "mips64el" ]; then \
CC=$(MUSLCC) linux$(ARCH_BIT_DEPTH) ./Configure --prefix="$(SUPPORT)" no-shared linux64-mips64; \
elif [ "$(ARCHITECTURE)" = "ppc64" ]; then \
CC=$(MUSLCC) linux$(ARCH_BIT_DEPTH) ./Configure --prefix="$(SUPPORT)" no-shared linux-ppc64le; \
elif [ "$(ARCHITECTURE)" = "armv7hl" ]; then \
CC=$(MUSLCC) linux$(ARCH_BIT_DEPTH) ./Configure --prefix="$(SUPPORT)" no-shared linux-armv4; \
else \
CC=$(MUSLCC) linux$(ARCH_BIT_DEPTH) ./config --prefix="$(SUPPORT)" no-shared; \
fi && \
$(MAKE) CC=$(MUSLCC) && \
$(MAKE) install_sw && \
$(MAKE) clean # openssl tests use quite a lot of disk
touch $(COMPLETED)/openssl
openssl: $(COMPLETED)/openssl
#
# Compiled binaries which will go into the output script. Populates $(SLASHBR)
#
vendor/busybox/.success_retrieving_source:
rm -rf vendor/busybox
mkdir -p vendor/busybox
git clone --depth=1 \
-b `git ls-remote --heads 'git://git.busybox.net/busybox' | \
awk -F/ '$$NF ~ /stable$$/ {print $$NF}' | \
sort -t _ -k1,1n -k2,2n -k3,3n -k4,4n -k5,5n | \
tail -n1` 'git://git.busybox.net/busybox' \
vendor/busybox
# patch in "x-" option support
cd vendor/busybox/ && patch -p1 < ../../src/patches/busybox-x-opt.patch
touch vendor/busybox/.success_retrieving_source
build/all/busybox/bedrock-config: vendor/busybox/.success_retrieving_source
rm -rf build/all/busybox
mkdir -p build/all
cp -r vendor/busybox/ build/all/busybox
# create busybox config helper
cd build/all/busybox && \
echo '#!/bin/sh' > set_bb_option && \
echo 'if grep -q "^$$1=" .config; then' >> set_bb_option && \
echo ' sed "s,^$$1=.*,$$1=$$2," .config > .config-new' >> set_bb_option && \
echo ' mv .config-new .config' >> set_bb_option && \
echo 'elif grep -q "^# $$1 is not set" .config; then' >> set_bb_option && \
echo ' sed "s,^# $$1 is not set,$$1=$$2," .config > .config-new' >> set_bb_option && \
echo ' mv .config-new .config' >> set_bb_option && \
echo 'else' >> set_bb_option && \
echo ' echo "$$1=$$2" >> .config' >> set_bb_option && \
echo 'fi' >> set_bb_option && \
chmod u+x set_bb_option
# start with default config
rm -f build/all/busybox/.config
cd build/all/busybox && \
$(MAKE) defconfig
# disable unused applets
cd build/all/busybox && \
for applet in $$(grep "^CONFIG_.*=y$$" .config | grep -v "FEATURE" | sed -e 's/^CONFIG_//' -e 's/=.*$$//' | tr '[A-Z_]' '[a-z-]' ); do \
if ! grep -rq "\<$$applet\>" $(ROOT)/src/slash-bedrock/ $(ROOT)/src/installer/installer.sh $(ROOT)/src/init/init; then \
echo "DISABLING $$applet"; \
./set_bb_option "CONFIG_$$(echo "$$applet" | tr '[a-z-]' '[A-Z_]')" "n"; \
fi; \
done
# explicitly enable known desired and explicitly undesired features
cd build/all/busybox && \
./set_bb_option "CONFIG_AR" "y" && \
./set_bb_option "CONFIG_ASH_BASH_COMPAT" "y" && \
./set_bb_option "CONFIG_ASH_CMDCMD" "y" && \
./set_bb_option "CONFIG_ASH_TEST" "y" && \
./set_bb_option "CONFIG_BUSYBOX_EXEC_PATH" '"/bedrock/libexec/busybox"' && \
./set_bb_option "CONFIG_DATE" "y" && \
./set_bb_option "CONFIG_DEPMOD" "y" && \
./set_bb_option "CONFIG_DESKTOP" "y" && \
./set_bb_option "CONFIG_FEATURE_AR_CREATE" "y" && \
./set_bb_option "CONFIG_FEATURE_AR_LONG_FILENAMES" "y" && \
./set_bb_option "CONFIG_FEATURE_CHECK_TAINTED_MODULE" "y" && \
./set_bb_option "CONFIG_FEATURE_FDISK_ADVANCED" "n" && \
./set_bb_option "CONFIG_FEATURE_FIND_MMIN" "y" && \
./set_bb_option "CONFIG_FEATURE_FIND_XDEV" "y" && \
./set_bb_option "CONFIG_FEATURE_GPT_LABEL" "y" && \
./set_bb_option "CONFIG_FEATURE_MODUTILS_ALIAS" "y" && \
./set_bb_option "CONFIG_FEATURE_MODUTILS_SYMBOLS" "y" && \
./set_bb_option "CONFIG_FEATURE_PREFER_APPLETS" "y" && \
./set_bb_option "CONFIG_FEATURE_SEAMLESS_BZ2" "y" && \
./set_bb_option "CONFIG_FEATURE_SEAMLESS_GZ" "y" && \
./set_bb_option "CONFIG_FEATURE_SEAMLESS_LZMA" "y" && \
./set_bb_option "CONFIG_FEATURE_SEAMLESS_XZ" "y" && \
./set_bb_option "CONFIG_FEATURE_SEAMLESS_Z" "y" && \
./set_bb_option "CONFIG_FEATURE_SH_STANDALONE" "y" && \
./set_bb_option "CONFIG_INIT" "n" && \
./set_bb_option "CONFIG_INSMOD" "y" && \
./set_bb_option "CONFIG_KILLALL" "y" && \
./set_bb_option "CONFIG_LAST_ID" "65535" && \
./set_bb_option "CONFIG_LAST_SYSTEM_ID" "65535" && \
./set_bb_option "CONFIG_LFS" "y" && \
./set_bb_option "CONFIG_LSMOD" "y" && \
./set_bb_option "CONFIG_PIVOT_ROOT" "y" && \
./set_bb_option "CONFIG_RMMOD" "y" && \
./set_bb_option "CONFIG_STATIC" "y" && \
./set_bb_option "CONFIG_SYSROOT" "\"\"" && \
./set_bb_option "CONFIG_TEST" "y" && \
./set_bb_option "CONFIG_TEST1" "y" && \
./set_bb_option "CONFIG_VI" "y" && \
./set_bb_option "CONFIG_DEPMOD" "n" && \
./set_bb_option "CONFIG_INSMOD" "n" && \
./set_bb_option "CONFIG_LSMOD" "n" && \
./set_bb_option "CONFIG_MODPROBE" "n" && \
./set_bb_option "CONFIG_RMMOD" "n" && \
./set_bb_option "CONFIG_WGET" "n"
cd build/all/busybox && \
cp .config bedrock-config
$(SLASHBR)/libexec/busybox: vendor/busybox/.success_retrieving_source build/all/busybox/bedrock-config $(COMPLETED)/builddir $(COMPLETED)/musl
rm -rf $(VENDOR)/busybox
cp -r vendor/busybox/ $(VENDOR)/busybox
cp build/all/busybox/bedrock-config $(VENDOR)/busybox/.config
# fix various busybox-linux-musl issues
cd $(SUPPORT)/include/netinet/ && \
awk '{p=1}/^struct ethhdr/,/^}/{print "//"$$0; p=0}p==1' if_ether.h > if_ether.h.new && \
mv if_ether.h.new if_ether.h
cd $(SUPPORT)/include/linux/ && \
echo '' > in.h
cd $(SUPPORT)/include/linux/ && \
echo '' > in6.h
cp $(SUPPORT)/include/linux/if_slip.h $(SUPPORT)/include/net/
# http://git.musl-libc.org/cgit/musl/commit/?id=5a105f19b5aae79dd302899e634b6b18b3dcd0d6
# This will be needed with musl at or after 1.2.0 and busybox preceding 1.32
cd $(VENDOR)/busybox && \
if [ "${ARCH_BIT_DEPTH}" = "32" ]; then \
for file in libbb/time.c runit/runsv.c coreutils/date.c; do \
sed -e 's/__NR_clock_gettime\>/__NR_clock_gettime32/g' $${file} > .time-tmp && \
mv .time-tmp $${file}; \
done; \
fi
cd $(VENDOR)/busybox && \
$(MAKE) CC=$(MUSLCC) && \
cp busybox $(SLASHBR)/libexec/busybox
busybox: $(SLASHBR)/libexec/busybox
vendor/curl/.success_retrieving_source:
rm -rf vendor/curl
mkdir -p vendor/curl
git clone --depth=1 \
-b `git ls-remote --tags 'https://github.com/curl/curl.git' | \
awk -F/ '{print $$NF}' | \
grep '^curl-[0-9_]*$$' | \
sort -t '_' -k1,1n -k2,2n -k3,3n -k4,4n -k5,5n | \
tail -n1` 'https://github.com/curl/curl.git' \
vendor/curl
touch vendor/curl/.success_retrieving_source
$(SLASHBR)/libexec/curl: vendor/curl/.success_retrieving_source $(COMPLETED)/builddir $(COMPLETED)/musl $(COMPLETED)/openssl
rm -rf $(VENDOR)/curl
cp -r vendor/curl $(VENDOR)
cd $(VENDOR)/curl && autoreconf -fi && \
CC=$(MUSLCC) CFLAGS="-I$(SUPPORT)/include -L$(SUPPORT)/lib" ./configure --with-openssl --enable-static --disable-shared --enable-https --enable-ipv6 && \
$(MAKE) CC=$(MUSLCC) CFLAGS="-I$(SUPPORT)/include -L$(SUPPORT)/lib" && \
cp src/curl $(SLASHBR)/libexec/curl
curl: $(SLASHBR)/libexec/curl
vendor/libattr/.success_retrieving_source:
git clone --depth=1 \
-b `git ls-remote --tags 'https://git.savannah.nongnu.org/git/attr.git' | \
awk -F/ '{print $$NF}' | \
sed 's/^v//g' | \
grep '^[0-9.]*$$' | \
sort -t . -k1,1n -k2,2n -k3,3n -k4,4n -k5,5n | \
tail -n1 | \
sed 's/^/v/'` 'https://git.savannah.nongnu.org/git/attr.git' \
vendor/libattr
touch vendor/libattr/.success_retrieving_source
$(COMPLETED)/libattr: vendor/libattr/.success_retrieving_source $(COMPLETED)/builddir $(COMPLETED)/musl
rm -rf $(VENDOR)/libattr
cp -r vendor/libattr/ $(VENDOR)
# Sometimes autogen does not take the first time despite returning 0. Thus, try a few times.
cd $(VENDOR)/libattr && \
./autogen.sh && \
CC=$(MUSLCC) ./configure --enable-static --disable-shared ; \
make clean && \
make CC=$(MUSLCC) getfattr setfattr && \
cp getfattr $(SLASHBR)/libexec/getfattr && \
cp setfattr $(SLASHBR)/libexec/setfattr
touch $(COMPLETED)/libattr
$(SLASHBR)/libexec/getfattr: $(COMPLETED)/libattr
$(SLASHBR)/libexec/setfattr: $(COMPLETED)/libattr
getfattr: $(COMPLETED)/libattr
setfattr: $(COMPLETED)/libattr
$(SLASHBR)/libexec/setcap: $(COMPLETED)/libcap
cp $(SUPPORT)/sbin/setcap $(SLASHBR)/libexec/setcap
setcap: $(SLASHBR)/libexec/setcap
vendor/netselect/.success_retrieving_source:
mkdir -p vendor/netselect
git clone --depth=1 'https://github.com/apenwarr/netselect.git' vendor/netselect
touch vendor/netselect/.success_retrieving_source
$(SLASHBR)/libexec/netselect: vendor/netselect/.success_retrieving_source $(COMPLETED)/builddir $(COMPLETED)/musl
rm -rf $(VENDOR)/netselect
cp -r vendor/netselect/ $(VENDOR)
# netselect uses non-standard types which musl does not recognize.
if ! grep -q '^#include "fix_types.h"' $(VENDOR)/netselect/netselect.c; then \
echo '#define u_char unsigned char' > $(VENDOR)/netselect/fix_types.h && \
echo '#define u_short unsigned short' >> $(VENDOR)/netselect/fix_types.h && \
echo '#define u_long unsigned long' >> $(VENDOR)/netselect/fix_types.h && \
echo '#include "fix_types.h"' > $(VENDOR)/netselect/netselect_fixed.c && \
cat $(VENDOR)/netselect/netselect.c >> $(VENDOR)/netselect/netselect_fixed.c && \
mv $(VENDOR)/netselect/netselect_fixed.c $(VENDOR)/netselect/netselect.c; fi
# patch netselect to avoid dropping domain in output
# users may prefer the domain to a raw IP, and some services (e.g.
# cloudflare) refuse to operate when contacted with raw IP.
if grep -q '^\s*if\s*(result.multi)$$' $(VENDOR)/netselect/netselect.c; then \
sed 's/^\s*if\s*(result.multi)$$/if(0)/' \
$(VENDOR)/netselect/netselect.c > $(VENDOR)/netselect/netselect_fixed.c && \
mv $(VENDOR)/netselect/netselect_fixed.c $(VENDOR)/netselect/netselect.c; fi
cd $(VENDOR)/netselect/ && \
make CC=$(MUSLCC) LDFLAGS='-static' && \
cp netselect $(SLASHBR)/libexec/netselect
netselect: $(SLASHBR)/libexec/netselect
vendor/lvm2/.success_retrieving_source:
rm -rf vendor/lvm2/
mkdir -p vendor/lvm2
# no `--depth 1` because this repo does not support it
git clone \
-b `git ls-remote --tags 'https://sourceware.org/git/lvm2.git' | \
awk -F/ '{print $$NF}' | \
grep '^v[0-9_]*$$' | \
sed 's/^v//g' | \
sort -t _ -k1,1n -k2,2n -k3,3n -k4,4n -k5,5n | \
tail -n1 | \
sed 's/^/v/'` 'https://sourceware.org/git/lvm2.git' \
vendor/lvm2
cd vendor/lvm2 && patch -p0 -i ../../patches/lvm2/fix-stdio.patch
# hack to fix bad imports looking for LOCK_EX
echo '#include <sys/file.h>' >> vendor/lvm2/lib/misc/lib.h
touch vendor/lvm2/.success_retrieving_source
$(COMPLETED)/lvm2: vendor/lvm2/.success_retrieving_source $(COMPLETED)/musl $(COMPLETED)/libaio $(COMPLETED)/util-linux
rm -rf $(VENDOR)/lvm2
cp -r vendor/lvm2 $(VENDOR)
cd $(VENDOR)/lvm2 && \
CC=$(MUSLCC) CFLAGS="-I$(SUPPORT)/include -L$(SUPPORT)/lib -fPIC" ./configure --disable-udev-systemd-background-jobs --disable-blkid_wiping --disable-selinux --enable-static_link && \
$(MAKE) tools SHELL=bash CC=$(MUSLCC) CFLAGS="-I$(SUPPORT)/include -L$(SUPPORT)/lib -L$(VENDOR)/lvm2/libdm/ioctl -fPIC" interfacebuilddir=$(VENDOR)/lvm2/libdm/ioctl
cd $(VENDOR)/lvm2/libdm/dm-tools && \
$(MAKE) SHELL=bash CC=$(MUSLCC) CFLAGS="-I$(SUPPORT)/include -L$(SUPPORT)/lib -L$(VENDOR)/lvm2/libdm/ioctl -fPIC" interfacebuilddir=$(VENDOR)/lvm2/libdm/ioctl
cp $(VENDOR)/lvm2/tools/lvm.static $(SLASHBR)/libexec/lvm
cp $(VENDOR)/lvm2/libdm/dm-tools/dmsetup.static $(SLASHBR)/libexec/dmsetup
touch $(COMPLETED)/lvm2
$(SLASHBR)/libexec/lvm: $(COMPLETED)/lvm2
$(SLASHBR)/libexec/dmsetup: $(COMPLETED)/lvm2
lvm2: $(SLASHBR)/libexec/dmsetup $(SLASHBR)/libexec/lvm
vendor/zstd/.success_retrieving_source:
rm -rf vendor/zstd/
mkdir -p vendor/zstd
git clone --depth 1 \
-b `git ls-remote --tags 'https://github.com/facebook/zstd.git' | \
awk -F/ '{print $$NF}' | \
sed -e 's/^v//g' | \
grep '^[0-9.]*$$' | \
sort -t . -k1,1n -k2,2n -k3,3n -k4,4n -k5,5n | \
tail -n1 | \
sed -e 's/^/v/'` 'https://github.com/facebook/zstd.git' \
vendor/zstd
touch vendor/zstd/.success_retrieving_source
$(COMPLETED)/zstd: vendor/zstd/.success_retrieving_source $(COMPLETED)/musl
rm -rf $(VENDOR)/zstd
cp -r vendor/zstd $(VENDOR)
cd $(VENDOR)/zstd && \
$(MAKE) CC=$(MUSLCC) zstd lib prefix=$(SUPPORT) install && \
cp zstd $(SLASHBR)/libexec/zstd
touch $(COMPLETED)/zstd
$(SLASHBR)/libexec/zstd: $(COMPLETED)/zstd
zstd: $(COMPLETED)/zstd
vendor/zlib/.success_retrieving_source:
rm -rf vendor/zlib/
mkdir -p vendor/zlib
cd vendor/zlib && wget -O- 'http://zlib.net/zlib-1.3.1.tar.gz' | gunzip | tar xf -
mv vendor/zlib/*/* vendor/zlib/
touch vendor/zlib/.success_retrieving_source
$(COMPLETED)/zlib: vendor/zlib/.success_retrieving_source $(COMPLETED)/musl
rm -rf $(VENDOR)/zlib
cp -r vendor/zlib $(VENDOR)
cd $(VENDOR)/zlib && \
./configure --prefix=$(SUPPORT) --static && \
$(MAKE) CC=$(MUSLCC) install prefix=$(SUPPORT)
touch $(COMPLETED)/zlib
zlib: $(COMPLETED)/zlib
# Hard code v5.4.6 until xz CVE is resolved
# https://nvd.nist.gov/vuln/detail/CVE-2024-3094
# https://www.openwall.com/lists/musl/2022/08/23/5
vendor/xz/.success_retrieving_source:
rm -rf vendor/xz/
mkdir -p vendor/xz
git clone \
-b v5.4.6 \
'https://git.tukaani.org/xz.git' \
vendor/xz
# sanity check branch is expected commit
cd vendor/xz/ && git show | head -n1 | grep -q 'commit 6e8732c5a317a349986a4078718f1d95b67072c5'
touch vendor/xz/.success_retrieving_source
$(COMPLETED)/xz: vendor/xz/.success_retrieving_source $(COMPLETED)/musl
rm -rf $(VENDOR)/xz
cp -r vendor/xz $(VENDOR)
cd $(VENDOR)/xz && \
./autogen.sh --no-po4a --no-doxygen
cd $(VENDOR)/xz && \
CFLAGS="-static" LDFLAGS="-static" ./configure --prefix=$(SUPPORT) --enable-static --disable-shared
cd $(VENDOR)/xz && $(MAKE) CC=$(MUSLCC) install prefix=$(SUPPORT)
rm $(SUPPORT)/lib/liblzma.la
touch $(COMPLETED)/xz
xz: $(COMPLETED)/xz
# Build our own kmod suite, rather than using busybox's, for .ko.zst support.
vendor/kmod/.success_retrieving_source:
rm -rf vendor/kmod/
mkdir -p vendor/kmod
git clone --depth 1 \
-b `git ls-remote --tags 'https://git.kernel.org/pub/scm/utils/kernel/kmod/kmod.git' | \
awk -F/ '{print $$NF}' | \
sed -e 's/^v//g' | \
grep '^[0-9.]*$$' | \
sort -t . -k1,1n -k2,2n -k3,3n -k4,4n -k5,5n | \
tail -n1 | \
sed -e 's/^/v/'` 'https://git.kernel.org/pub/scm/utils/kernel/kmod/kmod.git' \
vendor/kmod
touch vendor/kmod/.success_retrieving_source
$(SLASHBR)/libexec/kmod: vendor/kmod/.success_retrieving_source $(COMPLETED)/musl $(COMPLETED)/zstd $(COMPLETED)/zlib $(COMPLETED)/xz
rm -rf $(VENDOR)/kmod
cp -r vendor/kmod $(VENDOR)
cd $(VENDOR)/kmod && \
PATH="$(SUPPORT)/bin:${PATH}" ./autogen.sh --with-xz --with-zlib --with-zstd --disable-manpages --prefix=$(SUPPORT) --includedir=$(SUPPORT)/include --libdir=$(SUPPORT)/lib --bindir=$(SUPPORT)/bin \
CC=$(MUSLCC) CCLD=$(MUSLCC) LD=$(MUSLCC) PKG_CONFIG_PATH=$(SUPPORT)/lib/pkgconfig && \
./configure --with-xz --with-zlib --with-zstd --disable-manpages --prefix=$(SUPPORT) --includedir=$(SUPPORT)/include --libdir=$(SUPPORT)/lib --bindir=$(SUPPORT)/bin \
CC=$(MUSLCC) LDFLAGS="-L$(SUPPORT)/lib" PKG_CONFIG_PATH=$(SUPPORT)/lib/pkgconfig && \
$(MAKE) CC=$(MUSLCC) LDFLAGS="-L$(SUPPORT)/lib" PKG_CONFIG_PATH=$(SUPPORT)/lib/pkgconfig tools/kmod
cp $(VENDOR)/kmod/tools/kmod $(SLASHBR)/libexec/kmod
kmod: $(SLASHBR)/libexec/kmod
$(SLASHBR)/bin/strat: $(COMPLETED)/builddir $(COMPLETED)/musl $(COMPLETED)/libcap
rm -rf $(SRC)/strat
cp -r src/strat/ $(SRC)
cd $(SRC)/strat && \
$(MAKE) CC=$(MUSLCC) && \
cp ./strat $(SLASHBR)/bin/strat
strat: $(SLASHBR)/bin/strat
$(SLASHBR)/libexec/manage_tty_lock: $(COMPLETED)/builddir $(COMPLETED)/musl
rm -rf $(SRC)/manage_tty_lock
cp -r src/manage_tty_lock/ $(SRC)
cd $(SRC)/manage_tty_lock && \
$(MAKE) CC=$(MUSLCC) && \
cp manage_tty_lock $(SLASHBR)/libexec/manage_tty_lock
manage_tty_lock: $(SLASHBR)/libexec/manage_tty_lock
$(SLASHBR)/libexec/keyboard_is_present: $(COMPLETED)/builddir $(COMPLETED)/musl
rm -rf $(SRC)/keyboard_is_present
cp -r src/keyboard_is_present/ $(SRC)
cd $(SRC)/keyboard_is_present && \
$(MAKE) CC=$(MUSLCC) && \
cp keyboard_is_present $(SLASHBR)/libexec/keyboard_is_present
keyboard_is_present: $(SLASHBR)/libexec/keyboard_is_present
$(SLASHBR)/libexec/plymouth-quit: $(COMPLETED)/builddir $(COMPLETED)/musl
rm -rf $(SRC)/plymouth-quit
cp -r src/plymouth-quit/ $(SRC)
cd $(SRC)/plymouth-quit && \
$(MAKE) CC=$(MUSLCC) && \
cp plymouth-quit $(SLASHBR)/libexec/plymouth-quit
plymouth-quit: $(SLASHBR)/libexec/plymouth-quit
$(SLASHBR)/libexec/bouncer: $(COMPLETED)/builddir $(COMPLETED)/musl
rm -rf $(SRC)/bouncer
cp -r src/bouncer/ $(SRC)
cd $(SRC)/bouncer && \
$(MAKE) CC=$(MUSLCC) && \
cp ./bouncer $(SLASHBR)/libexec/bouncer
bouncer: $(SLASHBR)/libexec/bouncer
$(SLASHBR)/libexec/etcfs: $(COMPLETED)/builddir \
$(COMPLETED)/musl \
$(COMPLETED)/libfuse
rm -rf $(SRC)/etcfs
cp -r src/etcfs/ $(SRC)
cd $(SRC)/etcfs && \
make CC=$(MUSLCC) CFLAGS="$(CFLAGS)" && \
cp ./etcfs $(SLASHBR)/libexec/etcfs
etcfs: $(SLASHBR)/libexec/etcfs
$(SLASHBR)/libexec/crossfs: $(COMPLETED)/builddir \
$(COMPLETED)/musl \
$(COMPLETED)/libfuse \
$(COMPLETED)/uthash
rm -rf $(SRC)/crossfs
cp -r src/crossfs/ $(SRC)
cd $(SRC)/crossfs && \
make CC=$(MUSLCC) CFLAGS="$(CFLAGS)" && \
cp ./crossfs $(SLASHBR)/libexec/crossfs
crossfs: $(SLASHBR)/libexec/crossfs
#
# Use populated $(SLASHBR) to create the installer/updater script
#
$(BUILD)/userland.tar: \
$(COMPLETED)/builddir \
$(SLASHBR)/bin/strat \
$(SLASHBR)/libexec/bouncer \
$(SLASHBR)/libexec/busybox \
$(SLASHBR)/libexec/crossfs \
$(SLASHBR)/libexec/curl \
$(SLASHBR)/libexec/dmsetup \
$(SLASHBR)/libexec/etcfs \
$(SLASHBR)/libexec/getfattr \
$(SLASHBR)/libexec/keyboard_is_present \
$(SLASHBR)/libexec/kmod \
$(SLASHBR)/libexec/lvm \
$(SLASHBR)/libexec/manage_tty_lock \
$(SLASHBR)/libexec/netselect \
$(SLASHBR)/libexec/plymouth-quit \
$(SLASHBR)/libexec/setcap \
$(SLASHBR)/libexec/setfattr \
$(SLASHBR)/libexec/zstd
# remove symlinks which may have been created in a previous interrupted run
rm -f $(SLASHBR)/libexec/brl-strat
rm -f $(SLASHBR)/strata/init
rm -f $(SLASHBR)/strata/local
# ensure static
if [ -z "$${BEDROCK_SKIP_LDD_CHECK}" ]; then \
for bin in $(SLASHBR)/bin/* $(SLASHBR)/libexec/*; do \
if ldd "$$bin" >/dev/null 2>&1 || ! ldd "$$bin" 2>&1 | grep -q "not a dynamic executable" ; then \
echo "error: $$bin is dynamically linked"; exit 1; \
fi; \
done; \
fi
# ensure correct binary format
for bin in $(SLASHBR)/bin/* $(SLASHBR)/libexec/*; do \
if file "$$bin" | grep -q "sh script"; then \
continue ; \
elif file "$$bin" | grep -qi "$(FILE_ARCH_NAME)"; then \
continue ; \
fi; \
echo "ERROR: \`file $$bin\` does not contain $(FILE_ARCH_NAME)"; \
exit 1; \
done
# strip binaries
for bin in $(SLASHBR)/bin/* $(SLASHBR)/libexec/*; do \
if [ -r "$$bin" ] && ! [ -h "$$bin" ] && head -c4 "$$bin" | grep -q "ELF"; then \
strip "$$bin"; \
fi \
done
# ensure permissions
find $(SLASHBR) -exec chmod a-s {} \;
find $(SLASHBR) -type d -exec chmod 0755 {} \;
find $(SLASHBR) -type f -exec chmod 0644 {} \;
find $(SLASHBR)/bin/ -type f -exec chmod 0755 {} \;
find $(SLASHBR)/libexec/ -type f -exec chmod 0755 {} \;
chmod 700 $(SLASHBR)/gnupg-keys
chmod 600 $(SLASHBR)/gnupg-keys/*
chmod 755 $(SLASHBR)/share/resolvconf/00bedrock
chmod 755 $(BUILD)/sbin/init
# create symlinks
ln -s ../bin/strat $(SLASHBR)/libexec/brl-strat
ln -s /bedrock/run/init-alias $(SLASHBR)/strata/init
ln -s ../cross/.local-alias $(SLASHBR)/strata/local
# create a tarball
# qemu does not play nicely with fakeroot. In case we are using qemu
# strata to build non-native arches, try to grab native fakeroot.
cd $(BUILD) && if [ -e /bedrock/cross/bin/fakeroot ]; then \
/bedrock/cross/bin/fakeroot tar cf userland.tar-new bedrock/ sbin/init; \
else \
fakeroot tar cf userland.tar-new bedrock/ sbin/init; \
fi
cd $(BUILD) && mv userland.tar-new userland.tar
tarball: $(BUILD)/userland.tar
$(BUILD)/unsigned-installer.sh: $(BUILD)/userland.tar src/installer/installer.sh src/slash-bedrock/share/common-code
( \
cat src/installer/installer.sh | awk '/^[.] \/bedrock\/share\/common-code/{exit}1'; \
cat src/slash-bedrock/share/common-code | sed 's/BEDROCK-RELEASE/$(RELEASE)/' | grep -v 'pipefail'; \
cat src/installer/installer.sh | awk 'x{print}/^[.] \/bedrock\/share\/common-code/{x=1}' | sed \
-e 's/^ARCHITECTURE=.*/ARCHITECTURE="$(ARCHITECTURE)"/' \
-e 's/^TARBALL_SHA1SUM=.*/TARBALL_SHA1SUM="$(shell cat $(BUILD)/userland.tar | sha1sum - | cut -d' ' -f1)"/' \
; \
echo "-----BEGIN TARBALL-----"; \
cat $(BUILD)/userland.tar | gzip; \
echo ""; \
echo "-----END TARBALL-----"; \
) > $(BUILD)/unsigned-installer.sh-new
mv $(BUILD)/unsigned-installer.sh-new $(BUILD)/unsigned-installer.sh
$(INSTALLER): $(BUILD)/unsigned-installer.sh
if [ "$(SKIPSIGN)" = true ]; then \
cp $(BUILD)/unsigned-installer.sh $(INSTALLER)-new; \
mv $(INSTALLER)-new $(INSTALLER); \
elif [ -z "$(GPGID)" ]; then \
echo 'Either SKIPSIGN or GPGID must be set.'; \
echo 'To create an unsigned script, run:'; \
echo ' make SKIPSIGN=true'; \
echo 'Or to create a script with an embedded signature, run:'; \
echo ' make GPGID=<gpg-id-with-which-to-sign>'; \
exit 1; \
elif ! gpg --version >/dev/null 2>&1; then \
echo 'gpg not found in $$PATH, but required to sign build.'; \
echo 'Use `make SKIPSIGN=true` to opt out of signing'; \
exit 1; \
else \
rm -f $(BUILD)/signed-installer.sh; \
cp $(BUILD)/unsigned-installer.sh $(BUILD)/signed-installer.sh; \
gpg --output - --armor --detach-sign $(BUILD)/unsigned-installer.sh >> $(BUILD)/signed-installer.sh; \
mv $(BUILD)/signed-installer.sh $(INSTALLER); \
fi
chmod +x $(INSTALLER)
@ printf "\e[32m\n%s\n%s\n%s\n\e[39m\n" \
"$$(echo "=== Completed creating $(INSTALLER) ===" | sed 's/./=/g')" \
"$$(echo "=== Completed creating $(INSTALLER) ===")" \
"$$(echo "=== Completed creating $(INSTALLER) ===" | sed 's/./=/g')"
#
# Code quality enforcement
#
format:
# Standardizes code formatting
#
# requires:
#
# - shfmt (https://github.com/mvdan/sh)
# - indent (GNU)
#
# style shell scripts
for file in $$(find src/ -type f); do \
if head -n1 "$$file" | grep -q '^#!.*busybox sh$$'; then \
shfmt -p -w "$$file"; \
fi; \
if head -n1 "$$file" | grep -q '^#!.*bash$$'; then \