Update "missing" (automake) script to a later version
[geda-pcb/pcjc2.git] / lib / CreateLibraryContents.sh.in
blob8f38224f8ba2b291950184768bdb0de003533045
1 #!/bin/sh
3 # COPYRIGHT
4 #
5 # PCB, interactive printed circuit board design
6 # Copyright (C) 1994,1995,1996 Thomas Nau
7 #
8 # This program is free software; you can redistribute it and/or modify
9 # it under the terms of the GNU General Public License as published by
10 # the Free Software Foundation; either version 2 of the License, or
11 # (at your option) any later version.
13 # This program is distributed in the hope that it will be useful,
14 # but WITHOUT ANY WARRANTY; without even the implied warranty of
15 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 # GNU General Public License for more details.
18 # You should have received a copy of the GNU General Public License
19 # along with this program; if not, write to the Free Software
20 # Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
22 # Contact addresses for paper mail and Email:
23 # Thomas Nau, Schlehenweg 15, 88471 Baustetten, Germany
24 # Thomas.Nau@rz.uni-ulm.de
27 # create all objects as defined in passed list_files
29 # usage: CreateLibraryContents.sh common_macro_file file...
31 M4=@GNUM4@
34 # Check for input flags
37 while test -n "$1" ; do
38 case "$1"
40 -I|--include)
41 m4_flags="$m4_flags -I $2"
42 srcdir=$2
43 shift 2
46 -*)
47 echo "error: unknown flag $1 to $0"
48 exit 1
52 break
54 esac
55 done
57 # a TAB plus one blank for some stupid old sed implementations
59 SPACE="[ ]"
62 # Make sure we've been given a common file plus at least 1 list file
63 # as arguments
66 if [ $# -lt 2 ]; then
67 echo "usage: $0 common_macro_file file..." >&2; exit 1
69 CommonFile=$1
70 shift
73 # Make sure the common file exists
76 if [ ! -r $CommonFile ]; then
77 echo "$0: file '$CommonFile' isn't readable or doesn't exit" >&2; exit 1
81 # Process the list files
84 while [ $# -ne 0 ]; do
85 # strip the extension '.list'
89 # Turn something like foo.list in to
90 # /path/to/foo.m4
92 if [ -f $srcdir/$1 ]; then
93 ListFile="$srcdir/$1"
94 else
95 ListFile="$1"
97 PlainFile=`dirname $ListFile`/`basename $ListFile .list`
98 M4File=$PlainFile.m4
100 if [ ! -r $ListFile ]; then
101 echo "$0: file '$ListFile' isn't readable or doesn't exit" >&2; exit 1
103 if [ ! -r $M4File ]; then
104 echo "$0: file '$M4File' isn't readable or doesn't exit" >&2; exit 1
108 # for foo.list spit out "TYPE=~foo". This defines the library
109 # in the PCB library window
111 echo "TYPE=~`basename $PlainFile | sed -e 's/_/ /g'`"
113 sed -e 's/'"$SPACE"'*#.*$//' \
114 -e 's/'"$SPACE"'*:'"$SPACE"'*/:/g' \
115 -e '/^'"$SPACE"'*$/d' $ListFile |
117 IFS=:
118 export IFS
119 while read mask package values; do
120 set -- $values
121 while [ $# -ne 0 ]; do
122 echo "\`$mask:$package:$1:'Description_$mask\` [$package'ifdef(\`Param1_$mask', \` Param1_$mask')\`'ifdef(\`Param2_$mask', \` Param2_$mask')]"
123 shift
124 done
125 done
126 } | $M4 $m4_flags $CommonFile $M4File - | sed -e '/^'"$SPACE"'*$/d'
127 shift
128 done