#
# Makefile 1.40 2001/12/01 01:17:24 (David Hinds)
#

ifdef TOPDIR
include $(TOPDIR)/Rules.make
endif

ifeq (config.mk, $(wildcard config.mk))
include config.mk
endif

ALL  = modules clients wireless cardmgr flash debug-tools man etc
DIRS = cardmgr flash debug-tools man etc
ifndef CONFIG_PCMCIA
DIRS := modules clients wireless $(DIRS)
endif

# CMO modifs du makefile original
# * changement de la target all en compile
# * changement de la target clean en softclean

## Dbut des nouvelles target

SU-EXEC-$(CONFIG_PCMCIA_HOTPLUG) += build/sbin/cardmgr
SU-EXEC-$(CONFIG_PCMCIA_TESTING) += build/sbin/dump_cis build/sbin/cardctl
SU-EXEC=$(SU-EXEC-y)

all: 
	make compile
	make install

config.out:
	cp default_config config.out
	# make softclean
	# make oldconfig

# la target release prend les fichiers dans build et les met dans le programming kit
release: 
	$(INSTALL) -d $(ROOT_FS_DIR)/etc_ro_fs/init.d
	$(INSTALL) -m 755 -g root -o root build/etc/init.d/pcmcia $(ROOT_FS_DIR)/etc_ro_fs/init.d/pcmcia
	cp -a  build/etc/pcmcia $(ROOT_FS_DIR)/etc_ro_fs/pcmcia
	$(INSTALL) -d $(ROOT_FS_DIR)/etc_ro_fs/pcmcia/
	echo $(SU-EXEC)
	$(INSTALL) -m 755 -g root -o root $(SU-EXEC) $(ROOT_FS_DIR)/sbin

clean:	realclean
	rm -rf build

## Fin des nouvelles target

help:
	@echo "Pick one of the following targets:"
	@echo -e "\tmake config\t\t- configure and check system setup"
	@echo -e "\tmake oldconfig\t\t- reconfigure without prompting"
	@echo -e "\tmake all\t\t- build modules and programs"
	@echo -e "\tmake install\t\t- install modules and programs"
	@echo -e "\tmake clean\t\t- remove old binaries and dependency files"
	@echo -e "\tmake realclean\t\t- start from scratch"

config .prereq.ok: config.out
	@touch config.mk
	@$(MAKE) -s softclean
	
	make oldconfig

oldconfig:
	@touch config.mk
	ln -sf ../pcmcia/config.h include/linux/config.h
	ln -sf ../pcmcia/config.h include/linux/version.h
	ln -sf ../pcmcia/config.h include/linux/compile.h
	if [ ! -d include/static ] ; then \
	  mkdir include/static ;\
	  mkdir include/static/pcmcia ; \
	  ln -sf ../asm include/static/asm ;\
	  ln -sf ../linux include/static/linux ;\
	fi;
	ln -sf ../../pcmcia/ciscode.h include/static/pcmcia/ciscode.h
	ln -sf ../../pcmcia/version.h include/static/pcmcia/version.h
	@$(MAKE) -s softclean
	@./Configure -n

compile:	.prereq.ok kcheck
	@set -e ; for d in $(DIRS) ; do $(MAKE) -C $$d ; done
	@for f in *.mk ; do \
	    if [ $$f != config.mk -a $$f != rules.mk ] ; then \
	    $(MAKE) -f $$f all ; \
	fi ; done

softclean:
	@touch config.mk
	@set -e ; for d in $(ALL) ; do $(MAKE) -C $$d clean ; done
	rm -f .prereq.ok config.mk include/pcmcia/config.h
	rm -f include/linux/modversions.h

realclean:
	rm -f config.out
	@$(MAKE) softclean

install: .prereq.ok kcheck
	@set -e ; for d in $(DIRS) ; do $(MAKE) -C $$d install ; done
	@for f in *.mk ; do \
	    if [ $$f != config.mk -a $$f != rules.mk ] ; then \
	    $(MAKE) -f $$f install ; \
	fi ; done

kcheck:
	@. ./config.out ; \
	if [ "$$CHECK" != "" ] ; then \
	    if [ "`cksum < $$CHECK`" != "$$CKSUM" ] ; then \
		/bin/echo -n "Kernel configuration has changed." ; \
		/bin/echo "  Please re-run 'make config'." ; \
	    	make -C . clean ; \
		make -C . all ; \
	    fi ; \
	fi

