X-Git-Url: http://nitlanguage.org diff --git a/src/mkcsrc b/src/mkcsrc index 7be3152..a408697 100755 --- a/src/mkcsrc +++ b/src/mkcsrc @@ -1,70 +1,23 @@ -#!/bin/sh -# This file is part of NIT ( http://www.nitlanguage.org ). -# -# Copyright 2008 Jean Privat -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -# NAME -# mkcsrc - generate a new c_src directory from a current nitc bootstrap -# SYNOPSIS -# ./mkcsrc [number] -# DESCRIPTION -# transform a bootstrap result (generated by the nc tool) into a new -# c_src in the current directory (previous one will be errased). -# One c_src generated, you can replace the old one in the root. -# Before commiting, do not forget to: -# * verify any regression -# * add/remove files in c_src -# OPTION -# number is the bootstrap level to use. It corresponds to the nc -# level. By default, the lastest generated nitc is used. - -# prefix -p=$1 - -if [ "x$p" = "x" ]; then - p=`ls .nit_compile*/nitc._build.sh -t | head -1 | sed 's!\.nit_compile\(.*\)/nitc\._build\.sh!\1!'` - if [ "x$p" = "x" ]; then - echo "No generated nitc" - exit 1 - fi - echo "Lastest generated nitc is bootstrap level $p" -fi - -rm -r c_src 2> /dev/null -mkdir c_src - -# Copy sources -sed -n '/^ /{s!\\$!!;p}' .nit_compile${p}/nitc._build.sh | while read -r file; do - [ -f $file ] || continue - cp $file c_src - [ -r ${file%.c}.h ] && cp ${file%.c}.h c_src - # Copy included files - sed -ne 's|^#include "\(.*\)".*|\1|p' $file | while read -r subfile; do - cp "$(dirname "$file")/$subfile" c_src - done +#!/bin/bash +cd .. +out=c_src +rm -r "$out/" 2> /dev/null +set -e +set -x +src/nitg src/nith.nit --semi-global -v "$@" --compile-dir "$out" -o "$out/nitg" --no-cc +cp "$out/nith.mk" "$out/Makefile" +sed -i -e "s#../$out/##g" "$out/Makefile" + +# Copy all direct dependencies +for f in `grep -h -o '[^ ]*/[^ /]*\.c' "$out/Makefile" | sort -u`; do + cp "$out/$f" "$out/" + cp "$out/${f%c}h" "$out/" +done +for f in `grep -h -o '\.\..*\.h' "$out"/*.[ch] | sort -u`; do + cp "$out/$f" "$out/" done -sed -i -e 's|include ".*/|include "|' c_src/*[ch] # Cleanup includes - -# Prepare the build script -cp .nit_compile${p}/nitc._build.sh c_src/nitc._build.sh -chmod +x c_src/nitc._build.sh -sed -i -e "s|^ [^$].*/| |g" c_src/nitc._build.sh # Cleanup file paths -sed -i -e "s|.nit_compile${p}|.|g" c_src/nitc._build.sh # Cleanup remaining work dirs -sed -i -e "s|nitc_${p}|nitc|" c_src/nitc._build.sh # Cleanup exec name -sed -i -e 's/^CLIBDIR=.*/CLIBDIR="clib"/' c_src/nitc._build.sh # Cleanup CLIB PATH - -# Copy remaining files -cp -r ../c_src/Makefile ../c_src/README ../clib c_src +# Update references in file +perl -i -npe 's#"\.\./.*?([^/]*.h)"#"\1"#' "$out"/*.[ch] +perl -i -npe 's#\S*/([^/]*.[ch])#\1#' "$out/Makefile" +perl -i -npe 's#\.\./clib#.#' "$out/Makefile"