# Makefile for busybox
#
# Copyright (C) 1999-2000 Erik Andersen <andersee@debian.org>
# Copyright (C) 2000 Karl M. Hegbloom <karlheg@debian.org>
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
#

VERSION   := 0.42
BUILDTIME := $(shell TZ=GMT date "+%Y%m%d-%H%M")

OBJECTS   = $(shell ./busybox.sh) messages.o utility.o
CFLAGS    += -DBB_VER='"$(VERSION)"'
CFLAGS    += -DBB_BT='"$(BUILDTIME)"'

ifeq	(${MACHINE_BINARY}, i386)
INSTALLED_BUSYBOX=${DESTBIN}/
else
INSTALLED_BUSYBOX=/bin/
endif
#-----------------------------------------------------------------------------
.PHONY: all
all:	busybox busybox.links
#--------
busybox: $(OBJECTS)
#	$(CC) $(LDFLAGS) -o $@.elf $(OBJECTS) $(LDLIBS)
	$(LD) $(LDFLAGS) -o $@ ${LIBS} $(OBJECTS) $(LDADD)
#	$(CONVERT)
#--------
busybox.links: busybox.def.h busybox.c busybox.mkll
	- ./busybox.mkll | sort >$@
#--------
regexp.o nfsmount.o: %.o: %.h
$(OBJECTS): %.o: busybox.def.h internal.h  %.c
#--------
dmesg.o:	dmesg.c
	${CC} ${CFLAGS} -Wno-traditional -o dmesg.o -c dmesg.c
#--------
# Note: not "ln -sf" because that overwrites existing.
install: all
	${CP} busybox ${DESTBIN}
# Note: this only works if uC-src/bin is owned by user running.
# When "su" goes in, it requires sticky bits and correct ownerships.
	- for i in `cat busybox.links` ; do \
		cd ${DESTBIN}; \
		ln -s ${INSTALLED_BUSYBOX}/busybox $$i ; \
		done
#	- echo for i in `cat busybox.links` ";" do \
#		cd ${DESTBIN}";" \
#		ln -s /bin/busybox '$$i' ";" \
#		done | \
#	    ${SU} "/bin/sh -s"
#--------
.PHONY: test tests
test tests:
	cd tests && $(MAKE) ${MFLAGS} all
#--------
.PHONY: clean
clean:
	- rm -f busybox.links *.gdb *.elf *~ *.o core busybox
	- rm -rf _install
#	- cd tests && $(MAKE) ${MFLAGS} clean
#--------
.PHONY: distclean
distclean: clean
#	- rm -f busybox
#	- cd tests && $(MAKE) ${MFLAGS} distclean
#-----------------------------------------------------------------------------
