OSDN Git Service

2013.10.24
[uclinux-h8/uClinux-dist.git] / bin / mk-dist
1 #
2 #       Build a uClinux/distribution source package from git tree.
3 #
4 #       (C) Copyright 1999-2013, Greg Ungerer <greg.ungerer@accelecon.com>
5 #
6 #       Takes a git tree a ssource and builds a uClinux-dist package.
7 #
8
9 NAME=uClinux-dist
10 SOURCE=${1:-uclinux-dist.working}
11 PKGDIR=images
12
13 #
14 #       KEEP_BOOT=true
15 #       KEEP_IXP_MODULES=true
16 #       KEEP_OCF_MODULES=true
17 #       KEEP_PROP=true
18 #       KEEP_MODULE_CONFIGS=true
19 #
20
21 # If we keep crypto or ixp modules, we need to keep the module configs too.
22 [ "$KEEP_CRYPTO" = "true" -o "$KEEP_IXP_MODULES" = "true" ] && KEEP_MODULE_CONFIGS=true
23
24
25 DATE=`date +%Y%m%d`
26 PACKAGE=${NAME}-${DATE}
27
28 DIRS="README SOURCE COPYING Documentation Makefile config linux-2.4.x linux-3.x freeswan openswan lib glibc uClibc user include tools vendors bin"
29
30 [ "$KEEP_PROP" = "true" ] && DIRS="$DIRS prop"
31 [ "$KEEP_BOOT" = "true" ] && DIRS="$DIRS boot"
32
33 CURPWD=`pwd`
34 SRCDIR=${CURPWD}/${SOURCE}
35 DSTDIR=${CURPWD}/${NAME}
36 SLASHPKGDIR=${CURPWD}/${PKGDIR}/.
37
38
39 #
40 #       Check if target directory exists, bail if it does.
41 #
42 if [ -d "${DSTDIR}" ]
43 then
44         echo "ERROR: directory ${DSTDIR} exists, stopping now!"
45         exit 1
46 fi
47
48
49 #
50 #       Remove any old current images hanging around...
51 #
52 [ -d ${SLASHPKGDIR} ] || mkdir -p ${SLASHPKGDIR}
53 rm -f ${SLASHPKGDIR}/${PACKAGE}*
54
55
56 #
57 #       Start creating new directory
58 #
59 echo "Creating ${DSTDIR} directory..."
60 mkdir ${DSTDIR}
61 cd ${SRCDIR}
62 echo "Copying ${SRCDIR} to ${DSTDIR}..."
63 find ${DIRS} -print | grep -v CVS | cpio -pmd ${DSTDIR}
64
65 if [ "$KEEP_MODULE_CONFIGS" = "true" ]; then
66         echo "Copying module dir configs..."
67         mkdir -p ${DSTDIR}/modules
68         head -9 ${SRCDIR}/modules/Kconfig > ${DSTDIR}/modules/Kconfig
69         sed -e ':b /\\$/{ ; N ; s/\\\n// ; bb ; }' ${SRCDIR}/modules/Makefile |\
70                 sed -e "s/^subdir-m.*$/subdir-m := /" \
71                 > ${DSTDIR}/modules/Makefile
72 fi
73
74 if [ "$KEEP_OCF_MODULES" = "true" ]; then
75         echo "Copying modules/ocf..."
76         find modules/ocf -print | grep -v CVS | cpio -pd ${DSTDIR}
77         find ${DSTDIR}/modules/ocf -name "*.o" | xargs rm -f
78         echo "source ocf/Kconfig" >> ${DSTDIR}/modules/Kconfig
79         cp ${DSTDIR}/modules/Makefile ${DSTDIR}/modules/Makefile.bak
80         sed -e "s/^subdir-m := /subdir-m := ocf /" \
81                 ${DSTDIR}/modules/Makefile.bak \
82                 > ${DSTDIR}/modules/Makefile
83         rm ${DSTDIR}/modules/Makefile.bak
84         cp ${SRCDIR}/prop/include/octeon-asm.h ${DSTDIR}/modules/ocf/cryptocteon/
85 else
86         cd ${DSTDIR}
87         find vendors -name "config.linux*" |
88         while read FILE
89         do
90                 cp ${FILE} ${FILE}.org
91                 sed -e "s/CONFIG_KLIPS_OCF=y/# CONFIG_KLIPS_OCF is not set/g" \
92                     ${FILE}.org > ${FILE}
93                 rm -f ${FILE}.org
94         done
95         sed -e 's/-I$(ROOTDIR)\/modules\/ocf//' \
96                 ${SRCDIR}/linux-2.4.x/net/ipsec/Makefile \
97                 > ${DSTDIR}/linux-2.4.x/net/ipsec/Makefile
98         sed -e "s/bool '   IPsec: OCF HW Acceleration support' CONFIG_KLIPS_OCF//" \
99                 ${SRCDIR}/openswan/linux/net/ipsec/Config.in.os2_4 \
100                 > ${DSTDIR}/openswan/linux/net/ipsec/Config.in.os2_4
101         cd ${SRCDIR}
102 fi
103
104 if [ "$KEEP_IXP_MODULES" = "true" ]; then
105         echo "Copying modules/ixp425..."
106         find modules/ixp425 -print | grep -v CVS | cpio -pd ${DSTDIR}
107         find ${DSTDIR}/modules/ixp425 -name "*.o" | grep -v dsr.o | xargs rm -f
108         echo "source ixp425/Kconfig" >> ${DSTDIR}/modules/Kconfig
109         cp ${DSTDIR}/modules/Makefile ${DSTDIR}/modules/Makefile.bak
110         sed -e "s/^subdir-m := /subdir-m := ixp425 /" \
111                 ${DSTDIR}/modules/Makefile.bak \
112                 > ${DSTDIR}/modules/Makefile
113         rm ${DSTDIR}/modules/Makefile.bak
114 fi
115
116 if [ "$KEEP_PROP" != "true" ]; then
117         cp ${DSTDIR}/config/Kconfig /tmp/
118         grep -v prop /tmp/Kconfig > ${DSTDIR}/config/Kconfig
119         cp ${DSTDIR}/config/Makefile /tmp/
120         sed -e "s/\.\.\/prop\/Kconfig\.auto//g" < /tmp/Makefile |
121                 sed -e "s/\.\.\/prop\/Makefile\.auto//g" \
122                 > ${DSTDIR}/config/Makefile
123 fi
124
125
126 if [ "$KEEP_BOOT" != "true" ]; then
127         cp ${DSTDIR}/config/Kconfig /tmp/
128         grep -v boot /tmp/Kconfig > ${DSTDIR}/config/Kconfig
129         cp ${DSTDIR}/config/Makefile /tmp/
130         sed -e "s/\.\.\/boot\/Kconfig\.auto//g" < /tmp/Makefile |
131                 sed -e "s/\.\.\/boot\/Makefile\.auto//g" \
132                 > ${DSTDIR}/config/Makefile
133 fi
134
135 #
136 #       Remove all binaries, top level clean...
137 #
138 echo "Removing objects from ${DSTDIR}..."
139 cd ${DSTDIR}
140 make dep 2>&1 | cat > /tmp/dep
141 echo "making clean ..."
142 make distclean 2>&1 | cat > /tmp/clean
143 make -C linux-2.4.x distclean 2> /dev/null > /dev/null
144 make -C linux-3.x distclean 2> /dev/null > /dev/null
145 make -C config/scripts clean 2> /dev/null > /dev/null
146 make -C config/scripts/lxdialog clean 2> /dev/null > /dev/null
147 find linux-3.x -name ".*.cmd" | xargs rm -f
148 rm -f linux-3.x/scripts/kconfig/*.o
149 rm -f linux-3.x/scripts/kconfig/lex.zconf.c
150 rm -f linux-3.x/scripts/kconfig/zconf.hash.c
151 rm -f linux-3.x/scripts/kconfig/zconf.tab.c
152 rm -f linux-3.x/scripts/kconfig/conf
153 rm -f linux-3.x/scripts/basic/fixdep
154 rm -f linux-3.x/scripts/basic/docproc
155 rm -f linux-3.x/scripts/basic/hash
156 rm -rf linux-3.x/include/config
157 rm -f linux-2.4.x/include/asm-armnommu/arch
158 rm -f linux-2.4.x/include/asm-armnommu/proc
159 rm -f uClibc/extra/config/*.o
160 cd ..
161
162
163 #
164 #       Remove mention of some vendors from configs...
165 #
166 echo "removing vendors..."
167 rm -rf ${DSTDIR}/vendors/ATT
168
169
170 #
171 #       Remove other miscellaneous stuff...
172 #
173 echo "Cleaning out miscellaneous other stuff..."
174 cd ${DSTDIR}
175 find . -name errs -print | xargs rm -f
176 find . -name .depend -print | xargs rm -f
177 find . -name .depend.embed -print | xargs rm -f
178 find . -name .version -print | xargs rm -f
179 find . -name .svn -print | xargs rm -rf
180 find user/iptables -name "*.d" | xargs rm -f
181 rm -f linux-2.?.x/.config*
182 rm -f linux-2.?.x/include/linux/autoconf.h
183 rm -f linux-2.?.x/include/asm
184 rm -f linux-2.?.x/include/asm-arm/arch
185 rm -f linux-2.?.x/include/asm-arm/proc
186 rm -f .config config.arch
187 rm -f config/autoconf.h config/.config config/.config.old
188 rm -rf vendors/.config vendors/.config.old
189 rm -rf vendors/Hitachi/dsp
190 rm -f user/iptables/.makefirst
191 rm -f images/*
192 rm -rf romfs
193 rm -rf tools/c++ tools/gcc-* tools/misc/gcc-include
194 rm -f tools/misc/pivio*
195 rm -f tools/misc/nap5272.gdb
196 rm -f tools/misc/*.hdc
197 rm -rf tools/misc/mips/sg590.majic
198 rm -f lib/uClibc
199 rm -f uClibc/.config*
200 rm -f uClibc/extra/config/conf uClibc/extra/config/zconf.tab.[ch]
201 rm -f uClibc/extra/config/lex.zconf.c uClibc/extra/config/lkc_defs.h
202 rm -rf uClibc/include/bits
203 rm -f uClibc/include/fpu_control.h uClibc/include/net/bpf.h
204
205 if [ "$KEEP_MODULE_CONFIGS" != "true" ]; then
206         find vendors -name config.modules | xargs rm -f
207 fi
208
209 if [ "$KEEP_IXP_MODULES" != "true" ]; then
210         cd ${DSTDIR};
211         find vendors -name "config.linux-2.4.x" |
212         while read FILE
213         do
214                 cp ${FILE} ${FILE}.org
215                 sed -e "s/CONFIG_IXP4XX_CRYPTO=y/# CONFIG_IXP4XX_CRYPTO is not set/g" \
216                     ${FILE}.org > ${FILE}
217                 rm -f ${FILE}.org
218         done
219 fi
220
221
222 #
223 #       Remove private vendor names from config files.
224 #
225 cd ${DSTDIR}
226 find vendors -name "config.device*" |
227 while read FILE
228 do
229         grep -v "CONFIG_DEFAULTS_ADTRAN_" ${SRCDIR}/${FILE} | \
230             grep -v "CONFIG_DEFAULTS_ATT_" | \
231             grep -v "CONFIG_DEFAULTS_MARCONI_" | \
232             grep -v "CONFIG_DEFAULTS_GILBARCO_" \
233             > ${DSTDIR}/${FILE}
234 done
235
236
237 #
238 #       Change some permissions, so they look nice.
239 #
240 chmod 775 ${DSTDIR}/bin/*
241
242 #
243 #       Fix up some autogen files so they don't get rebuilt.
244 #
245 touch ${DSTDIR}/user/mawk/array.[ch]
246
247 echo "Packaging ${DSTDIR}..."
248 cd ${CURPWD}
249 tar cf ${PACKAGE}.tar ${NAME}
250 echo "gziping ${PACKAGE}.tar..."
251 bzip2 -9 -k ${PACKAGE}.tar
252 gzip -9 ${PACKAGE}.tar
253
254 mv ${PACKAGE}.tar.gz ${PACKAGE}.tar.bz2 ${PKGDIR}
255
256 exit 0