new devel tool: mkcsrc
[nit.git] / src / mkcsrc
1 #!/bin/sh
2 # This file is part of NIT ( http://www.nitlanguage.org ).
3 #
4 # Copyright 2008 Jean Privat <jean@pryen.org>
5 #
6 # Licensed under the Apache License, Version 2.0 (the "License");
7 # you may not use this file except in compliance with the License.
8 # You may obtain a copy of the License at
9 #
10 #     http://www.apache.org/licenses/LICENSE-2.0
11 #
12 # Unless required by applicable law or agreed to in writing, software
13 # distributed under the License is distributed on an "AS IS" BASIS,
14 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 # See the License for the specific language governing permissions and
16 # limitations under the License.
17
18 # NAME
19 #       mkcsrc - generate a new c_src directory from a current nitc bootstrap
20 # SYNOPSIS
21 #       ./mkcsrc [number]
22 # DESCRIPTION
23 #       transform a bootstrap result (generated by the nc tool) into a new
24 #       c_src in the current directory (previous one will be errased).
25 #       One c_src generated, you can replace the old one in the root.
26 #       Before commiting, do not forget to:
27 #        * verify any regression
28 #        * add/remove files in c_src
29 # OPTION
30 #       number is the bootstrap level (prefix) to use. It correspond to the nc
31 #       level.  By default, the lastest generated nitc is used
32
33 # prefix
34 p=$1
35
36 if [ "x$p" = "x" ]; then
37         p=`ls .nit_compile/nitc*.sh -t | head -1 | sed 's!\.nit_compile/nitc\.\(.*\)_build\.sh!\1!'`
38         if [ "x$p" = "x" ]; then
39                 echo "No generated nitc"
40                 exit 1
41         fi
42         echo "Lastest generated nitc uses prefix $p"
43 fi
44
45 rm -r c_src 2> /dev/null
46 mkdir c_src
47
48 sed -n "s|.nit_compile/\\(.*\\).${p}_sep.c.*|\\1|p" .nit_compile/nitc.${p}_build.sh | while read -r file; do
49         echo "* $file"
50         sed "/include/s/.${p}_/._/" ".nit_compile/$file.${p}_sep.c" > c_src/${file}._sep.c
51         sed "/include/s/.${p}_/._/" ".nit_compile/$file.${p}_sep.h" > c_src/${file}._sep.h
52 done
53 sed "/include/s/.${p}_/._/" .nit_compile/nitc.${p}_tables.c > c_src/nitc._tables.c
54 sed "s|.nit_compile|.|g;s|../bin/../|../|g;s/.${p}_/._/g;s|nitc_${p}|nitc|" .nit_compile/nitc.${p}_build.sh > c_src/nitc._build.sh 
55 chmod +x c_src/nitc._build.sh
56 cp ../c_src/Makefile ../c_src/README c_src
57