remove perl script from makefile
authorLaurent MAZET <laurent.mazet@thalesgroup.com>
Wed, 9 Oct 2024 09:36:15 +0000 (11:36 +0200)
committerLaurent MAZET <laurent.mazet@thalesgroup.com>
Wed, 9 Oct 2024 09:36:15 +0000 (11:36 +0200)
bf.c
getcomments.pl [deleted file]
makefile

diff --git a/bf.c b/bf.c
index 552c5b0bc30dd992a67495446bf7b3d51d8c33f7..be1622023d6bb63c6af416adf6be055156e339d6 100644 (file)
--- a/bf.c
+++ b/bf.c
@@ -1,6 +1,8 @@
 /* depend: */
 /* cflags: */
 /* linker: debug.o */
+/* winlnk: debug.o */
+/* doslnk: debug.o */
 
 #include <errno.h>
 #include <getopt.h>
diff --git a/getcomments.pl b/getcomments.pl
deleted file mode 100644 (file)
index 47edf67..0000000
+++ /dev/null
@@ -1,85 +0,0 @@
-#!/usr/bin/perl
-
-use strict;
-
-# default value
-my $format = "%";
-my $pattern = "";
-
-# help message
-sub usage() {
-
-  print <<EOF;
-usage: getcomments [-f string] [-h] [-p regex] file...
- -f|--format string: format string for output printing [%]
- -h|--help: help message
- -p|--pattern regex: pattern matching on block []
-
- Extract C/C++ block of comments
-
-Example: getcomments.pl -p='test:\\s' -f='./%' random.c
-EOF
-
-  exit 1;
-}
-
-usage() if ($#ARGV < 0);
-
-# process argument
-foreach my $arg (@ARGV) {
-  use vars qw/$caif $caip $naif $naip/;
-
-  # analyse format argument
-  ($caif, $_) = ($arg =~ /^(-f|--format)=(.*)/);
-  ($caif, $_) = (1, $arg) if ($naif);
-  next if ($naif = ($arg =~ /^(-f|--format)$/));
-  if ($caif) { $format = $_; next }
-
-  # check for help message
-  usage() if ($arg =~ /^(-h|--help)$/);
-
-  # analyse pattern argument
-  ($caip, $_) = ($arg =~ /^(-p|--pattern)=(.*)/);
-  ($caip, $_) = (1, $arg) if ($naip);
-  next if ($naip = ($arg =~ /^(-p|--pattern)$/));
-  if ($caip) { $pattern = $_; next }
-
-  # no more argument, only file
-  my $filename = $arg;
-
-  # open file
-  if (!open (IN, "<", $filename)) {
-    print "Can not open $filename\n";
-  }
-
-  # init table of comments
-  my @comments;
-  $#comments = -1;
-
-  # read all the file
-  while ($_ .= <IN>) {
-    my $cmt;
-
-    # process c++ comments
-    ($cmt, $_) = m{//\s*(.*?)\s*$()} if (m{//} && !m{/\*.*//});
-
-    # process standard c comments
-    ($cmt, $_) = m{^.*?/\*\s*(.*?)\s*\*/(.*)}s if (m{/\*.*\*/}s);
-
-    push(@comments, $cmt) if ($cmt);
-
-    # empty buffer if no comment is present
-    undef($_) if (!m{/[/*]});
-  }
-
-  # close file
-  close (IN);
-
-  # display comment blocks
-  foreach my $block (@comments) {
-    if (($block) = ($block =~ /$pattern(.*)/s)) {
-      ($_ = $format) =~ s/%/$block/gs;
-      print "$_\n";
-    }
-  }
-}
index dcf51e351e8be185406900661c64a0671914a296..dfe04eaf45a39b86ab9cc8d990d4748008dbcec4 100644 (file)
--- a/makefile
+++ b/makefile
@@ -11,15 +11,25 @@ OFLAGS  = -O4 -Os
 #OFLAGS += -minline-all-stringops -fsingle-precision-constant
 #OFLAGS += -malign-double
 CFLAGS += -W -Wall -Wextra -g
-#CFLAGS += -std=c99 -D_XOPEN_SOURCE=500
 CFLAGS += $(OFLAGS) $(INCLUDES) $(OPTIONS)
-LDFLAGS += -g $(OPTIONS)
-
-ifeq ($(OS),Windows_NT)
-#LDLIBS += -lws2_32
+LDFLAGS += -g $(LDOPTS) $(OPTIONS)
+
+LDOPT = linker
+MV = mv
+ifneq (, $(findstring linux, $(MAKE_HOST)))
+# Linux
+else ifneq (, $(findstring mingw, $(MAKE_HOST)))
+# Windows MinGw
+LDOPT = winlnk
+else ifneq (, $(findstring cygwin, $(MAKE_HOST)))
+# Windows CygWin
+LDOPT = winlnk
+else ifneq (, $(findstring msdos, $(MAKE_HOST)))
+# MSDOS
+LDOPT = doslnk
+MV = move
 endif
 
-
 # Targets
 
 ALLEXE  =
@@ -44,6 +54,9 @@ INSTALL = test -d `dirname $(2)` || $(call MKDIR, `dirname $(2)`) && cp -pa $(1)
 
 VALID = $(call TITLE, $(1)) && $(2) && $(call PASS, SUCCESS) || { $(call FAIL, FAILED); test; }
 
+GETCOMMENTS = awk '/\/\*\s*$(1):/,/\*\// { sub(/.*\/\*\s*$(1):/, ""); sub (/\s*\*\/.*/, ""); print } /\/\/\s*$(1):/ {sub (/.*\/\/\s*$(1):/, ""); print }' $(2)
+#GETCOMMENTS = perl -- getcomments.pl -p='$(1):\s' -f='%' $(2)
+
 ## Generic rules
 
 all: depends
@@ -55,7 +68,7 @@ count:
 clean:
        $(call TITLE, "Cleaning")
        touch clean
-       rm -f clean $(wildcard *.d *.ld *.log *.o *.test *~ .exec_* gmon.out)
+       rm -f clean $(wildcard *.d *.ld *.log *.o *.test *~ .exec_* gmon.out _)
        $(call PASS, SUCCESS)
 
 depends: $(patsubst %.c, %.d, $(wildcard *.c)) $(patsubst %, %.ld, $(ALLEXE))
@@ -72,7 +85,8 @@ purge: clean
        rm -f purge $(ALLEXE:%=%.exe)
        $(call PASS, SUCCESS)
 
-valgrinds: all
+valgrinds:
+       $(MAKE) all
        $(MAKE) $(addprefix valgrind_,$(ALLEXE))
 
 wipe: purge
@@ -81,7 +95,9 @@ wipe: purge
        rm -f wipe $(wildcard *.gcda *.gcno *.gcov *.glog)
        $(call PASS, SUCCESS)
 
-tests: all
+tests:
+       -rm -f $(ALLEXE)
+       $(MAKE) all
        $(MAKE) $(addprefix test_,$(ALLEXE))
 
 ## Main rules
@@ -91,7 +107,8 @@ include $(wildcard *.ld)
 
 gcov_%:
        $(MAKE) purge
-       OPTIONS="-coverage -O0" $(MAKE)
+       $(MAKE) depends
+       OPTIONS="-coverage -O0" $(MAKE) ${@:gcov_%=%}.exe
        $(MAKE) test_$(@:gcov_%=%)
        gcov `sed -e 's/\.exe:/.c/;s/\.o/.c/g' $(@:gcov_%=%.ld)`
        touch gcov
@@ -120,9 +137,9 @@ gprof_%:
 
 %.test: %.c
        $(call TITLE, "Building $@")
-#      awk '/\/\* *test:.*\*\// { sub(/^.*\/\* *test: */, ""); sub(/ *\*\/.*$$/, ""); print }' $< > $@
-       perl -- getcomments.pl -p='test:\s' -f='%' $< > $@
+       $(call GETCOMMENTS,test, $<) > $@
        $(call PASS, SUCCESS)
+       -rm -f _
 
 test_%: %.test %.exe
        IFS=$$'\n'; RC=0; \
@@ -142,24 +159,24 @@ valgrind_%: %.exe
 %.d: %.c
        $(call TITLE, "Building $@")
        $(CC) $(INCLUDES) -MM $< -o $@~
-       echo ${<:.c=.o}: $(shell perl -- getcomments.pl -p='depend:\s' -f='%' $<) >> $@~
-       mv $@~ $@
+       echo ${<:.c=.o}: $(shell $(call GETCOMMENTS,depends, $<)) >> $@~
+       $(MV) $@~ $@
        $(call PASS, SUCCESS)
 
 %.ld: %.c
        $(call TITLE, "Building $@")
-       echo ${<:.c=.exe}: $(shell perl -- getcomments.pl -p='linker:\s' -f='%' $< | awk '{for (i=1;i<=NF;i++) if ($$(i) ~ /.o$$/) printf " %s", $$(i)}') > $@
+       echo ${<:.c=.exe}: $(shell $(call GETCOMMENTS,$(LDOPT), $<) | awk '{for (i=1;i<=NF;i++) if ($$(i) ~ /.o$$/) printf " %s", $$(i)}') > $@
        $(call PASS, SUCCESS)
 
 %.o: %.c
        $(call TITLE, "Building $@")
-       $(CC) $(CFLAGS) $(INCLUDES) $(shell perl -- getcomments.pl -p='cflags:\s' -f='%' $<) -c $< -o $@
+       $(CC) $(CFLAGS) $(INCLUDES) $(shell $(call GETCOMMENTS,cflags, $<)) -c $< -o $@
        $(call PASS, SUCCESS)
 
 
 %.exe: %.o %.d
        $(call TITLE, "Building $@")
-       $(CC) $(LDFLAGS) $< $(shell perl -- getcomments.pl -p='linker:\s' -f='%' ${<:.o=.c}) $(LDLIBS) -o $@
+       $(CC) $(LDFLAGS) $< $(shell $(call GETCOMMENTS,$(LDOPT), ${<:.o=.c})) $(LDLIBS) -o $@
        $(call PASS, SUCCESS)
 
 ## Phony