File: autoproject.in

package info (click to toggle)
autoproject 0.20-11
  • links: PTS, VCS
  • area: main
  • in suites: bullseye, buster, sid
  • size: 924 kB
  • sloc: sh: 2,949; ansic: 1,677; cpp: 199; makefile: 59
file content (441 lines) | stat: -rwxr-xr-x 11,675 bytes parent folder | download | duplicates (5)
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
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
#!@bash@
# @configure_input@
#
# Script to start a programing project
#
# Jim Van Zandt <jrv@vanzandt.mv.com> 1999-06-09, based on dh_make by:
# Craig Small, <csmall@debian.org> 5 March 1998, based on deb-make by:
# Christoph Lameter, <clameter@debian.org> October 10, 1996

set -e
#set -v

prefix=@prefix@
DATADIR=@datadir@
AWK=awk
NAME=
EMAIL=
theoptions=a:d:e:i:l:n:o:p:vVh

# for testing: SKELETONS="/home/local/src/autoproject/lib"
SKELETONS="$HOME/.autoproject /etc/autoproject $DATADIR/autoproject"

# The version number for the new project is set in configure.in, and
# available in a C program as the #defined macro VERSION.
VERSION=0.1.0

# check what parsing facilities are available
if getopt -T; then 
    gnu_getopt=0;
else 
    if [ $? = 4 ]; then gnu_getopt=1; else gnu_getopt=0; fi
fi

if [ $gnu_getopt = 1 ]; then 

# Parse the autoproject options

    TEMP=`getopt -n autoproject -o L::$theoptions --longoptions author:,debug,description:,email:,interface:,language:,name:,option:,parser:,verbose,help,version -- "$@"`
    one=1; two=2;

    if [ $? != 0 ] ; then echo "Terminating..." >&2 ; exit 1 ; fi

    # Note the quotes around `$TEMP': they are essential!
    eval set -- "$TEMP"
else
    echo "WARNING - GNU getopt extensions not available, so autoproject's long options and optional arguments won't work"
    one=0; two=0;
fi

STDOPTS=" dry-run no-warn output brief quiet verbose directory cd interactive "
STDLANGS=" c sh c++ fortran lex yacc awk "
STDIFS=" cli "
STDPARSERS=" argp autogen clig none "

while 
    if [ $gnu_getopt = 1 ]; then 
	c=$1; OPTARG=$2; true; 
    else 
	getopts L:$theoptions c ; 
    fi; do

    case "$c" in
	a|-a|--author) AUTHOR="$OPTARG"; shift $two ;;
	D|-D|--debug)
	    DEBUGGING=yes; shift $one ;;
	d|-d|--description)
	    DESCRIPTION="$OPTARG"; shift $two ;;
	e|-e|--email) EMAIL="$OPTARG"; shift $two ;;
	i|-i|--interface)
	    if echo "$STDIFS"|grep -q -- " $OPTARG "; then
		IFACE="$OPTARG"; shift $two;
	    else
		echo "unrecognized interface $OPTARG";
		echo "the known interfaces are: $STDIFS";
		exit 1;
	    fi ;;
	L|-L)
	    if [ "$OPTARG" = "" ]; then 
		SKELETONS="";
	    else
		if (echo $OPTARG|grep ^/ >/dev/null); then true; \
		else OPTARG=`pwd`/$OPTARG; fi
		SKELETONS="$OPTARG $SKELETONS";
	    fi;
	    shift $two;;
	l|-l|--language)
	    if echo "$STDLANGS"|grep -F -q -- " $OPTARG "; then
		PROJECT_LANG="$PROJECT_LANG $OPTARG "; shift $two;
	    else
		echo "unrecognized language $OPTARG";
		echo "the known languages are: $STDLANGS";
		exit 1;
	    fi ;;
	n|-n|--name)
	    NAME=$OPTARG; shift $two ;;
	o|-o|--option)
	    if echo "$STDOPTS"|grep -q -- " $OPTARG "; then
		OPTS="$OPTS $OPTARG"; shift $two;
	    else
		echo "unrecognized option $OPTARG";
		echo "the known options are: $STDOPTS";
		exit 1;
	    fi ;;
	p|-p|--parser)
	    if echo "$STDPARSERS"|grep -q -- " $OPTARG "; then
		PARSER="$OPTARG"; shift $two;
	    else
		echo "unrecognized parser generator $OPTARG";
		echo "the known interfaces are: $STDPARSERS";
		exit 1;
	    fi ;;
	v|-v|--verbose) VERBOSE=yes; shift $one ;;
	V|-V|--version)
	    echo "autoproject @VERSION@"
	    exit 0
	    ;;
	\?|h|-h|--help)
	    cat <<EOF
