make/update-rules.sh

Mon, 18 Nov 2024 22:05:42 +0100

author
Mike Becker <universe@uap-core.de>
date
Mon, 18 Nov 2024 22:05:42 +0100
changeset 988
15b3ca7ee33f
parent 766
e59b76889f00
permissions
-rwxr-xr-x

make ucx C++ compatible again (and add tests for it) - fixes #486

#!/bin/sh

dir="$1"
target="$2"
extra_flags="$3"

if [ -z "$dir" ]; then
  echo "Usage: $0 <src_dir>"
  exit 1
fi

if [ -z "$target" ]; then
  target='$(build_dir)'
fi

if [ -d "$dir" ]; then
  :
else
  echo "'$dir' is not a directory"
  exit 1
fi

if [ -z "$CC" ]; then
  for cc in gcc clang ; do
    if command -v "$cc" > /dev/null ; then
      CC="$cc"
      break
    fi
  done
fi

if [ -z "$CC" ]; then
  echo "No suitable compiler found to generate make rules"
  exit 1
fi

if command -v sed > /dev/null ; then
  :
else
  echo "You need the 'sed' program for this script to work."
  exit 1
fi

cd "$dir"

mv Makefile Makefile.old
sed '/FORCE:/q' Makefile.old > Makefile
echo >> Makefile
for file in `ls *.c` ; do
  "$CC" -MT "$target/${file/.c/\$(OBJ_EXT)}" -MM $CFLAGS $extra_flags "$file"
  printf '\t@echo "Compiling $<"\n'
  printf '\t$(CC) -o $@ $(CFLAGS) %s -c $<\n\n' "$extra_flags"
done  >> Makefile
rm Makefile.old

mercurial