.PHONY: clean install uninstall

MANDIR=@MANDIR@
GZIP=@GZIP@
GZIP_SUFFIX=.3@GZIP_SUFFIX@
BUILD_DIR=@BUILD_DIR@
SRC_DIR=@SRC_DIR@
HTML_SUFFIX=.html

OBJECTS=CK_ARRAY_FOREACH		\
	ck_array_buffer			\
	ck_array_commit			\
	ck_array_deinit			\
	ck_array_init			\
	ck_array_initialized		\
	ck_array_length			\
	ck_array_put			\
	ck_array_put_unique		\
	ck_array_remove			\
	ck_array_deinit			\
	ck_brlock			\
	ck_ht_count 	  		\
	ck_ht_destroy	  		\
	ck_ht_gc			\
	ck_ht_get_spmc	  		\
	ck_ht_grow_spmc	  		\
	ck_ht_hash	  		\
	ck_ht_hash_direct	  	\
	ck_ht_init	  		\
	ck_ht_put_spmc	  		\
	ck_ht_remove_spmc	  	\
	ck_ht_reset_spmc	  	\
	ck_ht_reset_size_spmc	  	\
	ck_ht_set_spmc	  		\
	ck_ht_entry_empty	  	\
	ck_ht_entry_key			\
	ck_ht_entry_key_direct		\
	ck_ht_entry_key_length		\
	ck_ht_entry_key_set		\
	ck_ht_entry_key_set_direct	\
	ck_ht_entry_set			\
	ck_ht_entry_set_direct		\
	ck_ht_entry_value_direct	\
	ck_ht_entry_value		\
	ck_ht_iterator_init		\
	ck_ht_next			\
	ck_ht_stat			\
	ck_bitmap_init			\
	ck_bitmap_reset			\
	ck_bitmap_set			\
	ck_bitmap_bts			\
	ck_bitmap_test			\
	ck_bitmap_base			\
	ck_bitmap_union			\
	ck_bitmap_size			\
	ck_bitmap_clear			\
	ck_bitmap_bits			\
	ck_bitmap_buffer		\
	ck_bitmap_next			\
	ck_bitmap_iterator_init		\
	ck_elide			\
	ck_epoch_barrier		\
	ck_epoch_begin			\
	ck_epoch_call			\
	ck_epoch_end			\
	ck_epoch_init			\
	ck_epoch_poll			\
	ck_epoch_recycle		\
	ck_epoch_register		\
	ck_epoch_reclaim		\
	ck_epoch_synchronize		\
	ck_epoch_unregister		\
	ck_hs_gc			\
	ck_hs_init			\
	ck_hs_destroy			\
	CK_HS_HASH			\
	ck_hs_apply			\
	ck_hs_iterator_init		\
	ck_hs_next			\
	ck_hs_get			\
	ck_hs_put			\
	ck_hs_put_unique		\
	ck_hs_set			\
	ck_hs_fas			\
	ck_hs_remove			\
	ck_hs_move			\
	ck_hs_grow			\
	ck_hs_rebuild			\
	ck_hs_count			\
	ck_hs_reset			\
	ck_hs_reset_size		\
	ck_hs_stat			\
	ck_rhs_gc			\
	ck_rhs_init			\
	ck_rhs_destroy			\
	CK_RHS_HASH			\
	ck_rhs_apply			\
	ck_rhs_iterator_init		\
	ck_rhs_next			\
	ck_rhs_get			\
	ck_rhs_put			\
	ck_rhs_put_unique		\
	ck_rhs_set			\
	ck_rhs_fas			\
	ck_rhs_remove			\
	ck_rhs_move			\
	ck_rhs_grow			\
	ck_rhs_rebuild			\
	ck_rhs_count			\
	ck_rhs_reset			\
	ck_rhs_reset_size		\
	ck_rhs_stat			\
	ck_rwcohort			\
	CK_RWCOHORT_INIT		\
	CK_RWCOHORT_INSTANCE		\
	CK_RWCOHORT_PROTOTYPE		\
	CK_RWCOHORT_READ_LOCK		\
	CK_RWCOHORT_READ_UNLOCK		\
	CK_RWCOHORT_WRITE_LOCK		\
	CK_RWCOHORT_WRITE_UNLOCK	\
	ck_cohort			\
	CK_COHORT_PROTOTYPE		\
	CK_COHORT_TRYLOCK_PROTOTYPE	\
	CK_COHORT_INSTANCE		\
	CK_COHORT_INIT			\
	CK_COHORT_LOCK			\
	CK_COHORT_UNLOCK		\
	CK_COHORT_TRYLOCK		\
	ck_pr				\
	ck_pr_fence_acquire		\
	ck_pr_fence_release		\
	ck_pr_barrier			\
	ck_pr_fas			\
	ck_pr_fence_atomic		\
	ck_pr_fence_atomic_load		\
	ck_pr_fence_atomic_store	\
	ck_pr_fence_load		\
	ck_pr_fence_load_atomic		\
	ck_pr_fence_load_store		\
	ck_pr_fence_load_depends	\
	ck_pr_fence_memory		\
	ck_pr_fence_store		\
	ck_pr_fence_store_atomic	\
	ck_pr_fence_store_load		\
	ck_pr_stall			\
	ck_pr_faa			\
	ck_pr_inc			\
	ck_pr_dec			\
	ck_pr_not			\
	ck_pr_neg			\
	ck_pr_add			\
	ck_pr_sub			\
	ck_pr_and			\
	ck_pr_xor			\
	ck_pr_or			\
	ck_pr_cas			\
	ck_pr_bts			\
	ck_pr_btc			\
	ck_pr_btr			\
	ck_pr_store			\
	ck_pr_load			\
	ck_pr_rtm			\
	ck_queue			\
	ck_ring_init			\
	ck_ring_dequeue_spmc		\
	ck_ring_enqueue_spmc		\
	ck_ring_enqueue_spmc_size	\
	ck_ring_trydequeue_spmc		\
	ck_ring_dequeue_spsc		\
	ck_ring_enqueue_spsc		\
	ck_ring_enqueue_spsc_size	\
	ck_ring_size			\
	ck_ring_capacity		\
	ck_tflock			\
	ck_rwlock			\
	ck_pflock			\
	ck_swlock			\
	ck_sequence			\
	ck_spinlock

