Line 0
Link Here
|
|
|
1 |
# $FreeBSD$ |
2 |
# |
3 |
# This Makefile is designed to have a very simpe interface to create a |
4 |
# user-friendly interface to configure the options needed to build the |
5 |
# world and/or the kernel, but not the options used to compile the kernel |
6 |
# or the devices that will be statically linked to the kernel. |
7 |
|
8 |
.include <src.opts.mk> |
9 |
.include "${.CURDIR}/sys/conf/kern.opts.mk" |
10 |
.include <src.opts.desc.mk> |
11 |
|
12 |
DIALOG?=/usr/bin/dialog |
13 |
DIALOG_OPTS=--backtitle "FreeBSD Configurator" |
14 |
CHECK_LIST=--checklist "Build options" 50 80 45 |
15 |
MAKE=/usr/bin/make -C ${.CURDIR} |
16 |
MAKE_CONF=${MAKE} -f Makefile.config |
17 |
WARNMSG=The following options will be set because of the chosen options: |
18 |
|
19 |
SRCCONF?=/etc/src.conf |
20 |
SRCCONF_BEFORE=${SRCCONF} |
21 |
SRCCONF_DEFAULT=/dev/null |
22 |
SRCCONF_CURRENT=/tmp/`echo ${SRCCONF} | tr '/' '_'` |
23 |
|
24 |
SRC_ENV_CONF?=/etc/src-env.conf |
25 |
SRC_ENV_CONF_BEFORE=${SRC_ENV_CONF} |
26 |
SRC_ENV_CONF_DEFAULT=/dev/null |
27 |
SRC_ENV_CONF_CURRENT=/tmp/`echo ${SRC_ENV_CONF} | tr '/' '_'` |
28 |
|
29 |
CONFIG_OPTIONS= |
30 |
|
31 |
# Create the main menu with all the options to be configured. |
32 |
MAIN_MENU= |
33 |
.for __cat in ${CATEGORIES} |
34 |
MAIN_MENU+= ${__cat} |
35 |
.if defined(${__cat}_DESC) |
36 |
MAIN_MENU+= ${${__cat}_DESC} |
37 |
.else |
38 |
MAIN_MENU+= ${__cat} |
39 |
.endif |
40 |
|
41 |
# For every single category, get the options to be configured on it. |
42 |
.if defined(${__cat}) |
43 |
${__cat}_OPTS= |
44 |
.for __opt in ${${__cat}} |
45 |
${__cat}_OPTS+= ${__opt} |
46 |
.if defined(${__opt}_DESC) |
47 |
${__cat}_OPTS+= "${${__opt}_DESC}" |
48 |
.else |
49 |
${__cat}_OPTS+= "${__opt}" |
50 |
.endif |
51 |
|
52 |
.if defined(MK_${__opt}) |
53 |
.if ${MK_${__opt}} != "no" |
54 |
${__cat}_OPTS+= on |
55 |
.else |
56 |
${__cat}_OPTS+= off |
57 |
.endif |
58 |
.else |
59 |
${__cat}_OPTS+= off |
60 |
.endif |
61 |
|
62 |
.endfor |
63 |
|
64 |
|
65 |
config-${__cat:tl}: |
66 |
@${DIALOG} ${DIALOG_OPTS} ${CHECK_LIST} ${${__cat}_OPTS}\ |
67 |
2> /tmp/config || exit 0; \ |
68 |
touch ${SRCCONF_CURRENT}.tmp ${SRC_ENV_CONF_CURRENT}.tmp ; \ |
69 |
for ITEM in ${${__cat}};do \ |
70 |
FILE=${SRCCONF_CURRENT}.tmp ; \ |
71 |
echo ${__ENV_ONLY_OPTIONS} | grep -q "$${ITEM}"\ |
72 |
&& FILE=${SRC_ENV_CONF_CURRENT}.tmp; \ |
73 |
if grep -qE "(^|[[:space:]])$${ITEM}([[:space:]]|$$)" \ |
74 |
/tmp/config ; then \ |
75 |
echo "WITH_$${ITEM}=yes" >> $${FILE}; \ |
76 |
else \ |
77 |
echo "WITHOUT_$${ITEM}=yes" >> $${FILE} ; \ |
78 |
fi ; \ |
79 |
done ;\ |
80 |
sort ${SRCCONF_CURRENT}.tmp | uniq > ${SRCCONF_CURRENT} || true; \ |
81 |
sort ${SRC_ENV_CONF_CURRENT}.tmp | uniq > ${SRC_ENV_CONF_CURRENT} || true; \ |
82 |
rm -f /tmp/config-* ; \ |
83 |
${MAKE_CONF} check-config ; \ |
84 |
if [ ! -s "${SRCCONF}.tmp" -a ! -s "${SRC_CONF_ENV}.tmp" ] ;\ |
85 |
then \ |
86 |
comm -23 /tmp/config-current /tmp/config-default \ |
87 |
> ${SRCCONF} ;\ |
88 |
comm -23 /tmp/config-current.env /tmp/config-default.env \ |
89 |
> ${SRC_ENV_CONF} ; \ |
90 |
else \ |
91 |
WARNMSG="${WARNMSG}" ; \ |
92 |
for ITEM in $$(cut -d '=' -f1 ${SRCCONF}.tmp) ; do \ |
93 |
ONOFF=$$(echo $${ITEM} | cut -d '_' -f1) ; \ |
94 |
ITEM=$$(echo $${ITEM} | cut -d '_' -f2-) ; \ |
95 |
[ "$${ONOFF}" = "WITHOUT" ] && ONOFF="off" \ |
96 |
|| ONOFF="on" ;\ |
97 |
WARNMSG="$${WARNMSG}\n $${ITEM} -> $${ONOFF}"; \ |
98 |
done ; \ |
99 |
${DIALOG} ${DIALOG_OPTS} --msgbox "$${WARNMSG}" 30 70 ; \ |
100 |
${MAKE_CONF} config-${__cat:tl} ;\ |
101 |
fi |
102 |
.endif #defined(${__cat}) |
103 |
.endfor #${CATEGORIES} |
104 |
|
105 |
.for __conf in before default current |
106 |
config-${__conf}: |
107 |
@${MAKE} SRCCONF=${SRCCONF_${__conf:tu}} \ |
108 |
SRC_CONF_ENV=${SRC_ENV_CONF_${__conf:tu}} showconfig | \ |
109 |
while read OPTION _ VALUE; do \ |
110 |
FILE=/tmp/${.TARGET}.tmp ; \ |
111 |
echo ${__ENV_ONLY_OPTIONS} | grep -q "$${OPTION##MK_}" && \ |
112 |
FILE=/tmp/${.TARGET}.env.tmp ;\ |
113 |
[ "$${VALUE}" = "yes" ] && WHAT=WITH || WHAT=WITHOUT ; \ |
114 |
echo "$${WHAT}_$${OPTION##MK_}=yes" >> $${FILE} ;\ |
115 |
done ; sort /tmp/${.TARGET}.tmp | uniq > /tmp/${.TARGET} ; \ |
116 |
sort /tmp/${.TARGET}.env.tmp | uniq > /tmp/${.TARGET}.env ; \ |
117 |
rm -f /tmp/${.TARGET}.tmp /tmp/${.TARGET}.env.tmp |
118 |
|
119 |
.endfor |
120 |
|
121 |
config: ${SRCCONF} ${SRC_ENV_CONF} |
122 |
@cp ${SRCCONF} ${SRCCONF}.bak; \ |
123 |
cp ${SRC_ENV_CONF} ${SRC_ENV_CONF}.bak; \ |
124 |
while true ; do \ |
125 |
if [ -r "${SRCCONF_CURRENT}" ] ; then \ |
126 |
echo "There is another process trying to configure the build" \ |
127 |
", please finish it first." ;\ |
128 |
exit 1 ;\ |
129 |
fi ; \ |
130 |
cp ${SRCCONF} ${SRCCONF_CURRENT} ;\ |
131 |
if ! ${DIALOG} ${DIALOG_OPTS} --menu "Categories" 20 70 15 \ |
132 |
${MAIN_MENU} SAVE "Save the current configuration" \ |
133 |
2> /tmp/config ; then\ |
134 |
mv ${SRCCONF}.bak ${SRCCONF} ;\ |
135 |
mv ${SRC_ENV_CONF}.bak ${SRC_ENV_CONF} ;\ |
136 |
rm -f /tmp/config* ${SRCCONF_CURRENT}* \ |
137 |
${SRC_ENV_CONF_CURRENT}* ${SRCCONF}.tmp \ |
138 |
${SRC_ENV_CONF}.tmp ;\ |
139 |
exit 0 ;\ |
140 |
fi ;\ |
141 |
SUBMENU="config-`cat /tmp/config | tr '[:upper:]' '[:lower:]'`"; \ |
142 |
${MAKE_CONF} $${SUBMENU} ; \ |
143 |
rm -f /tmp/config* ${SRCCONF_CURRENT}* \ |
144 |
${SRC_ENV_CONF_CURRENT}* ${SRCCONF}.tmp \ |
145 |
${SRC_ENV_CONF}.tmp ;\ |
146 |
[ "$${SUBMENU}" = "config-save" ] && break ; \ |
147 |
done |
148 |
|
149 |
${SRCCONF} ${SRC_ENV_CONF}: |
150 |
@[ -r ${.TARGET} ] || touch ${.TARGET} |
151 |
|
152 |
check-config: ${SRCCONF} ${SRC_ENV_CONF} config-before config-default config-current |
153 |
@comm -23 /tmp/config-current /tmp/config-before | sort | uniq \ |
154 |
> ${SRCCONF_CURRENT}.diff ;\ |
155 |
comm -23 /tmp/config-current.env /tmp/config-before.env | sort | uniq \ |
156 |
> ${SRC_ENV_CONF_CURRENT}.diff ;\ |
157 |
cat ${SRCCONF_CURRENT}.diff | while read LINE ; do \ |
158 |
grep -qE "$${LINE} ${SRCCONF_CURRENT} && continue ;\ |
159 |
echo $${LINE} ; \ |
160 |
done > ${SRCCONF}.tmp ; \ |
161 |
cat ${SRC_ENV_CONF_CURRENT}.diff | while read LINE ; do \ |
162 |
grep -qE "$${LINE} ${SRC_ENV_CONF_CURRENT} && continue ;\ |
163 |
echo $${LINE} ; \ |
164 |
done > ${SRC_ENV_CONF}.tmp |
165 |
|
166 |
config-save: config-default config-current |
167 |
@if [ -r "${SRCCONF_CURRENT}" ] ; then \ |
168 |
mv ${SRCCONF_CURRENT} ${SRCCONF} ; \ |
169 |
rm -f ${SRCCONF}.bak ; \ |
170 |
else \ |
171 |
mv ${SRCCONF}.bak ${SRCCONF} ; \ |
172 |
fi |
173 |
@if [ -r "${SRC_ENV_CONF_CURRENT}" ] ; then \ |
174 |
mv ${SRC_ENV_CONF_CURRENT} ${SRC_ENV_CONF} ; \ |
175 |
rm ${SRC_ENV_CONF}.bak ; \ |
176 |
else \ |
177 |
mv ${SRC_ENV_CONF}.bak ${SRC_ENV_CONF} ; \ |
178 |
fi |
179 |
|