summaryrefslogtreecommitdiff
path: root/mail/prom-mew/files/byte-compile
blob: bd9a3b7897e1cdf8b727b58fb449f74525fcd277 (plain) (blame)
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
#!/bin/sh

PREFIX=${PREFIX:-/usr/local}
WRKDIR=${WRKDIR:-`pwd`}

tmprfx=`basename $0`

Usage="\
byte_compile [options] emacs_name port_name [files]
	-l load_el	: load *.el file when byte-compile
	-h		: show this message
	emacs_name	: should be one of below
			  \"emacs\", \"emacs20\", \"mule\", \"xemacs19\", \"xemacs20\",
			  \"xemacs21\", \"xemacs-mule\"
	port_name	: port name(replaced port_name.el when files not specified)
	files		: *.el files should be compiled"

while [ -z "`getopts "l: h" opt > /tmp/${tmprfx}:getopt_err.log`" \
	-a X"${opt}" != "X?" ]; do
    case ${opt} in
	l)
	    load_el=${OPTARG}
	    break
	    ;;
	h)
	    echo "${Usage}"
	    exit 1
	    ;;
	*)
	    ;;
    esac
#    echo "opt=${opt},OPTARG=${OPTARG}"
done

if [ -s /tmp/${tmprfx}:getopt_err.log ]; then
    cat /tmp/${tmprfx}:getopt_err.log
    rm -f /tmp/${tmprfx}:getopt_err.log
    exit 1
fi
rm -f /tmp/${tmprfx}:getopt_err.log

shift `expr ${OPTIND} - 1`

if [ -z "$1" -o -z "$2" ]; then
    echo "${Usage}"
    exit 1
fi

emacs_name=$1
shift
port_name=$1

if [ $# -le 1 ]; then
    files=${port_name}.el
else
    files=`echo $* | sed -e "s/${port_name} *//"`
fi

#echo "emacs_name=${emacs_name}"
#echo "port_name=${port_name}"
#echo "files=${files}"
#echo "load_el=${load_el}"
#exit 1

case ${emacs_name} in
    emacs)
	elispdir=${PREFIX}/share/emacs/site-lisp
	load_path=${PREFIX}/share/emacs/site-lisp/${load_el}
	emacscmd=emacs
	;;
    emacs20)
	elispdir=${PREFIX}/share/emacs/site-lisp
	load_path=${PREFIX}/share/emacs/site-lisp/${load_el}
	emacscmd=emacs20
	;;
    mule)
	elispdir=${PREFIX}/share/mule/site-lisp
	load_path=${PREFIX}/share/mule/site-lisp/${load_el}
	emacscmd=mule
	;;
    xemacs19)
	elispdir=${PREFIX}/lib/xemacs/site-lisp
	load_path=${PREFIX}/lib/xemacs/site-lisp/${load_el}
	emacscmd=xemacs
	;;
    xemacs20)
	elispdir=${PREFIX}/lib/xemacs/site-lisp
	load_path=${PREFIX}/lib/xemacs/site-lisp/${load_el}
	emacscmd=xemacs
	;;
    xemacs21)
	elispdir=${PREFIX}/lib/xemacs/site-packages/lisp/${port_name}
	load_path=${PREFIX}/lib/xemacs/site-packages/lisp/${load_el}
	pkg_path=${PREFIX}/lib/xemacs/site-packages
	emacscmd=xemacs
	package_install=yes
	;;
    xemacs-mule)
	elispdir=${PREFIX}/lib/xemacs/site-packages/lisp/${port_name}
	load_path=${PREFIX}/lib/xemacs/site-packages/lisp/${load_el}
	pkg_path=${PREFIX}/lib/xemacs/site-packages
	emacscmd=xemacs
	package_install=yes
	;;
    *)
	echo "${Usage}"
	exit 1
	;;
esac
if [ -n "${load_el}" ]; then
    echo "(setq load-path (cons \"${load_path}\" load-path))" > /tmp/${tmprfx}:load.el
fi
for f in ${files}; do
    if [ -f ${WRKDIR}/${f} ]; then
	f_elc=`basename ${f} .el`.elc
	if [ -n "${load_el}" ]; then
	    ${emacscmd} -batch -l /tmp/${tmprfx}:load.el -q -no-site-file \
		-f batch-byte-compile ${WRKDIR}/${f}
	else
	    ${emacscmd} -batch -q -no-site-file -f batch-byte-compile ${WRKDIR}/${f}
	fi
	if [ X"${WRKDIR}" != "X${elispdir}" -a -d ${elispdir} ]; then
	    rm -f ${elispdir}/${f_elc}
	    ln -sf ${WRKDIR}/${f} ${elispdir}/${f}
	    install -c -m 444 -g bin -o bin ${WRKDIR}/${f_elc} ${elispdir}/${f_elc}
	    rm -f ${WRKDIR}/${f_elc}
	fi
	if [ $? -eq 0 -a -n "${package_install}" -a -d ${elispdir} ]; then
	    cp ${pkg_path}/pkginfo/MANIFEST.${port_name} /tmp/${tmprfx}:tempfile
	    grep -v "${f_elc}" /tmp/${tmprfx}:tempfile \
		> ${pkg_path}/pkginfo/MANIFEST.${port_name}
	    echo "lisp/${port_name}/${f_elc}" >> ${pkg_path}/pkginfo/MANIFEST.${port_name}
	fi
    else
	echo "\"${WRKDIR}/${f}\": file not found!"
    fi
done

rm -f /tmp/${tmprfx}:load.el /tmp/${tmprfx}:tempfile