summaryrefslogtreecommitdiff
path: root/src/Makefile.am
diff options
context:
space:
mode:
authorPaul Eggert <eggert@cs.ucla.edu>2014-03-23 17:21:35 -0700
committerPaul Eggert <eggert@cs.ucla.edu>2014-03-23 17:25:20 -0700
commitb639643840ef506594b6c46e5b24d9980a33e78e (patch)
tree8e6065cf04b02495a84ca02320b28b945d0a47c4 /src/Makefile.am
parent0995fc11214ebbb1c99a4b6d675fe615b0ed8539 (diff)
downloadgrep-b639643840ef506594b6c46e5b24d9980a33e78e.tar.gz
egrep, fgrep: go back to shell scripts
Although egrep's and fgrep's switch from shell scripts to executables may have made sense in 2005, it complicated maintenance and recently has caused subtle performance bugs. Go back to the old way of doing things, as it's simpler and more easily separated from the mainstream implementation. This should be good enough nowadays, as POSIX has withdrawn egrep/fgrep and portable applications should be using -E/-F anyway. * po/POTFILES.in: Remove src/egrep.c, src/fgrep.c, src/main.c. * src/Makefile.am (bin_PROGRAMS): Remove egrep, fgrep. (bin_SCRIPTS): New macro. (grep_SOURCES): Move searchutils.c, dfa.c, dfasearch.c, kwset.c, kwsearch.c, pcresearch.c here from libgrep_a_SOURCES. (egrep_SOURCES, fgrep_SOURCES, noinst_LIBRARIES, libgrep_a_SOURCES): Remove. (LDADD): Remove libgrep.a. (egrep, fgrep): New rules. (CLEANFILES): New macro. * src/grep.c: Rename from src/main.c. (usage, setmatcher, main): Simplify, since there's now just one executable. (Gcompile, Ecompile, Acompile, GAcompile, PAcompile, matchers): Move here from the (removed) src/grep.c. (compile_fp_t, execute_fp_t, struct matcher, matchers): Move here from src/grep.h, as they no longer need to be public. (struct matcher.name): Avoid one level of indirection/relocation. (do_execute, main): Fix a performance bug when it was compiled as 'fgrep', due to confusion about which matcher was which. (main): Fix a performance bug with -P, likewise. * src/grep.h (before_options, after_options): Remove. * src/egrep.c, src/fgrep.c, src/grep.c: Remove.
Diffstat (limited to 'src/Makefile.am')
-rw-r--r--src/Makefile.am31
1 files changed, 22 insertions, 9 deletions
diff --git a/src/Makefile.am b/src/Makefile.am
index 9283d1a3..2b5a365c 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -21,23 +21,20 @@ AM_CFLAGS = $(WARN_CFLAGS) $(WERROR_CFLAGS)
# Tell the linker to omit references to unused shared libraries.
AM_LDFLAGS = $(IGNORE_UNUSED_LIBRARIES_CFLAGS)
-bin_PROGRAMS = grep egrep fgrep
-grep_SOURCES = grep.c
-egrep_SOURCES = egrep.c
-fgrep_SOURCES = fgrep.c
+bin_PROGRAMS = grep
+bin_SCRIPTS = egrep fgrep
+grep_SOURCES = grep.c searchutils.c \
+ dfa.c dfasearch.c \
+ kwset.c kwsearch.c \
+ pcresearch.c
noinst_HEADERS = grep.h dfa.h kwset.h search.h system.h mbsupport.h
-noinst_LIBRARIES = libgrep.a
-libgrep_a_SOURCES = kwset.c dfa.c searchutils.c dfasearch.c kwsearch.c \
- pcresearch.c main.c
-
# Sometimes, the expansion of $(LIBINTL) includes -lc which may
# include modules defining variables like 'optind', so libgreputils.a
# must precede $(LIBINTL) in order to ensure we use GNU getopt.
# But libgreputils.a must also follow $(LIBINTL), since libintl uses
# replacement functions defined in libgreputils.a.
LDADD = \
- libgrep.a \
../lib/libgreputils.a $(LIBINTL) ../lib/libgreputils.a $(LIBICONV) \
$(LIBTHREAD)
@@ -46,3 +43,19 @@ localedir = $(datadir)/locale
AM_CPPFLAGS = -I$(top_builddir)/lib -I$(top_srcdir)/lib
EXTRA_DIST = dosbuf.c
+
+egrep fgrep:
+ $(AM_V_GEN)grep=`echo grep | sed -e '$(transform)'` && \
+ case $@ in egrep) option=-E;; fgrep) option=-F;; esac && \
+ (echo '#!$(SHELL)' && \
+ echo 'grep=grep' && \
+ echo 'case $$0 in */*)' && \
+ echo ' g=$${0%/*}/'"'$$grep'" && \
+ echo ' test -x "$$g" && grep=$$g' && \
+ echo 'esac' && \
+ echo 'exec "$$grep" '"$$option"' "$$@"' \
+ ) >$@-t
+ $(AM_V_at)chmod +x $@-t
+ $(AM_V_at)mv $@-t $@
+
+CLEANFILES = egrep fgrep *-t