autoproject - start a programming project
usage: autoproject  [options]  [program_name]
options:
-a, --author NAME       specify the author of the program
-e, --email ADDR        specify the email address of the author
-d, --description TEXT  supply the short description
--debug                 leave intermediate files
-i, --interface TYPE    specify the type of user interface
                        (currently only cli, for command line interface)
-l, --language LANG     add LANG to the list of languages used
                        (currently accepted: $STDLANGS)
-L[DIR]                 Prepend DIR to the list of directories to
                        search for skeleton files.  If LIB is missing,
                        then the path is cleared.  
                        (default path: $SKELETONS)
-n, --name NAME         specify the name of the program
-o, --option OPT        add OPT to the list of long options accepted by 
                        the program, from among these: 
                       $STDOPTS
-p, --parser PARSER     specify the command line parser generator
                        (currently supported: $STDPARSERS)
-v, --verbose           display more information
-h, --help              display this help
-V, --version           display autoproject name and version
EOF
	    exit 0
	    ;;
	--) shift $one ; break ;;
	*) echo "Internal error!  no case for option \"$c\"" ; exit 1 ;;
    esac
done
if [ $gnu_getopt != 1 ]; then shift `expr $OPTIND - 1`; fi

# Prompt user to select from a list
choose_from_list(){
QUERY=$1; CHOICES=$2; DEFAULT=$3; HELP=$4;
finished=no
while [ $finished != yes ]; do
    echo "$QUERY";
    echo -n "    select from: $CHOICES [$DEFAULT]: "; read ans;
    if [ "$ans" = "" ]; then ans="$DEFAULT"; fi
    if [ "$ans" = "?" ]; then 
	if [ "$HELP" = "" ]; then
	    echo "    sorry, no help is available"
	else
	    echo "$HELP";
	fi
    else if echo "$CHOICES" | grep -q -- " $ans "; then
	finished=yes;
    else echo "    unrecognized choice $ans"; fi; fi
done
}

# prompt user for a string
type_string() {
    QUERY=$1; DEFAULT=$2; HELP=$3;
    finished=no
    while [ $finished != yes ]; do
	echo -n "$QUERY [$DEFAULT]: "; read ans;
	if [ "$ans" = "" ]; then ans="$DEFAULT"; fi
	if [ "$ans" = "?" ]; then
	    if [ "$HELP" = "" ]; then
		echo "sorry, no help is available"
	    else
		echo "$HELP";
	    fi
	else 
	    finished=yes;
	fi
    done
}

# Get all the values we need

LEGALNAME=no
if [ "$NAME" = "" ];  then
    if [ "$1" != "" ]; then
	NAME="$1"
    fi
fi
while [ $LEGALNAME = no ]; do
    if [ "$NAME" = "" ]; then
	echo -n "What is the program name? "; read NAME;
    fi
    if expr "$NAME" : '[a-z][_a-z0-9]*$' >/dev/null = 0; then
	echo "    Illegal program name $NAME. Must be lowercase letters and digits or \`_'."
	NAME=""
    else
	LEGALNAME=yes
    fi
done
CAPNAME=`echo "$NAME"|tr '[a-z]' '[A-Z]'`

