1# This file is part of xenv
2# Copyright (C) 2021 Sergey Poznyakoff
3#
4# Xenv is free software; you can redistribute it and/or modify it
5# under the terms of the GNU General Public License as published by the
6# Free Software Foundation; either version 3 of the License, or (at your
7# option) any later version.
8#
9# Xenv is distributed in the hope that it will be useful,
10# but WITHOUT ANY WARRANTY; without even the implied warranty of
11# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12# GNU General Public License for more details.
13#
14# You should have received a copy of the GNU General Public License along
15# with xenv. If not, see <http://www.gnu.org/licenses/>. */
16
17CPPFLAGS =
18CFLAGS = -O2 -Wall
19LEXFLAGS = -F
20
21# Installation prefix
22PREFIX  = /usr/local
23MANDIR  = $(PREFIX)/share/man
24BINDIR  = $(PREFIX)/bin
25MAN1DIR = $(MANDIR)/man1
26
27# Install program.  Use cp(1) if not available.
28INSTALL = install
29# Program to make a directory hierarchy.
30MKHIER  = install -d
31
32# #############################
33# Building the program.
34# #############################
35PACKAGE_NAME = xenv
36PACKAGE_VERSION = 1.2
37PACKAGE_TARNAME = $(PACKAGE_NAME)-$(PACKAGE_VERSION)
38PACKAGE_BUGREPORT = gray@gnu.org
39MK_CPPFLAGS = \
40 -DPACKAGE_NAME=\"$(PACKAGE_NAME)\"\
41 -DPACKAGE_VERSION=\"$(PACKAGE_VERSION)\"
42
43xenv: lex.yy.c
44	$(CC) -oxenv $(CPPFLAGS) $(MK_CPPFLAGS) $(CFLAGS) lex.yy.c
45lex.yy.c: xenv.l
46	flex $(LEXFLAGS) xenv.l
47clean:
48	rm -f xenv
49
50allclean: clean
51	rm -f lex.yy.c
52
53check: xenv testsuite
54	@./testsuite
55
56# ###############################
57# Building the testsuite.
58# ###############################
59AUTOM4TE = autom4te
60AUTOTEST = $(AUTOM4TE) --language=autotest
61
62TESTSUITE_AT = \
63 t/testsuite.at \
64 t/asndfl.at\
65 t/braces.at\
66 t/comment.at\
67 t/eof.at\
68 t/errmsg.at\
69 t/error.at\
70 t/ifdef.at\
71 t/ifndef.at\
72 t/ifnset.at\
73 t/ifset.at\
74 t/quote.at\
75 t/set.at\
76 t/sigil.at\
77 t/simple.at\
78 t/special.at\
79 t/ternary.at\
80 t/unset.at\
81 t/usealt.at\
82 t/usedfl.at\
83 t/verbatim.at
84
85package.m4: Makefile
86	{                                      \
87	  echo '# Signature of the current package.'; \
88	  echo 'm4_define([AT_PACKAGE_NAME],      [$(PACKAGE_NAME)])'; \
89	  echo 'm4_define([AT_PACKAGE_TARNAME],   [$(PACKAGE_TARNAME)])'; \
90	  echo 'm4_define([AT_PACKAGE_VERSION],   [$(PACKAGE_VERSION)])'; \
91	  echo 'm4_define([AT_PACKAGE_STRING],    [$(PACKAGE_TARNAME)])'; \
92	  echo 'm4_define([AT_PACKAGE_BUGREPORT], [$(PACKAGE_BUGREPORT)])'; \
93	} > package.m4
94
95EXTRA_DIST = atlocal package.m4
96
97testsuite: package.m4 $(TESTSUITE_AT)
98	$(AUTOTEST) -I . -I t t/testsuite.at -o testsuite
99
100# ###############################
101# Install
102# ###############################
103
104install: install-bin install-man
105
106install-bin: xenv
107	$(MKHIER) $(DESTDIR)$(BINDIR)
108	$(INSTALL) xenv $(DESTDIR)$(BINDIR)
109
110install-man:
111	$(MKHIER) $(DESTDIR)$(MAN1DIR)
112	$(INSTALL) xenv.1 $(DESTDIR)$(MAN1DIR)
113
114# ###############################
115# Distribution
116# ###############################
117DISTDIR = $(PACKAGE_TARNAME)
118DISTFILES = xenv.l xenv.1 Makefile lex.yy.c testsuite package.m4 README NEWS
119
120distdir: $(DISTFILES)
121	rm -rf $(DISTDIR)
122	mkdir $(DISTDIR)
123	cp $(DISTFILES) $(EXTRA_DIST) $(DISTDIR)
124	mkdir $(DISTDIR)/t
125	cp $(TESTSUITE_AT) $(DISTDIR)/t
126
127dist: distdir
128	tar zcf $(PACKAGE_TARNAME).tar.gz $(DISTDIR)
129	rm -rf $(DISTDIR)
130
131
132distcheck: dist
133	tar xfz $(PACKAGE_TARNAME).tar.gz
134	if $(MAKE) -C $(DISTDIR) $(DISTCHECKFLAGS) check; then \
135          text="$(DISTDIR).tar.gz ready for distribution"; \
136	  echo "$$text" | sed s/./=/g; \
137	  echo "$$text"; \
138	  echo "$$text" | sed s/./=/g; \
139          rm -rf $(DISTDIR); \
140        else \
141          exit 2; \
142        fi
143
144