#
# This Makefile is used for compatibility to the
# isdn4k-utils package. In order to superseede
# the original Makefile, it is called GNUmakefile.
#

ifeq (../.config,$(wildcard ../.config))
	include ../.config
	BUILDOPTS   :=
	ifeq ($(CONFIG_LIB_AREACODE),y)
		BUILDOPTS += SUBDIRS= LIBAREA=1
	endif
	#
	# Install as root with numeric Id's, since these are the
	# only ones that _really_ exist on _every_ system.
	#
	INSTALLOPTS += INSTALL= install -o 0 -g 0 -m 644
endif

all: .depend
	$(MAKE) -f Makefile $(BUILDOPTS) all

.depend:
	$(MAKE) -f Makefile depend

config:
	@cp Makefile.in GNUmakefile
	@rm -f areacode; ln -s ../areacode .
	@echo '/*' > policy.h
	@echo ' * Automatically generated by config: DO NOT EDIT' >> policy.h
	@echo ' */' >> policy.h
	@echo '#ifndef _POLICY_H_' >> policy.h
	@echo '#define _POLICY_H_' >> policy.h
	@echo '#include "../scripts/autoconf.h"' >> policy.h
	@echo '#define I4LCONFDIR CONFIG_I4LCONFDIR' >> policy.h
	@echo '#define CONFFILE CONFIG_CONFFILE' >> policy.h
	@echo '#define CALLERIDFILE CONFIG_CALLERIDFILE' >> policy.h
	@echo '#define USERCONFFILE CONFIG_USERCONFFILE' >> policy.h
	@echo '#define RUNDIR CONFIG_RUNDIR' >> policy.h
	@echo '#define LOCKDIR CONFIG_LOCKDIR' >> policy.h
	@echo '#define LOCKFILE CONFIG_LOCKFILE' >> policy.h
	@echo '#define S_COUNTRY_PREFIX CONFIG_COUNTRY_PREFIX' >> policy.h
	@echo '#define S_AREA_PREFIX CONFIG_AREA_PREFIX' >> policy.h
	@echo '#endif' >> policy.h

clean:
	$(MAKE) -f Makefile clean

distclean:
	$(MAKE) -f Makefile distclean
	rm -f GNUmakefile policy.h areacode

#
# Currently isdnlib.a is used in place.
# When using avon, I4LCONFDIR points to avon data.
# 
# TODO: build a shared version and install it.
#
install-avon:
	$(MAKE) -f Makefile I4LCONFDIR=$(CONFIG_I4LCONFDIR) install

uninstall-avon:
	$(MAKE) -f Makefile I4LCONFDIR=$(CONFIG_I4LCONFDIR) deinstall

ifeq ($(CONFIG_LIB_AREACODE),y)

install:
	$(MAKE) -f Makefile $(BUILDOPTS) all

uninstall:
else
install: install-avon
uninstall: uninstall-avon
endif