if [ "$DESCRIPTION" = "" ]; then
    echo ""
    echo "Please describe in one line what $NAME will do:"
    read DESCRIPTION
fi

DESCRIPTION=`echo $DESCRIPTION | sed 's,/,\\\\/,g'`
DESCRIPTIONC=`echo $DESCRIPTION | sed 's,",\\\\\\\\",g'`

if [ "$PROJECT_LANG" = "" ]; then 
    choose_from_list "The main program will be written in what language?" \
	"$STDLANGS" "c" ""
    PROJECT_LANG=" $ans "; 

    until
	choose_from_list "What other languages will be used in the package?" \
	    "$STDLANGS none " "none" ""
	[ "$ans" = "none" ]; do
	PROJECT_LANG="$PROJECT_LANG $ans "; 
    done
fi

PRIMARY_LANG=`echo $PROJECT_LANG | $AWK '{print $1}'`

if [ "$IFACE" = "" ]; then 
# this section will be enabled only after a GUI is supported
#    choose_from_list "What type of interface will the program use?" \
#	 "$STDIFS" "cli" \
#	 "cli = command line interface"
#    IFACE="$ans"; 
    IFACE=cli;
fi

if [ "$PARSER" = "" ]; then
    choose_from_list "What command line parser generator will be used?" \
	"$STDPARSERS" "none" ""
    PARSER="$ans";
fi	


echo "Please indicate which of the following standard options $NAME will use:"
for op in $STDOPTS; do
    if echo " $OPTS "|grep -q -- " $op "; then
	true;
    else
	echo -n "    $op? [yN] "; read ans;
	if [ "$ans" = "y" -o "$ans" = "Y" ]; then
	    OPTS="$OPTS $op";
	fi
    fi
done

# accept zero padding only if the GNU extension is not available
if [ `date +%-d` = %-d ]; then 
    # prevent user's locale settings from affecting %B
    DATE=`LC_ALL=POSIX date "+%B %d, %Y"`
else
    DATE=`LC_ALL=POSIX date "+%B %-d, %Y"`
fi
YEAR=`date "+%Y"`
ISODATE=`date "+%Y-%m-%d"`


if [ "$AUTHOR" = "" ]; then
    AUTHOR=`$AWK -F: -vUSER=$USER '$1 == USER { print $5; }' /etc/passwd`

    if [ "$AUTHOR" = "" -a -x /usr/bin/ypmatch ]; then
	# Give NIS a try
	AUTHOR=`ypmatch $USER passwd.byname|$AWK -F: '{ print $5; }'`
    fi
    if echo $AUTHOR | grep -q -- "\,"; then
    	X=`expr index "$AUTHOR" ","`
   	X=`expr $X - 1` || true
   	AUTHOR=`expr substr "$AUTHOR" 1 $X` || true
    fi
    type_string "What is the name of the author?" "$AUTHOR" ""
    AUTHOR="$ans"
fi


if [ "$EMAIL" = "" ]; then
    if [ -s /etc/mailname ]; then
	EMAIL="$USER@`cat /etc/mailname`"
	else if [ -s /etc/news/whoami ]; then
	    EMAIL="$USER@`cat /etc/news/whoami`"
	else EMAIL="`whoami`@`hostname`"
	fi
    fi
    type_string "What is the email address of the author?" "$EMAIL" ""
    EMAIL="$ans"
fi
# `@' must be escaped in a .texinfo file
EEMAIL=`echo $EMAIL|sed s/@/@@/`


echo "Program Name		: $NAME"
echo "Description	        : $DESCRIPTION"
echo "Version			: $VERSION"
echo "Language		:$PROJECT_LANG"
echo "Interface		: $IFACE"
echo "Parser Generator	: $PARSER"
echo "Long Options		:$OPTS"
echo "Author      		: $AUTHOR"
echo "Email-Address		: $EMAIL"
echo "Date		        : $DATE"



