Run command passed to if_not_there directly from Makefile.direct
authorIvan Maidanski <ivmai@mail.ru>
Wed, 24 Jan 2018 16:19:30 +0000 (19:19 +0300)
committerIvan Maidanski <ivmai@mail.ru>
Wed, 24 Jan 2018 16:19:30 +0000 (19:19 +0300)
Issue #199 (bdwgc).

if_not_there tool is modified to accept a single argument (file name).

* Makefile.direct (base_lib, cords, test_cpp, c++, mach_dep.o, mark_rts.o,
cord/cordtest, cord/de, gctest): Replace "if_not_there <file> <command>"
with "if_not_there <file> || <command>".
* Makefile.direct (c++): Add dependency on $(UTILS).
* Makefile.direct (gctest): Remove double spaces.
* tools/if_not_there.c: Update header comment.
* tools/if_not_there.c (main): Allow both 2 and 3 command-line arguments;
return 2 if the file does not exist and argc is 2; update the printed
usage message.

Makefile.direct
tools/if_not_there.c

index 4f830b6..56913e5 100644 (file)
@@ -202,8 +202,8 @@ base_lib gc.a: $(OBJS) dyn_load.o $(UTILS)
        ./if_mach SPARC SOLARIS $(AR) rus gc.a $(OBJS) dyn_load.o
        ./if_mach M68K AMIGA touch dont_ar_1
        ./if_mach M68K AMIGA $(AR) -vrus gc.a $(OBJS) dyn_load.o
-       ./if_not_there dont_ar_1 $(AR) ru gc.a $(OBJS) dyn_load.o
-       ./if_not_there dont_ar_1 $(RANLIB) gc.a || cat /dev/null
+       ./if_not_there dont_ar_1 || $(AR) ru gc.a $(OBJS) dyn_load.o
+       ./if_not_there dont_ar_1 || $(RANLIB) gc.a || cat /dev/null
        echo > base_lib
 #    Ignore ranlib failure; that usually means it doesn't exist, and
 #    isn't needed.
@@ -214,8 +214,8 @@ cords: $(CORD_OBJS) cord/cordtest$(EXEEXT) $(UTILS) base_lib
        ./if_mach SPARC SOLARIS $(AR) rus gc.a $(CORD_OBJS)
        ./if_mach M68K AMIGA touch dont_ar_3
        ./if_mach M68K AMIGA $(AR) -vrus gc.a $(CORD_OBJS)
-       ./if_not_there dont_ar_3 $(AR) ru gc.a $(CORD_OBJS)
-       ./if_not_there dont_ar_3 $(RANLIB) gc.a || cat /dev/null
+       ./if_not_there dont_ar_3 || $(AR) ru gc.a $(CORD_OBJS)
+       ./if_not_there dont_ar_3 || $(RANLIB) gc.a || cat /dev/null
        echo > cords
 
 gc_cpp.o: $(srcdir)/gc_cpp.cc $(srcdir)/include/gc_cpp.h $(srcdir)/include/gc.h
@@ -225,7 +225,7 @@ test_cpp$(EXEEXT): $(srcdir)/tests/test_cpp.cc $(srcdir)/include/gc_cpp.h \
   $(srcdir)/include/gc.h gc_cpp.o base_lib $(UTILS)
        rm -f test_cpp$(EXEEXT)
        ./if_mach HP_PA HPUX $(CXX) $(CXXFLAGS) -o test_cpp $(srcdir)/tests/test_cpp.cc gc_cpp.o gc.a -ldld `./threadlibs`
-       ./if_not_there test_cpp$(EXEEXT) $(CXX) $(CXXFLAGS) -o test_cpp$(EXEEXT) $(srcdir)/tests/test_cpp.cc gc_cpp.o gc.a `./threadlibs`
+       ./if_not_there test_cpp$(EXEEXT) || $(CXX) $(CXXFLAGS) -o test_cpp$(EXEEXT) $(srcdir)/tests/test_cpp.cc gc_cpp.o gc.a `./threadlibs`
 
 check-cpp: test_cpp$(EXEEXT)
        ./test_cpp
@@ -236,14 +236,14 @@ c++-t: c++ test_cpp$(EXEEXT)
 c++-nt: c++
        @echo "Use ./test_cpp 1 to test the leak library"
 
-c++: gc_cpp.o $(srcdir)/include/gc_cpp.h base_lib
+c++: gc_cpp.o $(srcdir)/include/gc_cpp.h base_lib $(UTILS)
        rm -f dont_ar_4
        ./if_mach SPARC SOLARIS touch dont_ar_4
        ./if_mach SPARC SOLARIS $(AR) rus gc.a gc_cpp.o
        ./if_mach M68K AMIGA touch dont_ar_4
        ./if_mach M68K AMIGA $(AR) -vrus gc.a gc_cpp.o
