-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathbuildepoch.sh
executable file
·185 lines (150 loc) · 5.46 KB
/
buildepoch.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
#!/bin/sh
# Script to built the Epoch Init System.
CMD()
{
printf "%s " $1
printf "\n"
$1
if [ "$?" != "0" ]; then
{
printf "Error building Epoch.\n"
exit 1;
}
fi
}
ShowHelp()
{
Green="\033[32m"
EndGreen="\033[0m"
printf $Green"--nommu"$EndGreen":\n\tUse this to build Epoch for a CPU with no MMU.\n"
printf $Green"--configdir dir"$EndGreen":\n\tSets the directory Epoch will search for epoch.conf.\n"
printf "\tDefault is /etc/epoch.\n"
printf $Green"--logfile file"$EndGreen":\n\tSets the file Epoch will use as its logfile.\n"
printf "\tDefault is /var/log.\n"
printf $Green"--binarypath path"$EndGreen":\n\tThe direct path to the Epoch binary. Default is /sbin/epoch.\n"
printf $Green"--env-home value"$EndGreen":\n\tDesired environment variable for \$HOME.\n"
printf "\tThis will be usable in Epoch start/stop commands.\n"
printf $Green"--env-user value"$EndGreen":\n\tDesired environment variable for \$USER.\n"
printf "\tThis will be usable in Epoch start/stop commands.\n"
printf $Green"--env-shell value"$EndGreen":\n\tDesired environment variable for \$SHELL.\n"
printf "\tThis will be usable in Epoch start/stop commands.\n"
printf $Green"--env-path value"$EndGreen":\n\tDesired environment variable for \$PATH.\n"
printf $Green"--outpath dir"$EndGreen":\n\tThe location that the compiled binary.\n"
printf "\tand symlinks will be placed upon completion.\n"
printf "\tSimilar to make install DESTDIR=\"\".\n"
printf $Green"--disable-backtraces"$EndGreen":\n\tThis flag is necessary for building with\n"
printf "\tuClibc and other libc implementations that don't provide execinfo.h.\n"
printf $Green"--disable-shell"$EndGreen":\n\tIf this flag is set, Epoch will be built\n"
printf "\tto not launch objects with /bin/sh, and will instead try to use an\n"
printf "\targument list. This may be useful on embedded systems,\n"
printf "\tbut comes at a high price of removing support for any shell characters,\n"
printf "\tsuch as '&' and '&&'.\n"
printf $Green"--shellpath"$EndGreen":\n\tThe shell that Epoch will use to assist in the launching of objects,\n"
printf "\tprovided that --disable-shell is not specified.\n"
printf $Green"--shell-forks-with-dashc"$EndGreen":\n\tShells such as busybox create a new process\n"
printf "\twhen we use 'sh -c', but most including bash, dash, ksh, csh, tcsh,\n"
printf "\tand zsh do not. You are encouraged to make sure this is set for\n"
printf "\tbusybox etc, because this option is used to assist tracking PIDs.\n"
printf $Green"--nokargsfile"$EndGreen":\n\tThe file that Epoch will check for to see if it should ignore kernel arg options.\n"
printf $Green"--cflags value"$EndGreen":\n\tSets \$CFLAGS to the desired value.\n"
printf $Green"--ldflags value"$EndGreen":\n\tSets \$LDFLAGS to the desired value.\n"
printf $Green"--cc value"$EndGreen":\n\tSets \$CC to be the compiler for Epoch.\n"
}
NEED_EMPTY_CFLAGS="0"
outdir="../built"
if [ "$CC" = "" ]; then
CC="cc"
fi
if [ "$#" != "0" ]; then
while [ -n "$1" ]
do
if [ "$1" = "--help" ]; then
ShowHelp
exit 0
elif [ "$1" = "--nommu" ]; then
CFLAGS=$CFLAGS" -DNOMMU"
elif [ "$1" = "--configdir" ];then
shift
CFLAGS=$CFLAGS" -DCONFIGDIR=\"$1\""
elif [ "$1" = "--binarypath" ]; then
shift
CFLAGS=$CFLAGS" -DEPOCH_BINARY_PATH=\"$1\""
elif [ "$1" = "--logfile" ]; then
shift
CFLAGS=$CFLAGS" -DLOGFILE=\"$1\""
elif [ "$1" = "--env-home" ]; then
shift
CFLAGS=$CFLAGS" -DENVVAR_HOME=\"$1\""
elif [ "$1" = "--env-user" ]; then
shift
CFLAGS=$CFLAGS" -DENVVAR_USER=\"$1\""
elif [ "$1" = "--env-shell" ]; then
shift
CFLAGS=$CFLAGS" -DENVVAR_SHELL=\"$1\""
elif [ "$1" = "--nokargsfile" ]; then
shift
CFLAGS=$CFLAGS" -DNOKARGSFILE=\"$1\""
elif [ "$1" = "--env-path" ]; then
shift
CFLAGS=$CFLAGS" -DENVVAR_PATH=\"$1\""
elif [ "$1" = "--shell-forks-with-dashc" ]; then
CFLAGS=$CFLAGS" -DSHELLDISSOLVES=false"
elif [ "$1" = "--outpath" ]; then
shift
outdir="$1"
elif [ "$1" = "--disable-shell" ]; then
CFLAGS=$CFLAGS" -DNOSHELL"
elif [ "$1" = "--disable-backtraces" ]; then
CFLAGS=$CFLAGS" -DNO_EXECINFO"
elif [ "$1" = "--shellpath" ]; then
shift
CFLAGS=$CFLAGS" -DSHELLPATH=\"$1\""
elif [ "$1" = "--cflags" ]; then
shift
CFLAGS=$CFLAGS" $1"
NEED_EMPTY_CFLAGS="1"
elif [ "$1" = "--cc" ]; then
shift
CC="$1"
elif [ "$1" = "--ldflags" ]; then
shift
LDFLAGS="$1"
fi
shift
done
fi
if [ "$NEED_EMPTY_CFLAGS" = "0" ]; then
CFLAGS=$CFLAGS" -std=gnu99 -pedantic -Wall -g -O0 -fstack-protector"
fi
if [ "$LDFLAGS" = "" ]; then
LDFLAGS="-rdynamic"
fi
printf "\nBuilding object files.\n\n"
rm -rf objects built
mkdir objects
cd objects
CMD "$CC $CFLAGS -c ../src/actions.c"
CMD "$CC $CFLAGS -c ../src/config.c"
CMD "$CC $CFLAGS -c ../src/console.c"
CMD "$CC $CFLAGS -c ../src/main.c"
CMD "$CC $CFLAGS -c ../src/membus.c"
CMD "$CC $CFLAGS -c ../src/modes.c"
CMD "$CC $CFLAGS -c ../src/parse.c"
CMD "$CC $CFLAGS -c ../src/utilfuncs.c"
printf "\nBuilding main executable.\n\n"
mkdir -p $outdir/sbin/
mkdir -p $outdir/bin/
CMD "$CC $CFLAGS -o $outdir/sbin/epoch\
actions.o config.o console.o main.o membus.o modes.o parse.o utilfuncs.o $LDFLAGS"
printf "\nCreating symlinks.\n"
cd $outdir/sbin/
CMD "ln -s -f ./epoch init"
CMD "ln -s -f ./epoch halt"
CMD "ln -s -f ./epoch poweroff"
CMD "ln -s -f ./epoch reboot"
CMD "ln -s -f ./epoch shutdown"
CMD "ln -s -f ./epoch killall5"
cd ../bin/
CMD "ln -s -f ../sbin/epoch wall"
printf "\nBuild complete.\n\n"
cd ..