Add local_syms script. Nice for cleaning the kernel namespace.
[dragonfly.git] / tools / tools / upgrade / move_aout_libs.sh
1 #!/bin/sh
2 #
3 # $FreeBSD: src/tools/tools/upgrade/move_aout_libs.sh,v 1.6 1999/08/28 00:54:34 peter Exp $
4 # $DragonFly: src/tools/tools/upgrade/Attic/move_aout_libs.sh,v 1.2 2003/06/17 04:29:11 dillon Exp $
5
6 # Search for a.out libraries and move them to an aout subdirectory of
7 # the elf library directory.
8 #
9 # The arguments are the directories to search.
10 #
11 libdirs="$*"
12
13 # Create a temporary tool to get the timestamp of libraries. No, I don't
14 # want to use perl or whatever.
15 create_get_time_stamp ( )
16 {
17         echo "#include <stdio.h>" > /tmp/get_time_stamp.c
18         echo "#include <sys/stat.h>" >> /tmp/get_time_stamp.c
19         echo "int main(int argc, char *argv[]) {" >> /tmp/get_time_stamp.c
20         echo "int ierr; struct stat fs;" >> /tmp/get_time_stamp.c
21         echo "if ((ierr = stat(argv[1],&fs)) == 0)" >> /tmp/get_time_stamp.c
22         echo "printf(\"%ld\n\",(long) fs.st_mtime);" >> /tmp/get_time_stamp.c
23         echo "return (ierr); }" >> /tmp/get_time_stamp.c
24         gcc -o /tmp/get_time_stamp /tmp/get_time_stamp.c
25         rm /tmp/get_time_stamp.c
26         return
27 }
28
29 # Move an a.out library to the aout subdirectory of the elf directory.
30 move_file ( ) 
31 {
32         if test -d $dir/aout; then
33         else
34                 echo "Creating directory $dir/aout"
35                 mkdir $dir/aout
36                 ldconfig -m $dir/aout
37         fi
38         fname=${file#$dir/}
39         if test -f $dir/aout/$fname; then
40                 if test -x /tmp/get_time_stamp; then
41                 else
42                         create_get_time_stamp
43                 fi
44                 t1=`/tmp/get_time_stamp $dir/aout/$fname`
45                 t2=`/tmp/get_time_stamp $file`
46                 if test $t1 -gt $t2; then
47                         echo $file is older than $dir/aout/$fname
48                         answer=""
49                         while test "$answer" != "y" -a "$answer" != "n"; do
50                                 read -p "OK to delete the older file? (y/n) " answer
51                         done
52                         if test $answer = "y"; then
53                                 echo Deleting $file
54                                 chflags noschg $file
55                                 rm $file
56                         else
57                                 echo "You need to move $file out of $dir because that's an elf directory"
58                         fi
59                 else
60                         echo $dir/aout/$fname is older than $file
61                         answer=""
62                         while test "$answer" != "y" -a "$answer" != "n"; do
63                                 read -p "OK to overwrite the older file? (y/n) " answer
64                         done
65                         if test $answer = "y"; then
66                                 echo Overwriting $dir/aout/$fname with $file
67                                 chflags noschg $file
68                                 mv $file $dir/aout/$fname
69                                 ldconfig -R
70                         else
71                                 echo "You need to move $file out of $dir because that's an elf directory"
72                         fi
73                 fi
74         else
75                 echo Move $fname from $dir to $dir/aout
76                 chflags noschg $file
77                 mv $file $dir/aout/$fname
78                 ldconfig -R
79         fi
80         return
81 }
82
83 # Given a list of files in a directory, find those that are a.out
84 # libraries and move them.
85 move_if_aout ( ) 
86 {
87         # Check each library
88         for file in $files
89         do
90                 # Don't touch symbolic links yet. It's not clear how
91                 # they should be handled.
92                 if test -h $file; then
93                 else
94                         # Check that this is a normal file.
95                         if test -f $file; then
96                                 # Identify the file by magic
97                                 filemagic=`file $file`
98
99                                 # Check if the file is an a.out library
100                                 if expr "$filemagic" : ".*$aoutmagic"; then
101                                         # Move the a.out library
102                                         move_file
103                                 fi
104                         fi
105                 fi
106         done
107         return
108 }
109
110 # Only search the directories specified.
111 for dir in $libdirs
112 do
113         # Make sure the directory exists, or ldconfig will choke later.
114         mkdir -p $dir $dir/aout
115
116         echo "Searching library directory $dir for a.out libraries..."
117
118         # Get a list of archive libraries.
119         files=`ls $dir/*.a 2> /dev/null`
120
121         # a.out archive libraries look like this:
122         aoutmagic="current ar archive random library"
123
124         # Move each a.out archive library:
125         move_if_aout
126
127         # Get a list of shared libraries
128         files=`ls $dir/*.so.*.* 2> /dev/null`
129
130         # a.out shared libraries look like this:
131         aoutmagic="FreeBSD/i386 compact demand paged shared library"
132
133         # Move each a.out shared library:
134         move_if_aout
135 done
136
137 # If we created the time stamp program, delete it:
138 if test -x /tmp/get_time_stamp; then
139         rm /tmp/get_time_stamp
140 fi