-       ./if_not_there dont_ar_4 $(AR) ru gc.a gc_cpp.o
-       ./if_not_there dont_ar_4 $(RANLIB) gc.a || cat /dev/null
+       ./if_not_there dont_ar_4 || $(AR) ru gc.a gc_cpp.o
+       ./if_not_there dont_ar_4 || $(RANLIB) gc.a || cat /dev/null
        echo > c++
 
 dyn_load_sunos53.o: dyn_load.c
@@ -300,16 +300,16 @@ mach_dep.o: $(srcdir)/mach_dep.c $(srcdir)/sparc_mach_dep.S \
        ./if_mach IA64 "" $(AS) -o ia64_save_regs_in_stack.o $(srcdir)/ia64_save_regs_in_stack.s
        ./if_mach IA64 "" $(CC) -c -o mach_dep1.o $(SPECIALCFLAGS) $(srcdir)/mach_dep.c
        ./if_mach IA64 "" $(LD) -r -o mach_dep.o mach_dep1.o ia64_save_regs_in_stack.o
-       -./if_not_there mach_dep.o $(CC) -c $(SPECIALCFLAGS) $(srcdir)/mach_dep.c
-       -./if_not_there mach_dep.o `cygpath -w /bin/sh` $(CC) -c $(SPECIALCFLAGS) $(srcdir)/mach_dep.c
-       -./if_not_there mach_dep.o /bin/sh $(CC) -c $(SPECIALCFLAGS) $(srcdir)/mach_dep.c
+       -./if_not_there mach_dep.o || $(CC) -c $(SPECIALCFLAGS) $(srcdir)/mach_dep.c
+       -./if_not_there mach_dep.o || `cygpath -w /bin/sh` $(CC) -c $(SPECIALCFLAGS) $(srcdir)/mach_dep.c
+       -./if_not_there mach_dep.o || /bin/sh $(CC) -c $(SPECIALCFLAGS) $(srcdir)/mach_dep.c
 
 mark_rts.o: $(srcdir)/mark_rts.c $(UTILS)
        rm -f mark_rts.o
        -./if_mach ALPHA OSF1 $(CC) -c $(CFLAGS) -Wo,-notail $(srcdir)/mark_rts.c
-       -./if_not_there mark_rts.o $(CC) -c $(CFLAGS) $(srcdir)/mark_rts.c
-       -./if_not_there mark_rts.o `cygpath -w /bin/sh` $(CC) -c $(CFLAGS) $(srcdir)/mark_rts.c
-       -./if_not_there mark_rts.o /bin/sh $(CC) -c $(CFLAGS) $(srcdir)/mark_rts.c
+       -./if_not_there mark_rts.o || $(CC) -c $(CFLAGS) $(srcdir)/mark_rts.c
+       -./if_not_there mark_rts.o || `cygpath -w /bin/sh` $(CC) -c $(CFLAGS) $(srcdir)/mark_rts.c
+       -./if_not_there mark_rts.o || /bin/sh $(CC) -c $(CFLAGS) $(srcdir)/mark_rts.c
 #   Work-around for DEC optimizer tail recursion elimination bug.
 #   The ALPHA-specific line should be removed if gcc is used.
 
@@ -337,7 +337,7 @@ cord/cordtest$(EXEEXT): $(srcdir)/cord/tests/cordtest.c $(CORD_OBJS) \
        ./if_mach SPARC DRSNX $(CC) $(CFLAGS) -o cord/cordtest $(srcdir)/cord/tests/cordtest.c $(CORD_OBJS) gc.a -lucb
        ./if_mach HP_PA HPUX $(CC) $(CFLAGS) -o cord/cordtest $(srcdir)/cord/tests/cordtest.c $(CORD_OBJS) gc.a -ldld `./threadlibs`
        ./if_mach M68K AMIGA $(CC) $(CFLAGS) -UGC_AMIGA_MAKINGLIB -o cord/cordtest $(srcdir)/cord/tests/cordtest.c $(CORD_OBJS) gc.a `./threadlibs`
-       ./if_not_there cord/cordtest$(EXEEXT) $(CC) $(CFLAGS) -o cord/cordtest$(EXEEXT) $(srcdir)/cord/tests/cordtest.c $(CORD_OBJS) gc.a `./threadlibs`
+       ./if_not_there cord/cordtest$(EXEEXT) || $(CC) $(CFLAGS) -o cord/cordtest$(EXEEXT) $(srcdir)/cord/tests/cordtest.c $(CORD_OBJS) gc.a `./threadlibs`
 
 cord/de: $(srcdir)/cord/tests/de.c cord/cordbscs.o cord/cordxtra.o base_lib \
   $(UTILS)
