1#  Copyright (c) 2012 Antti-Juhani Kaijanaho
2#
3#  Redistribution and use in source and binary forms, with or without
4#  modification, are permitted provided that the following conditions
5#  are met:
6#
7#  1. Redistributions of source code must retain the above copyright
8#     notice, this list of conditions and the following disclaimer.
9#
10#  2. Redistributions in binary form must reproduce the above
11#     copyright notice, this list of conditions and the following
12#     disclaimer in the documentation and/or other materials provided
13#     with the distribution.
14#
15#  THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS
16#  OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
17#  WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
18#  ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
19#  DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
20#  DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
21#  GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
22#  INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
23#  WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
24#  NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
25#  SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26
27SHELL = /bin/sh
28
29PACKAGE_TARNAME = @PACKAGE_TARNAME@
30PACKAGE_VERSION = @PACKAGE_VERSION@
31
32srcdir          = @srcdir@
33
34CC              = @CC@
35CPPFLAGS        = @CPPFLAGS@
36CFLAGS          = @CFLAGS@
37MDMF            = @MDMF@
38LDFLAGS         = @LDFLAGS@
39INSTALL         = @INSTALL@
40INSTALL_PROGRAM = @INSTALL_PROGRAM@
41INSTALL_DATA    = @INSTALL_DATA@
42INSTALL_DIR     = ${INSTALL} -d
43MKDIR_P         = @MKDIR_P@
44RANLIB		= @RANLIB@
45
46AR		= ar
47LN		= ln
48
49echoexec        = sh $(srcdir)/echoexec.sh
50link_alternative_names = sh $(srcdir)/link-alternative-names
51
52prefix          = @prefix@
53exec_prefix     = @exec_prefix@
54datarootdir     = @datarootdir@
55
56includedir      = @includedir@
57libdir          = @libdir@
58mandir          = @mandir@
59man3dir         = ${mandir}/man3
60man3ext	        = .3
61
62objs =  alloc/memdup.o          \
63	alloc/xmalloc.o         \
64	alloc/xrealloc.o        \
65	alloc/xfree.o           \
66	alloc/xstrdup.o         \
67	alloc/xmemdup.o         \
68	alloc/dynarr.o          \
69	base64/base64.o         \
70	bitarr/ba_and_ba.o      \
71	bitarr/ba_clear.o       \
72	bitarr/ba_clear_all.o   \
73	bitarr/ba_copy.o        \
74	bitarr/ba_create.o      \
75	bitarr/ba_destroy.o     \
76	bitarr/ba_not.o         \
77	bitarr/ba_or_ba.o       \
78	bitarr/ba_or_not_ba.o   \
79	bitarr/ba_query.o       \
80	bitarr/ba_resize.o      \
81	bitarr/ba_set.o         \
82	bitarr/ba_xor_ba.o      \
83	cmp/cmp.o               \
84	errormsg/errormsg.o     \
85	files/xgetaline.o       \
86	files/xfseek.o          \
87	files/xfopen.o          \
88	files/xfclose.o         \
89	files/getaline.o        \
90	files/fassert.o         \
91	files/file_io.o         \
92	fname/fnbase.o          \
93	fname/fndelbeg.o        \
94	fname/fndelend.o        \
95	fname/fndelsuf.o        \
96	fname/fndir.o           \
97	fname/fnhome.o          \
98	fname/fnjoin.o          \
99	fname/fnlastsuf.o       \
100	fname/fnpathfind.o      \
101	fname/fnqualify.o       \
102	fname/fnsetsuf.o        \
103	hash/hash_create.o      \
104	hash/hash_destroy.o     \
105	hash/hash_install.o     \
106	hash/hash_lookup.o      \
107	hash/hash_uninstall.o   \
108	hash/hash_iter.o        \
109	iset/iset_add.o         \
110	iset/iset_add_rng.o     \
111	iset/iset_clear.o       \
112	iset/iset_contains.o    \
113	iset/iset_copy.o        \
114	iset/iset_create.o      \
115	iset/iset_destroy.o     \
116	iset/iset_diff.o        \
117	iset/iset_is_empty.o    \
118	iset/iset_isect.o       \
119	iset/iset_nth_rng.o     \
120	iset/iset_range.o       \
121	iset/iset_remove.o      \
122	iset/iset_rm_rng.o      \
123	iset/iset_union.o       \
124	lockfile/lockfile.o     \
125	log/log.o               \
126	main/main_filter.o      \
127	nntp/nntp.o             \
128	nntp/nntpart.o          \
129	priq/priq.o             \
130	queue/queue.o           \
131	sbuf/sbuf.o             \
132	sbuf/sbuf_aux.o         \
133	sbuf/sbuf_srch.o        \
134	sbuf/sbuf_io.o          \
135	stack/stack_copy.o      \
136	stack/stack_create.o    \
137	stack/stack_destroy.o   \
138	stack/stack_emptyp.o    \
139	stack/stack_pop.o       \
140	stack/stack_push.o      \
141	strutil/memarrfill.o    \
142	strutil/memdel.o        \
143	strutil/memfill.o       \
144	strutil/memins.o        \
145	strutil/memisort.o      \
146	strutil/memmem.o        \
147	strutil/memoverlap.o    \
148	strutil/memrchr.o       \
149	strutil/memrev.o        \
150	strutil/memrmem.o       \
151	strutil/memshuffle.o    \
152	strutil/memswap.o       \
153	strutil/stracat.o       \
154	strutil/stranaxfrm.o    \
155	strutil/strchange.o     \
156	strutil/strcins.o       \
157	strutil/strcstr.o       \
158	strutil/strdel.o        \
159	strutil/strdiff.o       \
160	strutil/strend.o        \
161	strutil/strendzap.o     \
162	strutil/strgsub.o       \
163	strutil/strhash.o       \
164	strutil/strinit.o       \
165	strutil/strins.o        \
166	strutil/strltrim.o      \
167	strutil/strmaxcpy.o     \
168	strutil/strmove.o       \
169	strutil/strmtrim.o      \
170	strutil/strndup.o       \
171	strutil/strnins.o       \
172	strutil/strnlen.o       \
173	strutil/stroverlap.o    \
174	strutil/strrev.o        \
175	strutil/strright.o      \
176	strutil/strrot13.o      \
177	strutil/strrstr.o       \
178	strutil/strrtrim.o      \
179	strutil/strset.o        \
180	strutil/strshuffle.o    \
181	strutil/strsplit.o      \
182	strutil/strsub.o        \
183	strutil/strtabify.o     \
184	strutil/strtrexpand.o   \
185	strutil/strtrim.o       \
186	strutil/struncstr.o     \
187	strutil/struntabify.o   \
188	strutil/strvars.o       \
189	strutil/strzap.o        \
190	tbuf/tbuf.o
191
192srcs = $(objs:.o=.c)
193
194# excepting publib.h (special case!)
195includes =                          \
196	includes/publib/alloc.h     \
197	includes/publib/base64.h    \
198	includes/publib/bitarr.h    \
199	includes/publib/cmp.h       \
200	includes/publib/errormsg.h  \
201	includes/publib/files.h     \
202	includes/publib/fname.h     \
203	includes/publib/hash.h      \
204	includes/publib/iset.h      \
205	includes/publib/lockfile.h  \
206	includes/publib/log.h       \
207	includes/publib/main.h      \
208	includes/publib/nntp.h      \
209	includes/publib/priq.h      \
210	includes/publib/queue.h     \
211	includes/publib/sbuf.h      \
212	includes/publib/stack.h     \
213	includes/publib/strutil.h   \
214	includes/publib/tbuf.h
215
216manpages =                          \
217	man/bitarr.3                \
218	man/cmp.3                   \
219	man/dynarr.3                \
220	man/errormsg.3              \
221	man/files.3                 \
222	man/fname.3                 \
223	man/fnpathfind.3            \
224	man/fnqualify.3             \
225	man/hash.3                  \
226	man/iset.3                  \
227	man/log.3                   \
228	man/memarrfill.3            \
229	man/memdel.3                \
230	man/memfill.3               \
231	man/memins.3                \
232	man/memisort.3              \
233	man/memmem.3                \
234	man/memoverlap.3            \
235	man/memrchr.3               \
236	man/memrev.3                \
237	man/memrmem.3               \
238	man/memshuffle.3            \
239	man/memswap.3               \
240	man/publib.3                \
241	man/__set_liberror.3        \
242	man/stack.3                 \
243	man/stracat.3               \
244	man/stranaxfrm.3            \
245	man/strchange.3             \
246	man/strcins.3               \
247	man/strcstr.3               \
248	man/strdel.3                \
249	man/strdiff.3               \
250	man/strend.3                \
251	man/strendzap.3             \
252	man/strgsub.3               \
253	man/strhash.3               \
254	man/strinit.3               \
255	man/strins.3                \
256	man/strltrim.3              \
257	man/strmaxcpy.3             \
258	man/strmove.3               \
259	man/strmtrim.3              \
260	man/strndup.3               \
261	man/strnins.3               \
262	man/stroverlap.3            \
263	man/strrev.3                \
264	man/strright.3              \
265	man/strrot13.3              \
266	man/strrstr.3               \
267	man/strrtrim.3              \
268	man/strset.3                \
269	man/strshuffle.3            \
270	man/strsplit.3              \
271	man/strsub.3                \
272	man/strtabify.3             \
273	man/strtrexpand.3           \
274	man/strtrim.3               \
275	man/struncstr.3             \
276	man/struntabify.3           \
277	man/strvars.3               \
278	man/strzap.3                \
279	man/tbuf.3                  \
280	man/xmalloc.3
281
282tests = iset/test_add.c             \
283	main/test-main-filter.c     \
284	log/test-log.c              \
285	tbuf/test_tbuf_with_stats.c \
286	tbuf/test_tbuf.c            \
287	queue/test-queue.c          \
288	sbuf/test-colmark.c         \
289	sbuf/test-sbuf-undo.c       \
290	sbuf/test-sbuf.c            \
291	priq/test-priq.c            \
292	fname/test_fnqualify.c
293
294distfiles = $(srcs) $(includes) $(manpages) $(tests) \
295	aclocal.m4 ChangeLog.old configure configure.ac distcheck.mk \
296	echoexec.sh INSTALL includes/publib.h \
297	install-sh link-alternative-names Makefile.in NEWS README TODO
298
299all :	libpub.a
300
301clean mostlyclean :
302	$(RM) libpub.a */*.o */*.d
303
304distclean maintainer-clean : clean
305	$(RM) config.log config.status
306
307install : libpub.a
308	$(PRE_INSTALL)
309	$(NORMAL_INSTALL)
310	$(INSTALL_DIR) $(DESTDIR)$(includedir)/publib
311	$(INSTALL_DIR) $(DESTDIR)$(libdir)
312	$(INSTALL_DIR) $(DESTDIR)$(man3dir)
313	$(INSTALL_DATA) libpub.a $(DESTDIR)$(libdir)
314	$(INSTALL_DATA) includes/publib.h $(DESTDIR)$(includedir)
315	@for f in $(includes) ; do \
316	  $(echoexec) $(INSTALL_DATA) $$f $(DESTDIR)$(includedir)/publib/ ;\
317	done
318	@for f in $(manpages) ; do\
319	  if test -f $$f; then \
320	    t="$(DESTDIR)$(man3dir)/`basename $$f .3`$(man3ext)"; \
321	    $(echoexec) $(INSTALL_DATA) $$f "$$t" ;\
322	    $(echoexec) gzip -9f "$$t" ;\
323	    $(link_alternative_names) $$t $(DESTDIR)$(man3dir) $(man3ext) ;\
324	  fi ;\
325	done
326	$(POST_INSTALL)
327
328install-strip: install
329#	No point in stripping a static library ...
330
331uninstall :
332	$(PRE_UNINSTALL)
333	$(NORMAL_UNINSTALL)
334	$(RM) $(DESTDIR)$(libdir)/libpub.a
335	$(RM) $(DESTDIR)$(includedir)publib.h
336	@for f in $(includes) ; do \
337	  $(echoexec) $(RM) $(DESTDIR)$(includedir)/publib/`basename $$f` ;\
338	done
339	@for f in $(manpages) ; do\
340	  t="$(DESTDIR)$(man3dir)/`basename $$f .3`$(man3ext)"; \
341	  $(link_alternative_names) -r $$t $(DESTDIR)$(man3dir) $(man3ext) ;\
342	  $(echoexec) $(RM) "$$t".gz ;\
343	done
344	$(POST_UNINSTALL)
345
346libpub.a : $(objs)
347	$(AR) cr $@ $^
348	$(RANLIB) $@
349
350check : libpub.a
351	@set -e; for f in $(tests) ; do\
352	  $(echoexec) $(CC) -Iincludes $(CPPFLAGS) $(CFLAGS) $$f libpub.a ;\
353	  echo './a.out </dev/null >/dev/null' ;\
354	  ./a.out </dev/null >/dev/null ;\
355	  $(echoexec) $(RM) a.out ;\
356	  if test -r test.log; then rm test.log ; fi ;\
357	done
358
359dist_base = $(PACKAGE_TARNAME)-$(PACKAGE_VERSION)
360dist_tar = $(dist_base).tar
361dist_tgz = $(dist_tar).gz
362
363dist : $(dist_tgz)
364
365distsign : $(dist_tgz).asc
366
367$(dist_tgz) : $(distfiles)
368	@if test -e $(DESTDIR)$(dist_base) ; then \
369	  echo "$(DESTDIR)$(dist_base) exists; cannot continue" ; \
370	  exit 1 ;\
371	fi
372	$(MKDIR_P) $(DESTDIR)$(dist_base)
373	@set -e ; for f in $(distfiles) ; do \
374	  dir=$(DESTDIR)$(dist_base)/`dirname $$f` ; \
375	  if ! test -d $$dir ; then \
376	    $(echoexec) $(MKDIR_P) $$dir ;\
377	  fi ;\
378	  $(echoexec) $(LN) $$f $(DESTDIR)$(dist_base)/$$f ;\
379	done
380	cd $(DESTDIR). && tar cf $(dist_tar) $(dist_base)
381	gzip -9f $(DESTDIR)$(dist_tar)
382	$(RM) -r $(DESTDIR)$(dist_base)
383
384$(dist_tgz).asc : $(dist_tgz)
385	gpg --output $@ --clearsign --detach-sig $<
386
387distcheck_stage = distcheck_stage
388distcheck : $(dist_tgz)
389	@if test -e $(DESTDIR)$(distcheck_stage) ; then \
390	  echo "$(DESTDIR)$(distcheck_stage) exists; cannot continue" ; \
391	  exit 1 ;\
392	fi
393	$(MKDIR_P) $(DESTDIR)$(distcheck_stage)
394	cp $(dist_tgz) $(DESTDIR)$(distcheck_stage)
395	cp distcheck.mk $(DESTDIR)$(distcheck_stage)/Makefile
396	cp echoexec.sh $(DESTDIR)$(distcheck_stage)
397	$(MAKE) -C $(DESTDIR)$(distcheck_stage) \
398	  base=$(dist_base) tgz=$(dist_tgz) \
399	  includes="$(includes)" manpages="$(manpages)" \
400	  run_distcheck
401	$(RM) -r $(DESTDIR)$(distcheck_stage)
402.c.o:
403	$(CC) -Iincludes -D__publib__ $(CPPFLAGS) $(CFLAGS) $(MDMF) -c $< -o $@
404
405Makefile : Makefile.in config.status
406	./config.status
407
408config.status : configure
409	./configure
410
411configure : configure.ac aclocal.m4
412	autoconf
413
414aclocal.m4 :
415	aclocal
416
417.SUFFIXES:
418.SUFFIXES: .c .o
419
420-include */*.d
421
422