add script to update make rules

Tue, 07 Nov 2023 20:24:08 +0100

author
Mike Becker <universe@uap-core.de>
date
Tue, 07 Nov 2023 20:24:08 +0100
changeset 8
756b49205a29
parent 7
9dd76cbd6c90
child 9
6ad1a4213954

add script to update make rules

Makefile file | annotate | diff | comparison | revisions
make/update-rules.sh file | annotate | diff | comparison | revisions
--- a/Makefile	Wed Nov 01 21:00:33 2023 +0100
+++ b/Makefile	Tue Nov 07 20:24:08 2023 +0100
@@ -47,5 +47,9 @@
 	@echo "create config"
 	@./configure
 
+update-rules:
+	make/update-rules.sh src
+	CFLAGS=-I../src make/update-rules.sh test
+
 FORCE:
 
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/make/update-rules.sh	Tue Nov 07 20:24:08 2023 +0100
@@ -0,0 +1,48 @@
+#!/bin/sh
+
+dir="$1"
+
+if [ -z "$dir" ]; then
+  echo "Usage: $0 <src_dir>"
+  exit 1
+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 "\$(BUILD_DIR)/${file/.c/.o}" -MM $CFLAGS "$file"
+  printf '\t@echo "Compiling $<"\n'
+  printf '\t$(CC) -o $@ $(CFLAGS) -c $<\n\n'
+done  >> Makefile
+rm Makefile.old

mercurial