# Create the source directory
mkdir "$NAME"
cd "$NAME"


# Create a small awk script to select the appropriate options fragments

for op in $STDOPTS; do
    if echo " $OPTS " | grep -q -- " $op " ; then
	# lines like "@item --output=@var{name}" are not special
	cat >>optionsub <<EOF
/^@$op@\$/,/^@@\$/{if(\$0~/^@.*@\$/)next}
EOF
    else
	cat >>optionsub <<EOF
/^@$op@\$/,/^@@\$/{next}
EOF
    fi
done
cat >>optionsub <<EOF
{print}
EOF

# Customize files

process_file()
{
	sed -e "s/#NAME#/$NAME/g"			\
		-e "s/#CAPNAME#/$CAPNAME/g"		\
		-e "s/#VERSION#/$VERSION/g"		\
		-e "s/#EMAIL#/$EMAIL/g"			\
		-e "s/#EEMAIL#/$EEMAIL/g"		\
		-e "s/#DATE#/$DATE/g"			\
		-e "s/#ISODATE#/$ISODATE/g"		\
		-e "s/#YEAR#/$YEAR/g"			\
		-e "s/#AUTHOR#/$AUTHOR/g"		\
		-e "s/#DESCRIPTION#/$DESCRIPTION/g"	\
		-e "s/#DESCRIPTIONC#/$DESCRIPTIONC/g"
}

PROCESSED=0
for LIB in $SKELETONS; do
    if [ "$VERBOSE" = "yes" ]; then
	echo "looking for skeletons in: $LIB"
    fi
    for IF in $IFACE all; do
	for L in $PRIMARY_LANG all; do
	    for P in $PARSER all; do
    		DIR=$LIB/$IF/$L/$P
    		if [ -d $DIR ]; then
    		    X=`(cd $DIR;ls)`
    		    for i in $X; do
    			if [ ! -f $i ]; then
    			    if [ "$VERBOSE" = "yes" ]; then
    				echo "  processing: $DIR/$i"
    			    fi
    			    process_file <$DIR/$i |$AWK -f optionsub >$i
			    if [ -x $DIR/$i ]; then chmod +x $i; fi
			    PROCESSED=`awk "BEGIN{print $PROCESSED+1}"`
    			fi
    		    done
    		fi
	    done
	done
    done
done

echo "$PROCESSED files processed"
if [ ! -f configure.in ]; then
    echo "configure.in not found - either skeleton library was not found, 
or requested combination of options is not available"
fi

if [ "$DEBUGGING" = "yes" ]; then true; else rm optionsub; fi

# rename some files
X="`ls program* 2>/dev/null`"
if [ "$X" ]; then
    for i in $X; do
	mv $i `echo $i|sed -e "s/^program/$NAME/"`
    done
fi

# insert language-specific macros into configure.in
insert(){
if echo "$PROJECT_LANG"|grep -F -q -- " $1 "; then
    echo "using $1 - adding $2 to configure.in"
    $AWK "{print}/^AC_PROG_CC/{print \"$2\"}" \
	configure.in >tmp && mv tmp configure.in
fi
}

insert c++ AC_PROG_CXX
insert fortran AC_PROG_F77
insert fortran AC_F77_LIBRARY_LDFLAGS
insert yacc AC_PROG_YACC
insert lex AM_PROG_LEX
insert awk AC_PROG_AWK

# ensure .def file is newer than the skeleton man page
if [ -f checkopt.def ]; then
    if [ "$VERBOSE" = "yes" ]; then
	echo touching checkopt.def
    fi
    sleep 1; 
    touch checkopt.def; 
    mv checkopt.def $NAME-opt.def
    sed "s,checkopt,$NAME-opt,g" Makefile.am > Makefile.tmp
    mv -f Makefile.tmp Makefile.am
fi

if [ -x postinst ]; then
    ./postinst && rm postinst
fi

aclocal
autoheader
automake --add-missing
autoconf
./configure

exit 0