all: 
	for target in $(OBJECTS); do 			   \
		$(GZIP) $(SRC_DIR)/doc/$$target > $(BUILD_DIR)/doc/$$target$(GZIP_SUFFIX); \
	done

html:
	for target in $(OBJECTS); do 			   		\
		echo $$target;				   		\
		groff -man -Tascii $(SRC_DIR)/doc/$$target | col -bx >	\
		   $(BUILD_DIR)/doc/$$target$(HTML_SUFFIX); 		\
		sed -i.bk 's/\&/\&amp\;/g;s/>/\&gt\;/g;s/</\&lt\;/g;'	\
		   $(BUILD_DIR)/doc/$$target$(HTML_SUFFIX); 		\
	done

# check for entries that are missing in OBJECTS
objcheck: all
	for file in `ls * | egrep '(ck|CK)_' | egrep -v "($(GZIP_SUFFIX)|$(HTML_SUFFIX))$$"`; do \
		if [ ! -f $${file}$(GZIP_SUFFIX) ]; then	\
			echo "$$file is missing from OBJECTS" >&2;	\
		fi;						\
	done

# check for stale references
refcheck:
	@./refcheck.pl $(OBJECTS)

install:
	mkdir -p $(DESTDIR)/$(MANDIR)/man3 || exit
	cp *$(GZIP_SUFFIX) $(DESTDIR)/$(MANDIR)/man3 || exit

uninstall:
	for target in $(OBJECTS); do 			  \
		rm -f $(DESTDIR)/$(MANDIR)/man3/$$target$(GZIP_SUFFIX); \
	done

clean:
	rm -f $(BUILD_DIR)/doc/*~ $(BUILD_DIR)/doc/*$(GZIP_SUFFIX) $(BUILD_DIR)/doc/*$(HTML_SUFFIX)

