SBIN=/sbin
OBJS = error.o module.o symbol.o alloctxt.o str.o \
	config.o fgets.o load_obj.o
MAINS = main.o depmod.o modprobe.o
MAN1DIR=/usr/man/man1
MANS1=depmod.1

.SUFFIXES: .o .obt

#
# If you want to use /usr/bin/nm instead of the "mini-nm" in load_obj.c,
# Add "-DUSE_NM" to DEFINES below.
# Also check "module.c" if your nm doesn't live in /usr/bin
#
# If you want to use the "mini-nm" with BFD, add "-DUSE_BFD" to DEFINES
# below and add '-lbfd -liberty' to LIBS below;
# this requires correct version of /usr/include/bfd.h.
#
# BFD-support (esp. for Alpha) by:
#	Manabe Takashi <manabe@Roy.dsl.tutics.tut.ac.jp>
#

DEFINES=-DPUBLIC= -DPROTECTED= -DPRIVATE=

LIBS=

.c.o:
	g++ -O -I. $(DEFINES) -Wall -c $< -o $@

# To compile small tests at the end of source files
.c.obt:
	@echo $< '->' $@
	@g++ -DTEST -g -I. $(DEFINES) -Wall -c $< -o $@

all: modprobe depmod

modprobe: $(MAINS) $(OBJS)
	cc -s -o modprobe $(MAINS) $(OBJS) $(LIBS)

depmod: modprobe
	ln -fs modprobe depmod

proto:
	proto -p -co -flink.p -c+ -flink.pm -blink.h+link.pm=link.h \
		-bmodprobe.c+link.pm=modprobe.c *.c

clean:
	rm -f *~ *.bak *.o *.obt *.old x modprobe depmod lib.a

cleanall: clean
	rm -f depmod modprobe

install-binaries: all
	install --strip -m 755 -o bin -g bin modprobe $(SBIN)/modprobe
	ln -fs $(SBIN)/modprobe $(SBIN)/depmod

install-docs:
	@set -x ;for i in $(MANS1) ; do install -c $$i $(MAN1DIR) ; done
	ln -f $(MAN1DIR)/depmod.1 $(MAN1DIR)/modprobe.1

install: install-binaries install-docs

doc:
	nadoc -p depmod.template - depmod.txt

# Tests
config: config.obt
	gcc -g -o x config.obt lib.a