@@ -350,7 +350,7 @@ cord/de: $(srcdir)/cord/tests/de.c cord/cordbscs.o cord/cordxtra.o base_lib \
        ./if_mach ALPHA LINUX $(CC) $(CFLAGS) -o cord/de $(srcdir)/cord/tests/de.c cord/cordbscs.o cord/cordxtra.o gc.a -lcurses `./threadlibs`
        ./if_mach IA64 LINUX $(CC) $(CFLAGS) -o cord/de $(srcdir)/cord/tests/de.c cord/cordbscs.o cord/cordxtra.o gc.a -lcurses `./threadlibs`
        ./if_mach M68K AMIGA $(CC) $(CFLAGS) -UGC_AMIGA_MAKINGLIB -o cord/de $(srcdir)/cord/tests/de.c cord/cordbscs.o cord/cordxtra.o gc.a -lcurses
-       ./if_not_there cord/de$(EXEEXT) $(CC) $(CFLAGS) -o cord/de$(EXEEXT) $(srcdir)/cord/tests/de.c cord/cordbscs.o cord/cordxtra.o gc.a $(CURSES) `./threadlibs`
+       ./if_not_there cord/de$(EXEEXT) || $(CC) $(CFLAGS) -o cord/de$(EXEEXT) $(srcdir)/cord/tests/de.c cord/cordbscs.o cord/cordxtra.o gc.a $(CURSES) `./threadlibs`
 
 if_mach$(EXEEXT): $(srcdir)/tools/if_mach.c \
   $(srcdir)/include/private/gcconfig.h
@@ -372,10 +372,10 @@ clean:
 
 gctest$(EXEEXT): tests/test.o base_lib $(UTILS)
        rm -f gctest$(EXEEXT)
-       ./if_mach SPARC DRSNX $(CC) $(CFLAGS) -o gctest  tests/test.o gc.a -lucb
-       ./if_mach HP_PA HPUX $(CC) $(CFLAGS) -o gctest  tests/test.o gc.a -ldld `./threadlibs`
+       ./if_mach SPARC DRSNX $(CC) $(CFLAGS) -o gctest tests/test.o gc.a -lucb
+       ./if_mach HP_PA HPUX $(CC) $(CFLAGS) -o gctest tests/test.o gc.a -ldld `./threadlibs`
        ./if_mach M68K AMIGA $(CC) $(CFLAGS) -UGC_AMIGA_MAKINGLIB -o gctest  tests/test.o gc.a `./threadlibs`
-       ./if_not_there gctest$(EXEEXT) $(CC) $(CFLAGS) -o gctest$(EXEEXT) tests/test.o gc.a `./threadlibs`
+       ./if_not_there gctest$(EXEEXT) || $(CC) $(CFLAGS) -o gctest$(EXEEXT) tests/test.o gc.a `./threadlibs`
 
 # If an optimized setjmp_test generates a segmentation fault,
 # odds are your compiler is broken.  Gctest may still work.
index 190a582..10f5d14 100644 (file)
@@ -1,4 +1,6 @@
-/* Conditionally execute a command based if the file argv[1] doesn't exist */
+/* Conditionally execute the command argv[2] based if the file argv[1]  */
+/* does not exist.  If the command is omitted (and the file does not    */
+/* exist) then just exit with a non-zero code.                          */
 
 # include "private/gc_priv.h"
 # include <stdio.h>
@@ -16,7 +18,8 @@ int main(int argc, char **argv)
 #endif /* __DJGPP__ */
     char *fname;
 
-    if (argc < 3) goto Usage;
+    if (argc < 2 || argc > 3)
+        goto Usage;
 
     fname = TRUSTED_STRING(argv[1]);
     f = fopen(fname, "rb");
@@ -37,10 +40,13 @@ int main(int argc, char **argv)
 #endif
     printf("^^^^Starting command^^^^\n");
     fflush(stdout);
+    if (argc == 2)
+        return(2); /* the file does not exist but no command is given */
+
     execvp(TRUSTED_STRING(argv[2]), (void *)(argv + 2));
     exit(1);
 
 Usage:
-    fprintf(stderr, "Usage: %s file_name command\n", argv[0]);
+    fprintf(stderr, "Usage: %s file_name [command]\n", argv[0]);
     return(1);
 }