head	1.67;
access;
symbols
	RELENG_8_4:1.65.0.2
	RELENG_9_1_0_RELEASE:1.58.2.3.2.2
	RELENG_9_1:1.58.2.3.0.2
	RELENG_9_1_BP:1.58.2.3
	RELENG_8_3_0_RELEASE:1.50.2.5.2.1
	RELENG_8_3:1.50.2.5.0.2
	RELENG_8_3_BP:1.50.2.5
	RELENG_9_0_0_RELEASE:1.58.2.1.2.1
	RELENG_9_0:1.58.2.1.0.2
	RELENG_9_0_BP:1.58.2.1
	RELENG_9:1.58.0.2
	RELENG_9_BP:1.58
	RELENG_7_4_0_RELEASE:1.39.2.7.4.1
	RELENG_8_2_0_RELEASE:1.50.2.4.2.1
	RELENG_7_4:1.39.2.7.0.4
	RELENG_7_4_BP:1.39.2.7
	RELENG_8_2:1.50.2.4.0.2
	RELENG_8_2_BP:1.50.2.4
	RELENG_8_1_0_RELEASE:1.50.2.3.2.1
	RELENG_8_1:1.50.2.3.0.2
	RELENG_8_1_BP:1.50.2.3
	RELENG_7_3_0_RELEASE:1.39.2.7.2.1
	RELENG_7_3:1.39.2.7.0.2
	RELENG_7_3_BP:1.39.2.7
	RELENG_8_0_0_RELEASE:1.50.2.1.2.1
	RELENG_8_0:1.50.2.1.0.2
	RELENG_8_0_BP:1.50.2.1
	RELENG_8:1.50.0.2
	RELENG_8_BP:1.50
	RELENG_7_2_0_RELEASE:1.39.2.5.2.1
	RELENG_7_2:1.39.2.5.0.2
	RELENG_7_2_BP:1.39.2.5
	RELENG_7_1_0_RELEASE:1.39.2.2.2.1
	RELENG_6_4_0_RELEASE:1.37.2.2.4.1
	RELENG_7_1:1.39.2.2.0.2
	RELENG_7_1_BP:1.39.2.2
	RELENG_6_4:1.37.2.2.0.4
	RELENG_6_4_BP:1.37.2.2
	RELENG_7_0_0_RELEASE:1.39.2.1
	RELENG_6_3_0_RELEASE:1.37.2.2
	RELENG_7_0:1.39.2.1.0.2
	RELENG_7_0_BP:1.39.2.1
	RELENG_6_3:1.37.2.2.0.2
	RELENG_6_3_BP:1.37.2.2
	RELENG_7:1.39.0.2
	RELENG_7_BP:1.39
	RELENG_6_2_0_RELEASE:1.37.2.1
	RELENG_6_2:1.37.2.1.0.4
	RELENG_6_2_BP:1.37.2.1
	RELENG_5_5_0_RELEASE:1.29
	RELENG_5_5:1.29.0.8
	RELENG_5_5_BP:1.29
	RELENG_6_1_0_RELEASE:1.37.2.1
	RELENG_6_1:1.37.2.1.0.2
	RELENG_6_1_BP:1.37.2.1
	RELENG_6_0_0_RELEASE:1.37
	RELENG_6_0:1.37.0.4
	RELENG_6_0_BP:1.37
	RELENG_6:1.37.0.2
	RELENG_6_BP:1.37
	RELENG_5_4_0_RELEASE:1.29
	RELENG_5_4:1.29.0.6
	RELENG_5_4_BP:1.29
	RELENG_4_11_0_RELEASE:1.1.2.28
	RELENG_4_11:1.1.2.28.0.8
	RELENG_4_11_BP:1.1.2.28
	RELENG_5_3_0_RELEASE:1.29
	RELENG_5_3:1.29.0.4
	RELENG_5_3_BP:1.29
	RELENG_5:1.29.0.2
	RELENG_5_BP:1.29
	RELENG_4_10_0_RELEASE:1.1.2.28
	RELENG_4_10:1.1.2.28.0.6
	RELENG_4_10_BP:1.1.2.28
	RELENG_5_2_1_RELEASE:1.28
	RELENG_5_2_0_RELEASE:1.28
	RELENG_5_2:1.28.0.2
	RELENG_5_2_BP:1.28
	RELENG_4_9_0_RELEASE:1.1.2.28
	RELENG_4_9:1.1.2.28.0.4
	RELENG_4_9_BP:1.1.2.28
	RELENG_5_1_0_RELEASE:1.27
	RELENG_5_1:1.27.0.4
	RELENG_5_1_BP:1.27
	RELENG_4_8_0_RELEASE:1.1.2.28
	RELENG_4_8:1.1.2.28.0.2
	RELENG_4_8_BP:1.1.2.28
	RELENG_5_0_0_RELEASE:1.27
	RELENG_5_0:1.27.0.2
	RELENG_5_0_BP:1.27
	RELENG_4_7_0_RELEASE:1.1.2.27
	RELENG_4_7:1.1.2.27.0.2
	RELENG_4_7_BP:1.1.2.27
	RELENG_4_6_2_RELEASE:1.1.2.25
	RELENG_4_6_1_RELEASE:1.1.2.25
	RELENG_4_6_0_RELEASE:1.1.2.25
	RELENG_4_6:1.1.2.25.0.2
	RELENG_4_6_BP:1.1.2.25
	RELENG_4_5_0_RELEASE:1.1.2.20
	RELENG_4_5:1.1.2.20.0.2
	RELENG_4_5_BP:1.1.2.20
	RELENG_4_4_0_RELEASE:1.1.2.12
	RELENG_4_4:1.1.2.12.0.2
	RELENG_4_4_BP:1.1.2.12
	RELENG_4_3_0_RELEASE:1.1.2.5
	RELENG_4_3:1.1.2.5.0.2
	RELENG_4_3_BP:1.1.2.5
	RELENG_4:1.1.0.2;
locks; strict;
comment	@# @;


1.67
date	2013.05.06.00.31.33;	author svnexp;	state Exp;
branches;
next	1.66;

1.66
date	2013.05.06.00.30.06;	author svnexp;	state Exp;
branches;
next	1.65;

1.65
date	2012.12.23.22.45.05;	author svnexp;	state Exp;
branches
	1.65.2.1;
next	1.64;

1.64
date	2012.11.17.01.50.16;	author svnexp;	state Exp;
branches;
next	1.63;

1.63
date	2012.08.27.16.42.32;	author luigi;	state Exp;
branches;
next	1.62;

1.62
date	2012.05.03.20.50.55;	author luigi;	state Exp;
branches;
next	1.61;

1.61
date	2012.01.04.23.00.25;	author luigi;	state Exp;
branches;
next	1.60;

1.60
date	2012.01.04.19.37.25;	author luigi;	state Exp;
branches;
next	1.59;

1.59
date	2011.11.23.12.05.39;	author luigi;	state Exp;
branches;
next	1.58;

1.58
date	2011.02.05.23.03.40;	author luigi;	state Exp;
branches
	1.58.2.1;
next	1.57;

1.57
date	2010.11.12.12.48.41;	author luigi;	state Exp;
branches;
next	1.56;

1.56
date	2010.09.28.22.30.11;	author luigi;	state Exp;
branches;
next	1.55;

1.55
date	2010.02.14.15.55.30;	author luigi;	state Exp;
branches;
next	1.54;

1.54
date	2009.12.28.01.02.45;	author luigi;	state Exp;
branches;
next	1.53;

1.53
date	2009.12.28.00.51.00;	author luigi;	state Exp;
branches;
next	1.52;

1.52
date	2009.12.27.21.13.53;	author luigi;	state Exp;
branches;
next	1.51;

1.51
date	2009.12.09.17.48.05;	author luigi;	state Exp;
branches;
next	1.50;

1.50
date	2009.06.22.16.06.38;	author luigi;	state Exp;
branches
	1.50.2.1;
next	1.49;

1.49
date	2009.06.22.15.45.26;	author luigi;	state Exp;
branches;
next	1.48;

1.48
date	2009.03.25.14.02.26;	author luigi;	state Exp;
branches;
next	1.47;

1.47
date	2009.03.24.17.47.50;	author luigi;	state Exp;
branches;
next	1.46;

1.46
date	2009.03.24.16.03.46;	author luigi;	state Exp;
branches;
next	1.45;

1.45
date	2009.03.18.18.43.31;	author luigi;	state Exp;
branches;
next	1.44;

1.44
date	2009.02.20.14.28.56;	author luigi;	state Exp;
branches;
next	1.43;

1.43
date	2009.02.20.00.05.33;	author luigi;	state Exp;
branches;
next	1.42;

1.42
date	2008.06.25.21.33.28;	author ru;	state Exp;
branches;
next	1.41;

1.41
date	2007.11.14.07.38.22;	author luigi;	state Exp;
branches;
next	1.40;

1.40
date	2007.11.14.05.42.53;	author luigi;	state Exp;
branches;
next	1.39;

1.39
date	2006.05.17.09.33.06;	author phk;	state Exp;
branches
	1.39.2.1;
next	1.38;

1.38
date	2006.01.31.20.24.43;	author luigi;	state Exp;
branches;
next	1.37;

1.37
date	2004.12.21.12.21.26;	author ru;	state Exp;
branches
	1.37.2.1;
next	1.36;

1.36
date	2004.12.21.12.13.23;	author ru;	state Exp;
branches;
next	1.35;

1.35
date	2004.12.21.12.05.11;	author ru;	state Exp;
branches;
next	1.34;

1.34
date	2004.12.21.10.36.53;	author ru;	state Exp;
branches;
next	1.33;

1.33
date	2004.12.21.09.53.13;	author ru;	state Exp;
branches;
next	1.32;

1.32
date	2004.12.21.09.33.43;	author ru;	state Exp;
branches;
next	1.31;

1.31
date	2004.12.21.09.00.24;	author ru;	state Exp;
branches;
next	1.30;

1.30
date	2004.12.21.08.47.04;	author ru;	state Exp;
branches;
next	1.29;

1.29
date	2004.03.21.10.46.13;	author luigi;	state Exp;
branches;
next	1.28;

1.28
date	2003.11.07.12.49.55;	author simokawa;	state Exp;
branches;
next	1.27;

1.27
date	2002.07.14.12.07.06;	author luigi;	state Exp;
branches;
next	1.26;

1.26
date	2002.07.14.09.07.13;	author luigi;	state Exp;
branches;
next	1.25;

1.25
date	2002.03.22.18.36.41;	author ru;	state Exp;
branches;
next	1.24;

1.24
date	2002.03.21.03.15.06;	author luigi;	state Exp;
branches;
next	1.23;

1.23
date	2002.03.11.05.54.22;	author luigi;	state Exp;
branches;
next	1.22;

1.22
date	2002.03.08.02.24.21;	author luigi;	state Exp;
branches;
next	1.21;

1.21
date	2002.02.14.19.21.50;	author luigi;	state Exp;
branches;
next	1.20;

1.20
date	2001.11.24.20.24.36;	author luigi;	state Exp;
branches;
next	1.19;

1.19
date	2001.11.24.20.22.20;	author luigi;	state Exp;
branches;
next	1.18;

1.18
date	2001.11.20.01.00.52;	author joe;	state Exp;
branches;
next	1.17;

1.17
date	2001.11.01.16.17.37;	author luigi;	state Exp;
branches;
next	1.16;

1.16
date	2001.10.07.17.22.46;	author luigi;	state Exp;
branches;
next	1.15;

1.15
date	2001.10.02.17.06.51;	author luigi;	state Exp;
branches;
next	1.14;

1.14
date	2001.09.28.21.02.15;	author luigi;	state Exp;
branches;
next	1.13;

1.13
date	2001.09.20.13.34.16;	author joe;	state Exp;
branches;
next	1.12;

1.12
date	2001.09.20.13.09.01;	author joe;	state Exp;
branches;
next	1.11;

1.11
date	2001.09.20.02.52.02;	author luigi;	state Exp;
branches;
next	1.10;

1.10
date	2001.09.04.02.01.52;	author luigi;	state Exp;
branches;
next	1.9;

1.9
date	2001.09.01.19.16.00;	author luigi;	state Exp;
branches;
next	1.8;

1.8
date	2001.09.01.18.27.39;	author luigi;	state Exp;
branches;
next	1.7;

1.7
date	2001.06.21.08.49.46;	author luigi;	state Exp;
branches;
next	1.6;

1.6
date	2001.06.20.14.16.48;	author luigi;	state Exp;
branches;
next	1.5;

1.5
date	2001.05.11.07.39.40;	author luigi;	state Exp;
branches;
next	1.4;

1.4
date	2001.05.08.20.44.37;	author luigi;	state Exp;
branches;
next	1.3;

1.3
date	2001.04.23.19.52.13;	author joe;	state Exp;
branches;
next	1.2;

1.2
date	2001.02.20.17.09.40;	author luigi;	state Exp;
branches;
next	1.1;

1.1
date	2001.02.19.23.49.54;	author luigi;	state dead;
branches
	1.1.2.1;
next	;

1.65.2.1
date	2012.12.23.22.45.05;	author svnexp;	state dead;
branches;
next	1.65.2.2;

1.65.2.2
date	2013.03.28.13.03.30;	author svnexp;	state Exp;
branches;
next	;

1.58.2.1
date	2011.09.23.00.51.37;	author kensmith;	state Exp;
branches
	1.58.2.1.2.1;
next	1.58.2.2;

1.58.2.2
date	2012.01.12.11.08.21;	author luigi;	state Exp;
branches;
next	1.58.2.3;

1.58.2.3
date	2012.06.24.17.02.28;	author luigi;	state Exp;
branches
	1.58.2.3.2.1;
next	1.58.2.4;

1.58.2.4
date	2012.11.17.11.36.30;	author svnexp;	state Exp;
branches;
next	1.58.2.5;

1.58.2.5
date	2013.05.13.13.02.10;	author svnexp;	state Exp;
branches;
next	1.58.2.6;

1.58.2.6
date	2013.11.06.23.01.43;	author svnexp;	state Exp;
branches;
next	1.58.2.7;

1.58.2.7
date	2014.03.05.01.01.44;	author svnexp;	state Exp;
branches;
next	;

1.58.2.1.2.1
date	2011.11.11.04.20.22;	author kensmith;	state Exp;
branches;
next	1.58.2.1.2.2;

1.58.2.1.2.2
date	2012.11.17.08.36.29;	author svnexp;	state Exp;
branches;
next	;

1.58.2.3.2.1
date	2012.08.05.23.54.33;	author kensmith;	state Exp;
branches;
next	1.58.2.3.2.2;

1.58.2.3.2.2
date	2012.11.17.08.47.19;	author svnexp;	state Exp;
branches;
next	;

1.50.2.1
date	2009.08.03.08.13.06;	author kensmith;	state Exp;
branches
	1.50.2.1.2.1;
next	1.50.2.2;

1.50.2.2
date	2009.12.15.00.26.42;	author luigi;	state Exp;
branches;
next	1.50.2.3;

1.50.2.3
date	2010.03.08.13.37.14;	author luigi;	state Exp;
branches
	1.50.2.3.2.1;
next	1.50.2.4;

1.50.2.4
date	2010.11.16.17.44.09;	author luigi;	state Exp;
branches
	1.50.2.4.2.1;
next	1.50.2.5;

1.50.2.5
date	2012.02.13.18.10.13;	author luigi;	state Exp;
branches
	1.50.2.5.2.1;
next	1.50.2.6;

1.50.2.6
date	2012.11.17.10.36.14;	author svnexp;	state Exp;
branches;
next	1.50.2.7;

1.50.2.7
date	2013.11.07.05.22.18;	author svnexp;	state Exp;
branches;
next	;

1.50.2.1.2.1
date	2009.10.25.01.10.29;	author kensmith;	state Exp;
branches;
next	;

1.50.2.3.2.1
date	2010.06.14.02.09.06;	author kensmith;	state Exp;
branches;
next	;

1.50.2.4.2.1
date	2010.12.21.17.09.25;	author kensmith;	state Exp;
branches;
next	;

1.50.2.5.2.1
date	2012.03.03.06.15.13;	author kensmith;	state Exp;
branches;
next	1.50.2.5.2.2;

1.50.2.5.2.2
date	2012.11.17.08.24.55;	author svnexp;	state Exp;
branches;
next	;

1.39.2.1
date	2007.11.21.07.20.10;	author luigi;	state Exp;
branches;
next	1.39.2.2;

1.39.2.2
date	2008.08.22.10.18.18;	author luigi;	state Exp;
branches
	1.39.2.2.2.1;
next	1.39.2.3;

1.39.2.3
date	2009.03.01.15.03.08;	author luigi;	state Exp;
branches;
next	1.39.2.4;

1.39.2.4
date	2009.03.23.21.32.03;	author luigi;	state Exp;
branches;
next	1.39.2.5;

1.39.2.5
date	2009.04.06.11.15.28;	author luigi;	state Exp;
branches
	1.39.2.5.2.1;
next	1.39.2.6;

1.39.2.6
date	2009.06.25.09.28.44;	author luigi;	state Exp;
branches;
next	1.39.2.7;

1.39.2.7
date	2009.12.15.07.04.20;	author luigi;	state Exp;
branches
	1.39.2.7.2.1
	1.39.2.7.4.1;
next	1.39.2.8;

1.39.2.8
date	2012.11.17.08.03.28;	author svnexp;	state Exp;
branches;
next	;

1.39.2.2.2.1
date	2008.11.25.02.59.29;	author kensmith;	state Exp;
branches;
next	;

1.39.2.5.2.1
date	2009.04.15.03.14.26;	author kensmith;	state Exp;
branches;
next	;

1.39.2.7.2.1
date	2010.02.10.00.26.20;	author kensmith;	state Exp;
branches;
next	;

1.39.2.7.4.1
date	2010.12.21.17.10.29;	author kensmith;	state Exp;
branches;
next	1.39.2.7.4.2;

1.39.2.7.4.2
date	2012.11.17.08.16.53;	author svnexp;	state Exp;
branches;
next	;

1.37.2.1
date	2006.02.14.13.16.13;	author luigi;	state Exp;
branches;
next	1.37.2.2;

1.37.2.2
date	2007.11.13.15.19.35;	author luigi;	state Exp;
branches
	1.37.2.2.4.1;
next	1.37.2.3;

1.37.2.3
date	2012.11.17.07.41.09;	author svnexp;	state Exp;
branches;
next	;

1.37.2.2.4.1
date	2008.10.02.02.57.24;	author kensmith;	state Exp;
branches;
next	;

1.1.2.1
date	2001.02.19.23.49.54;	author luigi;	state Exp;
branches;
next	1.1.2.2;

1.1.2.2
date	2001.02.20.03.31.04;	author luigi;	state Exp;
branches;
next	1.1.2.3;

1.1.2.3
date	2001.02.20.07.03.19;	author luigi;	state Exp;
branches;
next	1.1.2.4;

1.1.2.4
date	2001.02.20.07.47.53;	author luigi;	state Exp;
branches;
next	1.1.2.5;

1.1.2.5
date	2001.03.13.21.45.26;	author luigi;	state Exp;
branches;
next	1.1.2.6;

1.1.2.6
date	2001.05.08.20.46.34;	author luigi;	state Exp;
branches;
next	1.1.2.7;

1.1.2.7
date	2001.05.11.07.42.19;	author luigi;	state Exp;
branches;
next	1.1.2.8;

1.1.2.8
date	2001.06.20.15.09.26;	author luigi;	state Exp;
branches;
next	1.1.2.9;

1.1.2.9
date	2001.08.29.21.49.44;	author luigi;	state Exp;
branches;
next	1.1.2.10;

1.1.2.10
date	2001.09.01.18.28.37;	author luigi;	state Exp;
branches;
next	1.1.2.11;

1.1.2.11
date	2001.09.01.19.16.38;	author luigi;	state Exp;
branches;
next	1.1.2.12;

1.1.2.12
date	2001.09.04.02.03.04;	author luigi;	state Exp;
branches;
next	1.1.2.13;

1.1.2.13
date	2001.09.20.03.05.57;	author luigi;	state Exp;
branches;
next	1.1.2.14;

1.1.2.14
date	2001.09.20.20.36.24;	author joe;	state Exp;
branches;
next	1.1.2.15;

1.1.2.15
date	2001.09.28.21.06.53;	author luigi;	state Exp;
branches;
next	1.1.2.16;

1.1.2.16
date	2001.10.02.17.11.04;	author luigi;	state Exp;
branches;
next	1.1.2.17;

1.1.2.17
date	2001.10.07.17.25.12;	author luigi;	state Exp;
branches;
next	1.1.2.18;

1.1.2.18
date	2001.11.01.16.27.49;	author luigi;	state Exp;
branches;
next	1.1.2.19;

1.1.2.19
date	2001.11.20.01.05.15;	author joe;	state Exp;
branches;
next	1.1.2.20;

1.1.2.20
date	2001.11.24.20.26.57;	author luigi;	state Exp;
branches;
next	1.1.2.21;

1.1.2.21
date	2002.02.14.19.23.22;	author luigi;	state Exp;
branches;
next	1.1.2.22;

1.1.2.22
date	2002.03.08.02.26.37;	author luigi;	state Exp;
branches;
next	1.1.2.23;

1.1.2.23
date	2002.03.11.05.55.15;	author luigi;	state Exp;
branches;
next	1.1.2.24;

1.1.2.24
date	2002.03.21.03.20.34;	author luigi;	state Exp;
branches;
next	1.1.2.25;

1.1.2.25
date	2002.03.22.18.40.30;	author ru;	state Exp;
branches;
next	1.1.2.26;

1.1.2.26
date	2002.07.14.09.08.51;	author luigi;	state Exp;
branches;
next	1.1.2.27;

1.1.2.27
date	2002.07.14.12.08.48;	author luigi;	state Exp;
branches;
next	1.1.2.28;

1.1.2.28
date	2002.12.02.22.33.50;	author luigi;	state Exp;
branches;
next	1.1.2.29;

1.1.2.29
date	2012.11.17.07.24.21;	author svnexp;	state Exp;
branches;
next	;


desc
@@


1.67
log
@## SVN ## Exported commit - http://svnweb.freebsd.org/changeset/base/250289
## SVN ## CVS IS DEPRECATED: http://wiki.freebsd.org/CvsIsDeprecated
@
text
@#!/bin/sh -
#
# $FreeBSD: head/release/picobsd/build/picobsd 250289 2013-05-05 20:59:22Z luigi $
# This file requires sysutils/makefs to run
#
# The PicoBSD build script. Invoked as
#
#	picobsd [options] image_type [site_name]
#
# CWARNFLAGS can be used to pass -Wall or similar options
#
# Where image_type is a directory with the picobsd config info,
# and ${image_type}/floppy.tree.${site_name} contains
# optional site-specific configuration.
#
# For Options, see the bottom of the file where the processing is
# done. The picobsd(8) manpage might be of some help, but code and docs
# tend to lose sync over time.
#
# This script depends on the following files:
#
# in ${PICO_TREE} :
#   Makefile.conf	Makefile used to build the kernel
#   config		shell variables, sourced here.
#   mfs.mtree		mtree config file
#   floppy.tree/	files which go on the floppy
#   mfs_tree/		files which go onto the mfs
#
# in ${MY_TREE} :
#   PICOBSD		kernel config file
#   config		shell variables, sourced here.
#   crunch.conf		crunchgen configuration
#   mfs.mtree		overrides ${PICO_TREE}/mfs.mtree
#   floppy.tree.exclude	files from floppy.tree/ which we do not need here.
#   floppy.tree/	local additions to ${PICO_TREE}/mfs_free
#   floppy.tree.${site}/ same as above, site specific.
#   mfs_tree/		local additions to the mfs_free
#   buildtree.mk	optional Makefile to build an extension for floppy tree
#			(generated in buildtree/ )

#
#--- The main entry point is at the end.
#

# There are two initialization functions:
#
# + set_defaults
#   is run on entry to the script, and is used to set default values
#   for all variables that do not depend on image type and source tree.
#
# + set_build_parameters
#   is run after command line parsing
#
# VARIABLE NAMES:
# + variables that control operation (e.g. verbosity) and are generally
#   set from the command line have o_ ("option") as a name prefix
#
# + variables that contain pathnames and values that should not change
#   have c_ ("constant") as a name prefix
#
# + variables exported to Makefiles and subshells are CAPITAL
#
# + variables local to the script are lowercase, possibly with
#   an l_ ("local") prefix.
#
# There are unfortunately exceptions:
# name, l_usrtree, l_objtree

# SRC points to your FreeBSD source tree.
# l_usrtree points to the /usr subdir for the source tree.
#     Normally /usr or ${SRC}/../usr
# l_objtree points to the obj tree. Normally ${l_usrtree}/obj-pico-${o_arch}
# c_label is either bsdlabel or disklabel
# PICO_TREE is where standard picobsd stuff resides.
#     Normally ${SRC}/release/picobsd
# You can set SRC with --src <directory>
# It is not recommended to override the other variables.

# MY_TREE (set later) is where this floppy type resides.
# BUILDDIR is the build directory

# log something on stdout if verbose.
o_verbose=0	# this needs to be here!
log() {	#	message
    local foo
    [ ${o_verbose} -gt 0 ] && printf "\n*** %s\n" "$*"
    [ ${o_verbose}  -gt 1 ] && read -p "=== Press enter to continue" foo
    return 0
}

# unconditionally log and wait for input
logverbose() {	# message
    local foo
    printf "\n*** %s\n" "$*"
    read -p "=== Press enter to continue" foo
    return 0
}

# set some default values for variables.
# needs to be done as the first thing in the script.

set_defaults() {	# no arguments
    # EDITOR is the editor you use
    # fd_size  floppy size in KB (default to 1440). You can use 1480,
    #	1720, 2880, etc. but beware that only 1440 and 1480 will boot
    #	from 1.44M floppy drives (1480 will not work on vmware).
    EDITOR=${EDITOR:-vi}
    fd_size=${fd_size:-1440}

    o_all_in_mfs="yes"		# put all files in mfs so you can boot
				# and run the image via diskless boot.
    o_clean=""			# set if you want to clean prev.builds.
    o_interactive=""		# default is interactive
    o_verbose=0			# verbose level, 0 is silent
    o_tarv=""			# tar verbose flag, "" or "v"
    o_init_src=""		# set to build libs and includes.
    o_makeopts=${MAKEOPTS:--s}	# make options, be silent by default
    o_no_devfs=			# default is use devfs.
	# You should only set it when building 4.x images
    o_do_modules=""		# do not build modules
    o_arch=`uname -m`		# default to amd64 or i386 ...

    SRC="/usr/src"		# default location for sources
    c_startdir=`pwd`		# directory where we start
				# used to lookup config and create BUILDDIR

    # XXX 6.x/7.x have a single /boot/boot block, which is the concatenation
    # of the old two. For the time being, we keep these, but this should
    # be fixed at some point.

    # blocks
    c_boot1=/boot/boot1		# boot blocks (in case you want custom ones)
    c_boot2=/boot/boot2

    c_reply=${c_reply:-`mktemp "/tmp/reply.XXXXXXXXXX"`}
    				# file where User replies will be put
    c_mnt=`mktemp -d "/tmp/picobsd.XXXXXXXXXX"`
    				# mountpoint used to build memory filesystems
    c_fs=fs.PICOBSD		# filename used for the memory filesystem
    c_img=picobsd.bin		# filename used for the picobsd image
    c_iso=picobsd.iso		# filename used for the ISO image
    generate_iso="NO"		# don't generate the iso image

    # select the right disklabel program
    case `uname -r` in
	4.*)
	    c_label="disklabel"
	    ;;
	*)
	    c_label="bsdlabel"
	    ;;
    esac

    set -e

    trap fail 2
    #trap fail 3
    #trap fail 6
    trap fail 15
}

# use the new build infrastructure to create libraries
# and also to build a specific target
create_includes_and_libraries2() { # opt_dir opt_target
    local no
    log "create_includes_and_libraries2() for ${SRC} $1"
    if [ ${OSVERSION} -ge 600000 ] ; then
	no="-DNO_CLEAN -DNO_PROFILE -DNO_GAMES -DNO_LIBC_R" # WITHOUT_CDDL=1"
	no="$no -DWITHOUT_CLANG -DMALLOC_PRODUCTION"
    else
	no="-DNOCLEAN -DNOPROFILE -DNOGAMES -DNOLIBC_R"
    fi
    ( cd ${SRC};
    # make -DNOCLEAN -DNOPROFILE -DNOGAMES -DNOLIBC_R -DPICOBSD buildworld
    if [ -d "$1" ] ; then
	cd $1 ; ${BINMAKE} ${o_par} $2	# specific target, e.g. ld-elf.so
    else
	export MAKEOBJDIRPREFIX=${l_objtree}
	make ${o_par} $no toolchain
	# XXX do we need any of these ?
        eval export `cd ${SRC}; ${BINMAKE} -f Makefile.inc1 -V WMAKEENV`
	[ ${o_arch} != `uname -m` ] && \
	    (cd ${l_objtree}; ln -s . ${o_arch}.${o_arch} || true )
    fi
    )
}

# entry for 4.x and earlier trees
create_includes_and_libraries() {
    local e i

    log "create_includes_and_libraries() for ${SRC}"
    # Optionally creates include directory and libraries.
    mkdir -p ${l_usrtree}/include	# the include directory...
    mkdir -p ${l_usrtree}/share/misc	# a few things go here
    mkdir -p ${l_usrtree}/lib		# libraries
    mkdir -p ${l_usrtree}/sbin		# some binaries
    # override variables for ownershiip and destinations
    # BINOWN:BINGRP are also used for include files
    (cd ${SRC}; \
	BINOWN=`id -un` BINGRP=`id -gn` \
	DESTDIR=${l_usrtree}/.. \
	make -m ${SRC}/share/mk includes ) || fail $? includes
    # Pick up the correct headers for libraries.
    CFLAGS="-nostdinc -I${l_usrtree}/include" ; export CFLAGS

    (cd ${SRC}
	# $e is the invocation of make with correct environment
	# XXX check the NO* options below, maybe system dependent.
	e="MAKEOBJDIRPREFIX=${l_objtree}/picobsd/libraries \
	    BINOWN=`id -un` BINGRP=`id -gn` \
	    DESTDIR=${l_usrtree}/.. \
	    make -m ${SRC}/share/mk \
		-DNOHTML -DNOINFO -DNOMAN -DNOSHARE -DNOFSCHG "
	log "do a 'make obj' in a few places."
	# This is very version-specific... The following works for 5.0
	for i in lib secure/lib gnu/lib \
		gnu/usr.bin/perl usr.bin/lex usr.sbin/config ; do
	    (cd ${i}; eval $e obj)
	done
	log "now make the static libraries"
	eval $e -DNOPROFILE -DNOPIC libraries
	(cd ${SRC}/usr.sbin/config
	eval $e		# build binary
	eval $e	install	# install it
	)
    ) || fail $? "libraries"
    log "Libraries done"
}

# set_type <the_type> [the_site] looks in user or system directories
# for the directory named as the first argument, reads the configuration
# files and sets variables according to the config.
# Also sets MY_TREE and BUILDDIR and SITE

set_type() {	# the_type the_site
    local a i

    log "set_type() : Type '$1' site '$2'"
    THETYPE=$1
    SITE=$2
    a=$1
    name=""	# clear in case of errors
    for i in ${c_startdir}/${a} ${PICO_TREE}/${a} ; do
	log "set_type: checking $i"
	[ -d $i -a -f $i/crunch.conf ] || continue
	# look for a kernel config file, privilege arch-specific
	l_kernconf=$i/PICOBSD.${o_arch}
	[ -f $l_kernconf ] || l_kernconf=$i/PICOBSD
	[ -f $l_kernconf ] || continue
	set -- `cat $l_kernconf | \
	    awk '/^#PicoBSD/ {print $2, $3, $4, $5, $6}'`
	[ x"$1" != "x" ] || continue
	MFS_SIZE=$1
	name=`(cd $i ; pwd) `
	name=`basename $name`
	MY_TREE=$i
	BUILDDIR=${c_startdir}/build_dir-${name}-${o_arch}
	log "Matching file $name in $i"
	return ;
    done
    logverbose "Type $a NOT FOUND"
}

clean_tree() {
    log "clean_tree()"
    if [ -z "${name}" ] ; then
	echo "---> Wrong floppy type"
	exit 3
    fi
    rm -rf ${BUILDDIR}
}

# prepare a message to be printed in the dialog menus.
set_msgs() {		# OK
    log "set_msgs()"

    MSG1="Type: ${THETYPE} name $name"

    MSG="PicoBSD build -- Current parameters:\n\n\t1.  ${MSG1}\n\
\t2.  MFS size: ${MFS_SIZE} kB\n\
\t3.  Site-info: ${SITE}\n\t4.  Full-path: ${MY_TREE}\n"
}

# Main build procedure. Builds both the disk image and the ISO
build_image() {
    log "build_image() <${name}>"
    [ -n "${name}" ] || fail $? bad_type
    clear
    set_msgs
    printf "${MSG}---> We'll use the sources living in ${SRC}\n\n"

    # read config variables from a global and then a type-specific file
    # basically STAND_LINKS and MY_DEVS, but can also override other
    # variables.
    # 
    . ${PICO_TREE}/build/config
    [ -f "${MY_TREE}/config" ]		&& . ${MY_TREE}/config
    [ -f "${o_additional_config}" ]	&& . ${o_additional_config}

    # location of the object directory
    PICO_OBJ=${l_objtree}/picobsd/${THETYPE}
    log "PICO_OBJ is ${PICO_OBJ}"

    # create build directory and subtree
    mkdir -p ${BUILDDIR}/crunch
    # remove any old stuff
    rm -f ${BUILDDIR}/kernel.gz ${BUILDDIR}/${c_fs}
    # invoke commands to build a kernel
    do_kernel
    # fill a subdirectory with things that go into the floppy
    # (mostly /etc and similar stuff)
    populate_floppy_fs
    # populate it and produce a file with the MFS image
    populate_mfs_tree		# things which go into mfs
    # create, mount and fill a filesystem with floppy image
    fill_floppy_image # copies everything into the floppy
}

# Set build parameters interactively

main_dialog() {
  local ans i l

  log "main_dialog()"
  while true ; do
    set_msgs
    rm ${c_reply}
    dialog --menu "PicoBSD build menu -- (29 sep 2001)" 19 70 12 \
	N "--> READY, build it <---" \
	T "${MSG1}" \
	K "edit Kernel config file" \
	E "Edit crunch.conf file" \
	S "MFS Size: ${MFS_SIZE}kB" \
	F "Floppy size: ${fd_size}kB" \
	$ "Site-info: ${SITE}" \
	Q "Quit" \
	2> ${c_reply}
    ans=`cat ${c_reply}`
    rm ${c_reply}
    case ${ans} in
    T)
	l=""
	for i in ${c_startdir} ${c_startdir}/* ${PICO_TREE}/* ; do
	    if [ -d $i -a -f $i/PICOBSD -a -f $i/crunch.conf ]; then
		l="$l `basename $i` `basename $i`"
	    fi
	done
	log $l
	{ dialog --menu "Setup the type of configuration" 12 70 5 $l \
		2> ${c_reply} && set_type "`cat ${c_reply}`" ${SITE} ; } || true
	;;

    K) ${EDITOR} ${MY_TREE}/PICOBSD ;;

    E) ${EDITOR} ${MY_TREE}/crunch.conf ;;

    S)
	{ dialog --title "MFS Size setup" --inputbox \
"MFS size depends on what you need to put on the MFS image. Typically \
ranges between 820kB (for very small bridge/router images) to \
as much as 2500kB kB for a densely packed image. \
Keep in mind that this memory is \
totally lost to other programs. Usually you want to keep \
this as small as possible. " 10 70 2> ${c_reply} \
	&& MFS_SIZE=`cat ${c_reply}` ; } || true
	;;

    \$)
	{ dialog --title "Site info setup" --inputbox \
	"Please enter the full path to the directory \
	containing site-specific setup. \
	This directory tree must contain files that replace \
	standard ones in floppy.tree/ and mfs.tree/ . " \
	10 70 2> ${c_reply} && SITE=`cat ${c_reply}` ; } || true
	;;

    F)
	{ dialog --menu "Set floppy size" 15 70 4 \
	    1440 "1.44MB" 1720 "1.72MB" 2880 "2.88MB" 4096 "4MB" \
		 2> ${c_reply} && fd_size=`cat ${c_reply}` ; } || true
	;;

    N) break 2
	;;

    Q) exit 0 ;;

    *) echo "Unknown option \"${ans}\". Try again."
	sleep 2
	clear
	;;
    esac
  done
}

# Call the build procedure
# Install image
do_install() {
    log "do_install()"

    if [ "${o_interactive}" = "NO" ] ; then
	echo "+++ Build completed +++"
	cat .build.reply || true
	return
    fi
    dialog --title "Build ${THETYPE} completed" --inputbox \
"\nThe build process was completed successfuly.\n\
`cat .build.reply` \n\n\
Now we are going to install the image on the floppy.\n\
Please insert a blank floppy in /dev/fd0.\\n
WARNING: the contents of the floppy will be permanently erased!\n\
\n\
Your options:\n\
	* ^C or [Cancel] to abort,\n\
	* Enter to install ${c_img},\n\
" 20 80 2> ${c_reply}
    if [ "$?" = "0" ]; then
	echo "Writing ${c_img}..."
	dd if=${BUILDDIR}/${c_img} of=/dev/fd0.${fd_size}
    else
	echo "Ok, the image is in ${c_img}"
    fi
    echo "Done."
}


#-------------------------------------------------------------------

# invoke the picobsd Makefile to compile the kernel.
# if MODULES is set (value is irrelevant) the makefile will build modules.
do_kernel() {		# OK
    log "do_kernel() Preparing kernel \"$name\" in $MY_TREE"
    (cd $MY_TREE; export name SRC BUILDDIR # used in this makefile ;
	# export CONFIG
	export WARNS CWARNFLAGS
	[ "${o_do_modules}" = "yes" ] && export MODULES=""
	# kernel build not parallelizable yet
	${BINMAKE} KERNCONF=${l_kernconf}	\
		-v -f ${PICO_TREE}/build/Makefile.conf ) || \
	    fail $? missing_kernel
}

# Populate the variable part of the floppy filesystem. Must be done before
# the MFS because its content might need to be copied there as well.
#
# This involves fetching files from three subtrees, in this order:
#
#  1. a standard one, from which type-specific files are excluded;
#  2. a type-specific one;
#  3. a site-specific one.
#
# Files are first copied to a local tree and then compressed.

populate_floppy_fs() {		# OK
    local dst excl srcdir

    log "populate_floppy_fs()"
    dst=${BUILDDIR}/floppy.tree
    log "pwd=`pwd` Populating floppy filesystem..."

    rm -rf ${dst} || true	# clean relics from old compilations.
    mkdir ${dst}		# create a clean tree

    # compute exclude list for generic tree
    excl=${MY_TREE}/floppy.tree.exclude
    if [ -f ${excl} ] ; then
	log "Files excluded from generic tree: `echo;cat ${excl}`"
	excl="--exclude-from ${excl}"
    else
	excl=""
    fi
    # copy from the floppy trees into the destination
    for FLOPPY_TREE in ${PICO_TREE}/floppy.tree ${MY_TREE}/floppy.tree \
		${MY_TREE}/floppy.tree.${SITE} ; do
	if [ -d ${FLOPPY_TREE} ] ; then
	    (cd ${FLOPPY_TREE} ; tar -cf - --exclude CVS \
		    --exclude .svn ${excl} . ) | \
		(cd ${dst} ; tar x${o_tarv}f - )
	    log "Copied from ${FLOPPY_TREE}"
	fi
	excl="" # reset the exclude list.
    done

    # add local manipulation
    if [ -f ${MY_TREE}/buildtree.mk ] ; then
	log "building local floppy tree"
	${BINMAKE} -C ${dst} -f ${MY_TREE}/buildtree.mk floppy.tree
    fi
 
    # compress the files in etc/, just in case
    # XXX this should be done in the makefile.
    # gzip returns an error if it fails to compress some file
    (cd $dst ; gzip -9 etc/*
	    log "Compressed files in etc/ `echo; ls -l etc`"
    ) || true
}

# Copy the specified files to the destination filesystem.
# Each file is specified as a pair "src dst", dst is assumed to be
# a directory (and created with mkdir -p) if it has a trailing /
# Be careful to escape metacharacters.
# You can use ${CROSS} to point to the root of the cross build
# (remember that it might be incomplete)

do_copyfiles() {	# rootdir varname
	log Copy files to $1
	local root=$1
	local srcs dst
	local CROSS=${_SHLIBDIRPREFIX}
	eval set "\${${2}}"
        srcs=""
	for dst in $* ; do
		[ -z "$srcs" ] && srcs=$dst && continue
		eval srcs="$srcs"	# expand wildcard and vars
		case x"$dst" in
		*/ )	mkdir -p ${root}/${dst} ;;
		# * )	mkdir -p `dirname ${root}/${dst}` ;;
		esac
		cp -p ${srcs} ${root}/${dst} || true
		srcs=""
        done
}

# do_links is a helper function to create links between programs
# in stand/
# This is done reading the names and destination from variable
# links in a config file, in the format
#	: dst names

do_links() {	# rootdir varname
	local root=$1
	local l i dst
	eval l="\${${2}}"
        dst=""
	log "Create links for ${l}"
	(cd ${root}/stand
	for i in $l ; do
	    if [ "$dst" = ":" -o "$i" = ":" ] ; then
		dst=$i
	    elif [ -n "${dst}" ] ; then
		ln -s ${dst} ${i}
	    fi
	done
	)
}

# find_progs is a helper function to locate the named programs
# or libraries in ${o_objdir} or ${_SHLIBDIRPREFIX},
# and return the full pathnames.
# Called as "find_progs [[-L libpath] [-P binpath]] prog1 prog2 ... "
# On return it sets ${u_progs} to the list of programs, and ${u_libs}
# to the list of shared libraries used.
# 
# '-L path' can be used to specify a search path for libraries
#    (which searches in $path/lib:$path/usr/lib:$path/usr/local/lib
# '-P binpath' can be used to specify a search path for programs
#    (which searches in a lot of places in the subtree)
# -L must be the first, followed by -P
#
# You can use it e.g. in a local confign file by writing
#
#  do_copyfiles_user() {
#	local dst=$1
#	find_progs nvi sed less grep
#	cp -p ${u_progs} ${dst}/bin
#	cp -p ${u_libs} ${dst}/lib
#	mkdir -p ${dst}/libexec
#	find_progs ld-elf.so.1
#	cp -p ${u_progs} ${dst}/libexec # ignore errors
#  }

find_progs() {	# programs
	local pass i old_libs="" tmp o=""
	if [ x"$1" = "x-L" -a -d "$2" ] ; then # set lib search path
		o="-P $2"; shift; shift
	fi
	# Result returned in global variables
	u_libs="" ; u_progs="`find_progs_helper $*`"
	[ -z "${u_progs}" ] && return 1	# not found, error
	# use objdump to find libraries. Iterate to fetch recursive
	# dependencies.
	tmp="${u_progs}" ; pass=1
	while [ $pass -lt 10 ] ; do
		pass=$(($pass + 1))
		i="`objdump -x ${tmp} | \
			awk '$1 == "NEEDED" { print $2 }' | sort | uniq`"
		if [ "$old_libs" = "$i" ] ; then
			log "libraries for: $my_progs ($u_progs) are ($i) $u_libs"
			log "--- done find_progs ---"
			return 0
		else
			# logverbose "old--- $old_libs --- new +++ $i +++"
		fi
		u_libs="`find_progs_helper $o $i`"
		old_libs="$i"
		tmp="$tmp $u_libs"
	done
	log "WARNING: Too many passes, giving up"
}

find_progs_helper() {	# programs
	local dir=${o_objdir:-${_SHLIBDIRPREFIX}/..}
	local ldir=""
	if [ x"$1" = "x-P" -a -d "$2" ] ; then # set path
		ldir=$2; shift; shift
	fi
	local progs="$*"
	local subdirs=". local/bin local/sbin local/lib local/libexec \
		bin sbin usr.bin usr.sbin libexec lib \
		gnu/usr.bin gnu/lib \
		secure/usr.bin secure/usr.sbin secure/libexec secure/lib"
	local names=""	# files to search
	local o=""
	local i
	for i in $progs ; do
		# full pathnames are just listed
		[ -f "$i" ] && echo $i && continue
		names="${names} ${o} -name $i"
		o="-o"
	done
	[ -z "${names}" ] && return 0
	local places=""				# places to search
	for i in $subdirs ; do
		[ -d "${dir}/${i}" ] && places="${places} ${dir}/${i}"
	done
	if [ -n "${ldir}" ] ; then
	    for i in $subdirs ; do
		[ -d "${ldir}/${i}" ] && places="${places} ${ldir}/${i}"
	    done
	fi
	for i in $progs ; do
		# full pathnames are just listed
		[ -f "$i" ] && echo $i && continue
		find ${places} -maxdepth 3 -type f -name ${i} | head -1
	done
	# use maxdepth 3 because some libs are way down
}

# Populate the memory filesystem with binaries and non-variable
# configuration files.
# First do an mtree pass, then create directory links and device entries,
# then run crunchgen etc. to build the binary and create links.
# Then copy the specific/generic mfs_tree.
# Finally, if required, make a copy of the floppy.tree onto /fd

populate_mfs_tree() {
    local i j a dst MFS_TREE

    log "populate_mfs_tree()"
    dst=${BUILDDIR}/mfs.tree
    rm -rf ${dst} || true	# clean relics from old compilations.
    mkdir ${dst}		# create a fresh tree

    log "pwd=`pwd`, Populating MFS tree..."

    # use type-specific mfs.mtree, default to generic one.
    a=${MY_TREE}/mfs.mtree
    [ -f ${a} ] || a=${PICO_TREE}/build/mfs.mtree
    log "Running mtree using $a..."
    mtree -deU -f $a -p ${dst} > /dev/null || fail $? mtree

    # Create symlinks using relative pathnames, so it is possible
    # to follow them also when building the image.
    # Note that names in STAND_LINKS should not have a leading /
    for i in ${STAND_LINKS}; do
	j=`echo $i | sed -E 's:^[^/]+::;s:/[^/]+:../:g'`
	ln -s ${j}stand ${dst}/$i
    done
    ln -s ../../dev/null ${dst}/var/run/log
    ln -s ../../../etc/termcap ${dst}/usr/share/misc/termcap

    ### now build the crunched binaries ###
    (
    cd ${BUILDDIR}/crunch
    log "Making and installing crunch1 from `pwd` src ${SRC}..."
    a=${BUILDDIR}/crunch1.conf
    ( export BUILDDIR SRC MY_TREE PICO_OBJ ;
	${BINMAKE} \
		-v -f ${PICO_TREE}/build/Makefile.conf ${BUILDDIR}/crunch.mk )
    log "Libs are ${LIBS} "
    export SRC # used by crunch.mk
    # export LIBS CFLAGS
    log "Now make -f crunch.mk"
    ${BINMAKE} ${o_makeopts} -f ${BUILDDIR}/crunch.mk
    strip --remove-section=.note --remove-section=.comment crunch1
    mv crunch1 ${dst}/stand/crunch
    chmod 555 ${dst}/stand/crunch
    log "Making links for binaries..."
    for i in `crunchgen -l $a` ; do
	ln ${dst}/stand/crunch ${dst}/stand/${i};
    done
    # rm $a # do not remove!
    ) || fail $? crunch

    if [ -f ${dst}/stand/sshd ] ; then
	log "Setting up host key for sshd:"
	if [ -f ${BUILDDIR}/floppy.tree/etc/ssh_host_key.gz ] ; then
	    log "Using existing host key"
	else
	    log "Generating new host key" 
	    ssh-keygen -t rsa1 -f ${BUILDDIR}/floppy.tree/etc/ssh_host_key \
		 -N "" -C "root@@picobsd"
	    gzip -9 ${BUILDDIR}/floppy.tree/etc/ssh_host_key* || true
	fi
    fi

    log "Copy generic and site-specific MFS tree..."
    for MFS_TREE in ${PICO_TREE}/mfs_tree ${MY_TREE}/mfs_tree ; do
	if [ -d ${MFS_TREE} ] ; then
	    log "Copy ${MFS_TREE} ..."
	    (cd ${MFS_TREE} ; tar -cf - --exclude CVS --exclude .svn . ) | \
		    (cd ${dst} ; tar x${o_tarv}f - )
	fi
    done

    if [ -f ${MY_TREE}/buildtree.mk ] ; then
	log "building local floppy tree"
	${BINMAKE} -C ${dst} -f ${MY_TREE}/buildtree.mk mfs.tree
    fi

    if [ "${o_all_in_mfs}" = "yes" ]; then
	log "Copy generic floppy_tree into MFS..."
	# ignore failure in case the floppy is empty
	cp -Rp ${BUILDDIR}/floppy.tree/* ${dst}/fd || true
    fi

    # 4.x compatibility - create device nodes
    if [ -n "${o_no_devfs}" ] ; then
	# create device entries using MAKEDEV
	(cd ${dst}/dev
	ln -s ${SRC}/etc/MAKEDEV ; chmod 555 MAKEDEV
	# log `pwd`
	sh ./MAKEDEV ${MY_DEVS}
	rm MAKEDEV
	)
    fi
    if [ "`id -u`" = "0" ] ; then
	log "Fixing permissions"
	(cd ${dst}; chown -R root . )
    fi

    log "for a shared 'crunch' take libraries and dynamic loader as well"
    find_progs ${dst}/stand/crunch
    if [ -n "${u_libs}" ] ; then
	mkdir -p ${dst}/lib && cp -p ${u_libs} ${dst}/lib
	mkdir -p ${dst}/libexec
        create_includes_and_libraries2 libexec/rtld-elf
        find_progs ld-elf.so.1 && cp -p ${u_progs} ${dst}/libexec
    fi

    [ -n "${copy_files}" ] && do_copyfiles ${dst} copy_files
    do_copyfiles_user ${dst} || true
    [ -n "${links}" ] && do_links ${dst} links
    strip ${dst}/libexec/* ${dst}/lib/* ${dst}/stand/* 2> /dev/null || true

    # The 'import_files' mechanism is deprecated, as it requires
    # root permissions to follow the symlinks, and also does
    # not let you rename the entries.
    if [ -n "${import_files}" ] ; then
	log "importing ${import_files} into mfs"
	# We do it in a chroot environment on the target so
	# symlinks are followed correctly.
	# Make sure we have a statically linked tar there.
	mkdir -p ${dst}/rescue
	cp /rescue/tar ${dst}/rescue
	(cd ${l_usrtree}/.. ; tar cf - ${import_files} ) | \
	    (chroot ${dst} /rescue/tar xPf - )
	rm -rf ${dst}/rescue
    fi

    # final step -- build the mfs image
    (cd ${BUILDDIR}
	# override the owner
	echo "/set uid=0 gid=0" > mtree.out
	mtree -ic -p ${dst} -k "" >> mtree.out
	log "mtre.out at ${BUILDDIR}/mtree.out"
	makefs -t ffs -o bsize=4096 -o fsize=512 \
		-s ${MFS_SIZE}k -f 1000 -F mtree.out ${c_fs} ${dst}
	ls -l ${c_fs} )
    log "done mfs image"
}

final_cleanup() {
    log "final_cleanup()"
    rm -rf ${c_mnt} ${c_reply} 2> /dev/null || true
}

# fail errno errcode
# This function is used to trap errors and print msgs
#
fail() {
    local errno errocode where

    errno=$1
    errcode=$2
    where=$3
    echo "---> fail: Error <${errno}> error code <${errcode}> in <${where}>"
    case ${errcode} in
    mtree)
	echo "Error while making hierarchy in ${c_mnt}"
	;;
    crunch)
	echo "Error while building ${name}."
	;;
    missing_kernel)
	echo "Error: you must build PICOBSD${suffix} kernel first"
	;;
    includes)
	echo "Error: failed while making includes"
	;;
    libraries)
	echo "Error: failed while making libraries"
	;;
    bad_type)
	echo "Error: unknown floppy type ${name}"
	;;
    no_space)
	echo "Error: no space left on device (${where})"
	;;
    no_mfs)
	echo "Error: while writing MFS into the kernel."
	;;
    "")
	echo "User break"
	errcode="userbreak"
	;;
    *)
	echo "unknown error, maybe user break: $errno $errcode"
	;;
    esac
    echo "---> Aborting $0"
    # try to cleanup the vnode.
    final_cleanup
    exit 2
}

fill_floppy_image() {
    local blocks dst mfs_start mfs_end mfs_size img_size

    log "fill_floppy_image()"
    dst=${c_mnt}	# where to create the image

    log "Preparing ${fd_size}kB floppy filesystem..."

    # correct blocks according to size.
    blocks=${fd_size};
    if [ "${blocks}" = "1720" ]; then
	blocks=1722
    elif [ "${blocks}" = "1480" ]; then
	blocks=1476
    fi

    log "Labeling floppy image"

    dst=${BUILDDIR}/image.tree
    rm -rf ${dst}
    mkdir -p ${dst}
    (
    cd ${BUILDDIR}
    set 0 0 # reset variables
    # $1 takes the offset of the MFS filesystem
    set `strings -at d kernel | grep "MFS Filesystem goes here"`
    mfs_start=$1
    set 0 0 # reset variables
    set `strings -at d kernel | grep "MFS Filesystem had better"`
    mfs_end=$1
    mfs_size="$((${mfs_end} - ${mfs_start}))"
    set -- `ls -l ${c_fs}`; imgsize="$5"
    if [ ${mfs_start} -gt 0 -a ${mfs_size} -ge ${imgsize} ] ; then
	mfs_ofs=$((${mfs_start} + 8192))
	log "Preload kernel with file ${c_fs} at ${mfs_ofs}"
	log "`ls -l ${c_fs}` to fit in ${mfs_size}"
	dd if=${c_fs} ibs=8192 iseek=1 of=kernel obs=${mfs_ofs} \
	    oseek=1 conv=notrunc # 2> /dev/null
    else
    	log "not loading mfs, size ${mfs_size} img ${imgsize}"
    fi
    log "Compress with kgzip and copy to floppy image"

    mkdir -p  ${dst}/boot/kernel
    # XXX loader.conf does not work unless we also load the .4th files
    echo "hint.acpi.0.disabled=\"1\"" > ${dst}/boot/loader.conf
    echo "console=\"comconsole\"" >> ${dst}/boot/loader.conf
    cp -p /boot/loader ${dst}/boot/loader || fail $? no_space "copying bootloader"
    gzip -c kernel > ${dst}/boot/kernel/kernel.gz || fail $? no_space "copying kernel"

    # now transfer the floppy tree. If it is already in mfs, dont bother.
    if [ "${o_all_in_mfs}" != "yes" ] ; then
	log "Now transfer floppy tree if not already in MFS image"
	cp -Rp floppy.tree/* ${dst} || \
		fail $? no_space "copying floppy tree"
    fi
    )

    # add local manipulation to the image
    if [ -f ${MY_TREE}/buildtree.mk ] ; then
	${BINMAKE} -C ${dst} -f ${MY_TREE}/buildtree.mk image.tree
    fi

    log "image used `du -s ${dst}` of ${blocks}k"
    if [ "${generate_iso}" = "YES" ]; then
	logverbose "generate_iso ${generate_iso}"
	# build_iso_image	# XXX not implemented yet
	(cd ${BUILDDIR}
	cp -p /boot/cdboot ${dst}/boot || fail $? no_space "copying cdboot"
	mkisofs -b boot/cdboot -no-emul-boot -J -r -ldots -l -L \
		-o ${c_iso} ${dst}
	)
    fi

    (cd ${BUILDDIR}
    makefs -t ffs -o bsize=4096 -o fsize=512 \
	-s ${blocks}k -f 50 ${c_img} ${dst}

    ${c_label} -w -f `pwd`/${c_img} auto # write in a label
    # copy partition c: into a: with some sed magic
    ${c_label} -f `pwd`/${c_img} | sed -e '/  c:/{p;s/c:/a:/;}' | \
	${c_label} -R -f `pwd`/${c_img} /dev/stdin
    ${c_label} -f `pwd`/${c_img}

    ls -l ${c_img}
    ${c_label} -f `pwd`/${c_img}
    log "after disklabel"
    )

    echo "BUILDDIR ${BUILDDIR}"

    # dump the primary and secondary boot
    # XXX primary is 512 bytes
    dd if=${c_boot1} of=${BUILDDIR}/${c_img} conv=notrunc 2>/dev/null
    # XXX secondary starts after the 0x114 = dec 276 bytes of the label
    # so we skip 276 from the source, and 276+512=788 from dst
    # the old style blocks used 512 and 1024 respectively

    dd if=${c_boot2} iseek=1 ibs=276 2> /dev/null | \
	dd of=${BUILDDIR}/${c_img} oseek=1 obs=788 conv=notrunc 2>/dev/null
    log "done disk image"
    # XXX (log "Fixing permissions"; cd ${dst}; chown -R root *)
    # leave build stuff if verbose
    [ ${o_verbose} -gt 0 ] && return

    rm -rf ${BUILDDIR}/floppy.tree || true # cleanup
    # df -ik ${dst} | colrm 70 > .build.reply
    rm -rf ${dst}
    rm ${BUILDDIR}/${c_fs}
    # rm ${BUILDDIR}/kernel.gz
}

# This function creates variables which depend on the source tree in use:
# SRC, l_usrtree, l_objtree
# Optionally creates libraries, includes and the like (for cross compiles,
# needs to be done once).

set_build_parameters() {
    if [ "${SRC}" = "/usr/src" ] ; then
	l_usrtree=${USR:-/usr}
    else
	l_usrtree=${USR:-${SRC}/../usr}
    fi
    l_objtree=${l_usrtree}/obj-pico-${o_arch}

    PICO_TREE=${PICO_TREE:-${SRC}/release/picobsd}
    set `grep "#define[\t ]__FreeBSD_version" ${SRC}/sys/sys/param.h`
    OSVERSION=$3
    log "OSVERSION is ${OSVERSION}"
    if [ ${OSVERSION} -ge 500035 ] ; then
	export MAKEOBJDIRPREFIX=${l_objtree}
	export TARGET_ARCH=${o_arch} TARGET=${o_arch}
	export WITHOUT_CLANG_IS_CC=1
	# XXX why change machine_arch ?
	#-- export MACHINE_ARCH=`uname -m` MACHINE=`uname -m`
	# export CWARNFLAGS="-Wextra -Wno-sign-compare -Wno-missing-field-initializers"
	eval "export BINMAKE=\"`cd ${SRC}; make -f Makefile -V BINMAKE`\""
    fi

    if [ "${o_init_src}" != "" ] ; then
	if [ ${OSVERSION} -lt 500035 ] ; then
	    create_includes_and_libraries
	else
	    create_includes_and_libraries2
	fi
    else
	eval export `cd ${SRC}; ${BINMAKE} -f Makefile.inc1 -V WMAKEENV`
    fi
    if [ ${OSVERSION} -lt 500035 ] ; then
	# Create the right LIBS and CFLAGS for further builds.
	# and build the config program
	LIBS="-L${l_usrtree}/lib"
	CFLAGS="-nostdinc -I${l_usrtree}/include"
	export LIBS CFLAGS
	CONFIG=${l_usrtree}/sbin/config
	export CONFIG
    fi

    # if we have o_objdir, find where bin/ is
    if [ ! -z "${o_objdir}" ] ; then
	if [ -d ${o_objdir}/bin ] ; then
	    # fine
	elif [ -d "${o_objdir}${SRC}/bin" ] ; then
	    o_objdir="${o_objdir}${SRC}"
	    log "Changing objdir to ${o_objdir}"
	else
	    log "Cannot find objdir in ${o_objdir}, sorry"
	    o_objdir=""
	fi
    fi
}

#-------------------------------------------------------------------
# Main entry of the script. Initialize variables, parse command line
# arguments.

# o_par="-j 8"	# parallel make and other make options

set_defaults
while [ true ]; do
    log "Parsing $1"
    case $1 in
    --par)
	o_par="-j 8"
	;;

    --src)	# set the source path instead of /usr/src
	SRC=`realpath $2`
	shift
	;;

    --init)	# run a partial buildworld on the source tree
	o_init_src="YES"
	;;

    --arch)	# override the target architecture
	o_arch=$2
	shift
	;;

    --floppy_size)	# image size
	fd_size=$2
	shift
	;;

    --all_in_mfs)
	o_all_in_mfs="yes"
	;;

    --no_all_in_mfs)
	o_all_in_mfs="no"
	;;

    --modules)	# also build kernel modules
	o_do_modules="yes"
	;;

    -n)
	o_interactive="NO"
	;;

    -clear|-clean|-c) # clean
	o_clean="YES"
	o_interactive="NO"
	;;

    -v) # need -v -v to wait for user input
	o_verbose=$((${o_verbose}+1))	# verbose level
	o_tarv="v"			# tar verbose flag
	o_makeopts="-d l" # be verbose
	;;

    --iso) # generate iso image
	generate_iso="YES"
	;;

    --cfg) # read additional config from this file
	o_additional_config=`realpath $2`
	shift
	;;

    --objdir)	# Place with results of a previous buildworld
		# useful if you want to copy shared binaries and libs
	o_objdir=`realpath $2`
	shift
	;;

    *)
	break
	;;

    esac
    shift
done

set_build_parameters	# things that depend on ${SRC}
set_type $1 $2		# type and site, respectively

[ "${o_interactive}" != "NO" ] && main_dialog

if [ "${o_clean}" = "YES" ] ; then
    clean_tree
else
    build_image
    do_install
fi
final_cleanup
exit 0
@


1.66
log
@## SVN ## Exported commit - http://svnweb.freebsd.org/changeset/base/250285
## SVN ## CVS IS DEPRECATED: http://wiki.freebsd.org/CvsIsDeprecated
@
text
@d3 1
a3 1
# $FreeBSD: head/release/picobsd/build/picobsd 250285 2013-05-05 18:54:25Z luigi $
d178 3
a180 9
	MAKEOBJDIRPREFIX=${l_objtree}
	export MAKEOBJDIRPREFIX
	# export WITH_RESCUE=yes	# build crunchide
	# ${BINMAKE} ${o_par} _+_= $no toolchain _includes _libraries
	(
	    # eval export `cd ${SRC}; ${BINMAKE} -f Makefile.inc1 -V BMAKEENV`
	    eval "export XMAKE=\"`cd ${SRC}; make -f Makefile -V XMAKE`\""
	    ${BINMAKE} ${o_par} _+_= $no toolchain
	)
a181 1
	${BINMAKE} ${o_par} _+_= $no _includes _libraries
d438 2
a439 1
	${BINMAKE} ${o_par} KERNCONF=${l_kernconf}	\
@


1.65
log
@## SVN ## Exported commit - http://svnweb.freebsd.org/changeset/base/244642
## SVN ## CVS IS DEPRECATED: http://wiki.freebsd.org/CvsIsDeprecated
@
text
@d3 1
a3 1
# $FreeBSD: head/release/picobsd/build/picobsd 244642 2012-12-23 22:41:54Z luigi $
a447 2
#		-DWITHOUT_CLANG_IS_CC			\

@


1.65.2.1
log
@file picobsd was added on branch RELENG_8_4 on 2013-03-28 13:03:30 +0000
@
text
@d1 1113
@


1.65.2.2
log
@## SVN ## Exported commit - http://svnweb.freebsd.org/changeset/base/248810
## SVN ## CVS IS DEPRECATED: http://wiki.freebsd.org/CvsIsDeprecated
@
text
@a0 1107
#!/bin/sh -
#
# $FreeBSD: releng/8.4/release/picobsd/build/picobsd 231590 2012-02-13 18:10:13Z luigi $
# This file requires sysutils/makefs to run
#
# The PicoBSD build script. Invoked as
#
#	picobsd [options] image_type [site_name]
#
# Where image_type is a directory with the picobsd config info,
# and ${image_type}/floppy.tree.${site_name} contains
# optional site-specific configuration.
#
# For Options, see the bottom of the file where the processing is
# done. The picobsd(8) manpage might be of some help, but code and docs
# tend to lose sync over time.
#
# This script depends on the following files:
#
# in ${PICO_TREE} :
#   Makefile.conf	Makefile used to build the kernel
#   config		shell variables, sourced here.
#   mfs.mtree		mtree config file
#   floppy.tree/	files which go on the floppy
#   mfs_tree/		files which go onto the mfs
#
# in ${MY_TREE} :
#   PICOBSD		kernel config file
#   config		shell variables, sourced here.
#   crunch.conf		crunchgen configuration
#   mfs.mtree		overrides ${PICO_TREE}/mfs.mtree
#   floppy.tree.exclude	files from floppy.tree/ which we do not need here.
#   floppy.tree/	local additions to ${PICO_TREE}/mfs_free
#   floppy.tree.${site}/ same as above, site specific.
#   mfs_tree/		local additions to the mfs_free
#   buildtree.mk	optional Makefile to build an extension for floppy tree
#			(generated in buildtree/ )

#
#--- The main entry point is at the end.
#

# There are two initialization functions:
#
# + set_defaults
#   is run on entry to the script, and is used to set default values
#   for all variables that do not depend on image type and source tree.
#
# + set_build_parameters
#   is run after command line parsing
#
# VARIABLE NAMES:
# + variables that control operation (e.g. verbosity) and are generally
#   set from the command line have o_ ("option") as a name prefix
#
# + variables that contain pathnames and values that should not change
#   have c_ ("constant") as a name prefix
#
# + variables exported to Makefiles and subshells are CAPITAL
#
# + variables local to the script are lowercase, possibly with
#   an l_ ("local") prefix.
#
# There are unfortunately exceptions:
# name, l_usrtree, l_objtree

# SRC points to your FreeBSD source tree.
# l_usrtree points to the /usr subdir for the source tree.
#     Normally /usr or ${SRC}/../usr
# l_objtree points to the obj tree. Normally ${l_usrtree}/obj-pico-${o_arch}
# c_label is either bsdlabel or disklabel
# PICO_TREE is where standard picobsd stuff resides.
#     Normally ${SRC}/release/picobsd
# You can set SRC with --src <directory>
# It is not recommended to override the other variables.

# MY_TREE (set later) is where this floppy type resides.
# BUILDDIR is the build directory

# log something on stdout if verbose.
o_verbose=0	# this needs to be here!
log() {	#	message
    local foo
    [ ${o_verbose} -gt 0 ] && printf "\n*** %s\n" "$*"
    [ ${o_verbose}  -gt 1 ] && read -p "=== Press enter to continue" foo
    return 0
}

# unconditionally log and wait for input
logverbose() {	# message
    local foo
    printf "\n*** %s\n" "$*"
    read -p "=== Press enter to continue" foo
    return 0
}

# set some default values for variables.
# needs to be done as the first thing in the script.

set_defaults() {	# no arguments
    # EDITOR is the editor you use
    # fd_size  floppy size in KB (default to 1440). You can use 1480,
    #	1720, 2880, etc. but beware that only 1440 and 1480 will boot
    #	from 1.44M floppy drives (1480 will not work on vmware).
    EDITOR=${EDITOR:-vi}
    fd_size=${fd_size:-1440}

    o_all_in_mfs="yes"		# put all files in mfs so you can boot
				# and run the image via diskless boot.
    o_clean=""			# set if you want to clean prev.builds.
    o_interactive=""		# default is interactive
    o_verbose=0			# verbose level, 0 is silent
    o_tarv=""			# tar verbose flag, "" or "v"
    o_init_src=""		# set to build libs and includes.
    o_makeopts=${MAKEOPTS:--s}	# make options, be silent by default
    o_no_devfs=			# default is use devfs.
	# You should only set it when building 4.x images
    o_do_modules=""		# do not build modules
    o_arch=`uname -m`		# default to amd64 or i386 ...

    SRC="/usr/src"		# default location for sources
    c_startdir=`pwd`		# directory where we start
				# used to lookup config and create BUILDDIR

    # XXX 6.x/7.x have a single /boot/boot block, which is the concatenation
    # of the old two. For the time being, we keep these, but this should
    # be fixed at some point.

    # blocks
    c_boot1=/boot/boot1		# boot blocks (in case you want custom ones)
    c_boot2=/boot/boot2

    c_reply=${c_reply:-`mktemp "/tmp/reply.XXXXXXXXXX"`}
    				# file where User replies will be put
    c_mnt=`mktemp -d "/tmp/picobsd.XXXXXXXXXX"`
    				# mountpoint used to build memory filesystems
    c_fs=fs.PICOBSD		# filename used for the memory filesystem
    c_img=picobsd.bin		# filename used for the picobsd image
    c_iso=picobsd.iso		# filename used for the ISO image
    generate_iso="NO"		# don't generate the iso image

    # select the right disklabel program
    case `uname -r` in
	4.*)
	    c_label="disklabel"
	    ;;
	*)
	    c_label="bsdlabel"
	    ;;
    esac

    set -e

    trap fail 2
    #trap fail 3
    #trap fail 6
    trap fail 15
}

# use the new build infrastructure to create libraries
# and also to build a specific target
create_includes_and_libraries2() { # opt_dir opt_target
    local no
    log "create_includes_and_libraries2() for ${SRC} $1"
    if [ ${OSVERSION} -ge 600000 ] ; then
	no="-DNO_CLEAN -DNO_PROFILE -DNO_GAMES -DNO_LIBC_R" # WITHOUT_CDDL=1"
    else
	no="-DNOCLEAN -DNOPROFILE -DNOGAMES -DNOLIBC_R"
    fi
    ( cd ${SRC};
    # make -DNOCLEAN -DNOPROFILE -DNOGAMES -DNOLIBC_R -DPICOBSD buildworld
    if [ -d "$1" ] ; then
	cd $1 ; ${BINMAKE} ${o_par} $2	# specific target, e.g. ld-elf.so
    else
	MAKEOBJDIRPREFIX=${l_objtree}
	export MAKEOBJDIRPREFIX
	# export WITH_RESCUE=yes	# build crunchide
	# ${BINMAKE} ${o_par} _+_= $no toolchain _includes _libraries
	(
	    # eval export `cd ${SRC}; ${BINMAKE} -f Makefile.inc1 -V BMAKEENV`
	    eval "export XMAKE=\"`cd ${SRC}; make -f Makefile -V XMAKE`\""
	    ${BINMAKE} ${o_par} _+_= $no toolchain
	)
        eval export `cd ${SRC}; ${BINMAKE} -f Makefile.inc1 -V WMAKEENV`
	${BINMAKE} ${o_par} _+_= $no _includes _libraries
	[ ${o_arch} != `uname -m` ] && \
	    (cd ${l_objtree}; ln -s . ${o_arch}.${o_arch} || true )
    fi
    )
}

# entry for 4.x and earlier trees
create_includes_and_libraries() {
    local e i

    log "create_includes_and_libraries() for ${SRC}"
    # Optionally creates include directory and libraries.
    mkdir -p ${l_usrtree}/include	# the include directory...
    mkdir -p ${l_usrtree}/share/misc	# a few things go here
    mkdir -p ${l_usrtree}/lib		# libraries
    mkdir -p ${l_usrtree}/sbin		# some binaries
    # override variables for ownershiip and destinations
    # BINOWN:BINGRP are also used for include files
    (cd ${SRC}; \
	BINOWN=`id -un` BINGRP=`id -gn` \
	DESTDIR=${l_usrtree}/.. \
	make -m ${SRC}/share/mk includes ) || fail $? includes
    # Pick up the correct headers for libraries.
    CFLAGS="-nostdinc -I${l_usrtree}/include" ; export CFLAGS

    (cd ${SRC}
	# $e is the invocation of make with correct environment
	# XXX check the NO* options below, maybe system dependent.
	e="MAKEOBJDIRPREFIX=${l_objtree}/picobsd/libraries \
	    BINOWN=`id -un` BINGRP=`id -gn` \
	    DESTDIR=${l_usrtree}/.. \
	    make -m ${SRC}/share/mk \
		-DNOHTML -DNOINFO -DNOMAN -DNOSHARE -DNOFSCHG "
	log "do a 'make obj' in a few places."
	# This is very version-specific... The following works for 5.0
	for i in lib secure/lib gnu/lib \
		gnu/usr.bin/perl usr.bin/lex usr.sbin/config ; do
	    (cd ${i}; eval $e obj)
	done
	log "now make the static libraries"
	eval $e -DNOPROFILE -DNOPIC libraries
	(cd ${SRC}/usr.sbin/config
	eval $e		# build binary
	eval $e	install	# install it
	)
    ) || fail $? "libraries"
    log "Libraries done"
}

# set_type <the_type> [the_site] looks in user or system directories
# for the directory named as the first argument, reads the configuration
# files and sets variables according to the config.
# Also sets MY_TREE and BUILDDIR and SITE

set_type() {	# the_type the_site
    local a i

    log "set_type() : Type '$1' site '$2'"
    THETYPE=$1
    SITE=$2
    a=$1
    name=""	# clear in case of errors
    for i in ${c_startdir}/${a} ${PICO_TREE}/${a} ; do
	log "set_type: checking $i"
	[ -d $i -a -f $i/crunch.conf ] || continue
	# look for a kernel config file, privilege arch-specific
	l_kernconf=$i/PICOBSD.${o_arch}
	[ -f $l_kernconf ] || l_kernconf=$i/PICOBSD
	[ -f $l_kernconf ] || continue
	set -- `cat $l_kernconf | \
	    awk '/^#PicoBSD/ {print $2, $3, $4, $5, $6}'`
	[ x"$1" != "x" ] || continue
	MFS_SIZE=$1
	name=`(cd $i ; pwd) `
	name=`basename $name`
	MY_TREE=$i
	BUILDDIR=${c_startdir}/build_dir-${name}-${o_arch}
	log "Matching file $name in $i"
	return ;
    done
    logverbose "Type $a NOT FOUND"
}

clean_tree() {
    log "clean_tree()"
    if [ -z "${name}" ] ; then
	echo "---> Wrong floppy type"
	exit 3
    fi
    rm -rf ${BUILDDIR}
}

# prepare a message to be printed in the dialog menus.
set_msgs() {		# OK
    log "set_msgs()"

    MSG1="Type: ${THETYPE} name $name"

    MSG="PicoBSD build -- Current parameters:\n\n\t1.  ${MSG1}\n\
\t2.  MFS size: ${MFS_SIZE} kB\n\
\t3.  Site-info: ${SITE}\n\t4.  Full-path: ${MY_TREE}\n"
}

# Main build procedure. Builds both the disk image and the ISO
build_image() {
    log "build_image() <${name}>"
    [ -n "${name}" ] || fail $? bad_type
    clear
    set_msgs
    printf "${MSG}---> We'll use the sources living in ${SRC}\n\n"

    # read config variables from a global and then a type-specific file
    # basically STAND_LINKS and MY_DEVS, but can also override other
    # variables.
    # 
    . ${PICO_TREE}/build/config
    [ -f "${MY_TREE}/config" ]		&& . ${MY_TREE}/config
    [ -f "${o_additional_config}" ]	&& . ${o_additional_config}

    # location of the object directory
    PICO_OBJ=${l_objtree}/picobsd/${THETYPE}
    log "PICO_OBJ is ${PICO_OBJ}"

    # create build directory and subtree
    mkdir -p ${BUILDDIR}/crunch
    # remove any old stuff
    rm -f ${BUILDDIR}/kernel.gz ${BUILDDIR}/${c_fs}
    # invoke commands to build a kernel
    do_kernel
    # fill a subdirectory with things that go into the floppy
    # (mostly /etc and similar stuff)
    populate_floppy_fs
    # populate it and produce a file with the MFS image
    populate_mfs_tree		# things which go into mfs
    # create, mount and fill a filesystem with floppy image
    fill_floppy_image # copies everything into the floppy
}

# Set build parameters interactively

main_dialog() {
  local ans i l

  log "main_dialog()"
  while true ; do
    set_msgs
    rm ${c_reply}
    dialog --menu "PicoBSD build menu -- (29 sep 2001)" 19 70 12 \
	N "--> READY, build it <---" \
	T "${MSG1}" \
	K "edit Kernel config file" \
	E "Edit crunch.conf file" \
	S "MFS Size: ${MFS_SIZE}kB" \
	F "Floppy size: ${fd_size}kB" \
	$ "Site-info: ${SITE}" \
	Q "Quit" \
	2> ${c_reply}
    ans=`cat ${c_reply}`
    rm ${c_reply}
    case ${ans} in
    T)
	l=""
	for i in ${c_startdir} ${c_startdir}/* ${PICO_TREE}/* ; do
	    if [ -d $i -a -f $i/PICOBSD -a -f $i/crunch.conf ]; then
		l="$l `basename $i` `basename $i`"
	    fi
	done
	log $l
	{ dialog --menu "Setup the type of configuration" 12 70 5 $l \
		2> ${c_reply} && set_type "`cat ${c_reply}`" ${SITE} ; } || true
	;;

    K) ${EDITOR} ${MY_TREE}/PICOBSD ;;

    E) ${EDITOR} ${MY_TREE}/crunch.conf ;;

    S)
	{ dialog --title "MFS Size setup" --inputbox \
"MFS size depends on what you need to put on the MFS image. Typically \
ranges between 820kB (for very small bridge/router images) to \
as much as 2500kB kB for a densely packed image. \
Keep in mind that this memory is \
totally lost to other programs. Usually you want to keep \
this as small as possible. " 10 70 2> ${c_reply} \
	&& MFS_SIZE=`cat ${c_reply}` ; } || true
	;;

    \$)
	{ dialog --title "Site info setup" --inputbox \
	"Please enter the full path to the directory \
	containing site-specific setup. \
	This directory tree must contain files that replace \
	standard ones in floppy.tree/ and mfs.tree/ . " \
	10 70 2> ${c_reply} && SITE=`cat ${c_reply}` ; } || true
	;;

    F)
	{ dialog --menu "Set floppy size" 15 70 4 \
	    1440 "1.44MB" 1720 "1.72MB" 2880 "2.88MB" 4096 "4MB" \
		 2> ${c_reply} && fd_size=`cat ${c_reply}` ; } || true
	;;

    N) break 2
	;;

    Q) exit 0 ;;

    *) echo "Unknown option \"${ans}\". Try again."
	sleep 2
	clear
	;;
    esac
  done
}

# Call the build procedure
# Install image
do_install() {
    log "do_install()"

    if [ "${o_interactive}" = "NO" ] ; then
	echo "+++ Build completed +++"
	cat .build.reply || true
	return
    fi
    dialog --title "Build ${THETYPE} completed" --inputbox \
"\nThe build process was completed successfuly.\n\
`cat .build.reply` \n\n\
Now we are going to install the image on the floppy.\n\
Please insert a blank floppy in /dev/fd0.\\n
WARNING: the contents of the floppy will be permanently erased!\n\
\n\
Your options:\n\
	* ^C or [Cancel] to abort,\n\
	* Enter to install ${c_img},\n\
" 20 80 2> ${c_reply}
    if [ "$?" = "0" ]; then
	echo "Writing ${c_img}..."
	dd if=${BUILDDIR}/${c_img} of=/dev/fd0.${fd_size}
    else
	echo "Ok, the image is in ${c_img}"
    fi
    echo "Done."
}


#-------------------------------------------------------------------

# invoke the picobsd Makefile to compile the kernel.
# if MODULES is set (value is irrelevant) the makefile will build modules.
do_kernel() {		# OK
    log "do_kernel() Preparing kernel \"$name\" in $MY_TREE"
    (cd $MY_TREE; export name SRC BUILDDIR # used in this makefile ;
	# export CONFIG
	export WARNS CWARNFLAGS
	[ "${o_do_modules}" = "yes" ] && export MODULES=""
	${BINMAKE} ${o_par} KERNCONF=${l_kernconf}	\
		-v -f ${PICO_TREE}/build/Makefile.conf ) || \
	fail $? missing_kernel
}

# Populate the variable part of the floppy filesystem. Must be done before
# the MFS because its content might need to be copied there as well.
#
# This involves fetching files from three subtrees, in this order:
#
#  1. a standard one, from which type-specific files are excluded;
#  2. a type-specific one;
#  3. a site-specific one.
#
# Files are first copied to a local tree and then compressed.

populate_floppy_fs() {		# OK
    local dst excl srcdir

    log "populate_floppy_fs()"
    dst=${BUILDDIR}/floppy.tree
    log "pwd=`pwd` Populating floppy filesystem..."

    rm -rf ${dst} || true	# clean relics from old compilations.
    mkdir ${dst}		# create a clean tree

    # compute exclude list for generic tree
    excl=${MY_TREE}/floppy.tree.exclude
    if [ -f ${excl} ] ; then
	log "Files excluded from generic tree: `echo;cat ${excl}`"
	excl="--exclude-from ${excl}"
    else
	excl=""
    fi
    # copy from the floppy trees into the destination
    for FLOPPY_TREE in ${PICO_TREE}/floppy.tree ${MY_TREE}/floppy.tree \
		${MY_TREE}/floppy.tree.${SITE} ; do
	if [ -d ${FLOPPY_TREE} ] ; then
	    (cd ${FLOPPY_TREE} ; tar -cf - --exclude CVS \
		    --exclude .svn ${excl} . ) | \
		(cd ${dst} ; tar x${o_tarv}f - )
	    log "Copied from ${FLOPPY_TREE}"
	fi
	excl="" # reset the exclude list.
    done

    # add local manipulation
    if [ -f ${MY_TREE}/buildtree.mk ] ; then
	log "building local floppy tree"
	${BINMAKE} -C ${dst} -f ${MY_TREE}/buildtree.mk floppy.tree
    fi
 
    # compress the files in etc/, just in case
    # XXX this should be done in the makefile.
    # gzip returns an error if it fails to compress some file
    (cd $dst ; gzip -9 etc/*
	    log "Compressed files in etc/ `echo; ls -l etc`"
    ) || true
}

# Copy the specified files to the destination filesystem.
# Each file is specified as a pair "src dst", dst is assumed to be
# a directory (and created with mkdir -p) if it has a trailing /
# Be careful to escape metacharacters.
# You can use ${CROSS} to point to the root of the cross build
# (remember that it might be incomplete)

do_copyfiles() {	# rootdir varname
	log Copy files to $1
	local root=$1
	local srcs dst
	local CROSS=${_SHLIBDIRPREFIX}
	eval set "\${${2}}"
        srcs=""
	for dst in $* ; do
		[ -z "$srcs" ] && srcs=$dst && continue
		eval srcs="$srcs"	# expand wildcard and vars
		case x"$dst" in
		*/ )	mkdir -p ${root}/${dst} ;;
		# * )	mkdir -p `dirname ${root}/${dst}` ;;
		esac
		cp -p ${srcs} ${root}/${dst} || true
		srcs=""
        done
}

# do_links is a helper function to create links between programs
# in stand/
# This is done reading the names and destination from variable
# links in a config file, in the format
#	: dst names

do_links() {	# rootdir varname
	local root=$1
	local l i dst
	eval l="\${${2}}"
        dst=""
	log "Create links for ${l}"
	(cd ${root}/stand
	for i in $l ; do
	    if [ "$dst" = ":" -o "$i" = ":" ] ; then
		dst=$i
	    elif [ -n "${dst}" ] ; then
		ln -s ${dst} ${i}
	    fi
	done
	)
}

# find_progs is a helper function to locate the named programs
# or libraries in ${o_objdir} or ${_SHLIBDIRPREFIX},
# and return the full pathnames.
# Called as "find_progs [[-L libpath] [-P binpath]] prog1 prog2 ... "
# On return it sets ${u_progs} to the list of programs, and ${u_libs}
# to the list of shared libraries used.
# 
# '-L path' can be used to specify a search path for libraries
#    (which searches in $path/lib:$path/usr/lib:$path/usr/local/lib
# '-P binpath' can be used to specify a search path for programs
#    (which searches in a lot of places in the subtree)
# -L must be the first, followed by -P
#
# You can use it e.g. in a local confign file by writing
#
#  do_copyfiles_user() {
#	local dst=$1
#	find_progs nvi sed less grep
#	cp -p ${u_progs} ${dst}/bin
#	cp -p ${u_libs} ${dst}/lib
#	mkdir -p ${dst}/libexec
#	find_progs ld-elf.so.1
#	cp -p ${u_progs} ${dst}/libexec # ignore errors
#  }

find_progs() {	# programs
	local pass i old_libs="" tmp o=""
	if [ x"$1" = "x-L" -a -d "$2" ] ; then # set lib search path
		o="-P $2"; shift; shift
	fi
	# Result returned in global variables
	u_libs="" ; u_progs="`find_progs_helper $*`"
	[ -z "${u_progs}" ] && return 1	# not found, error
	# use objdump to find libraries. Iterate to fetch recursive
	# dependencies.
	tmp="${u_progs}" ; pass=1
	while [ $pass -lt 10 ] ; do
		pass=$(($pass + 1))
		i="`objdump -x ${tmp} | \
			awk '$1 == "NEEDED" { print $2 }' | sort | uniq`"
		if [ "$old_libs" = "$i" ] ; then
			log "libraries for: $my_progs ($u_progs) are ($i) $u_libs"
			log "--- done find_progs ---"
	return 0
		else
			# logverbose "old--- $old_libs --- new +++ $i +++"
		fi
		u_libs="`find_progs_helper $o $i`"
		old_libs="$i"
		tmp="$tmp $u_libs"
	done
	log "WARNING: Too many passes, giving up"
}

find_progs_helper() {	# programs
	local dir=${o_objdir:-${_SHLIBDIRPREFIX}/..}
	local ldir=""
	if [ x"$1" = "x-P" -a -d "$2" ] ; then # set path
		ldir=$2; shift; shift
	fi
	local progs="$*"
	local subdirs=". local/bin local/sbin local/lib local/libexec \
		bin sbin usr.bin usr.sbin libexec lib \
		gnu/usr.bin gnu/lib \
		secure/usr.bin secure/usr.sbin secure/libexec secure/lib"
	local names=""	# files to search
	local o=""
	local i
	for i in $progs ; do
		# full pathnames are just listed
		[ -f "$i" ] && echo $i && continue
		names="${names} ${o} -name $i"
		o="-o"
	done
	[ -z "${names}" ] && return 0
	local places=""				# places to search
	for i in $subdirs ; do
		[ -d "${dir}/${i}" ] && places="${places} ${dir}/${i}"
	done
	if [ -n "${ldir}" ] ; then
	    for i in $subdirs ; do
		[ -d "${ldir}/${i}" ] && places="${places} ${ldir}/${i}"
	    done
	fi
	for i in $progs ; do
		# full pathnames are just listed
		[ -f "$i" ] && echo $i && continue
		find ${places} -maxdepth 3 -type f -name ${i} | head -1
	done
	# use maxdepth 3 because some libs are way down
}

# Populate the memory filesystem with binaries and non-variable
# configuration files.
# First do an mtree pass, then create directory links and device entries,
# then run crunchgen etc. to build the binary and create links.
# Then copy the specific/generic mfs_tree.
# Finally, if required, make a copy of the floppy.tree onto /fd

populate_mfs_tree() {
    local i j a dst MFS_TREE

    log "populate_mfs_tree()"
    dst=${BUILDDIR}/mfs.tree
    rm -rf ${dst} || true	# clean relics from old compilations.
    mkdir ${dst}		# create a fresh tree

    log "pwd=`pwd`, Populating MFS tree..."

    # use type-specific mfs.mtree, default to generic one.
    a=${MY_TREE}/mfs.mtree
    [ -f ${a} ] || a=${PICO_TREE}/build/mfs.mtree
    log "Running mtree using $a..."
    mtree -deU -f $a -p ${dst} > /dev/null || fail $? mtree

    # Create symlinks using relative pathnames, so it is possible
    # to follow them also when building the image.
    # Note that names in STAND_LINKS should not have a leading /
    for i in ${STAND_LINKS}; do
	j=`echo $i | sed -E 's:^[^/]+::;s:/[^/]+:../:g'`
	ln -s ${j}stand ${dst}/$i
    done
    ln -s ../../dev/null ${dst}/var/run/log
    ln -s ../../../etc/termcap ${dst}/usr/share/misc/termcap

    ### now build the crunched binaries ###
    (
    cd ${BUILDDIR}/crunch
    log "Making and installing crunch1 from `pwd` src ${SRC}..."
    a=${BUILDDIR}/crunch1.conf
    ( export BUILDDIR SRC MY_TREE PICO_OBJ ;
	${BINMAKE} \
		-v -f ${PICO_TREE}/build/Makefile.conf ${BUILDDIR}/crunch.mk )
    log "Libs are ${LIBS} "
    export SRC # used by crunch.mk
    # export LIBS CFLAGS
    log "Now make -f crunch.mk"
    ${BINMAKE} ${o_makeopts} -f ${BUILDDIR}/crunch.mk
    strip --remove-section=.note --remove-section=.comment crunch1
    mv crunch1 ${dst}/stand/crunch
    chmod 555 ${dst}/stand/crunch
    log "Making links for binaries..."
    for i in `crunchgen -l $a` ; do
	ln ${dst}/stand/crunch ${dst}/stand/${i};
    done
    # rm $a # do not remove!
    ) || fail $? crunch

    if [ -f ${dst}/stand/sshd ] ; then
	log "Setting up host key for sshd:"
	if [ -f ${BUILDDIR}/floppy.tree/etc/ssh_host_key.gz ] ; then
	    log "Using existing host key"
	else
	    log "Generating new host key" 
	    ssh-keygen -t rsa1 -f ${BUILDDIR}/floppy.tree/etc/ssh_host_key \
		 -N "" -C "root@@picobsd"
	    gzip -9 ${BUILDDIR}/floppy.tree/etc/ssh_host_key* || true
	fi
    fi

    log "Copy generic and site-specific MFS tree..."
    for MFS_TREE in ${PICO_TREE}/mfs_tree ${MY_TREE}/mfs_tree ; do
	if [ -d ${MFS_TREE} ] ; then
	    log "Copy ${MFS_TREE} ..."
	    (cd ${MFS_TREE} ; tar -cf - --exclude CVS --exclude .svn . ) | \
		    (cd ${dst} ; tar x${o_tarv}f - )
	fi
    done

    if [ -f ${MY_TREE}/buildtree.mk ] ; then
	log "building local floppy tree"
	${BINMAKE} -C ${dst} -f ${MY_TREE}/buildtree.mk mfs.tree
    fi

    if [ "${o_all_in_mfs}" = "yes" ]; then
	log "Copy generic floppy_tree into MFS..."
	# ignore failure in case the floppy is empty
	cp -Rp ${BUILDDIR}/floppy.tree/* ${dst}/fd || true
    fi

    # 4.x compatibility - create device nodes
    if [ -n "${o_no_devfs}" ] ; then
	# create device entries using MAKEDEV
	(cd ${dst}/dev
	ln -s ${SRC}/etc/MAKEDEV ; chmod 555 MAKEDEV
	# log `pwd`
	sh ./MAKEDEV ${MY_DEVS}
	rm MAKEDEV
	)
    fi
    if [ "`id -u`" = "0" ] ; then
	log "Fixing permissions"
	(cd ${dst}; chown -R root . )
    fi

    log "for a shared 'crunch' take libraries and dynamic loader as well"
    find_progs ${dst}/stand/crunch
    if [ -n "${u_libs}" ] ; then
	mkdir -p ${dst}/lib && cp -p ${u_libs} ${dst}/lib
	mkdir -p ${dst}/libexec
        create_includes_and_libraries2 libexec/rtld-elf
        find_progs ld-elf.so.1 && cp -p ${u_progs} ${dst}/libexec
    fi

    [ -n "${copy_files}" ] && do_copyfiles ${dst} copy_files
    do_copyfiles_user ${dst} || true
    [ -n "${links}" ] && do_links ${dst} links
    strip ${dst}/libexec/* ${dst}/lib/* ${dst}/stand/* 2> /dev/null || true

    # The 'import_files' mechanism is deprecated, as it requires
    # root permissions to follow the symlinks, and also does
    # not let you rename the entries.
    if [ -n "${import_files}" ] ; then
	log "importing ${import_files} into mfs"
	# We do it in a chroot environment on the target so
	# symlinks are followed correctly.
	# Make sure we have a statically linked tar there.
	mkdir -p ${dst}/rescue
	cp /rescue/tar ${dst}/rescue
	(cd ${l_usrtree}/.. ; tar cf - ${import_files} ) | \
	    (chroot ${dst} /rescue/tar xPf - )
	rm -rf ${dst}/rescue
    fi

    # final step -- build the mfs image
    (cd ${BUILDDIR}
	# override the owner
	echo "/set uid=0 gid=0" > mtree.out
	mtree -ic -p ${dst} -k "" >> mtree.out
	log "mtre.out at ${BUILDDIR}/mtree.out"
	makefs -t ffs -o bsize=4096 -o fsize=512 \
		-s ${MFS_SIZE}k -f 1000 -F mtree.out ${c_fs} ${dst}
	ls -l ${c_fs} )
    log "done mfs image"
}

final_cleanup() {
    log "final_cleanup()"
    rm -rf ${c_mnt} ${c_reply} 2> /dev/null || true
}

# fail errno errcode
# This function is used to trap errors and print msgs
#
fail() {
    local errno errocode where

    errno=$1
    errcode=$2
    where=$3
    echo "---> fail: Error <${errno}> error code <${errcode}> in <${where}>"
    case ${errcode} in
    mtree)
	echo "Error while making hierarchy in ${c_mnt}"
	;;
    crunch)
	echo "Error while building ${name}."
	;;
    missing_kernel)
	echo "Error: you must build PICOBSD${suffix} kernel first"
	;;
    includes)
	echo "Error: failed while making includes"
	;;
    libraries)
	echo "Error: failed while making libraries"
	;;
    bad_type)
	echo "Error: unknown floppy type ${name}"
	;;
    no_space)
	echo "Error: no space left on device (${where})"
	;;
    no_mfs)
	echo "Error: while writing MFS into the kernel."
	;;
    "")
	echo "User break"
	errcode="userbreak"
	;;
    *)
	echo "unknown error, maybe user break: $errno $errcode"
	;;
    esac
    echo "---> Aborting $0"
    # try to cleanup the vnode.
    final_cleanup
    exit 2
}

fill_floppy_image() {
    local blocks dst mfs_start mfs_end mfs_size img_size

    log "fill_floppy_image()"
    dst=${c_mnt}	# where to create the image

    log "Preparing ${fd_size}kB floppy filesystem..."

    # correct blocks according to size.
    blocks=${fd_size};
    if [ "${blocks}" = "1720" ]; then
	blocks=1722
    elif [ "${blocks}" = "1480" ]; then
	blocks=1476
    fi

    log "Labeling floppy image"

    dst=${BUILDDIR}/image.tree
    rm -rf ${dst}
    mkdir -p ${dst}
    (
    cd ${BUILDDIR}
    set 0 0 # reset variables
    # $1 takes the offset of the MFS filesystem
    set `strings -at d kernel | grep "MFS Filesystem goes here"`
    mfs_start=$1
    set 0 0 # reset variables
    set `strings -at d kernel | grep "MFS Filesystem had better"`
    mfs_end=$1
    mfs_size="$((${mfs_end} - ${mfs_start}))"
    set -- `ls -l ${c_fs}`; imgsize="$5"
    if [ ${mfs_start} -gt 0 -a ${mfs_size} -ge ${imgsize} ] ; then
	mfs_ofs=$((${mfs_start} + 8192))
	log "Preload kernel with file ${c_fs} at ${mfs_ofs}"
	log "`ls -l ${c_fs}` to fit in ${mfs_size}"
	dd if=${c_fs} ibs=8192 iseek=1 of=kernel obs=${mfs_ofs} \
	    oseek=1 conv=notrunc # 2> /dev/null
    else
    	log "not loading mfs, size ${mfs_size} img ${imgsize}"
    fi
    log "Compress with kgzip and copy to floppy image"

	mkdir -p  ${dst}/boot/kernel
    # XXX update loader.conf
	echo "hint.acpi.0.disabled=\"1\"" > ${dst}/boot/loader.conf
	echo "console=\"comconsole\"" >> ${dst}/boot/loader.conf
	cp -p /boot/loader ${dst}/boot/loader || fail $? no_space "copying bootloader"
    gzip -c kernel > ${dst}/boot/kernel/kernel.gz || fail $? no_space "copying kernel"

    # now transfer the floppy tree. If it is already in mfs, dont bother.
    if [ "${o_all_in_mfs}" != "yes" ] ; then
	log "Now transfer floppy tree if not already in MFS image"
	cp -Rp floppy.tree/* ${dst} || \
		fail $? no_space "copying floppy tree"
    fi
    )

    # add local manipulation to the image
    if [ -f ${MY_TREE}/buildtree.mk ] ; then
	${BINMAKE} -C ${dst} -f ${MY_TREE}/buildtree.mk image.tree
    fi

    log "image used `du -s ${dst}` of ${blocks}k"
    if [ "${generate_iso}" = "YES" ]; then
	logverbose "generate_iso ${generate_iso}"
	# build_iso_image	# XXX not implemented yet
	(cd ${BUILDDIR}
	cp -p /boot/cdboot ${dst}/boot || fail $? no_space "copying cdboot"
	mkisofs -b boot/cdboot -no-emul-boot -J -r -ldots -l -L \
		-o ${c_iso} ${dst}
	)
    fi

    (cd ${BUILDDIR}
    makefs -t ffs -o bsize=4096 -o fsize=512 \
	-s ${blocks}k -f 50 ${c_img} ${dst}

    ${c_label} -w -f `pwd`/${c_img} auto # write in a label
    # copy partition c: into a: with some sed magic
    ${c_label} -f `pwd`/${c_img} | sed -e '/  c:/{p;s/c:/a:/;}' | \
	${c_label} -R -f `pwd`/${c_img} /dev/stdin
    ${c_label} -f `pwd`/${c_img}

    ls -l ${c_img}
    ${c_label} -f `pwd`/${c_img}
    log "after disklabel"
    )

    echo "BUILDDIR ${BUILDDIR}"

    # dump the primary and secondary boot
    # XXX primary is 512 bytes
    dd if=${c_boot1} of=${BUILDDIR}/${c_img} conv=notrunc 2>/dev/null
    # XXX secondary starts after the 0x114 = dec 276 bytes of the label
    # so we skip 276 from the source, and 276+512=788 from dst
    # the old style blocks used 512 and 1024 respectively

    dd if=${c_boot2} iseek=1 ibs=276 2> /dev/null | \
	dd of=${BUILDDIR}/${c_img} oseek=1 obs=788 conv=notrunc 2>/dev/null
    log "done disk image"
    # XXX (log "Fixing permissions"; cd ${dst}; chown -R root *)
    # leave build stuff if verbose
    [ ${o_verbose} -gt 0 ] && return

    rm -rf ${BUILDDIR}/floppy.tree || true # cleanup
    # df -ik ${dst} | colrm 70 > .build.reply
    rm -rf ${dst}
    rm ${BUILDDIR}/${c_fs}
    # rm ${BUILDDIR}/kernel.gz
}

# This function creates variables which depend on the source tree in use:
# SRC, l_usrtree, l_objtree
# Optionally creates libraries, includes and the like (for cross compiles,
# needs to be done once).

set_build_parameters() {
    if [ "${SRC}" = "/usr/src" ] ; then
	l_usrtree=${USR:-/usr}
    else
	l_usrtree=${USR:-${SRC}/../usr}
    fi
    l_objtree=${l_usrtree}/obj-pico-${o_arch}

    PICO_TREE=${PICO_TREE:-${SRC}/release/picobsd}
    set `grep "#define[\t ]__FreeBSD_version" ${SRC}/sys/sys/param.h`
    OSVERSION=$3
    log "OSVERSION is ${OSVERSION}"
    if [ ${OSVERSION} -ge 500035 ] ; then
	export MAKEOBJDIRPREFIX=${l_objtree}
	export TARGET_ARCH=${o_arch} TARGET=${o_arch}
	# XXX why change machine_arch ?
	#-- export MACHINE_ARCH=`uname -m` MACHINE=`uname -m`
	# export CWARNFLAGS="-Wextra -Wno-sign-compare -Wno-missing-field-initializers"
	eval "export BINMAKE=\"`cd ${SRC}; make -f Makefile -V BINMAKE`\""
    fi

    if [ "${o_init_src}" != "" ] ; then
	if [ ${OSVERSION} -lt 500035 ] ; then
	    create_includes_and_libraries
	else
	    create_includes_and_libraries2
	fi
    else
	eval export `cd ${SRC}; ${BINMAKE} -f Makefile.inc1 -V WMAKEENV`
    fi
    if [ ${OSVERSION} -lt 500035 ] ; then
	# Create the right LIBS and CFLAGS for further builds.
	# and build the config program
	LIBS="-L${l_usrtree}/lib"
	CFLAGS="-nostdinc -I${l_usrtree}/include"
	export LIBS CFLAGS
	CONFIG=${l_usrtree}/sbin/config
	export CONFIG
    fi

    # if we have o_objdir, find where bin/ is
    if [ ! -z "${o_objdir}" ] ; then
	if [ -d ${o_objdir}/bin ] ; then
	    # fine
	elif [ -d "${o_objdir}${SRC}/bin" ] ; then
	    o_objdir="${o_objdir}${SRC}"
	    log "Changing objdir to ${o_objdir}"
	else
	    log "Cannot find objdir in ${o_objdir}, sorry"
	    o_objdir=""
	fi
    fi
}

#-------------------------------------------------------------------
# Main entry of the script. Initialize variables, parse command line
# arguments.

# o_par="-j 8"	# parallel make and other make options

set_defaults
while [ true ]; do
    log "Parsing $1"
    case $1 in
    --par)
	o_par="-j 8"
	;;

    --src)	# set the source path instead of /usr/src
	SRC=`realpath $2`
	shift
	;;

    --init)	# run a partial buildworld on the source tree
	o_init_src="YES"
	;;

    --arch)	# override the target architecture
	o_arch=$2
	shift
	;;

    --floppy_size)	# image size
	fd_size=$2
	shift
	;;

    --all_in_mfs)
	o_all_in_mfs="yes"
	;;

    --no_all_in_mfs)
	o_all_in_mfs="no"
	;;

    --modules)	# also build kernel modules
	o_do_modules="yes"
	;;

    -n)
	o_interactive="NO"
	;;

    -clear|-clean|-c) # clean
	o_clean="YES"
	o_interactive="NO"
	;;

    -v) # need -v -v to wait for user input
	o_verbose=$((${o_verbose}+1))	# verbose level
	o_tarv="v"			# tar verbose flag
	o_makeopts="-d l" # be verbose
	;;

    --iso) # generate iso image
	generate_iso="YES"
	;;

    --cfg) # read additional config from this file
	o_additional_config=`realpath $2`
	shift
	;;

    --objdir)	# Place with results of a previous buildworld
		# useful if you want to copy shared binaries and libs
	o_objdir=`realpath $2`
	shift
	;;

    *)
	break
	;;

    esac
    shift
done

set_build_parameters	# things that depend on ${SRC}
set_type $1 $2		# type and site, respectively

[ "${o_interactive}" != "NO" ] && main_dialog

if [ "${o_clean}" = "YES" ] ; then
    clean_tree
else
    build_image
    do_install
fi
final_cleanup
exit 0
@


1.64
log
@Switching exporter and resync
@
text
@d3 1
a3 1
# $FreeBSD: head/release/picobsd/build/picobsd 239738 2012-08-27 16:42:32Z luigi $
d448 2
d978 1
@


1.63
log
@SVN rev 239738 on 2012-08-27 16:42:32Z by luigi

use MALLOC_PRODUCTION for picobsd builds, be more frugal in memory usage.
@
text
@d3 1
a3 1
# $FreeBSD$
@


1.62
log
@SVN rev 234983 on 2012-05-03 20:50:55Z by luigi

Omit clang when building picobsd, it takes way too long.
Also note that loader.conf support is incomplete.
@
text
@d10 2
d169 1
a169 1
	no="$no -DWITHOUT_CLANG"
@


1.61
log
@SVN rev 229532 on 2012-01-04 23:00:25Z by luigi

now picobsd cross builds work (tried with host amd64, target i386 ).
The fix involved adding a proper build of ld-elf.so.1 ,
and also replacing ldd with objdump (suggested by Garrett Cooper)
to build the list of shared libraries needed by the binaries
and libraries on the target.
@
text
@d167 1
d886 1
a886 1
    # XXX update loader.conf
@


1.60
log
@SVN rev 229511 on 2012-01-04 19:37:25Z by luigi

remove some stale options (such as running without /boot/loader)

improve support for multi-arch and cross-arch builds, by adding
a suffix to the kernel config file and build_directory.
(cross builds not clean yet, a cross-built kernel boots
but fails when starting /sbin/init)
@
text
@d164 1
a164 1
    log "create_includes_and_libraries2() for ${SRC}"
a169 2
    MAKEOBJDIRPREFIX=${l_objtree}
    export MAKEOBJDIRPREFIX
d175 2
d554 1
a554 1
# Called as "find_progs [-L libpath] [-P binpath] prog1 prog2 ... "
d577 1
a577 4
	local i
	local oo=${o_objdir:-${_SHLIBDIRPREFIX}} # default objdir
	local lp=$oo/lib			# default lib.prefix
	local o=""				# additional objdir
d579 1
a579 3
		o=$2; shift; shift
		lp="$lp:$o/lib:$o/usr/lib:$o/usr/local/lib"
		o="-P $o"
d581 2
a582 3
	u_libs=""
	u_progs="`find_progs_helper $*`"
	log "looking for libs for <$u_progs> in $lp"
d584 19
a602 5
	i="`( LD_LIBRARY_PATH=$lp ldd ${u_progs} ) | \
		grep -v '^/' | awk '{print $1}' | sort | uniq`"
	u_libs="`find_progs_helper $o $i`"
	log "--- done find_progs ---"
	return 0
@


1.59
log
@SVN rev 227878 on 2011-11-23 12:05:39Z by luigi

some tweaks to build picobsd for different architectures.
@
text
@a107 5
    o_use_loader="yes"		# use /boot/loader
	# You should not change it unless you are really short
	# of space, and your kernel is small enough that the
	# bootblocks manage to load it.

d177 11
a187 1
	${BINMAKE} ${o_par} _+_= $no toolchain _includes _libraries
d250 6
a255 2
	[ -d $i -a -f $i/PICOBSD -a -f $i/crunch.conf ] || continue
	set -- `cat $i/PICOBSD | \
d258 1
a258 2
	MFS_SIZE=$1 ; init_name=$2
	mfs_inodes=$3 ; fd_inodes=$4
d262 1
a262 1
	BUILDDIR=${c_startdir}/build_dir-${name}
a338 1
	I "Init type: ${init_name}" \
a339 2
	M "MFS bytes per inode: ${mfs_inodes}" \
	U "UFS bytes per inode: ${fd_inodes}" \
a356 6
    I)
	{ dialog --menu "Choose your init(8) program" \
	10 70 2 init "Standard init (requires getty)" \
	oinit "small init from TinyWare" 2> ${c_reply} \
		&& init_name=`cat ${c_reply}` ; } || true
	;;
a387 14
    M)
	{ dialog --title "MFS bytes per inode:" --inputbox \
	"Enter MFS bytes per inode (typically 4096..65536). \
	A larger value means fewer inodes but more space on MFS" \
	10 70 2> ${c_reply} && mfs_inodes=`cat ${c_reply}`  ; } || true
	;;

    U)
	{ dialog --title "Floppy bytes per inode:" --inputbox \
	"Enter floppy bytes per inode (typically 3072..65536). \
	A larger value means fewer inodes but more space on the floppy." \
	10 70 2> ${c_reply} && fd_inodes=`cat ${c_reply}` ; } || true
	;;

d442 3
a444 2
	${BINMAKE} ${o_par} -v -f ${PICO_TREE}/build/Makefile.conf ) || \
	fail $? missing_kernel
d593 1
d627 5
a632 1
	find ${places} -maxdepth 3 -type f \( ${names} \)
a781 1
    rm -f ${c_reply}
a849 11
    b2=${BUILDDIR}/boot2 # modified boot2
    cp -f ${c_boot2} ${b2}
    chmod 0644 ${b2}

    if [ ${o_use_loader} = "no" ] ; then
	log "patch ${c_boot2} to boot /kernel right away"
	set `strings -at d ${b2} | grep "/boot/loader"`
	echo -e "/kernel\0\0\0\0\0" | \
	    dd of=${b2} obs=$1 oseek=1 conv=notrunc 2>/dev/null
    fi
    chmod 0444 ${b2}
d875 7
a881 11
    if [ ${o_use_loader} = "no" ] ; then
	kgzip -o kernel.gz kernel
	cp -p kernel.gz ${dst}/kernel || fail $? no_space "copying kernel"
    else
        gzip kernel
	mkdir -p  ${dst}/boot/kernel
	echo "hint.acpi.0.disabled=\"1\"" > ${dst}/boot/loader.conf
	echo "console=\"comconsole\"" >> ${dst}/boot/loader.conf
	cp -p /boot/loader ${dst}/boot/loader || fail $? no_space "copying bootloader"
	cp -p kernel.gz ${dst}/boot/kernel/kernel.gz || fail $? no_space "copying kernel"
    fi
d931 1
a931 1
    dd if=${b2} iseek=1 ibs=276 2> /dev/null | \
d935 3
d965 2
a968 1
	eval export `cd ${SRC}; ${BINMAKE} -f Makefile.inc1 -V WMAKEENV`
d977 2
d1014 4
d1022 2
a1023 1
    --init)
d1027 1
a1027 1
    --arch)
d1032 1
a1032 1
    --floppy_size)
a1036 5
    --no_loader)	# omit /boot/loader, just rely on boot2
			# (it may have problems with kernels > 4MB)
	o_use_loader="no"
	;;

d1048 1
@


1.58
log
@SVN rev 218359 on 2011-02-05 23:03:40Z by luigi

following the recent (218130) changes to Makefile and Makefile.inc1,
we need to set TARGET and TARGET_ARCH to get a correct WMAKEENV.
I am setting both to i386 since this is what picobsd is used for,
though there might be a better fix.

Add initial support for parallel make. This is disabled right now,
because there are incorrect dependencies somewhere which require
to run picobsd 2-3 times to complete a build.

MFC after:	2 weeks
@
text
@d70 1
a70 1
# l_objtree points to the obj tree. Normally ${l_usrtree}/obj-pico
d124 1
d455 1
d978 1
a978 1
    l_objtree=${l_usrtree}/obj-pico
d986 2
a987 1
	export TARGET_ARCH=i386 TARGET=i386
d1041 5
@


1.58.2.1
log
@SVN rev 225736 on 2011-09-23 00:51:37Z by kensmith

Copy head to stable/9 as part of 9.0-RELEASE release cycle.

Approved by:	re (implicit)
@
text
@@


1.58.2.2
log
@SVN rev 230009 on 2012-01-12 11:08:21Z by luigi

merge from head: support for building cross-arch versions of picobsd
@
text
@d70 1
a70 1
# l_objtree points to the obj tree. Normally ${l_usrtree}/obj-pico-${o_arch}
d108 5
a123 1
    o_arch=`uname -m`		# default to amd64 or i386 ...
d168 1
a168 1
    log "create_includes_and_libraries2() for ${SRC} $1"
d174 2
d181 1
a181 13
	MAKEOBJDIRPREFIX=${l_objtree}
	export MAKEOBJDIRPREFIX
	# export WITH_RESCUE=yes	# build crunchide
	# ${BINMAKE} ${o_par} _+_= $no toolchain _includes _libraries
	(
	    # eval export `cd ${SRC}; ${BINMAKE} -f Makefile.inc1 -V BMAKEENV`
	    eval "export XMAKE=\"`cd ${SRC}; make -f Makefile -V XMAKE`\""
	    ${BINMAKE} ${o_par} _+_= $no toolchain
	)
        eval export `cd ${SRC}; ${BINMAKE} -f Makefile.inc1 -V WMAKEENV`
	${BINMAKE} ${o_par} _+_= $no _includes _libraries
	[ ${o_arch} != `uname -m` ] && \
	    (cd ${l_objtree}; ln -s . ${o_arch}.${o_arch} || true )
d244 2
a245 6
	[ -d $i -a -f $i/crunch.conf ] || continue
	# look for a kernel config file, privilege arch-specific
	l_kernconf=$i/PICOBSD.${o_arch}
	[ -f $l_kernconf ] || l_kernconf=$i/PICOBSD
	[ -f $l_kernconf ] || continue
	set -- `cat $l_kernconf | \
d248 2
a249 1
	MFS_SIZE=$1
d253 1
a253 1
	BUILDDIR=${c_startdir}/build_dir-${name}-${o_arch}
d330 1
d332 2
d351 6
d388 14
a453 1
	export WARNS CWARNFLAGS
d455 1
a455 2
	${BINMAKE} ${o_par} KERNCONF=${l_kernconf}	\
		-v -f ${PICO_TREE}/build/Makefile.conf ) || \
d566 1
a566 1
# Called as "find_progs [[-L libpath] [-P binpath]] prog1 prog2 ... "
d589 4
a592 1
	local pass i old_libs="" tmp o=""
d594 3
a596 1
		o="-P $2"; shift; shift
d598 3
a600 2
	# Result returned in global variables
	u_libs="" ; u_progs="`find_progs_helper $*`"
d602 3
a604 10
	# use objdump to find libraries. Iterate to fetch recursive
	# dependencies.
	tmp="${u_progs}" ; pass=1
	while [ $pass -lt 10 ] ; do
		pass=$(($pass + 1))
		i="`objdump -x ${tmp} | \
			awk '$1 == "NEEDED" { print $2 }' | sort | uniq`"
		if [ "$old_libs" = "$i" ] ; then
			log "libraries for: $my_progs ($u_progs) are ($i) $u_libs"
			log "--- done find_progs ---"
a605 8
		else
			# logverbose "old--- $old_libs --- new +++ $i +++"
		fi
		u_libs="`find_progs_helper $o $i`"
		old_libs="$i"
		tmp="$tmp $u_libs"
	done
	log "WARNING: Too many passes, giving up"
a637 5
	for i in $progs ; do
		# full pathnames are just listed
		[ -f "$i" ] && echo $i && continue
		find ${places} -maxdepth 3 -type f -name ${i} | head -1
	done
d639 1
d789 1
d858 11
d894 5
a898 1

a899 1
    # XXX update loader.conf
d903 2
a904 1
    gzip -c kernel > ${dst}/boot/kernel/kernel.gz || fail $? no_space "copying kernel"
d954 1
a954 1
    dd if=${c_boot2} iseek=1 ibs=276 2> /dev/null | \
a957 3
    # leave build stuff if verbose
    [ ${o_verbose} -gt 0 ] && return

d976 1
a976 1
    l_objtree=${l_usrtree}/obj-pico-${o_arch}
d984 1
a984 4
	export TARGET_ARCH=${o_arch} TARGET=${o_arch}
	# XXX why change machine_arch ?
	#-- export MACHINE_ARCH=`uname -m` MACHINE=`uname -m`
	# export CWARNFLAGS="-Wextra -Wno-sign-compare -Wno-missing-field-initializers"
d986 1
a994 2
    else
	eval export `cd ${SRC}; ${BINMAKE} -f Makefile.inc1 -V WMAKEENV`
a1029 4
    --par)
	o_par="-j 8"
	;;

d1034 1
a1034 2

    --init)	# run a partial buildworld on the source tree
d1038 2
a1039 2
    --arch)	# override the target architecture
	o_arch=$2
d1043 3
a1045 3
    --floppy_size)	# image size
	fd_size=$2
	shift
a1058 1

@


1.58.2.3
log
@SVN rev 237536 on 2012-06-24 17:02:28Z by luigi

partial MFC. Mostly, do not build clang when initializing picobsd
@
text
@a166 1
	no="$no -DWITHOUT_CLANG"
d444 1
a444 1
	    fail $? missing_kernel
d594 1
a594 1
			return 0
d884 1
a884 1
    mkdir -p  ${dst}/boot/kernel
d886 3
a888 3
    echo "hint.acpi.0.disabled=\"1\"" > ${dst}/boot/loader.conf
    echo "console=\"comconsole\"" >> ${dst}/boot/loader.conf
    cp -p /boot/loader ${dst}/boot/loader || fail $? no_space "copying bootloader"
@


1.58.2.4
log
@## SVN ##
## SVN ## Exported commit - http://svnweb.freebsd.org/changeset/base/ 242902
## SVN ## CVS IS DEPRECATED: http://wiki.freebsd.org/CvsIsDeprecated
## SVN ##
## SVN ## ------------------------------------------------------------------------
## SVN ## r242902 | dteske | 2012-11-11 23:29:45 +0000 (Sun, 11 Nov 2012) | 10 lines
## SVN ##
## SVN ## Fix a regression introduced by SVN r211417 that saw the breakage of a feature
## SVN ## documented in usr.sbin/sysinstall/help/shortcuts.hlp (reproduced below):
## SVN ##
## SVN ## If /usr/sbin/sysinstall is linked to another filename, say
## SVN ## `/usr/local/bin/configPackages', then the basename will be used
## SVN ## as an implicit command name.
## SVN ##
## SVN ## Reviewed by:	adrian (co-mentor)
## SVN ## Approved by:	adrian (co-mentor)
## SVN ##
## SVN ## ------------------------------------------------------------------------
## SVN ##
@
text
@d3 1
a3 1
# $FreeBSD: stable/9/release/picobsd/build/picobsd 237536 2012-06-24 17:02:28Z luigi $
@


1.58.2.5
log
@## SVN ## Exported commit - http://svnweb.freebsd.org/changeset/base/250596
## SVN ## CVS IS DEPRECATED: http://wiki.freebsd.org/CvsIsDeprecated
@
text
@d3 1
a3 1
# $FreeBSD: stable/9/release/picobsd/build/picobsd 250596 2013-05-13 12:43:03Z luigi $
d176 9
a184 3
	export MAKEOBJDIRPREFIX=${l_objtree}
	make ${o_par} $no toolchain
	# XXX do we need any of these ?
d186 1
d443 1
a443 2
	# kernel build not parallelizable yet
	${BINMAKE} KERNCONF=${l_kernconf}	\
a973 1
	export WITHOUT_CLANG_IS_CC=1
@


1.58.2.6
log
@## SVN ## Exported commit - http://svnweb.freebsd.org/changeset/base/257766
## SVN ## CVS IS DEPRECATED: http://wiki.freebsd.org/CvsIsDeprecated
@
text
@d3 1
a3 1
# $FreeBSD: stable/9/release/picobsd/build/picobsd 257766 2013-11-06 22:35:23Z luigi $
a9 2
# CWARNFLAGS can be used to pass -Wall or similar options
#
d167 1
a167 1
	no="$no -DMALLOC_PRODUCTION"
d438 1
a438 1
		-f ${PICO_TREE}/build/Makefile.conf ) || \
d678 1
a678 1
		-f ${PICO_TREE}/build/Makefile.conf ${BUILDDIR}/crunch.mk )
d694 4
a697 4
    log "Setting up host key for sshd:"
    for K in rsa1 rsa dsa ; do
	if [ $K = rsa1 ] ; then
	    i=ssh_host_key
d699 4
a702 1
	    i=ssh_host_${K}_key
d704 1
a704 9
	if [ -f ${BUILDDIR}/floppy.tree/etc/$i.gz ] ; then
	    log "Using existing host key $i"
	else
	    log "Generating new host key $i" 
	    ssh-keygen -t $K -f ${BUILDDIR}/floppy.tree/etc/$i \
		     -N "" -C "root@@picobsd"
	    gzip -9 ${BUILDDIR}/floppy.tree/etc/${i}* || true
	fi
    done
d880 4
a883 6
    # XXX loader.conf does not work unless we also load the .4th files
    # echo "hint.acpi.0.disabled=\"1\"" > ${dst}/boot/loader.conf
    # echo "console=\"comconsole\"" >> ${dst}/boot/loader.conf
    local blf="loader* *.4th" # loader.rc loader.4th support.4th"
    (cd /boot; cp -p loader ${dst}/boot) || fail $? no_space "copying bootloader"
    cp ${MY_TREE}/floppy.tree/boot/loader.conf ${dst}/boot || true
d968 1
a968 7
	# XXX 20131001 see if CLANG fixes the build
	export WITHOUT_CLANG_IS_CC=yes
	export WITH_GCC=yes
	export WITH_GNUCXX=yes
	export WITHOUT_CLANG=yes
	export WITHOUT_ICONV=yes

a971 1
	# XXX BINMAKE does not really exist anymore
a972 2
	[ "$BINMAKE" = "" ] && \
	   eval "export BINMAKE=\"`cd ${SRC}; make -f Makefile -V SUB_MAKE`\""
@


1.58.2.7
log
@## SVN ## Exported commit - http://svnweb.freebsd.org/changeset/base/262762
## SVN ## CVS IS DEPRECATED: http://wiki.freebsd.org/CvsIsDeprecated
@
text
@d3 1
a3 1
# $FreeBSD: stable/9/release/picobsd/build/picobsd 262762 2014-03-05 00:48:11Z gjb $
d477 1
a477 1
	    (cd ${FLOPPY_TREE} ; tar -cf - \
d717 1
a717 1
	    (cd ${MFS_TREE} ; tar -cf - --exclude .svn . ) | \
@


1.58.2.3.2.1
log
@SVN rev 239080 on 2012-08-05 23:54:33Z by kensmith

Copy stable/9 to releng/9.1 as part of the 9.1-RELEASE release process.

Approved by:	re (implicit)
@
text
@@


1.58.2.3.2.2
log
@Switch importer
@
text
@d3 1
a3 1
# $FreeBSD: releng/9.1/release/picobsd/build/picobsd 237536 2012-06-24 17:02:28Z luigi $
@


1.58.2.1.2.1
log
@SVN rev 227445 on 2011-11-11 04:20:22Z by kensmith

Copy stable/9 to releng/9.0 as part of the FreeBSD 9.0-RELEASE release
cycle.

Approved by:	re (implicit)
@
text
@@


1.58.2.1.2.2
log
@Switch importer
@
text
@d3 1
a3 1
# $FreeBSD: releng/9.0/release/picobsd/build/picobsd 218359 2011-02-05 23:03:40Z luigi $
@


1.57
log
@SVN rev 215177 on 2010-11-12 12:48:41Z by luigi

move the initialization of BINMAKE earler, so it is
available throughout the entire build process.

Submitted by:	Matteo Landi
MFC after:	3 days
@
text
@d179 1
a179 1
	cd $1 ; ${BINMAKE} $2	# specific target, e.g. ld-elf.so
d181 1
a181 1
	${BINMAKE} _+_= $no toolchain _includes _libraries
d455 1
a455 1
	${BINMAKE} -v -f ${PICO_TREE}/build/Makefile.conf ) || \
d984 1
d1024 2
@


1.56
log
@SVN rev 213252 on 2010-09-28 22:30:11Z by luigi

use make from the toolchain, as the source tree may depend on
specific features (e.g. on recent HEAD, rtld fails with older 'make')

MFC after:	3 days
@
text
@a299 5
    if [ ${OSVERSION} -ge 500035 ] ; then
	export MAKEOBJDIRPREFIX=${l_objtree}
	eval "export BINMAKE=\"`cd ${SRC}; make -f Makefile -V BINMAKE`\""
	eval export `cd ${SRC}; ${BINMAKE} -f Makefile.inc1 -V WMAKEENV`
    fi
d977 1
d982 6
@


1.55
log
@SVN rev 203877 on 2010-02-14 15:55:30Z by luigi

use log instead of logverbose in three places so the build won't need
input to run to completion

MFC after:	3 days
@
text
@d179 1
a179 1
	cd $1 ; make $2	# specific target, e.g. ld-elf.so
d181 1
a181 1
	make _+_= $no toolchain _includes _libraries
@


1.54
log
@SVN rev 201073 on 2009-12-28 01:02:45Z by luigi

clear leftover from previous computations
@
text
@d892 1
a892 1
	logverbose "`ls -l ${c_fs}` to fit in ${mfs_size}"
d947 1
a947 1
    logverbose "after disklabel"
d961 1
a961 1
    logverbose "done floppy image"
@


1.53
log
@SVN rev 201072 on 2009-12-28 00:51:00Z by luigi

more support to import files and libraries from the host.
@
text
@d603 1
@


1.52
log
@SVN rev 201059 on 2009-12-27 21:13:53Z by luigi

fix a typo (not that it matters)
@
text
@d571 2
a572 1
# Sets ${u_progs} to the list of programs, and ${u_libs}
d574 6
d581 1
a581 1
# You can use it e.g. in a local configuration file by writing
d590 1
a590 1
#	cp -p ${u_progs} ${dst}/libexec
d595 8
d604 1
a604 2
	local o=${o_objdir:-${_SHLIBDIRPREFIX}}
	log "looking for libs for $u_progs in $_SHLIBDIRPREFIX"
d606 3
a608 2
	i="`LD_LIBRARY_PATH=$o/lib ldd ${u_progs} | grep -v '^/' | awk '{print $1}' | sort | uniq`"
	u_libs="`find_progs_helper $i`"
d613 5
d619 2
a620 2
	local i o places names
	local subdirs="bin sbin usr.bin usr.sbin libexec lib \
d623 3
a625 2
	names=""	# files to search
	o=""
d627 1
a627 1
		# plain programs come out verbatim
d633 1
a633 2
	places=""				# places to search
	o=${o_objdir:-${_SHLIBDIRPREFIX}/..}
d635 1
a635 1
		[ -d "${o}/${i}" ] && places="${places} ${o}/${i}"
d637 7
a643 1
	find ${places} -type f \( ${names} \)
@


1.51
log
@SVN rev 200301 on 2009-12-09 17:48:05Z by luigi

when calling ldd, use the cross libraries and not the host version

MFC after:	3 days
@
text
@d170 1
a170 1
	no="-DNO_CLEAN -DNO_PROFILE -DNO_GAMES -DNO_LIBC_R" # WITOUT_CDDL=1"
@


1.50
log
@SVN rev 194635 on 2009-06-22 16:06:38Z by luigi

fix wrong name for the iso!
@
text
@d170 1
a170 1
	no="-DNO_CLEAN -DNO_PROFILE -DNO_GAMES -DNO_LIBC_R"
d590 1
d592 1
a592 1
	i="`ldd ${u_progs} | grep -v '^/' | awk '{print $1}' | sort | uniq`"
d723 1
a723 2
    # If we are building a shared 'crunch', take the libraries
    # and the dynamic loader as well
@


1.50.2.1
log
@SVN rev 196045 on 2009-08-03 08:13:06Z by kensmith

Copy head to stable/8 as part of 8.0 Release cycle.

Approved by:	re (Implicit)
@
text
@@


1.50.2.2
log
@SVN rev 200560 on 2009-12-15 00:26:42Z by luigi

sync with head
@
text
@d170 1
a170 1
	no="-DNO_CLEAN -DNO_PROFILE -DNO_GAMES -DNO_LIBC_R" # WITOUT_CDDL=1"
a589 1
	log "looking for libs for $u_progs in $_SHLIBDIRPREFIX"
d591 1
a591 1
	i="`LD_LIBRARY_PATH=$o/lib ldd ${u_progs} | grep -v '^/' | awk '{print $1}' | sort | uniq`"
d722 2
a723 1
    log "for a shared 'crunch' take libraries and dynamic loader as well"
@


1.50.2.3
log
@SVN rev 204868 on 2010-03-08 13:37:14Z by luigi

MFC main build script and missing directory
@
text
@d170 1
a170 1
	no="-DNO_CLEAN -DNO_PROFILE -DNO_GAMES -DNO_LIBC_R" # WITHOUT_CDDL=1"
d571 1
a571 2
# Called as "find_progs [-L libpath] [-P binpath] prog1 prog2 ... "
# On return it sets ${u_progs} to the list of programs, and ${u_libs}
a572 6
# 
# '-L path' can be used to specify a search path for libraries
#    (which searches in $path/lib:$path/usr/lib:$path/usr/local/lib
# '-P binpath' can be used to specify a search path for programs
#    (which searches in a lot of places in the subtree)
# -L must be the first, followed by -P
d574 1
a574 1
# You can use it e.g. in a local confign file by writing
d583 1
a583 1
#	cp -p ${u_progs} ${dst}/libexec # ignore errors
a587 9
	local oo=${o_objdir:-${_SHLIBDIRPREFIX}} # default objdir
	local lp=$oo/lib			# default lib.prefix
	local o=""				# additional objdir
	if [ x"$1" = "x-L" -a -d "$2" ] ; then # set lib search path
		o=$2; shift; shift
		lp="$lp:$o/lib:$o/usr/lib:$o/usr/local/lib"
		o="-P $o"
	fi
	u_libs=""
d589 2
a590 1
	log "looking for libs for <$u_progs> in $lp"
d592 2
a593 3
	i="`( LD_LIBRARY_PATH=$lp ldd ${u_progs} ) | \
		grep -v '^/' | awk '{print $1}' | sort | uniq`"
	u_libs="`find_progs_helper $o $i`"
a597 5
	local dir=${o_objdir:-${_SHLIBDIRPREFIX}/..}
	local ldir=""
	if [ x"$1" = "x-P" -a -d "$2" ] ; then # set path
		ldir=$2; shift; shift
	fi
d599 2
a600 2
	local subdirs=". local/bin local/sbin local/lib local/libexec \
		bin sbin usr.bin usr.sbin libexec lib \
d603 2
a604 3
	local names=""	# files to search
	local o=""
	local i
d606 1
a606 1
		# full pathnames are just listed
d612 2
a613 1
	local places=""				# places to search
d615 1
a615 1
		[ -d "${dir}/${i}" ] && places="${places} ${dir}/${i}"
d617 1
a617 7
	if [ -n "${ldir}" ] ; then
	    for i in $subdirs ; do
		[ -d "${ldir}/${i}" ] && places="${places} ${ldir}/${i}"
	    done
	fi
	# use maxdepth 3 because some libs are way down
	find ${places} -maxdepth 3 -type f \( ${names} \)
d865 1
a865 1
	log "`ls -l ${c_fs}` to fit in ${mfs_size}"
d920 1
a920 1
    log "after disklabel"
d934 1
a934 1
    log "done disk image"
@


1.50.2.4
log
@SVN rev 215402 on 2010-11-16 17:44:09Z by luigi

sync with the version in HEAD -- use ${BINMAKE} built
by the toolchain and not the hosts's make
@
text
@d179 1
a179 1
	cd $1 ; ${BINMAKE} $2	# specific target, e.g. ld-elf.so
d181 1
a181 1
	${BINMAKE} _+_= $no toolchain _includes _libraries
d300 5
a981 1

a985 6
    if [ ${OSVERSION} -ge 500035 ] ; then
	export MAKEOBJDIRPREFIX=${l_objtree}
	eval "export BINMAKE=\"`cd ${SRC}; make -f Makefile -V BINMAKE`\""
	eval export `cd ${SRC}; ${BINMAKE} -f Makefile.inc1 -V WMAKEENV`
    fi

@


1.50.2.5
log
@SVN rev 231590 on 2012-02-13 18:10:13Z by luigi

MFC: cross-arch support for picobsd
@
text
@d70 1
a70 1
# l_objtree points to the obj tree. Normally ${l_usrtree}/obj-pico-${o_arch}
d108 5
a123 1
    o_arch=`uname -m`		# default to amd64 or i386 ...
d168 1
a168 1
    log "create_includes_and_libraries2() for ${SRC} $1"
d174 2
d179 1
a179 1
	cd $1 ; ${BINMAKE} ${o_par} $2	# specific target, e.g. ld-elf.so
d181 1
a181 13
	MAKEOBJDIRPREFIX=${l_objtree}
	export MAKEOBJDIRPREFIX
	# export WITH_RESCUE=yes	# build crunchide
	# ${BINMAKE} ${o_par} _+_= $no toolchain _includes _libraries
	(
	    # eval export `cd ${SRC}; ${BINMAKE} -f Makefile.inc1 -V BMAKEENV`
	    eval "export XMAKE=\"`cd ${SRC}; make -f Makefile -V XMAKE`\""
	    ${BINMAKE} ${o_par} _+_= $no toolchain
	)
        eval export `cd ${SRC}; ${BINMAKE} -f Makefile.inc1 -V WMAKEENV`
	${BINMAKE} ${o_par} _+_= $no _includes _libraries
	[ ${o_arch} != `uname -m` ] && \
	    (cd ${l_objtree}; ln -s . ${o_arch}.${o_arch} || true )
d244 2
a245 6
	[ -d $i -a -f $i/crunch.conf ] || continue
	# look for a kernel config file, privilege arch-specific
	l_kernconf=$i/PICOBSD.${o_arch}
	[ -f $l_kernconf ] || l_kernconf=$i/PICOBSD
	[ -f $l_kernconf ] || continue
	set -- `cat $l_kernconf | \
d248 2
a249 1
	MFS_SIZE=$1
d253 1
a253 1
	BUILDDIR=${c_startdir}/build_dir-${name}-${o_arch}
d330 1
d332 2
d351 6
d388 14
a453 1
	export WARNS CWARNFLAGS
d455 1
a455 2
	${BINMAKE} ${o_par} KERNCONF=${l_kernconf}	\
		-v -f ${PICO_TREE}/build/Makefile.conf ) || \
d566 1
a566 1
# Called as "find_progs [[-L libpath] [-P binpath]] prog1 prog2 ... "
d589 4
a592 1
	local pass i old_libs="" tmp o=""
d594 3
a596 1
		o="-P $2"; shift; shift
d598 3
a600 2
	# Result returned in global variables
	u_libs="" ; u_progs="`find_progs_helper $*`"
d602 3
a604 10
	# use objdump to find libraries. Iterate to fetch recursive
	# dependencies.
	tmp="${u_progs}" ; pass=1
	while [ $pass -lt 10 ] ; do
		pass=$(($pass + 1))
		i="`objdump -x ${tmp} | \
			awk '$1 == "NEEDED" { print $2 }' | sort | uniq`"
		if [ "$old_libs" = "$i" ] ; then
			log "libraries for: $my_progs ($u_progs) are ($i) $u_libs"
			log "--- done find_progs ---"
a605 8
		else
			# logverbose "old--- $old_libs --- new +++ $i +++"
		fi
		u_libs="`find_progs_helper $o $i`"
		old_libs="$i"
		tmp="$tmp $u_libs"
	done
	log "WARNING: Too many passes, giving up"
a637 5
	for i in $progs ; do
		# full pathnames are just listed
		[ -f "$i" ] && echo $i && continue
		find ${places} -maxdepth 3 -type f -name ${i} | head -1
	done
d639 1
d789 1
d858 11
d894 5
a898 1

a899 1
    # XXX update loader.conf
d903 2
a904 1
    gzip -c kernel > ${dst}/boot/kernel/kernel.gz || fail $? no_space "copying kernel"
d954 1
a954 1
    dd if=${c_boot2} iseek=1 ibs=276 2> /dev/null | \
a957 3
    # leave build stuff if verbose
    [ ${o_verbose} -gt 0 ] && return

d976 1
a976 1
    l_objtree=${l_usrtree}/obj-pico-${o_arch}
a983 4
	export TARGET_ARCH=${o_arch} TARGET=${o_arch}
	# XXX why change machine_arch ?
	#-- export MACHINE_ARCH=`uname -m` MACHINE=`uname -m`
	# export CWARNFLAGS="-Wextra -Wno-sign-compare -Wno-missing-field-initializers"
d985 1
a993 2
    else
	eval export `cd ${SRC}; ${BINMAKE} -f Makefile.inc1 -V WMAKEENV`
a1022 2
# o_par="-j 8"	# parallel make and other make options

a1026 4
    --par)
	o_par="-j 8"
	;;

d1031 1
a1031 2

    --init)	# run a partial buildworld on the source tree
d1035 2
a1036 2
    --arch)	# override the target architecture
	o_arch=$2
d1040 3
a1042 3
    --floppy_size)	# image size
	fd_size=$2
	shift
a1055 1

@


1.50.2.6
log
@## SVN ##
## SVN ## Exported commit - http://svnweb.freebsd.org/changeset/base/ 242909
## SVN ## CVS IS DEPRECATED: http://wiki.freebsd.org/CvsIsDeprecated
## SVN ##
## SVN ## ------------------------------------------------------------------------
## SVN ## r242909 | dim | 2012-11-12 07:47:19 +0000 (Mon, 12 Nov 2012) | 20 lines
## SVN ##
## SVN ## MFC r242625:
## SVN ##
## SVN ## Remove duplicate const specifiers in many drivers (I hope I got all of
## SVN ## them, please let me know if not).  Most of these are of the form:
## SVN ##
## SVN ## static const struct bzzt_type {
## SVN ##       [...list of members...]
## SVN ## } const bzzt_devs[] = {
## SVN ##       [...list of initializers...]
## SVN ## };
## SVN ##
## SVN ## The second const is unnecessary, as arrays cannot be modified anyway,
## SVN ## and if the elements are const, the whole thing is const automatically
## SVN ## (e.g. it is placed in .rodata).
## SVN ##
## SVN ## I have verified this does not change the binary output of a full kernel
## SVN ## build (except for build timestamps embedded in the object files).
## SVN ##
## SVN ## Reviewed by:	yongari, marius
## SVN ##
## SVN ## ------------------------------------------------------------------------
## SVN ##
@
text
@d3 1
a3 1
# $FreeBSD: stable/8/release/picobsd/build/picobsd 231590 2012-02-13 18:10:13Z luigi $
@


1.50.2.7
log
@## SVN ## Exported commit - http://svnweb.freebsd.org/changeset/base/257778
## SVN ## CVS IS DEPRECATED: http://wiki.freebsd.org/CvsIsDeprecated
@
text
@d3 1
a3 1
# $FreeBSD: stable/8/release/picobsd/build/picobsd 257778 2013-11-07 04:52:25Z luigi $
a9 2
# CWARNFLAGS can be used to pass -Wall or similar options
#
d175 9
a183 3
	export MAKEOBJDIRPREFIX=${l_objtree}
	make ${o_par} $no toolchain
	# XXX do we need any of these ?
d185 1
d442 3
a444 4
	# kernel build not parallelizable yet
	${BINMAKE} KERNCONF=${l_kernconf}	\
		-f ${PICO_TREE}/build/Makefile.conf ) || \
	    fail $? missing_kernel
d594 1
a594 1
			return 0
d683 1
a683 1
		-f ${PICO_TREE}/build/Makefile.conf ${BUILDDIR}/crunch.mk )
d699 4
a702 4
    log "Setting up host key for sshd:"
    for K in rsa1 rsa dsa ; do
	if [ $K = rsa1 ] ; then
	    i=ssh_host_key
d704 4
a707 1
	    i=ssh_host_${K}_key
d709 1
a709 9
	if [ -f ${BUILDDIR}/floppy.tree/etc/$i.gz ] ; then
	    log "Using existing host key $i"
	else
	    log "Generating new host key $i" 
	    ssh-keygen -t $K -f ${BUILDDIR}/floppy.tree/etc/$i \
		     -N "" -C "root@@picobsd"
	    gzip -9 ${BUILDDIR}/floppy.tree/etc/${i}* || true
	fi
    done
d884 5
a888 7
    mkdir -p  ${dst}/boot/kernel
    # XXX loader.conf does not work unless we also load the .4th files
    # echo "hint.acpi.0.disabled=\"1\"" > ${dst}/boot/loader.conf
    # echo "console=\"comconsole\"" >> ${dst}/boot/loader.conf
    local blf="loader* *.4th" # loader.rc loader.4th support.4th"
    (cd /boot; cp -p loader ${dst}/boot) || fail $? no_space "copying bootloader"
    cp ${MY_TREE}/floppy.tree/boot/loader.conf ${dst}/boot || true
a972 7
	# XXX 20131001 see if CLANG fixes the build
	export WITHOUT_CLANG_IS_CC=yes
	export WITH_GCC=yes
	export WITH_GNUCXX=yes
	export WITHOUT_CLANG=yes
	export WITHOUT_ICONV=yes

a975 1
	# XXX BINMAKE does not really exist anymore
a976 2
	[ "$BINMAKE" = "" ] && \
	   eval "export BINMAKE=\"`cd ${SRC}; make -f Makefile -V SUB_MAKE`\""
@


1.50.2.5.2.1
log
@SVN rev 232438 on 2012-03-03 06:15:13Z by kensmith

Copy stable/8 to releng/8.3 as part of 8.3-RELEASE release cycle.

Approved by:	re (implicit)
@
text
@@


1.50.2.5.2.2
log
@Switch importer
@
text
@d3 1
a3 1
# $FreeBSD: releng/8.3/release/picobsd/build/picobsd 231590 2012-02-13 18:10:13Z luigi $
@


1.50.2.4.2.1
log
@SVN rev 216617 on 2010-12-21 17:09:25Z by kensmith

Copy stable/8 to releng/8.2 in preparation for FreeBSD-8.2 release.

Approved by:	re (implicit)
@
text
@@


1.50.2.3.2.1
log
@SVN rev 209145 on 2010-06-14 02:09:06Z by kensmith

Copy stable/8 to releng/8.1 in preparation for 8.1-RC1.

Approved by:	re (implicit)
@
text
@@


1.50.2.1.2.1
log
@SVN rev 198460 on 2009-10-25 01:10:29Z by kensmith

Copy stable/8 to releng/8.0 as part of 8.0-RELEASE release procedure.

Approved by:	re (implicit)
@
text
@@


1.49
log
@SVN rev 194631 on 2009-06-22 15:45:26Z by luigi

Add code to generate a bootable ISO image, so we are finally
free from the 2.88MB that we had using El Torito emulation.

The --iso option was already there, just didn't do anything before.

Submitted by:	Marta Carbone
MFC after:	3 days
@
text
@d143 1
a143 1
    c_iso=picobsd.bin		# filename used for the ISO image
@


1.48
log
@SVN rev 190411 on 2009-03-25 14:02:26Z by luigi

add support for shared "crunch" binary.
@
text
@d143 1
d280 1
a280 9
# build the iso image
build_iso_image() {
    log "build_iso_image()"
    clear
    set_msgs
    printf "${MSG}---> Build the iso image not ready yet\n\n"
}

# Main build procedure.
d898 10
a923 5
    if [ "${generate_iso}" = "YES" ]; then
	echo "generate_iso ${generate_iso}"
	# build_iso_image	# XXX not implemented yet
	exit 1
    fi
@


1.47
log
@SVN rev 190383 on 2009-03-24 17:47:50Z by luigi

add a function to help copying shared binaries from the output
of a buildworld.
@
text
@d163 3
a165 2
# use the new build infrastructure
create_includes_and_libraries2() {
d177 5
a181 1
    make _+_= $no toolchain _includes _libraries
d261 1
a261 1
    if [ "${name}" = "" ] ; then
d290 1
a290 1
    [ "${name}" != "" ] || fail $? bad_type
d300 2
a301 6
    if [ -f ${MY_TREE}/config ] ; then
	. ${MY_TREE}/config
    fi
    if [ -f ${o_additional_config} ] ; then
	. ${o_additional_config}
    fi
d333 1
a333 1
  while [ true ] ; do
d541 1
a541 1
		[ x"$srcs" = x ] && srcs=$dst && continue
d552 23
d576 2
a577 1
# or libraries in ${o_objdir} and return the full pathnames.
a579 1
# If the first argument is - does not set u_libs
d596 1
d612 2
d617 1
d619 1
d621 1
a621 1
		places="${places} ${o_objdir}/${i}"
d625 1
a625 1
		
d715 1
a715 1
    if [ "${o_no_devfs}" != "" ] ; then
d729 8
a736 2
    if [ -n "${copy_files}" ] ; then
	do_copyfiles ${dst} copy_files
d738 2
d741 2
@


1.46
log
@SVN rev 190378 on 2009-03-24 16:03:46Z by luigi

remove unused "package" entry.
default to use devfs (we do that anyways)

Many small changes in comments
@
text
@d551 46
a911 1
    log "set_build_parameters() SRC is ${SRC}"
d938 13
d959 1
d962 1
a962 1
	SRC=`(cd $2; pwd)`
d1014 6
@


1.45
log
@SVN rev 189978 on 2009-03-18 18:43:31Z by luigi

add the option to picobsd to copy files from the host filesystem
without root privs. This is done, among other things, replacing
the absolute paths in the symlinks with relative paths, so we
do not need to do a chroot to follow them.

Still need to update the manpage.

MFC after:	3 days
@
text
@d6 1
a6 1
# The new PicoBSD build script. Invoked as
d8 1
a8 1
# picobsd [options] floppy_type site_name
d10 2
a11 2
# Where floppy_type is a directory where the picobsd config info
# is held, and ${floppy_type}/floppy.tree.${site_name} contains
d16 1
a16 1
# tend to lose sync over time...
d36 1
a36 1
#   buildtree.mk	optional makefile to build an extension for floppy tree
d43 1
a43 3
# There are two set of initialization. The first one (set_defaults)
# is done on entry to the script, and is used to set default values
# for all variables which do not depend on floppy type and source tree.
d45 3
a47 2
# The second set is done after command line parsing, e.g.
# to resolve dependencies on the source tree.
d49 4
a52 1
# Naming:
d56 1
a56 1
# + variables which contain pathnames and values that should not change
d62 4
a65 1
#   an l_ ("local") prefix
d71 1
a79 3
# set some default values for variables.
# needs to be done as the first thing in the script.

d82 1
a82 1
log() {
d89 2
a90 1
logverbose() {
d97 2
a98 2
set_defaults() {
    # no way to use logging in this function, variable not set yet.
d100 1
d109 7
a115 3
    o_all_in_mfs="yes"		# put all files in mfs so you can boot and run
				# the image via diskless boot.
    o_clean=""			# do not clean
d119 1
a119 1
    o_init_src=""		# non "" if we need to init libs and includes.
d121 2
a122 1
    o_no_devfs=yes		# we do not want devfs
d145 1
a145 1
    # select the right memory disk name
d147 2
a148 2
	7.*|6.*|5.*)
	    l_label="bsdlabel"
d151 1
a151 1
	    l_label="disklabel"
d186 1
a186 1
    mkdir -p ${l_usrtree}/include		# the include directory...
d223 4
a226 3
# set_type <type> looks in user or system directories for the floppy type
# specified as first argument, and sets variables according to the config.
# file. Also sets MY_TREE and BUILDDIR and SITE
d228 1
a228 1
set_type() {
a325 21
build_package() {
    local z msg

    log "build_package()"
    rm -rf build.status
    echo "##############################################" >>build.status
    echo "## `date` ">>build.status
    echo "##############################################" >>build.status
    for z in bridge dial router net isp ; do
	set_type ${z}
	echo "---------------------------------------------">>build.status
	echo "Building TYPE=${z}, SIZE=${MFS_SIZE}" >>build.status
	msg="(ok)"	# error message
	build_image || msg="** FAILED! **"
        echo "	${msg}">>build.status
	# where do i put things ?
	# clean_tree
    done
    exit 0
}

d657 1
d823 2
a824 2
    # ${l_label} -f `pwd`/${c_img}
    ${l_label} -w -f `pwd`/${c_img} auto # write in a label
d826 3
a828 3
    ${l_label} -f `pwd`/${c_img} | sed -e '/  c:/{p;s/c:/a:/;}' | \
	${l_label} -R -f `pwd`/${c_img} /dev/stdin
    ${l_label} -f `pwd`/${c_img}
d831 1
a831 1
    ${l_label} -f `pwd`/${c_img}
d838 1
a838 1
	#build_iso_image()
d962 1
a965 3
# If $1="package", it creates a neat set of floppies
[ "$1" = "package" ] && build_package

@


1.44
log
@SVN rev 188851 on 2009-02-20 14:28:56Z by luigi

when initializing, also build _includes and _libraries

On passing, fix a wrong comment

MFC after:	3 days
@
text
@d287 3
d535 26
d569 1
a569 1
    local a dst MFS_TREE
d584 3
a586 1
    # XXX create links
d588 2
a589 1
	ln -s /stand ${dst}/$i
d591 2
a592 2
    ln -s /dev/null ${dst}/var/run/log
    ln -s /etc/termcap ${dst}/usr/share/misc/termcap
d664 7
d683 1
d959 5
@


1.43
log
@SVN rev 188835 on 2009-02-20 00:05:33Z by luigi

use /boot/loader by default, because the boot code seems to
have problems with kernels larger than 4MB.
Add a flag to avoid the /boot/loader and use the old method.

Add support for an additional makefile to perform custom manipulation
(this is not documented yet).

Add support for building an ISO image (not complete)
@
text
@d153 1
a153 1
# entry for 4.x and earlier trees
d166 1
a166 1
    make _+_= $no toolchain
@


1.42
log
@SVN rev 180012 on 2008-06-25 21:33:28Z by ru

Enable GCC stack protection (aka Propolice) for userland:
- It is opt-out for now so as to give it maximum testing, but it may be
  turned opt-in for stable branches depending on the consensus.  You
  can turn it off with WITHOUT_SSP.
- WITHOUT_SSP was previously used to disable the build of GNU libssp.
  It is harmless to steal the knob as SSP symbols have been provided
  by libc for a long time, GNU libssp should not have been much used.
- SSP is disabled in a few corners such as system bootstrap programs
  (sys/boot), process bootstrap code (rtld, csu) and SSP symbols themselves.
- It should be safe to use -fstack-protector-all to build world, however
  libc will be automatically downgraded to -fstack-protector because it
  breaks rtld otherwise.
- This option is unavailable on ia64.

Enable GCC stack protection (aka Propolice) for kernel:
- It is opt-out for now so as to give it maximum testing.
- Do not compile your kernel with -fstack-protector-all, it won't work.

Submitted by:	Jeremie Le Hen <jeremie@@le-hen.org>
@
text
@a23 1
#
d31 1
d33 1
a33 1
#   floppy.tree/	local additions to the floppy.tree
d36 2
d103 1
d133 1
d153 1
d215 1
a215 1
# file. Sets THETYPE, SITE, name, MY_TREE and BUILDDIR
d263 7
a321 4
        if [ "${name}" = "" ] ; then
	    echo "*** TYPE=${z} not found" >>build.status
	    continue
	fi
d495 2
a496 3
    # clean relics from old compilations.
    rm -rf ${dst} || true
    mkdir ${dst}
d498 1
d506 6
a511 2
    (cd ${PICO_TREE}/floppy.tree ; tar -cf - --exclude CVS --exclude .svn \
    		${excl} . ) | \
d513 4
a516 19
    log "Copied from generic floppy-tree `echo; ls -laR ${dst}`"

    srcdir=${MY_TREE}/floppy.tree
    if [ -d ${srcdir} ] ; then
	log "update with type-specific files:"
	(cd ${srcdir} ; tar -cf - --exclude CVS --exclude .svn . ) | \
	    (cd ${dst} ; tar x${o_tarv}f - )
	log "Copied from type floppy-tree `echo; ls -laR ${dst}`"
    else
	log "No type-specific floppy-tree"
    fi
    if [ -d ${srcdir}.${SITE} ] ; then
	log "Update with site-specific (${SITE}) files:"
	(cd ${srcdir}.${SITE} ; tar -cf - --exclude CVS --exclude .svn . ) | \
	    (cd ${dst} ; tar x${o_tarv}f - )
	log "Copied from site floppy-tree `echo; ls -laR ${dst}`"
    else
	log "No site-specific floppy-tree"
    fi
d518 8
d540 1
a540 1
    local a dst
d544 2
a545 3
    # clean relics from old compilations.
    rm -rf ${dst} || true
    mkdir ${dst}
d562 1
a562 1

d606 5
d613 1
a613 1
	# this may fail in case the floppy is empty
d617 1
d636 3
a638 1
	cp `which tar` ${dst}/my_copy_of_tar
d640 2
a641 2
	    (chroot ${dst} /my_copy_of_tar xf - )
	rm ${dst}/my_copy_of_tar
d647 1
a647 1
	mtree -c -p ${dst} -k "" >> mtree.out
d650 1
a650 1
		-s ${MFS_SIZE}k -f 100 -F mtree.out ${c_fs} ${dst}
a726 1
    log "patch ${c_boot2} to boot /kernel right away"
d731 6
a736 3
    set `strings -at d ${b2} | grep "/boot/loader"`
    echo -e "/kernel\0\0\0\0\0" | \
	dd of=${b2} obs=$1 oseek=1 conv=notrunc 2>/dev/null
d756 1
d758 1
a758 1
	    oseek=1 conv=notrunc 2> /dev/null
d763 11
a773 2
    kgzip -o kernel.gz kernel
    cp -p kernel.gz ${dst}/kernel || fail $? no_space "copying kernel"
a774 1
    log "Now transfer floppy tree if not already in MFS image"
d777 1
d782 7
d798 1
d800 11
a810 2
	logverbose "after disklabel"
	 )
d825 2
a826 1
    rm ${BUILDDIR}/kernel.gz ${BUILDDIR}/${c_fs}
d869 1
a869 2
args=""
while [ x"$1" != x ]; do
d884 5
d894 1
a894 1
	o_all_in_mfs=""
d914 5
d920 1
a920 1
	args="$args $1"			# accumulate args
d927 1
a929 1
set -- ${args}
a931 2
set_type $args		# type and site, respectively

@


1.41
log
@Fix build of the "package" target, ignoring non existing
floppy types (in fact, we have only one left!)
Also cleanup some code, using || and && in some places, and
using "export VAR=value" instead of two separate lines.
@
text
@d498 2
a499 1
    (cd ${PICO_TREE}/floppy.tree ; tar -cf - --exclude CVS ${excl} . ) | \
d506 1
a506 1
	(cd ${srcdir} ; tar -cf - --exclude CVS . ) | \
d514 1
a514 1
	(cd ${srcdir}.${SITE} ; tar -cf - --exclude CVS . ) | \
d597 1
a597 1
	    (cd ${MFS_TREE} ; tar -cf - --exclude CVS . ) | \
@


1.40
log
@Fix picobsd builds. Changes include:
- use proper make configuration for the build, using
  ${BINMAKE} as evaluated by ${VERSION}/src/Makefile
- remove -lmytinfo from crunch.conf
- remove support for login_access in tinyware/login
- remove "machine i386" from the kernel config file

It might actually be interesting to extend the script to do
a cross build for !i386 ...

MFC after: 3 days
@
text
@d78 4
a81 6
    if [ ${o_verbose} -gt 0 ] ; then
	printf "\n*** %s\n" "$*"
	if [ ${o_verbose}  -gt 1 ] ; then
	    read -p "=== Press enter to continue" foo
	fi
    fi
a85 1

d88 1
d165 1
d210 1
a210 1
# file. Also sets MY_TREE and BUILDDIR and SITE
d215 1
a215 1
    log "set_type()"
d219 1
d222 2
a223 2
	if [ -d $i -a -f $i/PICOBSD -a -f $i/crunch.conf ] ; then
	    set -- `cat $i/PICOBSD | \
d225 9
a233 11
	    if [ "$1" != "" ]; then
		MFS_SIZE=$1 ; init_name=$2
		mfs_inodes=$3 ; fd_inodes=$4
		name=`(cd $i ; pwd) `
		name=`basename $name`
		MY_TREE=$i
		BUILDDIR=${c_startdir}/build_dir-${name}
		log "Matching file $name in $i"
		return ;
	    fi
	fi
d235 1
a235 1
    echo "Type $a NOT FOUND"
d281 1
a281 2
	MAKEOBJDIRPREFIX=${l_objtree}
	export MAKEOBJDIRPREFIX
a282 1
	log `cd ${SRC}; make -f Makefile.inc1 -V WMAKEENV`
d304 1
a304 1
    touch build.status
d310 4
d458 2
a459 1
# invoke the Makefile to compile the kernel.
d464 1
a464 4
	if [ "${o_do_modules}" = "yes" ] ; then
		MODULES=""
		export MODULES
	fi
d826 2
a827 1
while [ true ]; do
d868 1
a868 1
	break ;
a874 1
set_type $1 $2		# type and site, respectively
d877 6
a883 6
if [ "$1" = "package" ] ; then
    build_package
fi
if [ "${o_interactive}" != "NO" ] ; then
    main_dialog
fi
@


1.39
log
@Send the pcvt(4) driver off to retirement.
@
text
@d285 1
d287 1
a287 1
	eval export `cd ${SRC}; make -f Makefile.inc1 -V WMAKEENV`
d467 1
a467 1
	make -m ${SRC}/share/mk -v -f ${PICO_TREE}/build/Makefile.conf ) || \
d495 1
a496 1
	log "Files excluded from generic tree: `echo;cat ${excl}`"
d565 1
a565 1
	make -m ${SRC}/share/mk \
d571 1
a571 1
    make -m ${SRC}/share/mk ${o_makeopts} -f ${BUILDDIR}/crunch.mk
@


1.39.2.1
log
@MFC 2007-11-14 05:42:54 UTC

Fix picobsd builds. Changes include:
- use proper make configuration for the build, using
  ${BINMAKE} as evaluated by ${VERSION}/src/Makefile
- remove -lmytinfo from crunch.conf
- remove support for login_access in tinyware/login
- remove "machine i386" from the kernel config file

It might actually be interesting to extend the script to do
a cross build for !i386 ...

Approved by: re
@
text
@a284 1
	eval "export BINMAKE=\"`cd ${SRC}; make -f Makefile -V BINMAKE`\""
d286 1
a286 1
	eval export `cd ${SRC}; ${BINMAKE} -f Makefile.inc1 -V WMAKEENV`
d466 1
a466 1
	${BINMAKE} -v -f ${PICO_TREE}/build/Makefile.conf ) || \
d494 1
a495 1
	excl="--exclude-from ${excl}"
d564 1
a564 1
	${BINMAKE} \
d570 1
a570 1
    ${BINMAKE} ${o_makeopts} -f ${BUILDDIR}/crunch.mk
@


1.39.2.2
log
@SVN rev 182000 on 2008-08-22 10:18:18Z by luigi

MFC: sync with HEAD.

BTW, the change in rev.1.42 in head is totally unrelated to the
commit message: it only adds .svn to the exclude list when copying
files using tar.
@
text
@d78 6
a83 4
    local foo
    [ ${o_verbose} -gt 0 ] && printf "\n*** %s\n" "$*"
    [ ${o_verbose}  -gt 1 ] && read -p "=== Press enter to continue" foo
    return 0
d88 1
a90 1
    return 0
a166 1
# entry for 4.x and earlier trees
d211 1
a211 1
# file. Sets THETYPE, SITE, name, MY_TREE and BUILDDIR
d216 1
a216 1
    log "set_type() : Type '$1' site '$2'"
a219 1
    name=""	# clear in case of errors
d222 1
a222 1
	[ -d $i -a -f $i/PICOBSD -a -f $i/crunch.conf ] || continue
d225 1
a225 1
	[ x"$1" != "x" ] || continue
d234 2
d237 1
a237 1
    logverbose "Type $a NOT FOUND"
d283 2
a284 1
	export MAKEOBJDIRPREFIX=${l_objtree}
d286 1
d308 1
a308 1
    rm -rf build.status
a313 4
        if [ "${name}" = "" ] ; then
	    echo "*** TYPE=${z} not found" >>build.status
	    continue
	fi
d458 1
a458 2
# invoke the picobsd Makefile to compile the kernel.
# if MODULES is set (value is irrelevant) the makefile will build modules.
d463 4
a466 1
	[ "${o_do_modules}" = "yes" ] && export MODULES=""
d500 1
a500 2
    (cd ${PICO_TREE}/floppy.tree ; tar -cf - --exclude CVS --exclude .svn \
    		${excl} . ) | \
d507 1
a507 1
	(cd ${srcdir} ; tar -cf - --exclude CVS --exclude .svn . ) | \
d515 1
a515 1
	(cd ${srcdir}.${SITE} ; tar -cf - --exclude CVS --exclude .svn . ) | \
d598 1
a598 1
	    (cd ${MFS_TREE} ; tar -cf - --exclude CVS --exclude .svn . ) | \
d828 1
a828 2
args=""
while [ x"$1" != x ]; do
d869 1
a869 1
	args="$args $1"			# accumulate args
d876 1
a878 6
set -- ${args}
[ "$1" = "package" ] && build_package

set_type $args		# type and site, respectively

[ "${o_interactive}" != "NO" ] && main_dialog
d880 6
@


1.39.2.3
log
@SVN rev 189237 on 2009-03-01 15:03:08Z by luigi

sync the build script with the version in -current.
The most relevant changes are the building of libraries
in the --init call, and the ability to use /boot/loader
(on by default) which seems to be necessary for large kernels.
@
text
@d24 1
a31 1
#   mfs.mtree		overrides ${PICO_TREE}/mfs.mtree
d33 1
a33 1
#   floppy.tree/	local additions to ${PICO_TREE}/mfs_free
a35 2
#   buildtree.mk	optional makefile to build an extension for floppy tree
#			(generated in buildtree/ )
a100 1
    o_use_loader="yes"		# use /boot/loader
a129 1
    generate_iso="NO"		# don't generate the iso image
a148 1
# use the new build infrastructure
d161 1
a161 1
    make _+_= $no toolchain _includes _libraries
d210 1
a210 1
# file. Also sets MY_TREE and BUILDDIR and SITE
d223 1
a223 1
	set -- `cat $i/PICOBSD | \
d226 8
a233 8
	MFS_SIZE=$1 ; init_name=$2
	mfs_inodes=$3 ; fd_inodes=$4
	name=`(cd $i ; pwd) `
	name=`basename $name`
	MY_TREE=$i
	BUILDDIR=${c_startdir}/build_dir-${name}
	log "Matching file $name in $i"
	return ;
a257 7
# build the iso image
build_iso_image() {
    log "build_iso_image()"
    clear
    set_msgs
    printf "${MSG}---> Build the iso image not ready yet\n\n"
}
d310 4
d487 3
a489 2
    rm -rf ${dst} || true	# clean relics from old compilations.
    mkdir ${dst}		# create a clean tree
a490 1
    # compute exclude list for generic tree
d498 2
a499 6
    # copy from the floppy trees into the destination
    for FLOPPY_TREE in ${PICO_TREE}/floppy.tree ${MY_TREE}/floppy.tree \
		${MY_TREE}/floppy.tree.${SITE} ; do
	if [ -d ${FLOPPY_TREE} ] ; then
	    (cd ${FLOPPY_TREE} ; tar -cf - --exclude CVS \
		    --exclude .svn ${excl} . ) | \
d501 19
a519 4
	    log "Copied from ${FLOPPY_TREE}"
	fi
	excl="" # reset the exclude list.
    done
a520 8
    # add local manipulation
    if [ -f ${MY_TREE}/buildtree.mk ] ; then
	log "building local floppy tree"
	${BINMAKE} -C ${dst} -f ${MY_TREE}/buildtree.mk floppy.tree
    fi
 
    # compress the files in etc/, just in case
    # XXX this should be done in the makefile.
d535 1
a535 1
    local a dst MFS_TREE
d539 3
a541 2
    rm -rf ${dst} || true	# clean relics from old compilations.
    mkdir ${dst}		# create a fresh tree
d558 1
a558 1
    ### now build the crunched binaries ###
a601 5
    if [ -f ${MY_TREE}/buildtree.mk ] ; then
	log "building local floppy tree"
	${BINMAKE} -C ${dst} -f ${MY_TREE}/buildtree.mk mfs.tree
    fi

d604 1
a604 1
	# ignore failure in case the floppy is empty
a607 1
    # 4.x compatibility - create device nodes
d626 1
a626 3
	# Make sure we have a statically linked tar there.
	mkdir -p ${dst}/rescue
	cp /rescue/tar ${dst}/rescue
d628 2
a629 2
	    (chroot ${dst} /rescue/tar xPf - )
	rm -rf ${dst}/rescue
d635 1
a635 1
	mtree -ic -p ${dst} -k "" >> mtree.out
d638 1
a638 1
		-s ${MFS_SIZE}k -f 1000 -F mtree.out ${c_fs} ${dst}
d715 1
d720 3
a722 6
    if [ ${o_use_loader} = "no" ] ; then
	log "patch ${c_boot2} to boot /kernel right away"
	set `strings -at d ${b2} | grep "/boot/loader"`
	echo -e "/kernel\0\0\0\0\0" | \
	    dd of=${b2} obs=$1 oseek=1 conv=notrunc 2>/dev/null
    fi
a741 1
	logverbose "`ls -l ${c_fs}` to fit in ${mfs_size}"
d743 1
a743 1
	    oseek=1 conv=notrunc # 2> /dev/null
d748 2
a749 11
    if [ ${o_use_loader} = "no" ] ; then
	kgzip -o kernel.gz kernel
	cp -p kernel.gz ${dst}/kernel || fail $? no_space "copying kernel"
    else
        gzip kernel
	mkdir -p  ${dst}/boot/kernel
	echo "hint.acpi.0.disabled=\"1\"" > ${dst}/boot/loader.conf
	echo "console=\"comconsole\"" >> ${dst}/boot/loader.conf
	cp -p /boot/loader ${dst}/boot/loader || fail $? no_space "copying bootloader"
	cp -p kernel.gz ${dst}/boot/kernel/kernel.gz || fail $? no_space "copying kernel"
    fi
d751 1
a753 1
	log "Now transfer floppy tree if not already in MFS image"
a757 7

    # add local manipulation to the image
    if [ -f ${MY_TREE}/buildtree.mk ] ; then
	${BINMAKE} -C ${dst} -f ${MY_TREE}/buildtree.mk image.tree
    fi

    log "image used `du -s ${dst}` of ${blocks}k"
a766 1

d768 2
a769 11
    ${l_label} -f `pwd`/${c_img}
    logverbose "after disklabel"
    )

    echo "BUILDDIR ${BUILDDIR}"
    if [ "${generate_iso}" = "YES" ]; then
	echo "generate_iso ${generate_iso}"
	#build_iso_image()
	exit 1
    fi

d784 1
a784 2
    rm ${BUILDDIR}/${c_fs}
    # rm ${BUILDDIR}/kernel.gz
d827 2
a828 1
while [ true ]; do
a842 5
    --no_loader)	# omit /boot/loader, just rely on boot2
			# (it may have problems with kernels > 4MB)
	o_use_loader="no"
	;;

d848 1
a848 1
	o_all_in_mfs="no"
a867 5

    --iso) # generate iso image
	generate_iso="YES"
	;;

d869 1
a869 1
	break
a875 1
set_type $1 $2		# type and site, respectively
d878 1
d881 2
@


1.39.2.4
log
@SVN rev 190338 on 2009-03-23 21:32:03Z by luigi

MFC: add support for local config files and non-chroot
copy of files from the host filesystem
@
text
@a286 3
    if [ -f ${o_additional_config} ] ; then
	. ${o_additional_config}
    fi
a531 26
# Copy the specified files to the destination filesystem.
# Each file is specified as a pair "src dst", dst is assumed to be
# a directory (and created with mkdir -p) if it has a trailing /
# Be careful to escape metacharacters.
# You can use ${CROSS} to point to the root of the cross build
# (remember that it might be incomplete)

do_copyfiles() {	# rootdir varname
	log Copy files to $1
	local root=$1
	local srcs dst
	local CROSS=${_SHLIBDIRPREFIX}
	eval set "\${${2}}"
        srcs=""
	for dst in $* ; do
		[ x"$srcs" = x ] && srcs=$dst && continue
		eval srcs="$srcs"	# expand wildcard and vars
		case x"$dst" in
		*/ )	mkdir -p ${root}/${dst} ;;
		# * )	mkdir -p `dirname ${root}/${dst}` ;;
		esac
		cp -p ${srcs} ${root}/${dst} || true
		srcs=""
        done
}

d540 1
a540 1
    local i j a dst MFS_TREE
d555 1
a555 3
    # Create symlinks using relative pathnames, so it is possible
    # to follow them also when building the image.
    # Note that names in STAND_LINKS should not have a leading /
d557 1
a557 2
	j=`echo $i | sed -E 's:^[^/]+::;s:/[^/]+:../:g'`
	ln -s ${j}stand ${dst}/$i
d559 2
a560 2
    ln -s ../../dev/null ${dst}/var/run/log
    ln -s ../../../etc/termcap ${dst}/usr/share/misc/termcap
a631 7
    if [ -n "${copy_files}" ] ; then
	do_copyfiles ${dst} copy_files
    fi

    # The 'import_files' mechanism is deprecated, as it requires
    # root permissions to follow the symlinks, and also does
    # not let you rename the entries.
a643 1
    # final step -- build the mfs image
a918 5
    --cfg) # read additional config from this file
	o_additional_config=`realpath $2`
	shift
	;;

@


1.39.2.5
log
@SVN rev 190762 on 2009-04-06 11:15:28Z by luigi

MFC: bring in recent fixes to the picobsd script

Approved by:	re (blanket on picobsd)
@
text
@d6 1
a6 1
# The PicoBSD build script. Invoked as
d8 1
a8 1
#	picobsd [options] image_type [site_name]
d10 2
a11 2
# Where image_type is a directory with the picobsd config info,
# and ${image_type}/floppy.tree.${site_name} contains
d16 1
a16 1
# tend to lose sync over time.
d36 1
a36 1
#   buildtree.mk	optional Makefile to build an extension for floppy tree
d43 3
a45 1
# There are two initialization functions:
d47 2
a48 3
# + set_defaults
#   is run on entry to the script, and is used to set default values
#   for all variables that do not depend on image type and source tree.
d50 1
a50 4
# + set_build_parameters
#   is run after command line parsing
#
# VARIABLE NAMES:
d54 1
a54 1
# + variables that contain pathnames and values that should not change
d60 1
a60 4
#   an l_ ("local") prefix.
#
# There are unfortunately exceptions:
# name, l_usrtree, l_objtree
a65 1
# c_label is either bsdlabel or disklabel
d74 3
d79 1
a79 1
log() {	#	message
d86 1
a86 2
# unconditionally log and wait for input
logverbose() {	# message
d93 2
a94 2
# set some default values for variables.
# needs to be done as the first thing in the script.
a95 1
set_defaults() {	# no arguments
d104 3
a106 7
	# You should not change it unless you are really short
	# of space, and your kernel is small enough that the
	# bootblocks manage to load it.

    o_all_in_mfs="yes"		# put all files in mfs so you can boot
				# and run the image via diskless boot.
    o_clean=""			# set if you want to clean prev.builds.
d110 1
a110 1
    o_init_src=""		# set to build libs and includes.
d112 1
a112 2
    o_no_devfs=			# default is use devfs.
	# You should only set it when building 4.x images
d135 1
a135 1
    # select the right disklabel program
d137 2
a138 2
	4.*)
	    c_label="disklabel"
d141 1
a141 1
	    c_label="bsdlabel"
d153 2
a154 3
# use the new build infrastructure to create libraries
# and also to build a specific target
create_includes_and_libraries2() { # opt_dir opt_target
d166 1
a166 5
    if [ -d "$1" ] ; then
	cd $1 ; make $2	# specific target, e.g. ld-elf.so
    else
	make _+_= $no toolchain _includes _libraries
    fi
d176 1
a176 1
    mkdir -p ${l_usrtree}/include	# the include directory...
d213 3
a215 4
# set_type <the_type> [the_site] looks in user or system directories
# for the directory named as the first argument, reads the configuration
# files and sets variables according to the config.
# Also sets MY_TREE and BUILDDIR and SITE
d217 1
a217 1
set_type() {	# the_type the_site
d245 1
a245 1
    if [ -z "${name}" ] ; then
d274 1
a274 1
    [ -n "${name}" ] || fail $? bad_type
d284 6
a289 2
    [ -f "${MY_TREE}/config" ]		&& . ${MY_TREE}/config
    [ -f "${o_additional_config}" ]	&& . ${o_additional_config}
d315 21
d342 1
a342 1
  while true ; do
d550 1
a550 1
		[ -z "$srcs" ] && srcs=$dst && continue
a560 74
# do_links is a helper function to create links between programs
# in stand/
# This is done reading the names and destination from variable
# links in a config file, in the format
#	: dst names

do_links() {	# rootdir varname
	local root=$1
	local l i dst
	eval l="\${${2}}"
        dst=""
	log "Create links for ${l}"
	(cd ${root}/stand
	for i in $l ; do
	    if [ "$dst" = ":" -o "$i" = ":" ] ; then
		dst=$i
	    elif [ -n "${dst}" ] ; then
		ln -s ${dst} ${i}
	    fi
	done
	)
}

# find_progs is a helper function to locate the named programs
# or libraries in ${o_objdir} or ${_SHLIBDIRPREFIX},
# and return the full pathnames.
# Sets ${u_progs} to the list of programs, and ${u_libs}
# to the list of shared libraries used.
#
# You can use it e.g. in a local configuration file by writing
#
#  do_copyfiles_user() {
#	local dst=$1
#	find_progs nvi sed less grep
#	cp -p ${u_progs} ${dst}/bin
#	cp -p ${u_libs} ${dst}/lib
#	mkdir -p ${dst}/libexec
#	find_progs ld-elf.so.1
#	cp -p ${u_progs} ${dst}/libexec
#  }

find_progs() {	# programs
	local i
	u_progs="`find_progs_helper $*`"
	local o=${o_objdir:-${_SHLIBDIRPREFIX}}
	[ -z "${u_progs}" ] && return 1	# not found, error
	i="`ldd ${u_progs} | grep -v '^/' | awk '{print $1}' | sort | uniq`"
	u_libs="`find_progs_helper $i`"
	return 0
}

find_progs_helper() {	# programs
	local progs="$*"
	local i o places names
	local subdirs="bin sbin usr.bin usr.sbin libexec lib \
		gnu/usr.bin gnu/lib \
		secure/usr.bin secure/usr.sbin secure/libexec secure/lib"
	names=""	# files to search
	o=""
	for i in $progs ; do
		# plain programs come out verbatim
		[ -f "$i" ] && echo $i && continue
		names="${names} ${o} -name $i"
		o="-o"
	done
	[ -z "${names}" ] && return 0
	places=""				# places to search
	o=${o_objdir:-${_SHLIBDIRPREFIX}/..}
	for i in $subdirs ; do
		[ -d "${o}/${i}" ] && places="${places} ${o}/${i}"
	done
	find ${places} -type f \( ${names} \)
}

d650 1
a650 1
    if [ -n "${o_no_devfs}" ] ; then
d664 2
a665 8
    # If we are building a shared 'crunch', take the libraries
    # and the dynamic loader as well
    find_progs ${dst}/stand/crunch
    if [ -n "${u_libs}" ] ; then
	mkdir -p ${dst}/lib && cp -p ${u_libs} ${dst}/lib
	mkdir -p ${dst}/libexec
        create_includes_and_libraries2 libexec/rtld-elf
        find_progs ld-elf.so.1 && cp -p ${u_progs} ${dst}/libexec
a667 5
    [ -n "${copy_files}" ] && do_copyfiles ${dst} copy_files
    do_copyfiles_user ${dst} || true
    [ -n "${links}" ] && do_links ${dst} links
    strip ${dst}/libexec/* ${dst}/lib/* ${dst}/stand/* 2> /dev/null || true

d832 2
a833 2

    ${c_label} -w -f `pwd`/${c_img} auto # write in a label
d835 3
a837 3
    ${c_label} -f `pwd`/${c_img} | sed -e '/  c:/{p;s/c:/a:/;}' | \
	${c_label} -R -f `pwd`/${c_img} /dev/stdin
    ${c_label} -f `pwd`/${c_img}
d840 1
a840 1
    ${c_label} -f `pwd`/${c_img}
d847 1
a847 1
	# build_iso_image	# XXX not implemented yet
d875 1
a901 13

    # if we have o_objdir, find where bin/ is
    if [ ! -z "${o_objdir}" ] ; then
	if [ -d ${o_objdir}/bin ] ; then
	    # fine
	elif [ -d "${o_objdir}${SRC}/bin" ] ; then
	    o_objdir="${o_objdir}${SRC}"
	    log "Changing objdir to ${o_objdir}"
	else
	    log "Cannot find objdir in ${o_objdir}, sorry"
	    o_objdir=""
	fi
    fi
a909 1
    log "Parsing $1"
d912 1
a912 1
	SRC=`realpath $2`
a963 6
    --objdir)	# Place with results of a previous buildworld
		# useful if you want to copy shared binaries and libs
	o_objdir=`realpath $2`
	shift
	;;

a970 1

d974 3
@


1.39.2.6
log
@SVN rev 194948 on 2009-06-25 09:28:44Z by luigi

MFC: enable creation of ISO images
@
text
@a142 1
    c_iso=picobsd.iso		# filename used for the ISO image
d279 9
a287 1
# Main build procedure. Builds both the disk image and the ISO
a904 10
    if [ "${generate_iso}" = "YES" ]; then
	logverbose "generate_iso ${generate_iso}"
	# build_iso_image	# XXX not implemented yet
	(cd ${BUILDDIR}
	cp -p /boot/cdboot ${dst}/boot || fail $? no_space "copying cdboot"
	mkisofs -b boot/cdboot -no-emul-boot -J -r -ldots -l -L \
		-o ${c_iso} ${dst}
	)
    fi

d921 5
@


1.39.2.7
log
@SVN rev 200564 on 2009-12-15 07:04:20Z by luigi

MFC r200301
when calling ldd, use the cross libraries and not the host version
@
text
@d170 1
a170 1
	no="-DNO_CLEAN -DNO_PROFILE -DNO_GAMES -DNO_LIBC_R" # WITOUT_CDDL=1"
a589 1
	log "looking for libs for $u_progs in $_SHLIBDIRPREFIX"
d591 1
a591 1
	i="`LD_LIBRARY_PATH=$o/lib ldd ${u_progs} | grep -v '^/' | awk '{print $1}' | sort | uniq`"
d722 2
a723 1
    log "for a shared 'crunch' take libraries and dynamic loader as well"
@


1.39.2.8
log
@Switch importer
@
text
@d3 1
a3 1
# $FreeBSD: stable/7/release/picobsd/build/picobsd 200564 2009-12-15 07:04:20Z luigi $
@


1.39.2.7.4.1
log
@SVN rev 216618 on 2010-12-21 17:10:29Z by kensmith

Copy stable/7 to releng/7.4 in preparation for FreeBSD-7.4 release.

Approved by:	re (implicit)
@
text
@@


1.39.2.7.4.2
log
@Switch importer
@
text
@d3 1
a3 1
# $FreeBSD: releng/7.4/release/picobsd/build/picobsd 200564 2009-12-15 07:04:20Z luigi $
@


1.39.2.7.2.1
log
@SVN rev 203736 on 2010-02-10 00:26:20Z by kensmith

Copy stable/7 to releng/7.3 as part of the 7.3-RELEASE process.

Approved by:	re (implicit)
@
text
@@


1.39.2.5.2.1
log
@SVN rev 191087 on 2009-04-15 03:14:26Z by kensmith

Create releng/7.2 from stable/7 in preparation for 7.2-RELEASE.

Approved by:	re (implicit)
@
text
@@


1.39.2.2.2.1
log
@SVN rev 185281 on 2008-11-25 02:59:29Z by kensmith

Create releng/7.1 in preparation for moving into RC phase of 7.1 release
cycle.

Approved by:	re (implicit)
@
text
@@


1.38
log
@unbreak the build script.
Instead of using vnconfig/mdconfig it relies on the makefs
port to build the image (UFS1) without need for root permissions.
@
text
@d195 1
a195 1
	for i in lib secure/lib gnu/lib usr.sbin/pcvt/keycap \
@


1.37
log
@NOCLEAN -> NO_CLEAN
NOCLEANDIR -> NO_CLEANDIR
@
text
@d4 1
d115 2
a116 2
    c_startdir=`pwd`	# directory where we start
			# used to lookup config and create BUILDDIR
d118 5
d127 1
a127 1
    			# file where User replies will be put
d129 3
a131 3
    			# mountpoint used to build memory filesystems
    c_fs=fs.PICOBSD	# filename used for the memory filesystem
    c_img=picobsd.bin	# filename used for the picobsd image
d135 2
a136 3
	5.*)
	    l_vn="md"
	    l_makedev="${SRC}/etc/MAKEDEV"
d139 1
a139 2
	    l_vn="vn"
	    l_makedev="/dev/MAKEDEV"
a141 4
    l_newfs="-m 0 -o space -f 512 -b 4096"
    # Find a suitable vnode
    l_vnum=`mount | awk "/${l_vn}/ { num++ } END { printf \"%d\", num }"`
    l_vndev=${l_vn}${l_vnum}
a148 1
    free_vnode			# cleanup old vnodes
d152 1
d154 5
d162 2
a163 1
    make -DNO_CLEAN -DNO_PROFILE -DNO_GAMES -DNO_LIBC_R -DPICOBSD buildworld
d187 1
d192 1
a192 1
		-DNO_HTML -DNO_INFO -DNO_MAN -DNO_SHARE -DNO_FSCHG "
d200 1
a200 1
	eval $e -DNO_PROFILE -DNO_PIC libraries
a248 12
# free as much as possible from the vnode
free_vnode() {
    log "free_vnode() ${l_vndev} "
    umount ${c_mnt}    2> /dev/null || true
    umount /dev/${l_vndev}       2> /dev/null || true
    if [ "${l_vn}" = "vn" ] ; then
	vnconfig -u ${l_vndev} 2> /dev/null || true
    else
	mdconfig -d -u ${l_vnum} 2> /dev/null || true
    fi
}

d431 1
a431 1
	cat .build.reply
a526 24
create_mfs() {		# OK
    log "create_mfs() Preparing MFS filesystem..."

    free_vnode

    # zero-fill the MFS image
    init_fs_image ${BUILDDIR}/${c_fs} ${MFS_SIZE}

    log "Labeling MFS image"
    # Disklabel "auto" behaves strangely for sizes < 1024K. Basically
    # it fails to install a label on the system. On the other hand,
    # if you provide a specific disk type, the boot code is not
    # installed so you have more space on the disk...
    # For small image sizes, use std disktypes
    if [ ${MFS_SIZE} -lt 1024 ] ; then
	disklabel -rw ${l_vndev} fd${MFS_SIZE} || fail $? mfs_disklabel
    else
	disklabel -rw ${l_vndev} auto || fail $? mfs_disklabel
    fi
    newfs -i ${mfs_inodes} ${l_newfs} /dev/${l_vndev}c > /dev/null
    mount /dev/${l_vndev}c ${c_mnt} || fail $? no_mount
    log "`df /dev/${l_vndev}c`"
}

d538 4
a541 10
    early_mfs_mount=0
    if [ "${early_mfs_mount}" = "1" ] ; then
	create_mfs
        dst=${c_mnt}
    else
	dst=${BUILDDIR}/mfs.tree
	# clean relics from old compilations.
	rm -rf ${dst} || true
	mkdir ${dst}
    fi
d604 2
a605 1
	cp -Rp ${BUILDDIR}/floppy.tree/* ${dst}/fd
a607 19
    [ "`id -u`" = "0" ] || cat <<__EOF

### -------------------------------------------------------------------
###
### WARNING: You are not running with root permissions, so the next
### stages are likely to fail because they call commands such as
### chown, {vn|md}config, mount/umount which need adequate rights.
###
### The results of the compilation so far is in directory
###  ${BUILDDIR}
### which has the following content:

`ls -l ${BUILDDIR}`

###
### -------------------------------------------------------------------

__EOF

d611 3
a613 2
	ln -s ${l_makedev} ; chmod 555 MAKEDEV
	./MAKEDEV ${MY_DEVS}
d617 4
a620 2
    log "Fixing permissions"
    (cd ${dst}; chown -R root . )
d632 9
a640 11
    if [ "${early_mfs_mount}" != "1" ] ; then
	create_mfs
	log "Copy mfs tree into file"
	(cd ${dst} ; tar cf - . ) | ( cd ${c_mnt} ; tar xf - )
    fi
    # now umount and fsck the filesystem.
    log "Status of mfs image"
    df -ik ${c_mnt}
    umount ${c_mnt}
    fsck -p /dev/${l_vndev}c
    free_vnode
a644 1
    free_vnode
a659 11
    no_vnconfig)
	echo "Error in vnconfig on /dev/${l_vndev}..."
	echo "Either you are not running as root or your running kernel"
	echo "does not have the ${l_vn}(4) device."
	;;
    mfs_disklabel)
	echo "Error while labeling ${c_fs} size ${MFS_SIZE}"
	;;
    no_mount)
	echo "Error while mounting ${c_fs} (/dev/${l_vndev}c) on ${c_mnt}"
	;;
a665 3
    floppy_disklabel)
	echo "Error while doing disklabel on of floppy.img size $fd_size"
	;;
a697 20
#
# Create a zero-filled disk image with a boot sector, and vnconfig it.
#

init_fs_image() { # filename size_in_kbytes
    local imgname imgsize

    log "init_fs_image() $1 $2"
    imgname=$1 ; imgsize=$2
    dd if=/dev/zero of=${imgname} count=${imgsize} bs=1k 2> /dev/null
    dd if=${c_boot1}  of=${imgname} conv=notrunc 2> /dev/null

    if [ "${l_vn}" = "vn" ] ; then
	vnconfig -c -s labels ${l_vndev} ${imgname} || fail $? no_vnconfig
    else
	mdconfig -a -t vnode -u ${l_vnum} -f ${imgname} || fail $? no_vnconfig
    fi
}


d699 1
a699 1
    local blocks sectors dst
d706 2
a707 2
    # correct block and number of sectors according to size.
    blocks=${fd_size}; sectors=18
d709 1
a709 1
	blocks=1722 ; sectors=21
d711 1
a711 1
	blocks=1476 ;
a713 2
    init_fs_image ${BUILDDIR}/${c_img} ${blocks}

d715 1
d717 1
a717 1
    cp ${c_boot2} ${b2}
d719 1
d721 2
a722 1
    echo -e "/kernel\0\0\0\0\0" | dd of=${b2} obs=$1 oseek=1 conv=notrunc
d725 3
a727 14
    # create a disklabel ...
    disklabel -Brw -b ${c_boot1} -s ${b2} ${l_vndev} auto || \
	fail $?  floppy_disklabel

    # and copy partition c: into partition a: using some sed magic
    disklabel ${l_vndev} | sed -e '/  c:/{p;s/c:/a:/;}' | \
	disklabel -R ${l_vndev} /dev/stdin

    log "Newfs floppy image"
    newfs -i ${fd_inodes} ${l_newfs} /dev/${l_vndev}a > /dev/null

    log "Mounting floppy image"
    mount /dev/${l_vndev}a ${dst}

d730 1
d733 14
a746 4
    mfs_ofs=$(($1 + 8192))
    log "Preload kernel with file ${c_fs} at ${mfs_ofs}"
    dd if=${c_fs} ibs=8192 iseek=1 of=kernel obs=${mfs_ofs} \
	oseek=1 conv=notrunc
d751 1
a751 1
    log "now transfer floppy tree if needed"
d758 25
a782 5
    (log "Fixing permissions"; cd ${dst}; chown -R root *)
    # rm -rf ${BUILDDIR}/floppy.tree || true # cleanup

    df -ik ${dst} | colrm 70 > .build.reply
    free_vnode
@


1.37.2.1
log
@MFC: fixed picobsd script.
upcoming, tweaks for other config files and sys/dev/md/md.c

Approved by: re
@
text
@a3 1
# This file requires sysutils/makefs to run
d114 2
a115 2
    c_startdir=`pwd`		# directory where we start
				# used to lookup config and create BUILDDIR
a116 5
    # XXX 6.x/7.x have a single /boot/boot block, which is the concatenation
    # of the old two. For the time being, we keep these, but this should
    # be fixed at some point.

    # blocks
d121 1
a121 1
    				# file where User replies will be put
d123 3
a125 3
    				# mountpoint used to build memory filesystems
    c_fs=fs.PICOBSD		# filename used for the memory filesystem
    c_img=picobsd.bin		# filename used for the picobsd image
d129 3
a131 2
	7.*|6.*|5.*)
	    l_label="bsdlabel"
d134 2
a135 1
	    l_label="disklabel"
d138 4
d149 1
a152 1
    local no
a153 5
    if [ ${OSVERSION} -ge 600000 ] ; then
	no="-DNO_CLEAN -DNO_PROFILE -DNO_GAMES -DNO_LIBC_R"
    else
	no="-DNOCLEAN -DNOPROFILE -DNOGAMES -DNOLIBC_R"
    fi
d157 1
a157 2
    # make -DNOCLEAN -DNOPROFILE -DNOGAMES -DNOLIBC_R -DPICOBSD buildworld
    make _+_= $no toolchain
a180 1
	# XXX check the NO* options below, maybe system dependent.
d185 1
a185 1
		-DNOHTML -DNOINFO -DNOMAN -DNOSHARE -DNOFSCHG "
d193 1
a193 1
	eval $e -DNOPROFILE -DNOPIC libraries
d242 12
d436 1
a436 1
	cat .build.reply || true
d532 24
d567 10
a576 4
    dst=${BUILDDIR}/mfs.tree
    # clean relics from old compilations.
    rm -rf ${dst} || true
    mkdir ${dst}
d639 1
a639 2
	# this may fail in case the floppy is empty
	cp -Rp ${BUILDDIR}/floppy.tree/* ${dst}/fd || true
d642 19
d664 2
a665 3
	ln -s ${SRC}/etc/MAKEDEV ; chmod 555 MAKEDEV
	# log `pwd`
	sh ./MAKEDEV ${MY_DEVS}
d669 2
a670 4
    if [ "`id -u`" = "0" ] ; then
	log "Fixing permissions"
	(cd ${dst}; chown -R root . )
    fi
d682 11
a692 9
    (cd ${BUILDDIR}
	# override the owner
	echo "/set uid=0 gid=0" > mtree.out
	mtree -c -p ${dst} -k "" >> mtree.out
	log "mtre.out at ${BUILDDIR}/mtree.out"
	makefs -t ffs -o bsize=4096 -o fsize=512 \
		-s ${MFS_SIZE}k -f 100 -F mtree.out ${c_fs} ${dst}
	ls -l ${c_fs} )
    log "done mfs image"
d697 1
d713 11
d730 3
d765 20
d786 1
a786 1
    local blocks dst mfs_start mfs_end mfs_size img_size
d793 2
a794 2
    # correct blocks according to size.
    blocks=${fd_size};
d796 1
a796 1
	blocks=1722
d798 1
a798 1
	blocks=1476
d801 2
a803 1
    log "patch ${c_boot2} to boot /kernel right away"
d805 1
a805 1
    cp -f ${c_boot2} ${b2}
a806 1

d808 1
a808 2
    echo -e "/kernel\0\0\0\0\0" | \
	dd of=${b2} obs=$1 oseek=1 conv=notrunc 2>/dev/null
d811 14
a824 3
    dst=${BUILDDIR}/image.tree
    rm -rf ${dst}
    mkdir -p ${dst}
a826 1
    set 0 0 # reset variables
d829 4
a832 14
    mfs_start=$1
    set 0 0 # reset variables
    set `strings -at d kernel | grep "MFS Filesystem had better"`
    mfs_end=$1
    mfs_size="$((${mfs_end} - ${mfs_start}))"
    set -- `ls -l ${c_fs}`; imgsize="$5"
    if [ ${mfs_start} -gt 0 -a ${mfs_size} -ge ${imgsize} ] ; then
	mfs_ofs=$((${mfs_start} + 8192))
	log "Preload kernel with file ${c_fs} at ${mfs_ofs}"
	dd if=${c_fs} ibs=8192 iseek=1 of=kernel obs=${mfs_ofs} \
	    oseek=1 conv=notrunc 2> /dev/null
    else
    	log "not loading mfs, size ${mfs_size} img ${imgsize}"
    fi
d837 1
a837 1
    log "Now transfer floppy tree if not already in MFS image"
d844 5
a848 25
    (cd ${BUILDDIR}
    makefs -t ffs -o bsize=4096 -o fsize=512 \
	-s ${blocks}k -f 50 ${c_img} ${dst}
    # ${l_label} -f `pwd`/${c_img}
    ${l_label} -w -f `pwd`/${c_img} auto # write in a label
    # copy partition c: into a: with some sed magic
    ${l_label} -f `pwd`/${c_img} | sed -e '/  c:/{p;s/c:/a:/;}' | \
	${l_label} -R -f `pwd`/${c_img} /dev/stdin
    ${l_label} -f `pwd`/${c_img}
    ls -l ${c_img}
	logverbose "after disklabel"
	 )
    # dump the primary and secondary boot
    # XXX primary is 512 bytes
    dd if=${c_boot1} of=${BUILDDIR}/${c_img} conv=notrunc 2>/dev/null
    # XXX secondary starts after the 0x114 = dec 276 bytes of the label
    # so we skip 276 from the source, and 276+512=788 from dst
    # the old style blocks used 512 and 1024 respectively

    dd if=${b2} iseek=1 ibs=276 2> /dev/null | \
	dd of=${BUILDDIR}/${c_img} oseek=1 obs=788 conv=notrunc 2>/dev/null
    logverbose "done floppy image"
    # XXX (log "Fixing permissions"; cd ${dst}; chown -R root *)
    rm -rf ${BUILDDIR}/floppy.tree || true # cleanup
    # df -ik ${dst} | colrm 70 > .build.reply
@


1.37.2.2
log
@correct a minor bug when printing the list of files excluded.
This does not prevent the build but it is nicer to do it right.
(the problem affects also HEAD and RELENG_7 but there is probably
a lot more to be fixed there in order to produce buildable picobsd
images).
@
text
@d494 1
a495 1
	excl="--exclude-from ${excl}"
@


1.37.2.3
log
@Switch importer
@
text
@d3 1
a3 1
# $FreeBSD: stable/6/release/picobsd/build/picobsd 173582 2007-11-13 15:19:35Z luigi $
@


1.37.2.2.4.1
log
@SVN rev 183531 on 2008-10-02 02:57:24Z by kensmith

Create releng/6.4 from stable/6 in preparation for 6.4-RC1.

Approved by:	re (implicit)
@
text
@@


1.36
log
@NOSHARE -> NO_SHARE
@
text
@d157 1
a157 1
    make -DNOCLEAN -DNO_PROFILE -DNO_GAMES -DNO_LIBC_R -DPICOBSD buildworld
@


1.35
log
@NOHTML -> NO_HTML
@
text
@d185 1
a185 1
		-DNO_HTML -DNO_INFO -DNO_MAN -DNOSHARE -DNO_FSCHG "
@


1.34
log
@NOGAMES -> NO_GAMES
@
text
@d185 1
a185 1
		-DNOHTML -DNO_INFO -DNO_MAN -DNOSHARE -DNO_FSCHG "
@


1.33
log
@NOFSCHG -> NO_FSCHG
@
text
@d157 1
a157 1
    make -DNOCLEAN -DNO_PROFILE -DNOGAMES -DNO_LIBC_R -DPICOBSD buildworld
@


1.32
log
@NODOCCOMPRESS -> NO_DOCCOMPRESS
NOINFO -> NO_INFO
NOINFOCOMPRESS -> NO_INFOCOMPRESS
NOLINT -> NO_LINT
NOPIC -> NO_PIC
NOPROFILE -> NO_PROFILE
@
text
@d185 1
a185 1
		-DNOHTML -DNO_INFO -DNO_MAN -DNOSHARE -DNOFSCHG "
@


1.31
log
@NOLIBC_R -> NO_LIBC_R
NOLIBPTHREAD -> NO_LIBPTHREAD
NOLIBTHR -> NO_LIBTHR
@
text
@d157 1
a157 1
    make -DNOCLEAN -DNOPROFILE -DNOGAMES -DNO_LIBC_R -DPICOBSD buildworld
d185 1
a185 1
		-DNOHTML -DNOINFO -DNO_MAN -DNOSHARE -DNOFSCHG "
d193 1
a193 1
	eval $e -DNOPROFILE -DNOPIC libraries
@


1.30
log
@Start the dreaded NOFOO -> NO_FOO conversion.

OK'ed by:	core
@
text
@d157 1
a157 1
    make -DNOCLEAN -DNOPROFILE -DNOGAMES -DNOLIBC_R -DPICOBSD buildworld
@


1.29
log
@Fix various issues with the picobsd build script in -current:

+ declare some shell variables as 'local'
+ add a missing ';;' in a 'case' statement
+ centralize newfs options
+ properly override GID and UID when installing include files and libraries
+ add a missing '-r' in disklabel commands (maybe not necessary, but it
  does not harm and it was used in the RELENG_4 version)
+ no more require 'perl' when installing the secondary loader
+ use '-t rsa1' when invoking ssh-keygen
@
text
@d185 1
a185 1
		-DNOHTML -DNOINFO -DNOMAN -DNOSHARE -DNOFSCHG "
@


1.28
log
@Remove obsolete disklabel and newfs options.
@
text
@d86 2
d117 1
a117 2
    c_boot=/boot/boot	# boot blocks (in case you want custom ones)
    c_boot1=/boot/boot1
d136 1
d138 1
d162 2
d170 6
a175 2
    (cd ${SRC}; INCOWN=`id -un`  BINOWN=`id -un` DESTDIR=${l_usrtree}/.. \
		make -m ${SRC}/share/mk includes ) || fail $? includes
d182 2
a183 1
	    INCOWN=`id -un` BINOWN=`id -un` DESTDIR=${l_usrtree}/.. \
d207 1
a207 1
    local a
d547 1
a547 1
	disklabel -w ${l_vndev} fd${MFS_SIZE} || fail $? mfs_disklabel
d549 1
a549 1
	disklabel -w ${l_vndev} auto || fail $? mfs_disklabel
d551 1
a551 2
    newfs -i ${mfs_inodes} -m 0 -o space -f 512 -b 4096 \
	/dev/${l_vndev}c > /dev/null
d622 1
a622 1
	    ssh-keygen -f ${BUILDDIR}/floppy.tree/etc/ssh_host_key \
d804 6
a809 2
    b=${BUILDDIR}/boot # modified boot
    perl -pne 's/\/boot\/loader/\/kernel\0\0\0\0\0/' ${c_boot} > ${b}
d812 1
a812 1
    disklabel -Bw -b ${b} ${l_vndev} auto || \
d820 1
a820 2
    newfs -i ${fd_inodes} -m 0 -o space -f 512 -b 4096 \
	     /dev/${l_vndev}a > /dev/null
@


1.27
log
@Replace a logverbose call with log
@
text
@d3 1
a3 1
# $FreeBSD: src/release/picobsd/build/picobsd,v 1.26 2002/07/14 09:07:13 luigi Exp $
d34 1
d115 2
a116 1
    c_boot1=/boot/boot1	# boot blocks (in case you want custom ones)
d537 1
a537 1
	disklabel -rw ${l_vndev} fd${MFS_SIZE} || fail $? mfs_disklabel
d539 1
a539 1
	disklabel -rw ${l_vndev} auto || fail $? mfs_disklabel
d541 1
a541 1
    newfs -i ${mfs_inodes} -m 0 -p 0 -o space -f 512 -b 4096 \
d795 2
a796 2
    b2=${BUILDDIR}/boot2 # modified boot2
    perl -pne 's/\/boot\/loader/\/kernel\0\0\0\0\0/' ${c_boot2} > ${b2}
d799 1
a799 1
    disklabel -Brw -b ${c_boot1} -s ${b2} ${l_vndev} auto || \
d807 1
a807 1
    newfs -i ${fd_inodes} -m 0 -p 0 -o space -f 512 -b 4096 \
@


1.26
log
@Enable building of picobsd using CURRENT sources again.

Following a suggestion by Ruslan, the initial creation of the
includes and libraries (and build tools) is now done by
invoking "make buildworld" (with -DPICOBSD which eventually will
limit the amount of stuff built with a 2-line change in Makefile.inc1).
The correct environment is then used for subsequent builds.

Also remove write_mfs_in_kernel.c in favour of using dd

All the above is conditional on __FreeBSD_version, as the previous
method still worked for versions earlier than 500035, and I am
unsure on how the "new" method works for earlier versions.

Finally, note that the crunch.conf files need some work because
some libraries (e.g. gmd) have gone away from the base installation.
@
text
@d3 1
a3 1
# $FreeBSD$
d855 1
a855 1
    logverbose "OSVERSION is ${OSVERSION}"
@


1.25
log
@DESTDIR does not anymore does the -I${DESTDIR}/usr/include magic
in <bsd.prog.mk> and <bsd.lib.mk>.

Reviewed by:	luigi
@
text
@d3 1
a3 1
# $FreeBSD: src/release/picobsd/build/picobsd,v 1.24 2002/03/21 03:15:06 luigi Exp $
d147 9
d275 6
d453 2
a454 1
    (cd $MY_TREE; export name SRC CONFIG BUILDDIR # used in this makefile ;
d591 2
a592 1
    export SRC LIBS CFLAGS # used by crunch.mk
d813 6
a818 16
    log "Preload kernel with file ${c_fs}"
if [ true ] ; then
    if [ -f ${PICO_TREE}/build/write_mfs_in_kernel.c ] ; then
	cc -o wmk ${PICO_TREE}/build/write_mfs_in_kernel.c
    else
	cc -o wmk ${PICO_TREE}/../write_mfs_in_kernel.c
    fi
    ./wmk kernel ${c_fs} || fail $? no_mfs
    rm wmk
else	# not working yet, just a reminder
    objdump -h kernel
    objcopy --remove-section=md_root kernel
    objcopy --add-section md_root=${c_fs} kernel
    objcopy --set-section-flags md_root=contents,alloc,load,data kernel
    objdump -h kernel
fi
d840 1
a840 1
# SRC, l_usrtree, l_objtree LIBS, CFLAGS
d853 3
a855 1

d857 14
a870 1
	create_includes_and_libraries
a871 6
    # Create the right LIBS and CFLAGS for further builds.
    # and build the config program
    LIBS="-L${l_usrtree}/lib"
    CFLAGS="-nostdinc -I${l_usrtree}/include"
    export LIBS CFLAGS
    CONFIG=${l_usrtree}/sbin/config
@


1.24
log
@Gracefully exit when no MFS signature is found in the kernel.

Add support for a new "import_files" option (see manpage for details).
@
text
@d3 1
a3 1
# $FreeBSD$
d154 1
a154 1
    (cd ${SRC}; INCOWN=`id -un`  BINOWN=`id -un` DESTDIR=${SRC}/.. \
d156 2
a157 2
    # libraries already have the include path in the Makefile
    CFLAGS="-nostdinc" ; export CFLAGS
d162 1
a162 1
	    INCOWN=`id -un` BINOWN=`id -un` DESTDIR=${SRC}/.. \
@


1.23
log
@Fix detection of existing ssh host key, generate the new one
in floppy.tree instead of mfs_tree.

Do not cleanup ${BUILDDIR}/floppy.tree, it might be useful to look
at it after an image has been built.
@
text
@d644 10
d720 3
d803 1
a803 1
    ./wmk kernel ${c_fs}
@


1.22
log
@Misc fixes to the build script:

 + fix some dialog entries to correctly modify variables instead of working
   in a subshell

 + add a logverbose function for debugging purposes

 + force 512/4096 blocks on filesystems

 + use 'auto' for disklabel so it works irrespective of the floppy size.
   This is useful for larger images than 1720k
@
text
@d3 1
a3 1
# $FreeBSD: src/release/picobsd/build/picobsd,v 1.21 2002/02/14 19:21:50 luigi Exp $
d165 2
a166 2
	# need to 'make obj' in a few places. This is very
	# version-specific... The following works for 5.0
d171 1
a171 1
	# now make the static libraries
d379 1
a379 1
	10 70 2> ${c_reply} && mfs_inodes=`cat ${c_reply}` ; } || true
d497 1
d589 2
a590 2
	log "Creating host key for sshd"
	if [ -f ${dst}/etc/ssh_host_key ] ; then
d593 4
a596 1
	    ssh-keygen -f ${dst}/etc/ssh_host_key -N "" -C "root@@picobsd"
d605 1
a605 1
		(cd ${dst} ; tar x${o_tarv}f - )
d776 1
a776 1
	/dev/${l_vndev}a > /dev/null
d811 1
a811 1
    rm -rf ${BUILDDIR}/floppy.tree || true # cleanup
@


1.21
log
@Use { } instead of ( ) for grouping shell commands so that
variable assignments are retained ( () creates a subshell)

Reported-by: Michael Bretterklieber <mbretter@@inode.at>
@
text
@d3 1
a3 1
# $FreeBSD$
d84 5
d370 1
a370 1
	(dialog --menu "Set floppy size" 15 70 4 \
d372 1
a372 1
		 2> ${c_reply} && fd_size=`cat ${c_reply}` ) || true
d376 1
a376 1
	(dialog --title "MFS bytes per inode:" --inputbox \
d379 1
a379 1
	10 70 2> ${c_reply} && mfs_inodes=`cat ${c_reply}` ) || true
d383 1
a383 1
	(dialog --title "Floppy bytes per inode:" --inputbox \
d386 1
a386 1
	10 70 2> ${c_reply} && fd_inodes=`cat ${c_reply}` ) || true
d522 2
a523 1
    newfs -i ${mfs_inodes} -m 0 -p 0 -o space /dev/${l_vndev}c > /dev/null
d596 8
a603 9
    if [ -d ${MY_TREE}/mfs_tree ]; then
	log "Copy site-specific MFS tree..."
	MFS_TREE=${MY_TREE}/mfs_tree
    else
	log "Copy generic MFS tree..."
	MFS_TREE=${PICO_TREE}/mfs_tree
    fi
    (cd ${MFS_TREE} ; tar -cf - --exclude CVS . ) | \
	    (cd ${dst} ; tar x${o_tarv}f - )
d761 3
a763 1
    disklabel -Brw -b ${c_boot1} -s ${b2} ${l_vndev} fd${fd_size} || \
d766 4
d771 2
a772 1
    newfs -i ${fd_inodes} -m 0 -p 0 -o space /dev/${l_vndev}c > /dev/null
d775 1
a775 1
    mount /dev/${l_vndev}c ${dst}
@


1.20
log
@Whoops... left some junk in previous commit.
@
text
@d330 2
a331 2
	(dialog --menu "Setup the type of configuration" 12 70 5 $l \
		2> ${c_reply} && set_type "`cat ${c_reply}`" ${SITE} ) || true
d334 1
a334 1
	(dialog --menu "Choose your init(8) program" \
d337 1
a337 1
		&& init_name=`cat ${c_reply}` ) || true
d345 1
a345 1
	( dialog --title "MFS Size setup" --inputbox \
d352 1
a352 1
	&& MFS_SIZE=`cat ${c_reply}` ) || true
d356 1
a356 1
	(dialog --title "Site info setup" --inputbox \
d361 1
a361 1
	10 70 2> ${c_reply} && SITE=`cat ${c_reply}` ) || true
@


1.19
log
@Let "make" use the .mk files from the correct source tree instead
of the default ones (which could be incorrect when doing cross builds).

Also, try to be backward compatible when compiling wmk (the goal being
able to use the most recent "picobsd" script on a wide range of
source trees).
@
text
@a2 1
<<<<<<< picobsd
a3 3
=======
# $FreeBSD: src/release/picobsd/build/picobsd,v 1.18 2001/11/20 01:00:52 joe Exp $
>>>>>>> 1.18
@


1.18
log
@Use a local write_mfs_in_kernel.c instead of the one in ncvs/src/release
which is likely to be removed shortly, after repo-copying it from
there.
@
text
@d3 5
a7 1
# $FreeBSD: src/release/picobsd/build/picobsd,v 1.17 2001/11/01 16:17:37 luigi Exp $
d154 1
a154 1
		make includes ) || fail $? includes
d162 2
a163 1
	    make -DNOHTML -DNOINFO -DNOMAN -DNOSHARE -DNOFSCHG "
d442 1
a442 1
	make -v -f ${PICO_TREE}/build/Makefile.conf ) || \
d569 2
a570 1
	make -v -f ${PICO_TREE}/build/Makefile.conf ${BUILDDIR}/crunch.mk )
d574 1
a574 1
    make ${o_makeopts} -f ${BUILDDIR}/crunch.mk
a770 1
    cc -o wmk ${PICO_TREE}/build/write_mfs_in_kernel.c
d772 6
d780 7
@


1.17
log
@Provide a new picobsd option, "--modules", to also build modules
(modload and friends are sufficiently small to consider their inclusion
in PicoBSD images).
@
text
@d3 1
a3 1
# $FreeBSD$
d765 1
a765 1
    cc -o wmk ${PICO_TREE}/../write_mfs_in_kernel.c
@


1.16
log
@Use host keys from the config directory if they exist, instead of
regenerating them.

Make the script handle relative paths for the source directory.
@
text
@d103 1
d401 5
d433 4
d843 3
@


1.15
log
@A somewhat large change of this script.

From the user's perspective:
 * everything is now built outside the source tree (more precisely,
   in `pwd`/builddir-${name}/ ) except for the kernel config file(s)
   which still need to be copied into src/sys/i386/conf because of
   "config" limitations. I am not sure if there is an easy way
   to get away from this without changing "config" or replicating
   some part of the source tree.
   This is really the only change that most users should worry about,
   but it is a good one.

 * if you do cross-compiles (using "picobsd --src somedir/src [--init] ... ")
   then the libraries and include directories etc.  are searched/created
   in "somedir/usr" ;

 * you can do most things (basically build the kernel and the crunched
   binary and the filesystem trees) without root privileges. You need
   privileges to use mdconfig/vnconfig to create the actual MFS and
   floppy image, unfortunately.

 * the -v option now prints some diagnostic but does not stop for
   user input at each step. You need to specify -v -v to have the
   old behaviour.

Internally, the script has been reshuffled quite a bit to support
the above features. Many shell variables have been renamed or
made local in an effort to avoid undesired side effects. There is
a somewhat better error handling in case something goes wrong.
@
text
@d571 5
a575 1
	ssh-keygen -f ${dst}/etc/ssh_host_key -N "" -C "root@@picobsd"
d813 1
a813 1
	SRC=$2
@


1.14
log
@Move a bunch of initialization into a function which must be run
before parsing the command line.
Move code to build include and libraries in a separate function,
so we can use the verbose flag for that.
Chang ownership of some directories so more of the build process
(namely, builds of include and libs) can be run without root
permission (we still depend on root permission to mount a memory
filesystem).
@
text
@a35 1
#--- here are various functions used by the script.
d39 18
a56 17
# initialize some shell variables used by the script.
# This must be done after option parsing so user-specified values
# are used to compute dependent ones. Make sure to use the
# VAR=${VAR:-value} construct for those variables which can
# be overridden from the command line.

init_vars() {	# OK
    # if you include the floppy tree in the mfs, you
    # can boot from the image via diskless. Default to yes.
    INCLUDE_FLOPPY_IN_MFS=${INCLUDE_FLOPPY_IN_MFS:-yes}

    # SRC points to your FreeBSD source tree.
    # OBJ points to the obj tree. Normally /usr/obj-pico.
    # PICO_TREE is where standard picobsd stuff resides.
    # MY_TREE (set later) is where this floppy type resides.
    # START_DIR is the directory where we start
    # BUILDDIR is the build directory, which is the current one.
d58 8
a65 4
    SRC=${SRC:-/usr/src}
    OBJ=${OBJ:-${SRC}/usr/obj-pico}
    PICO_TREE=${PICO_TREE:-${SRC}/release/picobsd}
    START_DIR=`pwd`
d67 2
d70 13
a82 4
    # Various temporary files and directories.
    # User replies will be put in $RISU
    RISU=${RISU:-`mktemp "/tmp/reply.XXXXXXXXXX"`}
    MFS_MOUNTPOINT=`mktemp -d "/tmp/picobsd.XXXXXXXXXX"`
d84 2
a85 1
    MFS_NAME=fs.PICOBSD
d88 1
a88 2
    # SITE is site_name above.
    # FLOPPY_SIZE  floppy size in KB (default to 1440). You can use 1480,
d92 1
a92 2
    SITE=${SITE:-}
    FLOPPY_SIZE=${FLOPPY_SIZE:-1440}
d94 23
a116 1
    NO_DEVFS=yes # DEVFS is currently broken. Always set this.
d118 10
d129 2
a130 7
    VNUM=`mount | awk "/${VN}/ { num++ } END { printf \"%d\", num }"`
    VNDEV=${VN}${VNUM}
    log "---> Using ${VNDEV}..."

    # Location of the boot blocks (in case you want them custom-built)
    boot1=/boot/boot1
    boot2=/boot/boot2
a131 2
    makeopts=${MAKEOPTS:--s}	# be silent by default
    # abort in case of error...
d134 5
a138 2
    trap fail 2	# catch user interrupt
    free_vnode
d141 11
a151 7
# log something on stdout if verbose.
log() {
    if [ "$verbose" != "" ] ; then
	printf "%s\n" "$*"
	read -p "(log) enter to continue" foo
    fi
}
d153 31
a183 5
# set_type <type> looks for the floppy type specified as
# first argument in user- or standard- directory.
# If found set variables accordingly.

set_type() {		# OK
d185 1
a185 1
    for i in ${START_DIR}/${a} ${PICO_TREE}/${a} ; do
d191 2
a192 2
		MFS_SIZE=$1 ; INIT=$2
		MFS_INODES=$3 ; FLOPPY_INODES=$4
d196 2
a197 2
		BUILDDIR=${START_DIR}/build_dir-${name}
		log "---> Matching file $name in $i"
d206 1
d208 1
a208 1
	echo "---> wrong floppy type"
d216 5
a220 5
    log "free_vnode, VN is ${VN} "
    umount ${MFS_MOUNTPOINT}    2> /dev/null || true
    umount /dev/${VNDEV}       2> /dev/null || true
    if [ "${VN}" = "vn" ] ; then
	vnconfig -u ${VNDEV} 2> /dev/null || true
d222 1
a222 1
	mdconfig -d -u ${VNUM} 2> /dev/null || true
d228 2
d240 2
a241 5
    if [ "${name}" = "" ] ; then
	echo "-> wrong floppy type"
	final_cleanup
	exit 1
    fi
d244 14
a257 7
    printf "${MSG}"
    echo "-> We'll use the sources living in ${SRC}"
    echo "-> vnode is ${VNDEV}"
    echo ""
    echo "-> I hope you have checked the PICOBSD config file..."
    echo ""
    echo ""
d259 5
a263 1
    init_stage1
d265 6
a270 3
    populate_floppy_fs	# things which go into floppy
    create_mfs
    populate_mfs		# things which go into mfs
d275 3
d286 5
a290 9
	build_image
	if [ "X$?" != "X0" ] ; then
	    echo "	** FAILED! **">>build.status
	else
	    echo "	(ok)">>build.status
	fi
	mv ${BUILDDIR}/picobsd.bin ${BUILDDIR}/picobsd.${name}.bin
	echo "Cleaning ${z}">>build.status
	clean_tree
d298 3
d303 2
a304 1
    dialog --menu "PicoBSD build menu -- (29 aug 2001)" 19 70 12 \
d310 4
a313 4
	I "Init type: ${INIT}" \
	F "Floppy size: ${FLOPPY_SIZE}kB" \
	M "MFS bytes per inode: ${MFS_INODES}" \
	U "UFS bytes per inode: ${FLOPPY_INODES}" \
d316 3
a318 3
	2> ${RISU}
    ans=`cat ${RISU}`
    rm ${RISU}
d322 1
a322 1
	for i in ${START_DIR} ${START_DIR}/* ${PICO_TREE}/* ; do
d328 2
a329 6
	dialog --menu "Setup the type of configuration" 12 70 5 $l \
		2> ${RISU} || rm ${RISU}
	if [ -f ${RISU} ] ; then
	    THETYPE=`cat ${RISU}`
	    set_type $THETYPE
	fi
d332 1
a332 1
	dialog --menu "Choose your init(8) program" \
d334 2
a335 4
	oinit "small init from TinyWare" 2> ${RISU} || rm ${RISU}
	if [ -f ${RISU} ] ; then
	    INIT=`cat ${RISU}`
	fi
d343 1
a343 1
	dialog --title "MFS Size setup" --inputbox \
d349 2
a350 4
this as small as possible. " 10 70 2> ${RISU} || rm ${RISU}
	if [ -f ${RISU} ] ; then
	    MFS_SIZE=`cat ${RISU}`
	fi
d354 1
a354 1
	dialog --title "Site info setup" --inputbox \
d359 1
a359 4
	10 70 2> ${RISU} || rm ${RISU}
	if [ -f ${RISU} ] ; then
	    SITE=`cat ${RISU}`
	fi
d363 3
a365 6
	dialog --menu "Set floppy size" 15 70 4 \
		1440 "1.44MB" 1720 "1.72MB" \
		2880 "2.88MB" 4096 "4MB" 2> ${RISU} || rm ${RISU}
	if [ -f ${RISU} ] ; then
	    FLOPPY_SIZE=`cat ${RISU}`
	fi
d369 1
a369 1
	dialog --title "MFS bytes per inode:" --inputbox \
d372 1
a372 4
	10 70 2> ${RISU} || rm ${RISU}
	if [ -f ${RISU} ] ; then
	    MFS_INODES=`cat ${RISU}`
	fi
d376 1
a376 1
	dialog --title "Floppy bytes per inode:" --inputbox \
d379 1
a379 4
	10 70 2> ${RISU} || rm ${RISU}
	if [ -f ${RISU} ] ; then
	    FLOPPY_INODES=`cat ${RISU}`
	fi
d398 2
d409 2
a410 2
	* Enter to install \"picobsd.bin\",\n\
" 20 80 2> ${RISU}
d412 2
a413 2
	echo "Writing picobsd.bin..."
	dd if=${BUILDDIR}/picobsd.bin of=/dev/fd0.${FLOPPY_SIZE}
d415 1
a415 1
	echo "Ok, the image is in picobsd.bin"
d423 1
a423 26
init_stage1() {

    # read config variables from a global and then a type-specific file
    # 
    . ${PICO_TREE}/build/config
    if [ -f ${MY_TREE}/config ]; then
	. ${MY_TREE}/config
    fi

    PICO_OBJ=${OBJ}/picobsd/${THETYPE}
    log "PICO_OBJ is ${PICO_OBJ}"

    if [ ! -d ${BUILDDIR} ]; then
	log "Creating builddir"
	mkdir $BUILDDIR
	if [ ! -d ${BUILDDIR}/crunch ]; then
	    log "creating crunch dir"
	    mkdir ${BUILDDIR}/crunch
	fi
    else
	rm -f ${BUILDDIR}/kernel.gz ${BUILDDIR}/${MFS_NAME}    # cleanup...
    fi
}

# invoke the makefile to compile the kernel.
# Then copy it here and strip as much as possible.
d425 1
a425 1
    log "---> Preparing kernel \"$name\" in $MY_TREE"
d431 2
a432 2
# Populate the variable part of the floppy filesystem. Should be
# done before the MFS because it might need to be copied there as well.
d434 1
a434 1
# This involves three subtrees, in this order:
d436 1
a436 1
#  1. a standard one from which type-specific files are excluded;
d445 1
d447 1
a447 1
    log "---> pwd=`pwd` Populating floppy filesystem..."
d456 1
a456 1
	log "---> Files excluded from generic tree: `echo;cat ${excl}`"
d461 2
a462 2
		(cd ${dst} ; tar x${TAR_VERBOSE}f - )
    log "---> Copied from generic floppy-tree `echo; ls -laR ${dst}`"
d466 1
a466 1
	log "---> update with type-specific files:"
d468 2
a469 2
	    (cd ${dst} ; tar x${TAR_VERBOSE}f - )
	log "---> Copied from type floppy-tree `echo; ls -laR ${dst}`"
d471 1
a471 1
	log "---> No type-specific floppy-tree"
d474 1
a474 1
	log "-> update with site-specific (${SITE}) files:"
d476 2
a477 2
	    (cd ${dst} ; tar x${TAR_VERBOSE}f - )
	log "---> Copied from site floppy-tree `echo; ls -laR ${dst}`"
d479 1
a479 1
	log "---> No site-specific floppy-tree"
d482 2
a483 3
    (cd $dst
    gzip -9 etc/*
    log "---> Compressed files in etc/ `echo; ls -l etc`"
d488 1
a488 1
    log "---> Preparing MFS filesystem..."
d493 1
a493 1
    init_fs_image ${BUILDDIR}/${MFS_NAME} ${MFS_SIZE}
d495 1
a495 1
    log "---> Labeling MFS image"
d502 1
a502 1
	disklabel -rw ${VNDEV} fd${MFS_SIZE} || fail $? mfs_disklabel
d504 1
a504 1
	disklabel -rw ${VNDEV} auto || fail $? mfs_disklabel
d506 3
a508 3
    newfs -i ${MFS_INODES} -m 0 -p 0 -o space /dev/${VNDEV}c > /dev/null
    mount /dev/${VNDEV}c ${MFS_MOUNTPOINT} || fail $? no_mount
    log "`df /dev/${VNDEV}c`"
d518 8
a525 7
populate_mfs() {
    log "---> pwd=`pwd`, Populating MFS tree..."
    # cd ${THETYPE}

    log "---> Running mtree ..."
    if [ -f ${MY_TREE}/mfs.mtree ] ; then
	a=${MY_TREE}/mfs.mtree
d527 4
a530 1
	a=${PICO_TREE}/build/mfs.mtree
d532 8
a539 1
    mtree -deU -f $a -p ${MFS_MOUNTPOINT} > /dev/null || fail $? mtree
d543 1
a543 1
	ln -s /stand ${MFS_MOUNTPOINT}/$i
d545 2
a546 2
    ln -s /dev/null ${MFS_MOUNTPOINT}/var/run/log
    ln -s /etc/termcap ${MFS_MOUNTPOINT}/usr/share/misc/termcap
a547 5
    # XXX-fixme in -current, MAKEDEV is from /usr/src/etc/MAKEDEV
    if [ "${NO_DEVFS}" != "" ] ; then
	(cd ${MFS_MOUNTPOINT}/dev ; ln -s ${MAKEDEV} ; chmod 555 MAKEDEV ;
	    ./MAKEDEV ${MY_DEVS}; rm MAKEDEV)
    fi
d551 1
a551 1
    log "---> Making and installing crunch1 from `pwd` src ${SRC}..."
d555 1
a555 1
    log "-- libs are ${LIBS} "
d558 1
a558 1
    make ${makeopts} -f ${BUILDDIR}/crunch.mk
d560 3
a562 3
    mv crunch1 ${MFS_MOUNTPOINT}/stand/crunch
    chmod 555 ${MFS_MOUNTPOINT}/stand/crunch
    log "---> Making links for binaries..."
d564 1
a564 1
	ln ${MFS_MOUNTPOINT}/stand/crunch ${MFS_MOUNTPOINT}/stand/${i};
d569 3
a571 3
    if [ -f ${MFS_MOUNTPOINT}/stand/sshd ] ; then
	log "creating host key for sshd"
	ssh-keygen -f ${MFS_MOUNTPOINT}/etc/ssh_host_key -N "" -C "root@@picobsd"
d575 1
a575 1
	log "---> Copy site-specific MFS tree..."
d578 1
a578 1
	log "---> Copy generic MFS tree..."
d582 1
a582 1
	    (cd ${MFS_MOUNTPOINT} ; tar x${TAR_VERBOSE}f - )
d584 45
a628 8
    if [ "${INCLUDE_FLOPPY_IN_MFS}" = "yes" ]; then
	log "---> Copy generic floppy_tree into MFS..."
	cp -Rp ${BUILDDIR}/floppy.tree/* ${MFS_MOUNTPOINT}/fd
    fi
    (log "---> Fixing permissions"; cd ${MFS_MOUNTPOINT}; chown -R root . )
    df -ik ${MFS_MOUNTPOINT}
    umount ${MFS_MOUNTPOINT}
    fsck -p /dev/${VNDEV}c
d633 1
d635 2
a636 1
    rm -rf ${MFS_MOUNTPOINT} ${RISU} 2> /dev/null || true
d643 2
d647 3
a649 2
    echo "---> fail: Error <$errno> error code <$errcode>"
    case $errcode in
d651 3
a653 2
	echo "Error while doing vnconfig of ${imgname} on /dev/${VNDEV}..."
	echo "   Most probably your running kernel doesn't have the ${VN}(4) device."
d656 1
a656 1
	echo "Error while labeling ${MFS_NAME} size ${MFS_SIZE}"
d659 1
a659 1
	echo "Error while mounting ${MFS_NAME} (/dev/${VNDEV}c) on ${MFS_MOUNTPOINT}"
d662 1
a662 1
	echo "Error while making hierarchy in ${MFS_MOUNTPOINT}"
d668 1
a668 1
	echo "Error while doing disklabel on of floppy.img size $FLOPPY_SIZE"
d679 6
d687 1
a687 1
	errcode="userbreak";
d704 3
d709 1
a709 1
    dd if=${boot1}  of=${imgname} conv=notrunc 2> /dev/null
d711 2
a712 2
    if [ "${VN}" = "vn" ] ; then
	vnconfig -c -s labels ${VNDEV} ${imgname} || fail $? no_vnconfig
d714 1
a714 1
	mdconfig -a -t vnode -u ${VNUM} -f ${imgname} || fail $? no_vnconfig
d720 6
a725 1
    log "---> Preparing ${FLOPPY_SIZE}kB floppy filesystem..."
d728 1
a728 1
    blocks=${FLOPPY_SIZE}; sectors=18
d735 1
a735 1
    init_fs_image ${BUILDDIR}/picobsd.bin ${blocks}
d737 1
a737 1
    log "---> Labeling floppy image"
d739 2
a740 2
    perl -pne 's/\/boot\/loader/\/kernel\0\0\0\0\0/' ${boot2} > ${b2}
    disklabel -Brw -b ${boot1} -s ${b2} ${VNDEV} fd${FLOPPY_SIZE} || \
d743 2
a744 1
    newfs -i ${FLOPPY_INODES} -m 0 -p 0 -o space /dev/${VNDEV}c > /dev/null
d746 2
a747 1
    mount /dev/${VNDEV}c ${MFS_MOUNTPOINT}
a748 1
    # preload kernel, compress with kgzip and copy to floppy image
d752 2
a753 1
    ./wmk kernel ${MFS_NAME}
d755 1
d757 1
a757 1
    cp -p kernel.gz ${MFS_MOUNTPOINT}/kernel
d759 1
d761 3
a763 2
    if [ "${INCLUDE_FLOPPY_IN_MFS}" != "yes" ]; then
	cp -Rp floppy.tree/* ${MFS_MOUNTPOINT}
d766 1
a766 1
    (log "---> Fixing permissions"; cd ${MFS_MOUNTPOINT}; chown -R root *)
d769 1
a769 1
    df -ik ${MFS_MOUNTPOINT} | colrm 70 > .build.reply
d771 2
a772 2
    rm -rf ${MFS_MOUNTPOINT}
    rm ${BUILDDIR}/kernel.gz ${BUILDDIR}/${MFS_NAME}
d775 14
a788 14
#
# this code creates variables to point to the correct
# source tree, and optionally initializes it.
init_src_tree() {
    if [ "${src}" = "" ] ; then
	return
    fi
    SRC=${src}
    log "using src tree in ${SRC}, init ${init_src}"
    if [ "${init_src}" != "" ] ; then
	# Optionally creates include directory and libraries.
	mkdir -p ${SRC}/usr/include	# the include directory...
	mkdir -p ${SRC}/usr/share/misc	# a few things go here
	mkdir -p ${SRC}/usr/lib		# libraries
d790 2
a791 20
	(cd ${SRC}; INCOWN=`id -un`  BINOWN=`id -un` DESTDIR=${SRC} \
		make includes ) || fail $? includes
	# libraries already have the include path in the Makefile
	CFLAGS="-nostdinc" ; export CFLAGS

	(cd ${SRC}
	    # $e is the invocation of make with correct environment
	    e="MAKEOBJDIRPREFIX=${SRC}/usr/obj-pico/picobsd/libraries \
		INCOWN=`id -un` BINOWN=`id -un` DESTDIR=${SRC} \
		make -DNOHTML -DNOINFO -DNOMAN -DNOSHARE -DNOFSCHG "
	    # need to 'make obj' in a few places. This is very
	    # version-specific... The following works for 5.0
	    for i in lib secure/lib gnu/lib usr.sbin/pcvt/keycap \
		    gnu/usr.bin/perl usr.bin/lex  ; do
		(cd ${i}; eval $e obj)
	    done
	    # now make the static libraries
	    eval $e -DNOPROFILE -DNOPIC libraries
	) || fail $? "libraries"
	log "libraries done"
d793 1
a793 1
    # pass the right LIBS and CFLAGS to the Makefile,
d795 2
a796 2
    LIBS="-L${SRC}/usr/lib"
    CFLAGS="-nostdinc -I${SRC}/usr/include"
d798 1
a798 2
    (cd ${SRC}/usr.sbin/config ; CFLAGS="" make )
    CONFIG=${SRC}/usr.sbin/config/config
d801 3
a803 20
# set some default values for variables.
# needs to be done as the first thing in the script.

default_vars() {
    verbose=""
    TAR_VERBOSE=""
    CONFIG=config
    src=""		# not set by user
    init_src=""
    # select the right memory disk name
    case `uname -r` in
	5.*)
	    VN="md"
	    MAKEDEV="${SRC}/etc/MAKEDEV"
	    ;;
	*)
	    VN="vn"
	    MAKEDEV="/dev/MAKEDEV"
    esac
}
d805 1
a805 3
#-------------------------------------------------------------------
# Main entry of the script
default_vars
d809 1
a809 1
	src=$2
d811 3
a813 4
	if [ "$2" = "--init" ] ; then
	    init_src=$2
	    shift
	fi
d817 1
a817 1
	FLOPPY_SIZE=$2
d820 9
d830 6
a835 1
	interactive="NO"
d837 5
a841 8
    -c*) # clean
	clean="YES"
	interactive="NO"
	;;
    -v)
	verbose="YES"
	TAR_VERBOSE="v"
	makeopts="-d l" # be verbose
d850 2
a851 6
init_src_tree	# possibly a nop. Needs to be done before init_vars
init_vars	# set other variables depending on cmdline args.

THETYPE=$1
SITE=$2
set_type $THETYPE
d858 1
a858 1
if [ "$interactive" != "NO" ] ; then
d861 1
a861 1
if [ "$clean" = "YES" ] ; then
@


1.13
log
@On -current with devfs there is no MAKEDEV in /dev anymore, so use
it from ${SRC}/etc/MAKEDEV instead.

We may want to do this on -stable as well, but for now -stable still
uses /dev/MAKEDEV.
@
text
@d3 1
a3 1
# $FreeBSD: src/release/picobsd/build/picobsd,v 1.12 2001/09/20 13:09:01 joe Exp $
d59 1
a59 1
    OBJ=${OBJ:-/usr/obj-pico}
a62 10
    # select the right memory disk name
    case `uname -r` in
	5.*)
	    VN="md"
	    MAKEDEV="${SRC}/etc/MAKEDEV"
	    ;;
	*)
	    VN="vn"
	    MAKEDEV="/dev/MAKEDEV"
    esac
d143 1
d661 66
d729 1
a729 5

verbose=""
TAR_VERBOSE=""
CONFIG=config

d733 4
a736 2
	SRC=$2
	if [ "$3" = "--init" ] ; then
d738 1
a738 35
	    # Optionally creates include directory and libraries.
	    mkdir -p ${SRC}/usr/include		# the include directory...
	    mkdir -p ${SRC}/usr/share/misc	# a few things go here
	    mkdir -p ${SRC}/usr/lib		# libraries

	    (cd ${SRC}; INCOWN=`id -un` DESTDIR=${SRC} make includes ) || \
		fail $? includes
	    # libraries already have the include path in the Makefile
	    CFLAGS="-nostdinc" ; export CFLAGS

	    (cd ${SRC}
		# $e is the invocation of make with correct environment
		e="MAKEOBJDIRPREFIX=/usr/obj-pico/picobsd/libraries \
		    BINOWN=`id -un` DESTDIR=${SRC} \
		    make -DNOHTML -DNOINFO -DNOMAN -DNOSHARE -DNOFSCHG "
		# need to 'make obj' in a few places. This is very
		# version-specific... The following works for 5.0
		for i in lib secure/lib gnu/lib usr.sbin/pcvt/keycap \
			gnu/usr.bin/perl usr.bin/lex  ; do
		    (cd ${i}; eval $e obj)
		done
		# now make the static libraries
		eval $e -DNOPROFILE -DNOPIC libraries
	    ) || fail $? "libraries"
	    log "libraries done"
	fi
	# pass the right LIBS and CFLAGS to the Makefile,
	# and build the config program
	LIBS="-L${SRC}/usr/lib"
	CFLAGS="-nostdinc -I${SRC}/usr/include"
	export LIBS CFLAGS
	(cd ${SRC}/usr.sbin/config ; CFLAGS="" make )
	CONFIG=${SRC}/usr.sbin/config/config

	shift
d764 2
a765 1
init_vars
@


1.12
log
@Relocate the memory disk selection code to the same place the other
variables are set.
@
text
@d3 1
a3 1
# $FreeBSD: src/release/picobsd/build/picobsd,v 1.11 2001/09/20 02:52:02 luigi Exp $
d67 1
d71 1
d502 1
a502 1
	(cd ${MFS_MOUNTPOINT}/dev ; ln -s /dev/MAKEDEV ;
@


1.11
log
@Make the script aware of mdconfig, so it can hopefully run on -CURRENT
as well. This works by selecting "md" or "vn" depending on "uname -r"
output, so we can use the same script on -CURRENT and -STABLE.
Also included minor bugfixes and code cleanup.

Testers welcome, as this code has only been tested on -STABLE
(and for this reason I am doing an immediate MFC).
@
text
@d3 1
a3 1
# $FreeBSD$
a45 9
# select the right memory disk name
case `uname -r` in
    5.*)
	VN="md"
	;;
    *)
	VN="vn"
esac

d62 9
@


1.10
log
@Move commands to create stripped kernel into Makefile.conf,
so as to make the "picobsd" script less version-specific.

Improve handling of cross-builds (which requires creation of
includes and libraries for the new source tree).

The "picobsd" script will not probably work on -current because it still
uses 'vn' instead of 'md', but i am commiting it anyways to keep it
in sync with the version in -stable.
@
text
@d46 9
a55 1

d91 3
a93 2
    VNUM=`mount | awk "/vn/ { num++ } END { printf \"%d\", num }"`
    log "---> Using vn${VNUM}..."
d149 11
d181 1
a181 1
    echo "-> vnode is $VNUM"
d349 1
a349 1
	dd if=${BUILDDIR}/picobsd.bin of=/dev/rfd0.${FLOPPY_SIZE}
d404 1
d409 3
a411 3
    # clean relics from old compilations. This is the destination.
    rm -rf $dst || true
    mkdir $dst
d416 1
a416 2
	log "---> Exclude following files from generic tree:
`cat ${excl}`"
d444 1
a444 2
    log "---> Compressed files in etc/
`ls -l etc`"
d463 1
a463 1
	disklabel -rw vn${VNUM} fd${MFS_SIZE} || fail $? mfs_disklabel
d465 1
a465 1
	disklabel -rw vn${VNUM} auto || fail $? mfs_disklabel
d467 3
a469 3
    newfs -i ${MFS_INODES} -m 0 -p 0 -o space /dev/rvn${VNUM}c > /dev/null
    mount /dev/vn${VNUM}c ${MFS_MOUNTPOINT} || fail $? no_mount
    log "`df /dev/vn${VNUM}c`"
d498 1
d506 1
a506 1
    log "---> Making and installing crunch1 from `pwd`..."
d511 1
a511 1
    export LIBS CFLAGS # used by crunch.mk
d546 2
a547 9
    fsck -p /dev/rvn${VNUM}c
    vnconfig -u vn${VNUM}
}

# free as much as possible from the vnode
free_vnode() {
    umount ${MFS_MOUNTPOINT}    2> /dev/null || true
    umount /dev/vn${VNUM}       2> /dev/null || true
    vnconfig -u vn${VNUM} 2> /dev/null || true
d564 2
a565 2
	echo "Error while doing vnconfig of ${imgname} on /dev/rvn${VNUM}..."
	echo "   Most probably your running kernel doesn't have the vn(4) device."
d571 1
a571 1
	echo "Error while mounting ${MFS_NAME} (/dev/vn${VNUM}c) on ${MFS_MOUNTPOINT}"
d614 5
a618 1
    vnconfig -c -s labels vn${VNUM} ${imgname} || fail $? no_vnconfig
d638 1
a638 1
    disklabel -Brw -b ${boot1} -s ${b2} vn${VNUM} fd${FLOPPY_SIZE} || \
d641 1
a641 1
    newfs -i ${FLOPPY_INODES} -m 0 -p 0 -o space /dev/vn${VNUM}c > /dev/null
d643 1
a643 1
    mount /dev/vn${VNUM}c ${MFS_MOUNTPOINT}
d680 1
@


1.9
log
@Supply a default value for the kernel config binary.
@
text
@d3 1
a3 1
# $FreeBSD: src/release/picobsd/build/picobsd,v 1.8 2001/09/01 18:27:39 luigi Exp $
d202 1
a202 1
    dialog --menu "PicoBSD build menu -- (19 feb 2000)" 19 70 12 \
d367 2
a368 3
    (cd $MY_TREE; export name SRC CONFIG # used in this makefile ;
	make -v -f ${PICO_TREE}/build/Makefile.conf )
    cp -p ${SRC}/sys/compile/PICOBSD-${name}/kernel ${BUILDDIR}/kernel || \
a369 4
    (cd ${BUILDDIR};
    strip kernel
    strip --remove-section=.note --remove-section=.comment kernel
    )
d489 3
a491 6
    make -v -f ${PICO_TREE}/build/Makefile.conf ${BUILDDIR}/crunch.mk )
    # update crunch.mk for new libs
    if [ "${LIBS}" != "" ] ; then
	sed -e "s@@^LIBS=@@  LIBS= ${LIBS}@@" ${BUILDDIR}/crunch.mk > ${BUILDDIR}/crunch1.mk
	mv ${BUILDDIR}/crunch1.mk ${BUILDDIR}/crunch.mk
    fi
d572 6
d662 33
a694 26
	# Optionally creates include directory, and set cflags
	# accordingly. Note that you will still need the right
	# libraries...

	i=${SRC}/usr/include	# the include directory...
	if [ \! -d $i ] ; then
	    echo "Create \"$i\" as include directory"
	    mkdir -p $i
	    (cd ${SRC};
	    INCOWN=`id -un` DESTDIR=${SRC} make includes
	    )
	fi
	CFLAGS="-nostdinc -I$i" ; export CFLAGS
	i=${SRC}/usr/lib
	if [ \! -d $i ]; then
	    echo "Create libraries (this takes long...)"
	    mkdir -p $i
	    (cd ${SRC};
		BINOWN=`id -un` DESTDIR=${SRC} \
		make -DNOHTML -DNOINFO -DNOMAN -DNOFSCHG libraries
	    )
	fi
	LIBS=" -L$i"
	(cd ${SRC}/usr.sbin/config ;
	make
	)
d699 1
@


1.8
log
@Bugfix: Use the correct variable for picobsd type (same bug is
present in STABLE).  Also add a bit more logging (when enabled).
@
text
@d3 1
a3 1
# $FreeBSD: src/release/picobsd/build/picobsd,v 1.7 2001/06/21 08:49:46 luigi Exp $
d658 1
@


1.7
log
@Move handling of crunch* files into Makefile.conf, which is a
better place to handle dependencies.

Make another step at helping cross-compiling: when the user specifies
an alternate source tree, the script takes care of creating include
files and libraries for the new tree.
Furthermore, build and use a version of the "config" program which
matches the new sources.

It takes a long time to create libraries, and it might even not do
the right thing at once, there might be some dependencies that i
have forgotten. At any rate, with this code i have been able to
build a working picobsd image using -CURRENT sources on -STABLE

MFC after: 3 days
@
text
@d3 1
a3 1
# $FreeBSD$
d316 1
a316 1
    dialog --title "Build ${TYPE} completed" --inputbox \
d348 2
a349 1
    PICO_OBJ=${OBJ}/picobsd/${TYPE}
d391 1
a391 1
    log "---> Populating floppy filesystem..."
d466 2
a467 2
    log "---> Populating MFS tree..."
    cd ../${TYPE}
@


1.6
log
@Move variable assignement after argument parsing, to improve handling
of alternate source trees.

Also improve verbose behaviour.
@
text
@a347 4
    export MFS_MOUNTPOINT	# used in the makefiles.
    export PICO_OBJ		# used in the makefiles
    export SRC			# used in the makefiles.

d366 2
a367 2
    export name SRC # used in this makefile
    (cd $MY_TREE; make -v -f ${PICO_TREE}/build/Makefile.conf )
d492 6
a497 5
    cat ${MY_TREE}/crunch.conf|sed -e "s@@/usr/src@@${SRC}@@" | \
	sed -e "s@@CWD@@${MY_TREE}@@" > $a
    arg=""
    if [ -f ${MY_TREE}/crunch.inc ] ; then
	h="-h ${MY_TREE}/crunch.inc"
a498 2
    crunchgen -p ${PICO_OBJ} -o $arg -m ${BUILDDIR}/crunch.mk $a || true
    # failure is not critical here
d508 1
a508 1
    rm $a
d666 24
a689 7
	#i=${SRC}/usr/include	# the include directory...
	#if [ \! -d $i ] ; then
	#    echo "Create \"$i\" as include directory"
	#    mkdir -p $i
	#    (cd ${SRC}; DESTDIR=${SRC} make includes )
	#fi
	#CFLAGS="-nostdinc -I$i" ; export CFLAGS
@


1.5
log
@Sync picobsd script with the one in -stable, and also
patch boot2 so it goes to load /kernel right away

Perl code from Josef Karthauser
@
text
@d3 1
a3 1
# $FreeBSD: src/release/picobsd/build/picobsd,v 1.4 2001/05/08 20:44:37 luigi Exp $
d14 2
a15 1
# done... so
d41 4
d49 2
a50 2
    # can boot from the image via diskless.
    INCLUDE_FLOPPY_IN_MFS="yes"
d61 1
a61 1
    PICO_TREE=${PICO_TREE:-/usr/src/release/picobsd}
d77 1
a77 1
    SITE=
d90 1
d113 1
d369 1
a369 1
    log "---> Preparing kernel "$name" in $MY_TREE"
d505 1
a505 1
    make -s -f ${BUILDDIR}/crunch.mk
d660 2
a661 1
init_vars
d665 15
d694 1
d703 1
@


1.4
log
@remove a reference to a nonexisting script, "clean", when
building all images. Also, build "bridge" image as well.

Reported-by: Bruce Montague
@
text
@d3 1
a3 1
# $FreeBSD: src/release/picobsd/build/picobsd,v 1.3 2001/04/23 19:52:13 joe Exp $
d600 1
a600 1
    vnconfig -c vn${VNUM} ${imgname} || fail $? no_vnconfig
d618 3
a620 1
    disklabel -Brw -b ${boot1} -s ${boot2} vn${VNUM} fd${FLOPPY_SIZE} || \
@


1.3
log
@MF4S: Remove some unused error messages. (revision 1.1.2.5)
@
text
@d3 1
a3 1
# $FreeBSD: src/release/picobsd/build/picobsd,v 1.2 2001/02/20 17:09:40 luigi Exp $
d173 1
a173 2
    ./clean dial
    for z in dial router net isp ; do
@


1.2
log
@Bring the new script into -current. Still untested here, but there
is a high chance that they work modulo minor things.
@
text
@d3 1
a3 1
# $FreeBSD$
a568 3
    makedevs)
	echo "Error while making devices in ${MFS_MOUNTPOINT}"
	;;
a571 3
    vnconfig2)
	echo "Error while doing vnconfig of floppy.img on /dev/rvn${VNUM}..."
	;;
a574 6
    kernel_compress)
	echo "Error while copying compressed kernel to disk"
	;;
    mfs_compress)
	echo "Error while copying compressed mfs image to disk"
	;;
d576 1
a576 1
	echo "-> ERROR: you must build PICOBSD${suffix} kernel first"
@


1.1
log
@file picobsd was initially added on branch RELENG_4.
@
text
@d1 710
@


1.1.2.1
log
@Add the new picobsd build script, and remove the old ones.
This script should be a significant improvement over the old
ones for the following reasons (modulo bugs...):

 + it can be run from anywhere;
 + a single script does everything including cleanup;
 + removes the need for a number of makefiles used before;
 + it does not write anymore into /usr/src/release/picobsd/ ;
 + all the files produced by the compilation are put into a single
   directory (plus OBJDIR as specified by the various programs);
 + it has slightly better diagnosting and debugging modes;
 + it permits PicoBSD configurations to be placed anywhere;
 + configurations can now be as simple as two files -- PICOBSD
   and crunch.conf, thus removing the need for supporting
   language-specific versions. You just define a new floppy
   type and populate the tree.
@
text
@a0 703
#!/bin/sh -
#
# $FreeBSD$
#
# The new PicoBSD build script. Invoked as
#
# picobsd [options] floppy_type site_name
#
# Where floppy_type is a directory where the picobsd config info
# is held, and ${floppy_type}/floppy.tree.${site_name} contains
# optional site-specific configuration.
#
# For Options, see the bottom of the file where the processing is
# done... so
#
# This script depends on the following files:
#
# in ${PICO_TREE} :
#   Makefile.conf	Makefile used to build the kernel
#   config		shell variables, sourced here.
#   mfs.mtree		mtree config file
#
#   floppy.tree/	files which go on the floppy
#   mfs_tree/		files which go onto the mfs
#
# in ${MY_TREE} :
#   PICOBSD		kernel config file
#   config		shell variables, sourced here.
#   crunch.conf		crunchgen configuration
#   floppy.tree.exclude	files from floppy.tree/ which we do not need here.
#   floppy.tree/	local additions to the floppy.tree
#   floppy.tree.${site}/ same as above, site specific.

#
#--- here are various functions used by the script.
#--- The main entry point is at the end.
#

# initialize some shell variables used by the script.

init_vars() {	# OK

    # if you include the floppy tree in the mfs, you
    # can boot from the image via diskless.
    INCLUDE_FLOPPY_IN_MFS="yes"

    # SRC points to your FreeBSD source tree.
    # OBJ points to the obj tree. Normally /usr/obj-pico.
    # PICO_TREE is where standard picobsd stuff resides.
    # MY_TREE (set later) is where this floppy type resides.
    # START_DIR is the directory where we start
    # BUILDDIR is the build directory, which is the current one.

    SRC=${SRC:-/usr/src}
    OBJ=${OBJ:-/usr/obj-pico}
    PICO_TREE=${PICO_TREE:-/usr/src/release/picobsd}
    START_DIR=`pwd`

    # Various temporary files and directories.
    # The script will build a list of available images in $IMAGE_LIST
    # User replies will be put in $RISU
    IMAGE_LIST=${IMAGE_LIST:-`mktemp "/tmp/image_list.XXXXXXXXXX"`}
    RISU=${RISU:-`mktemp "/tmp/reply.XXXXXXXXXX"`}
    MFS_MOUNTPOINT=`mktemp -d "/tmp/picobsd.XXXXXXXXXX"`

    MFS_NAME=fs.PICOBSD

    # EDITOR is the editor you use
    # SITE is site_name above.
    # FLOPPY_SIZE  floppy size in KB (default to 1440). You can use 1480,
    #	1720, 2880, etc. but beware that only 1440 and 1480 will boot
    #	from 1.44M floppy drives (1480 will not work on vmware).
    EDITOR=${EDITOR:-vi}
    SITE=
    FLOPPY_SIZE=${FLOPPY_SIZE:-1440}

    NO_DEVFS=yes # DEVFS is currently broken. Always set this.

    # Find a suitable vnode
    VNUM=`mount | awk "/vn/ { num++ } END { printf \"%d\", num }"`
    log "---> Using vn${VNUM}..."

    # Location of the boot blocks (in case you want them custom-built)
    boot1=/boot/boot1
    boot2=/boot/boot2

    # abort in case of error...
    set -e

    trap fail 2	# catch user interrupt
    free_vnode
}

# log something on stdout if verbose.
log() {
    if [ "$verbose" != "" ] ; then
	printf "%s\n" "$*"
	read -p "(log) enter to continue" foo
    fi
}

# set_type <type> looks for the floppy type specified as
# first argument in user- or standard- directory.
# If found set variables accordingly.

set_type() {		# OK
    a=$1
    for i in ${START_DIR}/${a} ${PICO_TREE}/${a} ; do
	if [ -d $i -a -f $i/PICOBSD -a -f $i/crunch.conf ] ; then
	    set -- `cat $i/PICOBSD | \
	    awk '/^#PicoBSD/ {print $2, $3, $4, $5, $6}'`
	    if [ "$1" != "" ]; then
		MFS_SIZE=$1 ; INIT=$2
		MFS_INODES=$3 ; FLOPPY_INODES=$4
		name=`(cd $i ; pwd) `
		name=`basename $name`
		MY_TREE=$i
		BUILDDIR=${START_DIR}/build_dir-${name}
		log "---> Matching file $name in $i"
		return ;
	    fi
	fi
    done
    echo "Type $a NOT FOUND"
}

clean_tree() {
    if [ "${name}" = "" ] ; then
       echo "-> wrong floppy type"
       exit 10
    fi
    rm -rf ${BUILDDIR}
}

# prepare a message to be printed in the dialog menus.
set_msgs() {		# OK
    MSG1="Type: ${THETYPE} name $name"

    MSG="PicoBSD build -- Current parameters:\n\n\t1.  ${MSG1}\n\
\t2.  MFS size: ${MFS_SIZE} kB\n\
\t3.  Site-info: ${SITE}\n\t4.  Full-path: ${MY_TREE}\n"
}


# Main build procedure.
build_image() {
    if [ "${name}" = "" ] ; then
       echo "-> wrong floppy type"
       exit 10
    fi
    clear
    set_msgs
    printf "${MSG}"
    echo "-> We'll use the sources living in ${SRC}"
    echo ""
    echo "-> I hope you have checked the PICOBSD config file..."
    echo ""
    echo ""

    init_stage1
    do_kernel
    populate_floppy_fs	# things which go into floppy
    create_mfs
    populate_mfs		# things which go into mfs
    fill_floppy_image # copies everything into the floppy
}

build_package() {
    touch build.status
    echo "##############################################" >>build.status
    echo "## `date` ">>build.status
    echo "##############################################" >>build.status
    ./clean dial
    for z in dial router net isp ; do
	set_type ${z}
	echo "---------------------------------------------">>build.status
	echo "Building TYPE=${z}, SIZE=${MFS_SIZE}" >>build.status
	build_image
	if [ "X$?" != "X0" ] ; then
	    echo "	** FAILED! **">>build.status
	else
	    echo "	(ok)">>build.status
	fi
	mv ${BUILDDIR}/picobsd.bin ${BUILDDIR}/picobsd.${name}.bin
	echo "Cleaning ${z}">>build.status
	clean_tree
    done
    exit 0
}

# Set build parameters interactively

main_dialog() {
  while [ true ] ; do
    set_msgs
    dialog --menu "PicoBSD build menu -- (19 feb 2000)" 19 70 12 \
	N "--> READY, build it <---" \
	T "${MSG1}" \
	K "edit Kernel config file" \
	E "Edit crunch.conf file" \
	S "MFS Size: ${MFS_SIZE}kB" \
	I "Init type: ${INIT}" \
	F "Floppy size: ${FLOPPY_SIZE}kB" \
	M "MFS bytes per inode: ${MFS_INODES}" \
	U "UFS bytes per inode: ${FLOPPY_INODES}" \
	$ "Site-info: ${SITE}" \
	Q "Quit" \
	2> ${RISU}
    ans=`cat ${RISU}`
    rm ${RISU}
    case ${ans} in
    T)
	l=""
	for i in ${START_DIR} ${START_DIR}/* ${PICO_TREE}/* ; do
	    if [ -d $i -a -f $i/PICOBSD -a -f $i/crunch.conf ]; then
		l="$l `basename $i` `basename $i`"
	    fi
	done
	log $l
	dialog --menu "Setup the type of configuration" 12 70 5 $l \
		2> ${RISU} || rm ${RISU}
	if [ -f ${RISU} ] ; then
	    THETYPE=`cat ${RISU}`
	    set_type $THETYPE
	fi
	;;
    I)
	dialog --menu "Choose your init(8) program" \
	10 70 2 init "Standard init (requires getty)" \
	oinit "small init from TinyWare" 2> ${RISU} || rm ${RISU}
	if [ -f ${RISU} ] ; then
	    INIT=`cat ${RISU}`
	fi
	;;

    K) ${EDITOR} ${MY_TREE}/PICOBSD ;;

    E) ${EDITOR} ${MY_TREE}/crunch.conf ;;

    S)
	dialog --title "MFS Size setup" --inputbox \
"MFS size depends on what you need to put on the MFS image. Typically \
ranges between 820kB (for very small bridge/router images) to \
as much as 2500kB kB for a densely packed image. \
Keep in mind that this memory is \
totally lost to other programs. Usually you want to keep \
this as small as possible. " 10 70 2> ${RISU} || rm ${RISU}
	if [ -f ${RISU} ] ; then
	    MFS_SIZE=`cat ${RISU}`
	fi
	;;

    \$)
	dialog --title "Site info setup" --inputbox \
	"Please enter the full path to the directory \
	containing site-specific setup. \
	This directory tree must contain files that replace \
	standard ones in floppy.tree/ and mfs.tree/ . " \
	10 70 2> ${RISU} || rm ${RISU}
	if [ -f ${RISU} ] ; then
	    SITE=`cat ${RISU}`
	fi
	;;

    F)
	dialog --menu "Set floppy size" 15 70 4 \
		1440 "1.44MB" 1720 "1.72MB" \
		2880 "2.88MB" 4096 "4MB" 2> ${RISU} || rm ${RISU}
	if [ -f ${RISU} ] ; then
	    FLOPPY_SIZE=`cat ${RISU}`
	fi
	;;

    M)
	dialog --title "MFS bytes per inode:" --inputbox \
	"Enter MFS bytes per inode (typically 4096..65536). \
	A larger value means fewer inodes but more space on MFS" \
	10 70 2> ${RISU} || rm ${RISU}
	if [ -f ${RISU} ] ; then
	    MFS_INODES=`cat ${RISU}`
	fi
	;;

    U)
	dialog --title "Floppy bytes per inode:" --inputbox \
	"Enter floppy bytes per inode (typically 3072..65536). \
	A larger value means fewer inodes but more space on the floppy." \
	10 70 2> ${RISU} || rm ${RISU}
	if [ -f ${RISU} ] ; then
	    FLOPPY_INODES=`cat ${RISU}`
	fi
	;;

    N) break 2
	;;

    Q) exit 0 ;;

    *) echo "Unknown option \"${ans}\". Try again."
	sleep 2
	clear
	;;
    esac
  done
}

# Call the build procedure
# Install image
do_install() {
    dialog --title "Build ${TYPE} completed" --inputbox \
"\nThe build process was completed successfuly.\n\
`cat .build.reply` \n\n\
Now we are going to install the image on the floppy.\n\
Please insert a blank floppy in /dev/fd0.\\n
WARNING: the contents of the floppy will be permanently erased!\n\
\n\
Your options:\n\
	* ^C or [Cancel] to abort,\n\
	* Enter to install \"picobsd.bin\",\n\
" 20 80 2> ${RISU}
    if [ "$?" = "0" ]; then
	echo "Writing picobsd.bin..."
	dd if=${BUILDDIR}/picobsd.bin of=/dev/rfd0.${FLOPPY_SIZE}
    else
	echo "Ok, the image is in picobsd.bin"
    fi
    echo "Done."
}


#-------------------------------------------------------------------

init_stage1() {

    # read config variables from a global and then a type-specific file
    # 
    . ${PICO_TREE}/build/config
    if [ -f ${MY_TREE}/config ]; then
	. ${MY_TREE}/config
    fi

    export MFS_MOUNTPOINT	# used in the makefiles.
    export PICO_OBJ		# used in the makefiles
    export SRC			# used in the makefiles.

    PICO_OBJ=${OBJ}/picobsd/${TYPE}

    if [ ! -d ${BUILDDIR} ]; then
	log "Creating builddir"
	mkdir $BUILDDIR
	if [ ! -d ${BUILDDIR}/crunch ]; then
	    log "creating crunch dir"
	    mkdir ${BUILDDIR}/crunch
	fi
    else
	rm -f ${BUILDDIR}/kernel.gz ${BUILDDIR}/${MFS_NAME}    # cleanup...
    fi
}

# invoke the makefile to compile the kernel.
# Then copy it here and strip as much as possible.
do_kernel() {		# OK
    log "---> Preparing kernel "$name" in $MY_TREE"
    export name SRC # used in this makefile
    (cd $MY_TREE; make -v -f ${PICO_TREE}/build/Makefile.conf )
    cp -p ${SRC}/sys/compile/PICOBSD-${name}/kernel ${BUILDDIR}/kernel || \
	fail $? missing_kernel
    (cd ${BUILDDIR};
    strip kernel
    strip --remove-section=.note --remove-section=.comment kernel
    )
}

# Populate the variable part of the floppy filesystem. Should be
# done before the MFS because it might need to be copied there as well.
#
# This involves three subtrees, in this order:
#
#  1. a standard one from which type-specific files are excluded;
#  2. a type-specific one;
#  3. a site-specific one.
#
# Files are first copied to a local tree and then compressed.

populate_floppy_fs() {		# OK

    dst=${BUILDDIR}/floppy.tree
    log "---> Populating floppy filesystem..."

    # clean relics from old compilations. This is the destination.
    rm -rf $dst || true
    mkdir $dst

    excl=${MY_TREE}/floppy.tree.exclude
    if [ -f ${excl} ] ; then
	excl="--exclude-from ${excl}"
	log "---> Exclude following files from generic tree:
`cat ${excl}`"
    else
	excl=""
    fi
    (cd ${PICO_TREE}/floppy.tree ; tar -cf - --exclude CVS ${excl} . ) | \
		(cd ${dst} ; tar x${TAR_VERBOSE}f - )
    log "---> Copied from generic floppy-tree `echo; ls -laR ${dst}`"

    srcdir=${MY_TREE}/floppy.tree
    if [ -d ${srcdir} ] ; then
	log "-> update with type-specific files:"
	(cd ${srcdir} ; tar -cf - --exclude CVS . ) | \
	    (cd ${dst} ; tar x${TAR_VERBOSE}f - )
	log "---> Copied from type floppy-tree `echo; ls -laR ${dst}`"
    else
	log "---> No type-specific floppy-tree"
    fi
    if [ -d ${srcdir}.${SITE} ] ; then
	log "-> update with site-specific (${SITE}) files:"
	(cd ${srcdir}.${SITE} ; tar -cf - --exclude CVS . ) | \
	    (cd ${dst} ; tar x${TAR_VERBOSE}f - )
	log "---> Copied from site floppy-tree `echo; ls -laR ${dst}`"
    else
	log "---> No site-specific floppy-tree"
    fi
    # gzip returns an error if it fails to compress some file
    (cd $dst
    gzip -9 etc/*
    log "---> Compressed files in etc/
`ls -l etc`"
    ) || true
}

create_mfs() {		# OK
    log "---> Preparing MFS filesystem..."

    free_vnode

    # zero-fill the MFS image
    init_fs_image ${BUILDDIR}/${MFS_NAME} ${MFS_SIZE}

    log "---> Labeling MFS image"
    # This command does weird things on 2.2.x systems.
    # For small image sizes, use std disktypes
    if [ ${MFS_SIZE} -lt 1024 ] ; then
	disklabel -rw /dev/rvn${VNUM} fd${MFS_SIZE} || fail $? disklabel
    else
	disklabel -rw vn${VNUM} auto || fail $? disklabel
    fi

    newfs -i ${MFS_INODES} -m 0 -p 0 -o space /dev/rvn${VNUM}c > /dev/null
    mount /dev/vn${VNUM}c ${MFS_MOUNTPOINT} || fail $? no_mount

    pwd=`pwd`
}

# Populate the memory filesystem with binaries and non-variable
# configuration files.
# First do an mtree pass, then create directory links and device entries,
# then run crunchgen etc. to build the binary and create links.
# Then copy the specific/generic mfs_tree.
# Finally, if required, make a copy of the floppy.tree onto /fd

populate_mfs() {
    log "---> Populating MFS tree..."
    cd ../${TYPE}

    log "---> Running mtree ..."
    if [ -f ${MY_TREE}/mfs.mtree ] ; then
	a=${MY_TREE}/mfs.mtree
    else
	a=${PICO_TREE}/build/mfs.mtree
    fi
    mtree -deU -f $a -p ${MFS_MOUNTPOINT} > /dev/null || fail $? mtree

    # XXX create links
    for i in ${STAND_LINKS}; do
	ln -s /stand ${MFS_MOUNTPOINT}/$i
    done
    ln -s /dev/null ${MFS_MOUNTPOINT}/var/run/log
    ln -s /etc/termcap ${MFS_MOUNTPOINT}/usr/share/misc/termcap

    if [ "${NO_DEVFS}" != "" ] ; then
	(cd ${MFS_MOUNTPOINT}/dev ; ln -s /dev/MAKEDEV ;
	    ./MAKEDEV ${MY_DEVS}; rm MAKEDEV)
    fi

    log "---> Making and installing crunch1..."
    (
    cd ${BUILDDIR}/crunch
    a=${BUILDDIR}/crunch1.conf
    cat ${MY_TREE}/crunch.conf|sed -e "s@@/usr/src@@${SRC}@@" > $a
    (if [ -f ${MY_TREE}/crunch.inc ] ; then
	crunchgen -p ${PICO_OBJ} -o -h ${MY_TREE}/crunch.inc $a
    else
	crunchgen -p ${PICO_OBJ} -o $a
    fi
    ) || true # failure is not critical here
    make -s -f crunch1.mk
    strip --remove-section=.note --remove-section=.comment crunch1
    mv crunch1 ${MFS_MOUNTPOINT}/stand/crunch
    chmod 555 ${MFS_MOUNTPOINT}/stand/crunch
    log "---> Making links for binaries..."
    for i in `crunchgen -l $a` ; do
	ln ${MFS_MOUNTPOINT}/stand/crunch ${MFS_MOUNTPOINT}/stand/${i};
    done
    rm $a
    ) || fail $? crunch

    if [ -f ${MFS_MOUNTPOINT}/stand/sshd ] ; then
	log "creating host key for sshd"
	ssh-keygen -f ${MFS_MOUNTPOINT}/etc/ssh_host_key -N "" -C "root@@picobsd"
    fi

    if [ -d ${MY_TREE}/mfs_tree ]; then
	log "---> Copy site-specific MFS tree..."
	MFS_TREE=${MY_TREE}/mfs_tree
    else
	log "---> Copy generic MFS tree..."
	MFS_TREE=${PICO_TREE}/mfs_tree
    fi
    (cd ${MFS_TREE} ; tar -cf - --exclude CVS . ) | \
	    (cd ${MFS_MOUNTPOINT} ; tar x${TAR_VERBOSE}f - )

    if [ "${INCLUDE_FLOPPY_IN_MFS}" = "yes" ]; then
	log "---> Copy generic floppy_tree into MFS..."
	cp -Rp ${BUILDDIR}/floppy.tree/* ${MFS_MOUNTPOINT}/fd
    fi
    (log "---> Fixing permissions"; cd ${MFS_MOUNTPOINT}; chown -R root . )
    df -ik ${MFS_MOUNTPOINT}
    umount ${MFS_MOUNTPOINT}
    fsck -p /dev/rvn${VNUM}c
    vnconfig -u /dev/rvn${VNUM}
}

# free as much as possible from the vnode
free_vnode() {
    umount ${MFS_MOUNTPOINT}    2> /dev/null || true
    umount /dev/vn${VNUM}       2> /dev/null || true
    vnconfig -u /dev/rvn${VNUM} 2> /dev/null || true
}

final_cleanup() {
    free_vnode
    rm -rf ${MFS_MOUNTPOINT} ${IMAGE_LIST} ${RISU} 2> /dev/null || true
}

# fail errno errcode
# This function is used to trap errors and print msgs
#
fail() {
    errno=$1
    errcode=$2
    log "---> fail: Error <$errno> error code <$errcode>"
    case $errcode in
    no_vnconfig)
	echo "Error while doing vnconfig of ${imgname} on /dev/rvn${VNUM}..."
	echo "   Most probably your running kernel doesn't have the vn(4) device."
	;;
    disklabel)
	echo "Error while labeling ${MFS_NAME} size ${MFS_SIZE}"
	;;
    no_mount)
	echo "Error while mounting ${MFS_NAME} (/dev/vn${VNUM}c) on ${MFS_MOUNTPOINT}"
	;;
    mtree)
	echo "Error while making hierarchy in ${MFS_MOUNTPOINT}"
	;;
    makedevs)
	echo "Error while making devices in ${MFS_MOUNTPOINT}"
	;;
    crunch)
	echo "Error while building ../${TYPE}/crunch1..."
	;;
    vnconfig2)
	echo "Error while doing vnconfig of floppy.img on /dev/rvn${VNUM}..."
	;;
    disklabel)
	echo "Error while doing disklabel on of floppy.img size $FLOPPY_SIZE"
	;;
    kernel_compress)
	echo "Error while copying compressed kernel to disk"
	;;
    mfs_compress)
	echo "Error while copying compressed mfs image to disk"
	;;
    missing_kernel)
	echo "-> ERROR: you must build PICOBSD${suffix} kernel first"
	;;
    "")
	echo "User break"
	errcode="userbreak";
	;;
    *)
	echo "unknown error, maybe user break: $errno $errcode"
	;;
    esac
    echo "---> Aborting $0"
    # try to cleanup the vnode.
    final_cleanup
    exit 10
}

#
# Create a zero-filled disk image with a boot sector, and vnconfig it.
#

init_fs_image() { # filename size_in_kbytes
    imgname=$1 ; imgsize=$2
    dd if=/dev/zero of=${imgname} count=${imgsize} bs=1k 2> /dev/null
    dd if=${boot1}  of=${imgname} conv=notrunc 2> /dev/null

    vnconfig -c /dev/rvn${VNUM} ${imgname} || fail $? no_vnconfig
}


fill_floppy_image() {
    log "---> Preparing ${FLOPPY_SIZE}kB floppy filesystem..."

    # correct block and number of sectors according to size.
    blocks=${FLOPPY_SIZE}; sectors=18
    if [ "${blocks}" = "1720" ]; then
	blocks=1722 ; sectors=21
    elif [ "${blocks}" = "1480" ]; then
	blocks=1476 ;
    fi

    init_fs_image ${BUILDDIR}/picobsd.bin ${blocks}

    log "---> Labeling floppy image"
    disklabel -Brw -b ${boot1} -s ${boot2} /dev/vn${VNUM}c fd${FLOPPY_SIZE} || \
	fail $?  disklabel

    newfs -i ${FLOPPY_INODES} -m 0 -p 0 -o space /dev/rvn${VNUM}c > /dev/null

    mount /dev/vn${VNUM}c ${MFS_MOUNTPOINT}

    # preload kernel, compress with kgzip and copy to floppy image
    cc -o ${BUILDDIR}/wmk ${PICO_TREE}/../write_mfs_in_kernel.c
    ${BUILDDIR}/wmk ${BUILDDIR}/kernel ${BUILDDIR}/${MFS_NAME}
    rm ${BUILDDIR}/wmk
    kgzip -o ${BUILDDIR}/kernel.gz ${BUILDDIR}/kernel
    cp -p ${BUILDDIR}/kernel.gz ${MFS_MOUNTPOINT}/kernel

    # now transfer the floppy tree
    cp -Rp ${BUILDDIR}/floppy.tree/* ${MFS_MOUNTPOINT}
    (log "---> Fixing permissions"; cd ${MFS_MOUNTPOINT}; chown -R root *)
    rm -rf ${BUILDDIR}/floppy.tree || true # cleanup

    df -ik ${MFS_MOUNTPOINT} | colrm 70 > .build.reply
    free_vnode
    rm -rf ${MFS_MOUNTPOINT}
    rm ${BUILDDIR}/kernel.gz ${BUILDDIR}/${MFS_NAME}
}

#-------------------------------------------------------------------
# Main entry of the script

init_vars

while [ true ]; do
    case $1 in
    --floppy_size)
	FLOPPY_SIZE=$2
	shift
	;;
    -n)
	interactive="NO"
	;;
    -c*) # clean
	clean="YES"
	interactive="NO"
	;;
    -v)
	echo "verbose"
	verbose="YES"
	TAR_VERBOSE="v"
	;;
    *)
	break ;
	;;

    esac
    shift
done

THETYPE=$1
SITE=$2
set_type $THETYPE

# If $1="package", it creates a neat set of floppies

if [ "$1" = "package" ] ; then
    build_package
fi
if [ "$interactive" != "NO" ] ; then
    main_dialog
fi
if [ "$clean" = "YES" ] ; then
    clean_tree
else
    build_image
    do_install
fi
final_cleanup
exit 0
@


1.1.2.2
log
@Miscellaneous cleanups of the script.
@
text
@d3 1
a3 1
# $FreeBSD: src/release/picobsd/build/picobsd,v 1.1.2.1 2001/02/19 23:49:54 luigi Exp $
d60 1
d62 1
d129 2
a130 2
	echo "---> wrong floppy type"
	exit 3
d148 2
a149 3
	echo "-> wrong floppy type"
	final_cleanup
	exit 1
d408 1
a408 1
	log "---> update with type-specific files:"
d440 1
a440 4
    # Disklabel "auto" behaves strangely for sizes < 1024K. Basically
    # it fails to install a label on the system. On the other hand,
    # if you provide a specific disk type, the boot code is not
    # installed so you have more space on the disk...
d443 1
a443 1
	disklabel -rw /dev/rvn${VNUM} fd${MFS_SIZE} || fail $? mfs_disklabel
d445 1
a445 1
	disklabel -rw vn${VNUM} auto || fail $? mfs_disklabel
d447 1
d450 2
a451 1
    log "`df /dev/vn${VNUM}c`"
d542 1
a542 1
    rm -rf ${MFS_MOUNTPOINT} ${RISU} 2> /dev/null || true
d551 1
a551 1
    echo "---> fail: Error <$errno> error code <$errcode>"
d557 1
a557 1
    mfs_disklabel)
d570 1
a570 1
	echo "Error while building ${name}."
d575 1
a575 1
    floppy_disklabel)
d598 1
a598 1
    exit 2
d629 1
a629 1
	fail $?  floppy_disklabel
d636 8
a643 13
    (
    cd ${BUILDDIR}
    cc -o wmk ${PICO_TREE}/../write_mfs_in_kernel.c
    ./wmk kernel ${MFS_NAME}
    rm wmk
    kgzip -o kernel.gz kernel
    cp -p kernel.gz ${MFS_MOUNTPOINT}/kernel

    # now transfer the floppy tree. If it is already in mfs, dont bother.
    if [ "${INCLUDE_FLOPPY_IN_MFS}" != "yes" ]; then
	cp -Rp floppy.tree/* ${MFS_MOUNTPOINT}
    fi
    )
d672 1
@


1.1.2.3
log
@More cleanup, including run crunchgen in the same directory as
crunch.conf so relative path have a better chance of working
@
text
@d3 1
a3 1
# $FreeBSD: src/release/picobsd/build/picobsd,v 1.1.2.2 2001/02/20 03:31:04 luigi Exp $
a153 1
    echo "-> vnode is $VNUM"
d445 1
a445 1
	disklabel -rw vn${VNUM} fd${MFS_SIZE} || fail $? mfs_disklabel
d485 1
d487 1
a487 2
    cd ${MY_TREE} # so relative paths in crunch.conf have a chance
    log "---> Making and installing crunch1 from `pwd`..."
d490 7
a496 8
    arg=""
    if [ -f ${MY_TREE}/crunch.inc ] ; then
	h="-h ${MY_TREE}/crunch.inc"
    fi
    crunchgen -p ${PICO_OBJ} -o $arg -m ${BUILDDIR}/crunch.mk $a || true
    # failure is not critical here
    log "Now make -f crunch.mk"
    make -s -f ${BUILDDIR}/crunch.mk
d530 1
a530 1
    vnconfig -u vn${VNUM}
d537 1
a537 1
    vnconfig -u vn${VNUM} 2> /dev/null || true
d610 1
a610 1
    vnconfig -c vn${VNUM} ${imgname} || fail $? no_vnconfig
d628 1
a628 1
    disklabel -Brw -b ${boot1} -s ${boot2} vn${VNUM} fd${FLOPPY_SIZE} || \
d631 1
a631 1
    newfs -i ${FLOPPY_INODES} -m 0 -p 0 -o space /dev/vn${VNUM}c > /dev/null
@


1.1.2.4
log
@The previous solution for relative paths would clutter the
source directory -- crunchgen still generate relative paths
which is not what we want.
For the time being, use the following trick: in crunch.conf,
prefix relative paths by the string CWD which will be replaced
by the absolute path during the build process.
@
text
@d3 1
a3 1
# $FreeBSD: src/release/picobsd/build/picobsd,v 1.1.2.3 2001/02/20 07:03:19 luigi Exp $
d487 1
a487 1
    cd ${BUILDDIR}/crunch
d490 1
a490 2
    cat ${MY_TREE}/crunch.conf|sed -e "s@@/usr/src@@${SRC}@@" | \
	sed -e "s@@CWD@@${MY_TREE}@@" > $a
@


1.1.2.5
log
@Add -s labels to vnconfig. Remove some unused error messages.

Reported-By: Bruce Montague and others
Approved-By: jkh
@
text
@d3 1
a3 1
# $FreeBSD: src/release/picobsd/build/picobsd,v 1.1.2.4 2001/02/20 07:47:53 luigi Exp $
d569 3
d575 3
d581 6
d588 1
a588 1
	echo "Error: you must build PICOBSD${suffix} kernel first"
d613 1
a613 1
    vnconfig -c -s labels vn${VNUM} ${imgname} || fail $? no_vnconfig
@


1.1.2.6
log
@MFC: remove reference to "clean" script, include "bridge" in build
list
@
text
@d3 1
a3 1
# $FreeBSD: src/release/picobsd/build/picobsd,v 1.1.2.5 2001/03/13 21:45:26 luigi Exp $
d173 2
a174 1
    for z in bridge dial router net isp ; do
@


1.1.2.7
log
@MFC: patch boot2 so it goes right away to load /kernel
@
text
@d3 1
a3 1
# $FreeBSD: src/release/picobsd/build/picobsd,v 1.1.2.6 2001/05/08 20:46:34 luigi Exp $
d618 1
a618 3
    b2=${BUILDDIR}/boot2 # modified boot2
    perl -pne 's/\/boot\/loader/\/kernel\0\0\0\0\0/' ${boot2} > ${b2}
    disklabel -Brw -b ${boot1} -s ${b2} vn${VNUM} fd${FLOPPY_SIZE} || \
@


1.1.2.8
log
@MFC: minor cleanup of the build script for better handling of alternate
source trees.
[immediate mfc as nobody will test this code in -current, so the
delay would only help forgetting to update].
@
text
@d3 1
a3 1
# $FreeBSD$
d14 1
a14 2
# done. The picobsd(8) manpage might be of some help, but code and docs
# tend to lose sync over time...
a39 4
# This must be done after option parsing so user-specified values
# are used to compute dependent ones. Make sure to use the
# VAR=${VAR:-value} construct for those variables which can
# be overridden from the command line.
d44 2
a45 2
    # can boot from the image via diskless. Default to yes.
    INCLUDE_FLOPPY_IN_MFS=${INCLUDE_FLOPPY_IN_MFS:-yes}
d56 1
a56 1
    PICO_TREE=${PICO_TREE:-${SRC}/release/picobsd}
d72 1
a72 1
    SITE=${SITE:-}
a84 1
    makeopts=${MAKEOPTS:--s}	# be silent by default
a106 1
	log "set_type: checking $i"
d362 1
a362 1
    log "---> Preparing kernel \"$name\" in $MY_TREE"
d498 1
a498 1
    make ${makeopts} -f ${BUILDDIR}/crunch.mk
d653 1
a653 2
verbose=""
TAR_VERBOSE=""
a656 15
    --src)	# set the source path instead of /usr/src
	SRC=$2
	# Optionally creates include directory, and set cflags
	# accordingly. Note that you will still need the right
	# libraries...

	#i=${SRC}/usr/include	# the include directory...
	#if [ \! -d $i ] ; then
	#    echo "Create \"$i\" as include directory"
	#    mkdir -p $i
	#    (cd ${SRC}; DESTDIR=${SRC} make includes )
	#fi
	#CFLAGS="-nostdinc -I$i" ; export CFLAGS
	shift
	;;
a670 1
	makeopts="-d l" # be verbose
a678 1
init_vars
@


1.1.2.9
log
@MFC: picobsd script now lets you specify which source tree to use,
which in turn makes it possible to cross-build picobsd images on
a -stable system.

Major applications are building -current images for testing purposes,
and building old versions (based on 2.x or 3.x) of picobsd.

Approved By: re
@
text
@d3 1
a3 1
# $FreeBSD: src/release/picobsd/build/picobsd,v 1.1.2.8 2001/06/20 15:09:26 luigi Exp $
d202 1
a202 1
    dialog --menu "PicoBSD build menu -- (29 aug 2001)" 19 70 12 \
d348 4
d370 2
a371 2
    (cd $MY_TREE; export name SRC CONFIG # used in this makefile ;
	make -v -f ${PICO_TREE}/build/Makefile.conf )
d496 5
a500 6
    ( export BUILDDIR SRC MY_TREE PICO_OBJ ;
    make -v -f ${PICO_TREE}/build/Makefile.conf ${BUILDDIR}/crunch.mk )
    # update crunch.mk for new libs
    if [ "${LIBS}" != "" ] ; then
	sed -e "s@@^LIBS=@@  LIBS= ${LIBS}@@" ${BUILDDIR}/crunch.mk > ${BUILDDIR}/crunch1.mk
	mv ${BUILDDIR}/crunch1.mk ${BUILDDIR}/crunch.mk
d502 2
d513 1
a513 1
    # rm $a # do not remove!
d671 7
a677 24
	i=${SRC}/usr/include	# the include directory...
	if [ \! -d $i ] ; then
	    echo "Create \"$i\" as include directory"
	    mkdir -p $i
	    (cd ${SRC};
	    INCOWN=`id -un` DESTDIR=${SRC} make includes
	    )
	fi
	CFLAGS="-nostdinc -I$i" ; export CFLAGS
	i=${SRC}/usr/lib
	if [ \! -d $i ]; then
	    echo "Create libraries (this takes long...)"
	    mkdir -p $i
	    (cd ${SRC};
		BINOWN=`id -un` DESTDIR=${SRC} \
		make -DNOHTML -DNOINFO -DNOMAN -DNOFSCHG libraries
	    )
	fi
	LIBS=" -L$i"
	(cd ${SRC}/usr.sbin/config ;
	make
	)
	CONFIG=${SRC}/usr.sbin/config/config

@


1.1.2.10
log
@MFC: bugfix -- use correct variable to identify picobsd type.
@
text
@d3 1
a3 1
# $FreeBSD$
d316 1
a316 1
    dialog --title "Build ${THETYPE} completed" --inputbox \
d348 1
a348 2
    PICO_OBJ=${OBJ}/picobsd/${THETYPE}
    log "PICO_OBJ is ${PICO_OBJ}"
d390 1
a390 1
    log "---> pwd=`pwd` Populating floppy filesystem..."
d465 2
a466 2
    log "---> pwd=`pwd`, Populating MFS tree..."
    # cd ${THETYPE}
@


1.1.2.11
log
@MFC: (bugfix) supply a default value for kernel config binary.
@
text
@d3 1
a3 1
# $FreeBSD: src/release/picobsd/build/picobsd,v 1.1.2.10 2001/09/01 18:28:37 luigi Exp $
a657 1
CONFIG=config
@


1.1.2.12
log
@MFC: move rules to create the stripped kernel into Makefile.conf,
and improve handling of cross-builds.

Approved By: jordan
@
text
@d3 1
a3 1
# $FreeBSD: src/release/picobsd/build/picobsd,v 1.1.2.11 2001/09/01 19:16:38 luigi Exp $
d367 3
a369 2
    (cd $MY_TREE; export name SRC CONFIG BUILDDIR # used in this makefile ;
	make -v -f ${PICO_TREE}/build/Makefile.conf ) || \
d371 4
d494 6
a499 3
	make -v -f ${PICO_TREE}/build/Makefile.conf ${BUILDDIR}/crunch.mk )
    log "-- libs are ${LIBS} "
    export LIBS CFLAGS # used by crunch.mk
a579 6
    includes)
	echo "Error: failed while making includes"
	;;
    libraries)
	echo "Error: failed while making libraries"
	;;
d664 26
a689 33
	if [ "$3" = "--init" ] ; then
	    # Optionally creates include directory and libraries.
	    mkdir -p ${SRC}/usr/include		# the include directory...
	    mkdir -p ${SRC}/usr/share/misc	# a few things go here
	    mkdir -p ${SRC}/usr/lib		# libraries

	    (cd ${SRC}; INCOWN=`id -un` DESTDIR=${SRC} make includes ) || \
		fail $? includes
	    # libraries already have the include path in the Makefile
	    CFLAGS="-nostdinc" ; export CFLAGS

	    (cd ${SRC}
		# $e is the invocation of make with correct environment
		e="MAKEOBJDIRPREFIX=/usr/obj-pico/picobsd/libraries \
		    BINOWN=`id -un` DESTDIR=${SRC} \
		    make -DNOHTML -DNOINFO -DNOMAN -DNOSHARE -DNOFSCHG "
		# need to 'make obj' in a few places. This is very
		# version-specific... The following works for 5.0
		for i in lib secure/lib gnu/lib usr.sbin/pcvt/keycap \
			gnu/usr.bin/perl usr.bin/lex  ; do
		    (cd ${i}; eval $e obj)
		done
		# now make the static libraries
		eval $e -DNOPROFILE -DNOPIC libraries
	    ) || fail $? "libraries"
	    log "libraries done"
	fi
	# pass the right LIBS and CFLAGS to the Makefile,
	# and build the config program
	LIBS="-L${SRC}/usr/lib"
	CFLAGS="-nostdinc -I${SRC}/usr/include"
	export LIBS CFLAGS
	(cd ${SRC}/usr.sbin/config ; CFLAGS="" make )
a693 1

@


1.1.2.13
log
@MFC: make script aware of the correct memory disk to use.
Also, minor fixes and code cleanup.
@
text
@d3 1
a3 1
# $FreeBSD$
d46 1
a46 8
# select the right memory disk name
case `uname -r` in
    5.*)
	VN="md"
	;;
    *)
	VN="vn"
esac
a47 1
init_vars() {	# OK
d83 2
a84 3
    VNUM=`mount | awk "/${VN}/ { num++ } END { printf \"%d\", num }"`
    VNDEV=${VN}${VNUM}
    log "---> Using ${VNDEV}..."
a139 11
# free as much as possible from the vnode
free_vnode() {
    umount ${MFS_MOUNTPOINT}    2> /dev/null || true
    umount /dev/${VNDEV}       2> /dev/null || true
    if [ "${VN}" = "vn" ] ; then
	vnconfig -u ${VNDEV} 2> /dev/null || true
    else
	mdconfig -d -u ${VNUM} 2> /dev/null || true
    fi
}

d161 1
a161 1
    echo "-> vnode is ${VNDEV}"
d329 1
a329 1
	dd if=${BUILDDIR}/picobsd.bin of=/dev/fd0.${FLOPPY_SIZE}
a383 1
    local dst excl srcdir
d388 3
a390 3
    # clean relics from old compilations.
    rm -rf ${dst} || true
    mkdir ${dst}
d395 2
a396 1
	log "---> Files excluded from generic tree: `echo;cat ${excl}`"
d424 2
a425 1
    log "---> Compressed files in etc/ `echo; ls -l etc`"
d444 1
a444 1
	disklabel -rw ${VNDEV} fd${MFS_SIZE} || fail $? mfs_disklabel
d446 1
a446 1
	disklabel -rw ${VNDEV} auto || fail $? mfs_disklabel
d448 3
a450 3
    newfs -i ${MFS_INODES} -m 0 -p 0 -o space /dev/${VNDEV}c > /dev/null
    mount /dev/${VNDEV}c ${MFS_MOUNTPOINT} || fail $? no_mount
    log "`df /dev/${VNDEV}c`"
a478 1
    # XXX-fixme in -current, MAKEDEV is from /usr/src/etc/MAKEDEV
d486 1
a486 1
    log "---> Making and installing crunch1 from `pwd` src ${SRC}..."
d491 1
a491 1
    export SRC LIBS CFLAGS # used by crunch.mk
d526 9
a534 2
    fsck -p /dev/${VNDEV}c
    free_vnode
d551 2
a552 2
	echo "Error while doing vnconfig of ${imgname} on /dev/${VNDEV}..."
	echo "   Most probably your running kernel doesn't have the ${VN}(4) device."
d558 1
a558 1
	echo "Error while mounting ${MFS_NAME} (/dev/${VNDEV}c) on ${MFS_MOUNTPOINT}"
d601 1
a601 5
    if [ "${VN}" = "vn" ] ; then
	vnconfig -c -s labels ${VNDEV} ${imgname} || fail $? no_vnconfig
    else
	mdconfig -a -t vnode -u ${VNUM} -f ${imgname} || fail $? no_vnconfig
    fi
d621 1
a621 1
    disklabel -Brw -b ${boot1} -s ${b2} ${VNDEV} fd${FLOPPY_SIZE} || \
d624 1
a624 1
    newfs -i ${FLOPPY_INODES} -m 0 -p 0 -o space /dev/${VNDEV}c > /dev/null
d626 1
a626 1
    mount /dev/${VNDEV}c ${MFS_MOUNTPOINT}
a662 1
	    shift
@


1.1.2.14
log
@MFC: Use MAKEDEV from ${SRC} on -current where it's being run with devfs.
     This keeps this script the same between -current and -stable.
@
text
@d3 1
a3 1
# $FreeBSD: src/release/picobsd/build/picobsd,v 1.1.2.13 2001/09/20 03:05:57 luigi Exp $
d46 9
a71 11
    # select the right memory disk name
    case `uname -r` in
	5.*)
	    VN="md"
	    MAKEDEV="${SRC}/etc/MAKEDEV"
	    ;;
	*)
	    VN="vn"
	    MAKEDEV="/dev/MAKEDEV"
    esac

d500 1
a500 1
	(cd ${MFS_MOUNTPOINT}/dev ; ln -s ${MAKEDEV} ; chmod 555 MAKEDEV ;
@


1.1.2.15
log
@MFC: picobsd script fixes from 1.14
@
text
@d3 1
a3 1
# $FreeBSD: src/release/picobsd/build/picobsd,v 1.1.2.14 2001/09/20 20:36:24 joe Exp $
d59 1
a59 1
    OBJ=${OBJ:-${SRC}/usr/obj-pico}
d63 10
a152 1
    log "free_vnode, VN is ${VN} "
a669 66
#
# this code creates variables to point to the correct
# source tree, and optionally initializes it.
init_src_tree() {
    if [ "${src}" = "" ] ; then
	return
    fi
    SRC=${src}
    log "using src tree in ${SRC}, init ${init_src}"
    if [ "${init_src}" != "" ] ; then
	# Optionally creates include directory and libraries.
	mkdir -p ${SRC}/usr/include	# the include directory...
	mkdir -p ${SRC}/usr/share/misc	# a few things go here
	mkdir -p ${SRC}/usr/lib		# libraries

	(cd ${SRC}; INCOWN=`id -un`  BINOWN=`id -un` DESTDIR=${SRC} \
		make includes ) || fail $? includes
	# libraries already have the include path in the Makefile
	CFLAGS="-nostdinc" ; export CFLAGS

	(cd ${SRC}
	    # $e is the invocation of make with correct environment
	    e="MAKEOBJDIRPREFIX=${SRC}/usr/obj-pico/picobsd/libraries \
		INCOWN=`id -un` BINOWN=`id -un` DESTDIR=${SRC} \
		make -DNOHTML -DNOINFO -DNOMAN -DNOSHARE -DNOFSCHG "
	    # need to 'make obj' in a few places. This is very
	    # version-specific... The following works for 5.0
	    for i in lib secure/lib gnu/lib usr.sbin/pcvt/keycap \
		    gnu/usr.bin/perl usr.bin/lex  ; do
		(cd ${i}; eval $e obj)
	    done
	    # now make the static libraries
	    eval $e -DNOPROFILE -DNOPIC libraries
	) || fail $? "libraries"
	log "libraries done"
    fi
    # pass the right LIBS and CFLAGS to the Makefile,
    # and build the config program
    LIBS="-L${SRC}/usr/lib"
    CFLAGS="-nostdinc -I${SRC}/usr/include"
    export LIBS CFLAGS
    (cd ${SRC}/usr.sbin/config ; CFLAGS="" make )
    CONFIG=${SRC}/usr.sbin/config/config
}

# set some default values for variables.
# needs to be done as the first thing in the script.

default_vars() {
    verbose=""
    TAR_VERBOSE=""
    CONFIG=config
    src=""		# not set by user
    init_src=""
    # select the right memory disk name
    case `uname -r` in
	5.*)
	    VN="md"
	    MAKEDEV="${SRC}/etc/MAKEDEV"
	    ;;
	*)
	    VN="vn"
	    MAKEDEV="/dev/MAKEDEV"
    esac
}

d672 5
a676 1
default_vars
d680 37
a716 1
	src=$2
a717 4
	if [ "$2" = "--init" ] ; then
	    init_src=$2
	    shift
	fi
d743 1
a743 2
init_src_tree	# possibly a nop. Needs to be done before init_vars
init_vars	# set other variables depending on cmdline args.
@


1.1.2.16
log
@MFC import 1.14->1.15 changes into -stable
@
text
@d3 1
a3 1
# $FreeBSD$
d36 1
d40 17
a56 27
# There are two set of initialization. The first one (set_defaults)
# is done on entry to the script, and is used to set default values
# for all variables which do not depend on floppy type and source tree.
#
# The second set is done after command line parsing, e.g.
# to resolve dependencies on the source tree.
#
# Naming:
# + variables that control operation (e.g. verbosity) and are generally
#   set from the command line have o_ ("option") as a name prefix
#
# + variables which contain pathnames and values that should not change
#   have c_ ("constant") as a name prefix
#
# + variables exported to Makefiles and subshells are CAPITAL
#
# + variables local to the script are lowercase, possibly with
#   an l_ ("local") prefix

# SRC points to your FreeBSD source tree.
# l_usrtree points to the /usr subdir for the source tree.
#     Normally /usr or ${SRC}/../usr
# l_objtree points to the obj tree. Normally ${l_usrtree}/obj-pico
# PICO_TREE is where standard picobsd stuff resides.
#     Normally ${SRC}/release/picobsd
# You can set SRC with --src <directory>
# It is not recommended to override the other variables.
d58 4
a61 2
# MY_TREE (set later) is where this floppy type resides.
# BUILDDIR is the build directory
a62 2
# set some default values for variables.
# needs to be done as the first thing in the script.
d64 4
a67 10
# log something on stdout if verbose.
o_verbose=0	# this needs to be here!
log() {
    if [ ${o_verbose} -gt 0 ] ; then
	printf "\n*** %s\n" "$*"
	if [ ${o_verbose}  -gt 1 ] ; then
	    read -p "=== Press enter to continue" foo
	fi
    fi
}
d69 1
a69 2
set_defaults() {
    # no way to use logging in this function, variable not set yet.
d72 2
a73 1
    # fd_size  floppy size in KB (default to 1440). You can use 1480,
d77 2
a78 1
    fd_size=${fd_size:-1440}
d80 1
a80 23
    o_all_in_mfs="yes"		# put all files in mfs so you can boot and run
				# the image via diskless boot.
    o_clean=""			# do not clean
    o_interactive=""		# default is interactive
    o_verbose=0			# verbose level, 0 is silent
    o_tarv=""			# tar verbose flag, "" or "v"
    o_init_src=""		# non "" if we need to init libs and includes.
    o_makeopts=${MAKEOPTS:--s}	# make options, be silent by default
    o_no_devfs=yes		# we do not want devfs

    SRC="/usr/src"		# default location for sources
    c_startdir=`pwd`	# directory where we start
			# used to lookup config and create BUILDDIR

    c_boot1=/boot/boot1	# boot blocks (in case you want custom ones)
    c_boot2=/boot/boot2

    c_reply=${c_reply:-`mktemp "/tmp/reply.XXXXXXXXXX"`}
    			# file where User replies will be put
    c_mnt=`mktemp -d "/tmp/picobsd.XXXXXXXXXX"`
    			# mountpoint used to build memory filesystems
    c_fs=fs.PICOBSD	# filename used for the memory filesystem
    c_img=picobsd.bin	# filename used for the picobsd image
a81 10
    # select the right memory disk name
    case `uname -r` in
	5.*)
	    l_vn="md"
	    l_makedev="${SRC}/etc/MAKEDEV"
	    ;;
	*)
	    l_vn="vn"
	    l_makedev="/dev/MAKEDEV"
    esac
d83 7
a89 2
    l_vnum=`mount | awk "/${l_vn}/ { num++ } END { printf \"%d\", num }"`
    l_vndev=${l_vn}${l_vnum}
d91 2
d95 10
a104 5
    trap fail 2
    #trap fail 3
    #trap fail 6
    trap fail 15
    free_vnode			# cleanup old vnodes
d107 3
a109 11
create_includes_and_libraries() {
    log "create_includes_and_libraries() for ${SRC}"
    # Optionally creates include directory and libraries.
    mkdir -p ${l_usrtree}/include		# the include directory...
    mkdir -p ${l_usrtree}/share/misc	# a few things go here
    mkdir -p ${l_usrtree}/lib		# libraries
    mkdir -p ${l_usrtree}/sbin		# some binaries
    (cd ${SRC}; INCOWN=`id -un`  BINOWN=`id -un` DESTDIR=${SRC}/.. \
		make includes ) || fail $? includes
    # libraries already have the include path in the Makefile
    CFLAGS="-nostdinc" ; export CFLAGS
d111 1
a111 31
    (cd ${SRC}
	# $e is the invocation of make with correct environment
	e="MAKEOBJDIRPREFIX=${l_objtree}/picobsd/libraries \
	    INCOWN=`id -un` BINOWN=`id -un` DESTDIR=${SRC}/.. \
	    make -DNOHTML -DNOINFO -DNOMAN -DNOSHARE -DNOFSCHG "
	# need to 'make obj' in a few places. This is very
	# version-specific... The following works for 5.0
	for i in lib secure/lib gnu/lib usr.sbin/pcvt/keycap \
		gnu/usr.bin/perl usr.bin/lex usr.sbin/config ; do
	    (cd ${i}; eval $e obj)
	done
	# now make the static libraries
	eval $e -DNOPROFILE -DNOPIC libraries
	(cd ${SRC}/usr.sbin/config
	eval $e		# build binary
	eval $e	install	# install it
	)
    ) || fail $? "libraries"
    log "Libraries done"
}

# set_type <type> looks in user or system directories for the floppy type
# specified as first argument, and sets variables according to the config.
# file. Also sets MY_TREE and BUILDDIR and SITE

set_type() {
    local a

    log "set_type()"
    THETYPE=$1
    SITE=$2
d113 1
a113 1
    for i in ${c_startdir}/${a} ${PICO_TREE}/${a} ; do
d119 2
a120 2
		MFS_SIZE=$1 ; init_name=$2
		mfs_inodes=$3 ; fd_inodes=$4
d124 2
a125 2
		BUILDDIR=${c_startdir}/build_dir-${name}
		log "Matching file $name in $i"
a133 1
    log "clean_tree()"
d135 1
a135 1
	echo "---> Wrong floppy type"
d143 5
a147 5
    log "free_vnode() ${l_vndev} "
    umount ${c_mnt}    2> /dev/null || true
    umount /dev/${l_vndev}       2> /dev/null || true
    if [ "${l_vn}" = "vn" ] ; then
	vnconfig -u ${l_vndev} 2> /dev/null || true
d149 1
a149 1
	mdconfig -d -u ${l_vnum} 2> /dev/null || true
a154 2
    log "set_msgs()"

d165 5
a169 2
    log "build_image() <${name}>"
    [ "${name}" != "" ] || fail $? bad_type
d172 7
a178 14
    printf "${MSG}---> We'll use the sources living in ${SRC}\n\n"

    # read config variables from a global and then a type-specific file
    # basically STAND_LINKS and MY_DEVS, but can also override other
    # variables.
    # 
    . ${PICO_TREE}/build/config
    if [ -f ${MY_TREE}/config ] ; then
	. ${MY_TREE}/config
    fi

    # location of the object directory
    PICO_OBJ=${l_objtree}/picobsd/${THETYPE}
    log "PICO_OBJ is ${PICO_OBJ}"
d180 1
a180 5
    # create build directory and subtree
    mkdir -p ${BUILDDIR}/crunch
    # remove any old stuff
    rm -f ${BUILDDIR}/kernel.gz ${BUILDDIR}/${c_fs}
    # invoke commands to build a kernel
d182 3
a184 6
    # fill a subdirectory with things that go into the floppy
    # (mostly /etc and similar stuff)
    populate_floppy_fs
    # populate it and produce a file with the MFS image
    populate_mfs_tree		# things which go into mfs
    # create, mount and fill a filesystem with floppy image
a188 3
    local z msg

    log "build_package()"
d197 9
a205 5
	msg="(ok)"	# error message
	build_image || msg="** FAILED! **"
        echo "	${msg}">>build.status
	# where do i put things ?
	# clean_tree
a212 3
  local ans i l

  log "main_dialog()"
d215 1
a215 2
    rm ${c_reply}
    dialog --menu "PicoBSD build menu -- (29 sep 2001)" 19 70 12 \
d221 4
a224 4
	I "Init type: ${init_name}" \
	F "Floppy size: ${fd_size}kB" \
	M "MFS bytes per inode: ${mfs_inodes}" \
	U "UFS bytes per inode: ${fd_inodes}" \
d227 3
a229 3
	2> ${c_reply}
    ans=`cat ${c_reply}`
    rm ${c_reply}
d233 1
a233 1
	for i in ${c_startdir} ${c_startdir}/* ${PICO_TREE}/* ; do
d239 6
a244 2
	(dialog --menu "Setup the type of configuration" 12 70 5 $l \
		2> ${c_reply} && set_type "`cat ${c_reply}`" ${SITE} ) || true
d247 1
a247 1
	(dialog --menu "Choose your init(8) program" \
d249 4
a252 2
	oinit "small init from TinyWare" 2> ${c_reply} \
		&& init_name=`cat ${c_reply}` ) || true
d260 1
a260 1
	( dialog --title "MFS Size setup" --inputbox \
d266 4
a269 2
this as small as possible. " 10 70 2> ${c_reply} \
	&& MFS_SIZE=`cat ${c_reply}` ) || true
d273 1
a273 1
	(dialog --title "Site info setup" --inputbox \
d278 4
a281 1
	10 70 2> ${c_reply} && SITE=`cat ${c_reply}` ) || true
d285 6
a290 3
	(dialog --menu "Set floppy size" 15 70 4 \
	    1440 "1.44MB" 1720 "1.72MB" 2880 "2.88MB" 4096 "4MB" \
		 2> ${c_reply} && fd_size=`cat ${c_reply}` ) || true
d294 1
a294 1
	(dialog --title "MFS bytes per inode:" --inputbox \
d297 4
a300 1
	10 70 2> ${c_reply} && mfs_inodes=`cat ${c_reply}` ) || true
d304 1
a304 1
	(dialog --title "Floppy bytes per inode:" --inputbox \
d307 4
a310 1
	10 70 2> ${c_reply} && fd_inodes=`cat ${c_reply}` ) || true
a328 2
    log "do_install()"

d338 2
a339 2
	* Enter to install ${c_img},\n\
" 20 80 2> ${c_reply}
d341 2
a342 2
	echo "Writing ${c_img}..."
	dd if=${BUILDDIR}/${c_img} of=/dev/fd0.${fd_size}
d344 1
a344 1
	echo "Ok, the image is in ${c_img}"
d352 26
a377 1
# invoke the Makefile to compile the kernel.
d379 1
a379 1
    log "do_kernel() Preparing kernel \"$name\" in $MY_TREE"
d385 2
a386 2
# Populate the variable part of the floppy filesystem. Must be done before
# the MFS because its content might need to be copied there as well.
d388 1
a388 1
# This involves fetching files from three subtrees, in this order:
d390 1
a390 1
#  1. a standard one, from which type-specific files are excluded;
a398 1
    log "populate_floppy_fs()"
d400 1
a400 1
    log "pwd=`pwd` Populating floppy filesystem..."
d409 1
a409 1
	log "Files excluded from generic tree: `echo;cat ${excl}`"
d414 2
a415 2
		(cd ${dst} ; tar x${o_tarv}f - )
    log "Copied from generic floppy-tree `echo; ls -laR ${dst}`"
d419 1
a419 1
	log "update with type-specific files:"
d421 2
a422 2
	    (cd ${dst} ; tar x${o_tarv}f - )
	log "Copied from type floppy-tree `echo; ls -laR ${dst}`"
d424 1
a424 1
	log "No type-specific floppy-tree"
d427 1
a427 1
	log "Update with site-specific (${SITE}) files:"
d429 2
a430 2
	    (cd ${dst} ; tar x${o_tarv}f - )
	log "Copied from site floppy-tree `echo; ls -laR ${dst}`"
d432 1
a432 1
	log "No site-specific floppy-tree"
d435 3
a437 2
    (cd $dst ; gzip -9 etc/*
	    log "Compressed files in etc/ `echo; ls -l etc`"
d442 1
a442 1
    log "create_mfs() Preparing MFS filesystem..."
d447 1
a447 1
    init_fs_image ${BUILDDIR}/${c_fs} ${MFS_SIZE}
d449 1
a449 1
    log "Labeling MFS image"
d456 1
a456 1
	disklabel -rw ${l_vndev} fd${MFS_SIZE} || fail $? mfs_disklabel
d458 1
a458 1
	disklabel -rw ${l_vndev} auto || fail $? mfs_disklabel
d460 3
a462 3
    newfs -i ${mfs_inodes} -m 0 -p 0 -o space /dev/${l_vndev}c > /dev/null
    mount /dev/${l_vndev}c ${c_mnt} || fail $? no_mount
    log "`df /dev/${l_vndev}c`"
d472 7
a478 8
populate_mfs_tree() {
    local a dst

    log "populate_mfs_tree()"
    early_mfs_mount=0
    if [ "${early_mfs_mount}" = "1" ] ; then
	create_mfs
        dst=${c_mnt}
d480 1
a480 4
	dst=${BUILDDIR}/mfs.tree
	# clean relics from old compilations.
	rm -rf ${dst} || true
	mkdir ${dst}
d482 1
a482 8

    log "pwd=`pwd`, Populating MFS tree..."

    # use type-specific mfs.mtree, default to generic one.
    a=${MY_TREE}/mfs.mtree
    [ -f ${a} ] || a=${PICO_TREE}/build/mfs.mtree
    log "Running mtree using $a..."
    mtree -deU -f $a -p ${dst} > /dev/null || fail $? mtree
d486 1
a486 1
	ln -s /stand ${dst}/$i
d488 2
a489 2
    ln -s /dev/null ${dst}/var/run/log
    ln -s /etc/termcap ${dst}/usr/share/misc/termcap
d491 5
d499 1
a499 1
    log "Making and installing crunch1 from `pwd` src ${SRC}..."
d503 1
a503 1
    log "Libs are ${LIBS} "
d506 1
a506 1
    make ${o_makeopts} -f ${BUILDDIR}/crunch.mk
d508 3
a510 3
    mv crunch1 ${dst}/stand/crunch
    chmod 555 ${dst}/stand/crunch
    log "Making links for binaries..."
d512 1
a512 1
	ln ${dst}/stand/crunch ${dst}/stand/${i};
d517 3
a519 3
    if [ -f ${dst}/stand/sshd ] ; then
	log "Creating host key for sshd"
	ssh-keygen -f ${dst}/etc/ssh_host_key -N "" -C "root@@picobsd"
d523 1
a523 1
	log "Copy site-specific MFS tree..."
d526 1
a526 1
	log "Copy generic MFS tree..."
d530 1
a530 1
	    (cd ${dst} ; tar x${o_tarv}f - )
d532 8
a539 45
    if [ "${o_all_in_mfs}" = "yes" ]; then
	log "Copy generic floppy_tree into MFS..."
	cp -Rp ${BUILDDIR}/floppy.tree/* ${dst}/fd
    fi

    [ "`id -u`" = "0" ] || cat <<__EOF

### -------------------------------------------------------------------
###
### WARNING: You are not running with root permissions, so the next
### stages are likely to fail because they call commands such as
### chown, {vn|md}config, mount/umount which need adequate rights.
###
### The results of the compilation so far is in directory
###  ${BUILDDIR}
### which has the following content:

`ls -l ${BUILDDIR}`

###
### -------------------------------------------------------------------

__EOF

    if [ "${o_no_devfs}" != "" ] ; then
	# create device entries using MAKEDEV
	(cd ${dst}/dev
	ln -s ${l_makedev} ; chmod 555 MAKEDEV
	./MAKEDEV ${MY_DEVS}
	rm MAKEDEV
	)
    fi
    log "Fixing permissions"
    (cd ${dst}; chown -R root . )

    if [ "${early_mfs_mount}" != "1" ] ; then
	create_mfs
	log "Copy mfs tree into file"
	(cd ${dst} ; tar cf - . ) | ( cd ${c_mnt} ; tar xf - )
    fi
    # now umount and fsck the filesystem.
    log "Status of mfs image"
    df -ik ${c_mnt}
    umount ${c_mnt}
    fsck -p /dev/${l_vndev}c
a543 1
    log "final_cleanup()"
d545 1
a545 2
    rm -rf ${c_mnt} ${c_reply} 2> /dev/null || true
    rm -f ${c_reply}
a551 2
    local errno errocode where

d554 2
a555 3
    where=$3
    echo "---> fail: Error <${errno}> error code <${errcode}> in <${where}>"
    case ${errcode} in
d557 2
a558 3
	echo "Error in vnconfig on /dev/${l_vndev}..."
	echo "Either you are not running as root or your running kernel"
	echo "does not have the ${l_vn}(4) device."
d561 1
a561 1
	echo "Error while labeling ${c_fs} size ${MFS_SIZE}"
d564 1
a564 1
	echo "Error while mounting ${c_fs} (/dev/${l_vndev}c) on ${c_mnt}"
d567 1
a567 1
	echo "Error while making hierarchy in ${c_mnt}"
d573 1
a573 1
	echo "Error while doing disklabel on of floppy.img size $fd_size"
a583 6
    bad_type)
	echo "Error: unknown floppy type ${name}"
	;;
    no_space)
	echo "Error: no space left on device (${where})"
	;;
d586 1
a586 1
	errcode="userbreak"
a602 3
    local imgname imgsize

    log "init_fs_image() $1 $2"
d605 1
a605 1
    dd if=${c_boot1}  of=${imgname} conv=notrunc 2> /dev/null
d607 2
a608 2
    if [ "${l_vn}" = "vn" ] ; then
	vnconfig -c -s labels ${l_vndev} ${imgname} || fail $? no_vnconfig
d610 1
a610 1
	mdconfig -a -t vnode -u ${l_vnum} -f ${imgname} || fail $? no_vnconfig
d616 1
a616 6
    local blocks sectors dst

    log "fill_floppy_image()"
    dst=${c_mnt}	# where to create the image

    log "Preparing ${fd_size}kB floppy filesystem..."
d619 1
a619 1
    blocks=${fd_size}; sectors=18
d626 1
a626 1
    init_fs_image ${BUILDDIR}/${c_img} ${blocks}
d628 1
a628 1
    log "Labeling floppy image"
d630 2
a631 2
    perl -pne 's/\/boot\/loader/\/kernel\0\0\0\0\0/' ${c_boot2} > ${b2}
    disklabel -Brw -b ${c_boot1} -s ${b2} ${l_vndev} fd${fd_size} || \
d634 1
a634 2
    log "Newfs floppy image"
    newfs -i ${fd_inodes} -m 0 -p 0 -o space /dev/${l_vndev}c > /dev/null
d636 1
a636 2
    log "Mounting floppy image"
    mount /dev/${l_vndev}c ${dst}
d638 1
d642 1
a642 2
    log "Preload kernel with file ${c_fs}"
    ./wmk kernel ${c_fs}
a643 1
    log "Compress with kgzip and copy to floppy image"
d645 1
a645 1
    cp -p kernel.gz ${dst}/kernel || fail $? no_space "copying kernel"
a646 1
    log "now transfer floppy tree if needed"
d648 2
a649 3
    if [ "${o_all_in_mfs}" != "yes" ] ; then
	cp -Rp floppy.tree/* ${dst} || \
		fail $? no_space "copying floppy tree"
d652 1
a652 1
    (log "Fixing permissions"; cd ${dst}; chown -R root *)
d655 1
a655 1
    df -ik ${dst} | colrm 70 > .build.reply
d657 2
a658 2
    rm -rf ${dst}
    rm ${BUILDDIR}/kernel.gz ${BUILDDIR}/${c_fs}
d661 19
a679 14
# This function creates variables which depend on the source tree in use:
# SRC, l_usrtree, l_objtree LIBS, CFLAGS
# Optionally creates libraries, includes and the like (for cross compiles,
# needs to be done once).

set_build_parameters() {
    log "set_build_parameters() SRC is ${SRC}"
    if [ "${SRC}" = "/usr/src" ] ; then
	l_usrtree=${USR:-/usr}
    else
	l_usrtree=${USR:-${SRC}/../usr}
    fi
    l_objtree=${l_usrtree}/obj-pico
    PICO_TREE=${PICO_TREE:-${SRC}/release/picobsd}
d681 15
a695 2
    if [ "${o_init_src}" != "" ] ; then
	create_includes_and_libraries
d697 1
a697 1
    # Create the right LIBS and CFLAGS for further builds.
d699 2
a700 2
    LIBS="-L${l_usrtree}/lib"
    CFLAGS="-nostdinc -I${l_usrtree}/include"
d702 23
a724 1
    CONFIG=${l_usrtree}/sbin/config
d728 2
a729 4
# Main entry of the script. Initialize variables, parse command line
# arguments.

set_defaults
d733 1
a733 1
	SRC=$2
d735 4
a738 3
	;;
    --init)
	o_init_src="YES"
d742 1
a742 1
	fd_size=$2
a744 9

    --all_in_mfs)
	o_all_in_mfs="yes"
	;;

    --no_all_in_mfs)
	o_all_in_mfs=""
	;;

d746 1
a746 6
	o_interactive="NO"
	;;

    -clear|-clean|-c) # clean
	o_clean="YES"
	o_interactive="NO"
d748 8
a755 5

    -v) # need -v -v to wait for user input
	o_verbose=$((${o_verbose}+1))	# verbose level
	o_tarv="v"			# tar verbose flag
	o_makeopts="-d l" # be verbose
d764 6
a769 2
set_build_parameters	# things that depend on ${SRC}
set_type $1 $2		# type and site, respectively
d776 1
a776 1
if [ "${o_interactive}" != "NO" ] ; then
d779 1
a779 1
if [ "${o_clean}" = "YES" ] ; then
@


1.1.2.17
log
@MFC: use host keys from the config directory if they exist, instead of
regenerating them on the fly.

Make the script handle relative paths for the source directory.
@
text
@d3 1
a3 1
# $FreeBSD: src/release/picobsd/build/picobsd,v 1.1.2.16 2001/10/02 17:11:04 luigi Exp $
d571 1
a571 5
	if [ -f ${dst}/etc/ssh_host_key ] ; then
	    log "Using existing host key"
	else
	    ssh-keygen -f ${dst}/etc/ssh_host_key -N "" -C "root@@picobsd"
	fi
d809 1
a809 1
	SRC=`(cd $2; pwd)`
@


1.1.2.18
log
@MFC: add option to build modules.
@
text
@d3 1
a3 1
# $FreeBSD$
a102 1
    o_do_modules=""		# do not build modules
a399 5
    if [ "${o_interactive}" = "NO" ] ; then
	echo "+++ Build completed +++"
	cat .build.reply
	return
    fi
a426 4
	if [ "${o_do_modules}" = "yes" ] ; then
		MODULES=""
		export MODULES
	fi
a832 3
    --modules)	# also build kernel modules
	o_do_modules="yes"
	;;
@


1.1.2.19
log
@MFC: Use a local edition of write_mfs_in_kernel.c.
@
text
@d3 1
a3 1
# $FreeBSD: src/release/picobsd/build/picobsd,v 1.1.2.18 2001/11/01 16:27:49 luigi Exp $
d765 1
a765 1
    cc -o wmk ${PICO_TREE}/build/write_mfs_in_kernel.c
@


1.1.2.20
log
@MFC: use correct .mk files, and be backward compatible in locating wmk sources.
@
text
@d3 1
a3 1
# $FreeBSD$
d150 1
a150 1
		make -m ${SRC}/share/mk includes ) || fail $? includes
d158 1
a158 2
	    make -m ${SRC}/share/mk \
		-DNOHTML -DNOINFO -DNOMAN -DNOSHARE -DNOFSCHG "
d437 1
a437 1
	make -m ${SRC}/share/mk -v -f ${PICO_TREE}/build/Makefile.conf ) || \
d564 1
a564 2
	make -m ${SRC}/share/mk \
		-v -f ${PICO_TREE}/build/Makefile.conf ${BUILDDIR}/crunch.mk )
d568 1
a568 1
    make -m ${SRC}/share/mk ${o_makeopts} -f ${BUILDDIR}/crunch.mk
d765 1
a766 6
if [ true ] ; then
    if [ -f ${PICO_TREE}/build/write_mfs_in_kernel.c ] ; then
	cc -o wmk ${PICO_TREE}/build/write_mfs_in_kernel.c
    else
	cc -o wmk ${PICO_TREE}/../write_mfs_in_kernel.c
    fi
a768 7
else	# not working yet, just a reminder
    objdump -h kernel
    objcopy --remove-section=md_root kernel
    objcopy --add-section md_root=${c_fs} kernel
    objcopy --set-section-flags md_root=contents,alloc,load,data kernel
    objdump -h kernel
fi
@


1.1.2.21
log
@MFC: use {} instead of () for shell command grouping.
@
text
@d3 1
a3 1
# $FreeBSD: src/release/picobsd/build/picobsd,v 1.1.2.20 2001/11/24 20:26:57 luigi Exp $
d330 2
a331 2
	{ dialog --menu "Setup the type of configuration" 12 70 5 $l \
		2> ${c_reply} && set_type "`cat ${c_reply}`" ${SITE} ; } || true
d334 1
a334 1
	{ dialog --menu "Choose your init(8) program" \
d337 1
a337 1
		&& init_name=`cat ${c_reply}` ; } || true
d345 1
a345 1
	{ dialog --title "MFS Size setup" --inputbox \
d352 1
a352 1
	&& MFS_SIZE=`cat ${c_reply}` ; } || true
d356 1
a356 1
	{ dialog --title "Site info setup" --inputbox \
d361 1
a361 1
	10 70 2> ${c_reply} && SITE=`cat ${c_reply}` ; } || true
@


1.1.2.22
log
@MFC: sync with rev 1.22
@
text
@d3 1
a3 1
# $FreeBSD$
a83 5
logverbose() {
    printf "\n*** %s\n" "$*"
    read -p "=== Press enter to continue" foo
}

d365 1
a365 1
	{ dialog --menu "Set floppy size" 15 70 4 \
d367 1
a367 1
		 2> ${c_reply} && fd_size=`cat ${c_reply}` ; } || true
d371 1
a371 1
	{ dialog --title "MFS bytes per inode:" --inputbox \
d374 1
a374 1
	10 70 2> ${c_reply} && mfs_inodes=`cat ${c_reply}`  ; } || true
d378 1
a378 1
	{ dialog --title "Floppy bytes per inode:" --inputbox \
d381 1
a381 1
	10 70 2> ${c_reply} && fd_inodes=`cat ${c_reply}` ; } || true
d517 1
a517 2
    newfs -i ${mfs_inodes} -m 0 -p 0 -o space -f 512 -b 4096 \
	/dev/${l_vndev}c > /dev/null
d590 9
a598 8
    log "Copy generic and site-specific MFS tree..."
    for MFS_TREE in ${PICO_TREE}/mfs_tree ${MY_TREE}/mfs_tree ; do
	if [ -d ${MFS_TREE} ] ; then
	    log "Copy ${MFS_TREE} ..."
	    (cd ${MFS_TREE} ; tar -cf - --exclude CVS . ) | \
		    (cd ${dst} ; tar x${o_tarv}f - )
	fi
    done
d756 1
a756 3

    # create a disklabel ...
    disklabel -Brw -b ${c_boot1} -s ${b2} ${l_vndev} auto || \
a758 6
    # and copy partition c: into partition a: using some sed magic
    disklabel ${l_vndev} | sed -e '/  c:/{p;s/c:/a:/;}' | \
	disklabel -R ${l_vndev} /dev/stdin

    logverbose "`disklabel ${l_vndev}`"

d760 1
a760 3
    newfs -i ${fd_inodes} -m 0 -p 0 -o space -f 512 -b 4096 \
	     /dev/${l_vndev}a > /dev/null
    logverbose "`disklabel ${l_vndev}`"
d763 1
a763 1
    mount /dev/${l_vndev}a ${dst}
@


1.1.2.23
log
@MFC: sync with -current.
@
text
@d165 2
a166 2
	log "do a 'make obj' in a few places."
	# This is very version-specific... The following works for 5.0
d171 1
a171 1
	log "now make the static libraries"
a496 1

d588 2
a589 2
	log "Setting up host key for sshd:"
	if [ -f ${BUILDDIR}/floppy.tree/etc/ssh_host_key.gz ] ; then
d592 1
a592 4
	    log "Generating new host key" 
	    ssh-keygen -f ${BUILDDIR}/floppy.tree/etc/ssh_host_key \
		 -N "" -C "root@@picobsd"
	    gzip -9 ${BUILDDIR}/floppy.tree/etc/ssh_host_key* || true
d770 2
d775 1
d810 1
a810 1
    # rm -rf ${BUILDDIR}/floppy.tree || true # cleanup
@


1.1.2.24
log
@MFC: better handling of "missing MFS" errors, and import_files option.
@
text
@a643 10
    if [ -n "${import_files}" ] ; then
	log "importing ${import_files} into mfs"
	# We do it in a chroot environment on the target so
	# symlinks are followed correctly.
	cp `which tar` ${dst}/my_copy_of_tar
	(cd ${l_usrtree}/.. ; tar cf - ${import_files} ) | \
	    (chroot ${dst} /my_copy_of_tar xf - )
	rm ${dst}/my_copy_of_tar
    fi

a709 3
    no_mfs)
	echo "Error: while writing MFS into the kernel."
	;;
d790 1
a790 1
    ./wmk kernel ${c_fs} || fail $? no_mfs
@


1.1.2.25
log
@MFC: PicoBSD building fixes.

Requested by:	luigi
@
text
@d3 1
a3 1
# $FreeBSD: src/release/picobsd/build/picobsd,v 1.1.2.24 2002/03/21 03:20:34 luigi Exp $
d154 1
a154 1
    (cd ${SRC}; INCOWN=`id -un`  BINOWN=`id -un` DESTDIR=${l_usrtree}/.. \
d156 2
a157 2
    # Pick up the correct headers for libraries.
    CFLAGS="-nostdinc -I${l_usrtree}/include" ; export CFLAGS
d162 1
a162 1
	    INCOWN=`id -un` BINOWN=`id -un` DESTDIR=${l_usrtree}/.. \
@


1.1.2.26
log
@MFC 1.26: fix (cross) building of picobsd using -CURRENT sources.
@
text
@d3 1
a3 1
# $FreeBSD$
a146 9
create_includes_and_libraries2() {
    log "create_includes_and_libraries2() for ${SRC}"
    MAKEOBJDIRPREFIX=${l_objtree}
    export MAKEOBJDIRPREFIX
    ( cd ${SRC};
    make -DNOCLEAN -DNOPROFILE -DNOGAMES -DNOLIBC_R -DPICOBSD buildworld
    )
}

a265 6
    if [ ${OSVERSION} -ge 500035 ] ; then
	MAKEOBJDIRPREFIX=${l_objtree}
	export MAKEOBJDIRPREFIX
	log `cd ${SRC}; make -f Makefile.inc1 -V WMAKEENV`
	eval export `cd ${SRC}; make -f Makefile.inc1 -V WMAKEENV`
    fi
d438 1
a438 2
    (cd $MY_TREE; export name SRC BUILDDIR # used in this makefile ;
	# export CONFIG
d575 1
a575 2
    export SRC # used by crunch.mk
    # export LIBS CFLAGS
d796 16
a811 6
    # $1 takes the offset of the MFS filesystem
    set `strings -at d kernel | grep "MFS Filesystem goes here"`
    mfs_ofs=$(($1 + 8192))
    log "Preload kernel with file ${c_fs} at ${mfs_ofs}"
    dd if=${c_fs} ibs=8192 iseek=1 of=kernel obs=${mfs_ofs} \
	oseek=1 conv=notrunc
d833 1
a833 1
# SRC, l_usrtree, l_objtree
d846 1
a846 3
    set `grep "#define[\t ]__FreeBSD_version" ${SRC}/sys/sys/param.h`
    OSVERSION=$3
    logverbose "OSVERSION is ${OSVERSION}"
d848 1
a848 14
	if [ ${OSVERSION} -lt 500035 ] ; then
	    create_includes_and_libraries
	else
	    create_includes_and_libraries2
	fi
    fi
    if [ ${OSVERSION} -lt 500035 ] ; then
	# Create the right LIBS and CFLAGS for further builds.
	# and build the config program
	LIBS="-L${l_usrtree}/lib"
	CFLAGS="-nostdinc -I${l_usrtree}/include"
	export LIBS CFLAGS
	CONFIG=${l_usrtree}/sbin/config
	export CONFIG
d850 6
@


1.1.2.27
log
@MFC: replace one instance of logverbose with log.
@
text
@d3 1
a3 1
# $FreeBSD: src/release/picobsd/build/picobsd,v 1.1.2.26 2002/07/14 09:08:51 luigi Exp $
d855 1
a855 1
    log "OSVERSION is ${OSVERSION}"
@


1.1.2.28
log
@Fix a long standing problem with ssh-keygen missing the '-t rsa1' option.

Remove historical '-p 0' option from newfs

Use 'strings' and 'dd' magic instead of perl (unavailable in -current)
to patch the boot2 block.

Will go into -current as soon as re@@ approve

Submitted by: Bruce Montague
MFC After: 3 days
@
text
@d3 1
a3 1
# $FreeBSD$
d539 1
a539 1
    newfs -i ${mfs_inodes} -m 0 -o space -f 512 -b 4096 \
d611 1
a611 1
	    ssh-keygen -t rsa1 -f ${BUILDDIR}/floppy.tree/etc/ssh_host_key \
d794 1
a794 5
    cp ${c_boot2} ${b2}
    chmod 0644 ${b2}
    set `strings -at d ${b2} | grep "/boot/loader"`
    echo -e "/kernel\0\0\0\0\0" | dd of=${b2} obs=$1 oseek=1 conv=notrunc
    chmod 0444 ${b2}
d805 1
a805 1
    newfs -i ${fd_inodes} -m 0 -o space -f 512 -b 4096 \
@


1.1.2.29
log
@Switch importer
@
text
@d3 1
a3 1
# $FreeBSD: stable/4/release/picobsd/build/picobsd 107532 2002-12-02 22:33:50Z luigi $
@


