add update-rules script

Thu, 23 Nov 2023 23:33:09 +0100

author
Mike Becker <universe@uap-core.de>
date
Thu, 23 Nov 2023 23:33:09 +0100
changeset 755
255ee4abf2ec
parent 754
4bc7d966c9db
child 756
0b635553b86a

add update-rules script

Makefile file | annotate | diff | comparison | revisions
make/update-rules.sh file | annotate | diff | comparison | revisions
src/Makefile file | annotate | diff | comparison | revisions
--- a/Makefile	Wed Oct 18 21:07:02 2023 +0200
+++ b/Makefile	Thu Nov 23 23:33:09 2023 +0100
@@ -57,7 +57,7 @@
 	@cd src && $(MAKE) static
 
 check: test-compile FORCE
-	$(build_dir)/tests/ucxtest
+	test "$(WITH_TESTS)" = "yes" && $(build_dir)/tests/ucxtest
 
 test-compile:
 	@(test "$(WITH_TESTS)" = "yes" && cd tests && $(MAKE)) \
@@ -69,4 +69,7 @@
 	@(test "$(WITH_DOCS_HTML)" = "yes" && cd docs && $(MAKE) all-html) \
 		|| echo "[ Generation of HTML Docs disabled - skipped ]"
 
+update-rules:
+	make/update-rules.sh src
+
 FORCE:
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/make/update-rules.sh	Thu Nov 23 23:33:09 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/\$(OBJ_EXT)}" -MM $CFLAGS "$file"
+  printf '\t@echo "Compiling $<"\n'
+  printf '\t$(CC) -o $@ $(CFLAGS) -c $<\n\n'
+done  >> Makefile
+rm Makefile.old
--- a/src/Makefile	Wed Oct 18 21:07:02 2023 +0200
+++ b/src/Makefile	Thu Nov 23 23:33:09 2023 +0100
@@ -49,65 +49,72 @@
 	$(SYMLINK) $(libdir)/libucx$(SHLIB_EXT).$(LIBVERSION) $(libdir)/libucx$(SHLIB_EXT).$(LIBVERSION_MAJOR)
 	$(SYMLINK) $(libdir)/libucx$(SHLIB_EXT).$(LIBVERSION_MAJOR) $(libdir)/libucx$(SHLIB_EXT)
 
+FORCE:
+
 $(build_dir)/allocator$(OBJ_EXT): allocator.c cx/allocator.h cx/common.h
-	echo "Compiling $<"
+	@echo "Compiling $<"
 	$(CC) -o $@ $(CFLAGS) -c $<
 
 $(build_dir)/array_list$(OBJ_EXT): array_list.c cx/array_list.h cx/list.h \
  cx/common.h cx/collection.h cx/allocator.h cx/iterator.h
-	echo "Compiling $<"
+	@echo "Compiling $<"
 	$(CC) -o $@ $(CFLAGS) -c $<
 
-$(build_dir)/buffer$(OBJ_EXT): buffer.c cx/buffer.h cx/common.h cx/allocator.h \
- cx/utils.h
-	echo "Compiling $<"
+$(build_dir)/buffer$(OBJ_EXT): buffer.c cx/buffer.h cx/common.h \
+ cx/allocator.h cx/utils.h
+	@echo "Compiling $<"
 	$(CC) -o $@ $(CFLAGS) -c $<
 
 $(build_dir)/compare$(OBJ_EXT): compare.c cx/compare.h cx/common.h
-	echo "Compiling $<"
+	@echo "Compiling $<"
 	$(CC) -o $@ $(CFLAGS) -c $<
 
 $(build_dir)/hash_key$(OBJ_EXT): hash_key.c cx/hash_key.h cx/common.h
-	echo "Compiling $<"
+	@echo "Compiling $<"
 	$(CC) -o $@ $(CFLAGS) -c $<
 
-$(build_dir)/hash_map$(OBJ_EXT): hash_map.c cx/hash_map.h cx/map.h cx/common.h \
- cx/collection.h cx/allocator.h cx/iterator.h cx/string.h cx/hash_key.h \
- cx/utils.h
-	echo "Compiling $<"
+$(build_dir)/hash_map$(OBJ_EXT): hash_map.c cx/hash_map.h cx/map.h \
+ cx/common.h cx/collection.h cx/allocator.h cx/iterator.h cx/string.h \
+ cx/hash_key.h cx/utils.h
+	@echo "Compiling $<"
 	$(CC) -o $@ $(CFLAGS) -c $<
 
-$(build_dir)/linked_list$(OBJ_EXT): linked_list.c cx/linked_list.h cx/common.h \
- cx/list.h cx/collection.h cx/allocator.h cx/iterator.h cx/utils.h
-	echo "Compiling $<"
+$(build_dir)/linked_list$(OBJ_EXT): linked_list.c cx/linked_list.h \
+ cx/common.h cx/list.h cx/collection.h cx/allocator.h cx/iterator.h \
+ cx/utils.h
+	@echo "Compiling $<"
 	$(CC) -o $@ $(CFLAGS) -c $<
 
 $(build_dir)/list$(OBJ_EXT): list.c cx/list.h cx/common.h cx/collection.h \
  cx/allocator.h cx/iterator.h
-	echo "Compiling $<"
+	@echo "Compiling $<"
 	$(CC) -o $@ $(CFLAGS) -c $<
 
 $(build_dir)/map$(OBJ_EXT): map.c cx/map.h cx/common.h cx/collection.h \
  cx/allocator.h cx/iterator.h cx/string.h cx/hash_key.h
-	echo "Compiling $<"
+	@echo "Compiling $<"
 	$(CC) -o $@ $(CFLAGS) -c $<
 
-$(build_dir)/mempool$(OBJ_EXT): mempool.c cx/mempool.h cx/common.h cx/allocator.h \
- cx/utils.h
-	echo "Compiling $<"
+$(build_dir)/mempool$(OBJ_EXT): mempool.c cx/mempool.h cx/common.h \
+ cx/allocator.h cx/utils.h
+	@echo "Compiling $<"
 	$(CC) -o $@ $(CFLAGS) -c $<
 
-$(build_dir)/printf$(OBJ_EXT): printf.c cx/printf.h cx/common.h cx/string.h \
- cx/allocator.h
-	echo "Compiling $<"
+$(build_dir)/printf$(OBJ_EXT): printf.c cx/printf.h cx/common.h \
+ cx/string.h cx/allocator.h
+	@echo "Compiling $<"
 	$(CC) -o $@ $(CFLAGS) -c $<
 
-$(build_dir)/string$(OBJ_EXT): string.c cx/string.h cx/common.h cx/allocator.h \
- cx/utils.h
-	echo "Compiling $<"
+$(build_dir)/string$(OBJ_EXT): string.c cx/string.h cx/common.h \
+ cx/allocator.h cx/utils.h
+	@echo "Compiling $<"
+	$(CC) -o $@ $(CFLAGS) -c $<
+
+$(build_dir)/szmul$(OBJ_EXT): szmul.c
+	@echo "Compiling $<"
 	$(CC) -o $@ $(CFLAGS) -c $<
 
 $(build_dir)/utils$(OBJ_EXT): utils.c cx/utils.h cx/common.h
-	echo "Compiling $<"
+	@echo "Compiling $<"
 	$(CC) -o $@ $(CFLAGS) -c $<
 

mercurial