DEST	      = .

PRINT	      = cpg -b -c -l55

MAKEFILE    = makefile

#
# These are the objects that are common to the mirrored as
# well as the non-mirrored commands.
#
COMMON_OBJS	= lvdisplay.o \
		lvlnboot.o \
		lvremove.o \
		lvrmboot.o \
		pvchange.o \
		pvcreate.o \
		pvdisplay.o \
		pvmove.o \
		sdstolvm.o \
		vgcfgbackup.o \
		vgcfgrestore.o \
		vgchange.o \
		vgcreate.o \
		vgdisplay.o \
		vgexport.o \
		vgextend.o \
		vgimport.o \
		vgreduce.o \
		vgremove.o \
		vgscan.o

#
# These are the objects for the commands that are different in 
# their mirrored and non-mirrored forms. Lvmerge, lvsplit
# lvsync, vgsync and nomwcsyncd will be empty objects for the 
# non-mirrored case.
#
M_OBJS		= lvchange.o \
		lvcreate.o \
		lvextend.o \
		lvmerge.o \
		lvmmain.o \
		lvreduce.o \
		lvsplit.o \
		lvsync.o \
		nomwcsyncd.o \
		vgsync.o \
		hpux_rel.o

#
# The objects that will be used to build lvchange
#
GEN_OBJS	= $(COMMON_OBJS) $(M_OBJS)


#
# The objects that will be used to build lvchange.mir
#
MIR_OBJS	= $(COMMON_OBJS) $(M_OBJS:.o=_m.o)

#
# All the source files
#
SRCS			= $(GEN_OBJS:.o=.c)

PROGRAMS	= lvchange lvchange.mir lvmmigrate lvmtabmig


HDIR			= ./h
LIBDIR		= ./lib

IDIR			= /etc/

BE				= /Build/9_0

MSGHDRS		= lvm_msg.h
CATFILES	= lvm.cat

HDRS 			= ${HDIR}/debug.h ${HDIR}/dump.h ${HDIR}/logvol.h \
	 			  ${HDIR}/lvmcmds.h ${HDIR}/lvmdefmsg.h ${HDIR}/lvmtab.h \
				  ${HDIR}/maps.h ${HDIR}/options.h ${HDIR}/user_interf.h \
				  ${HDIR}/utilities.h ${HDIR}/lvmraw.h ${HDIR}/${MSGHDRS} \
				  ${HDIR}/hp.h

LIBRARIES		= ${LIBDIR}/liblvmraw.a ${LIBDIR}/liblvmc.a

ILIST			= ${LVMCMDS}

#
# Header file include directories.
#
INCFLAGS		= -Ih -I.

#
# All the flags for by $(CC)
#
LVM_CFLAGS		= ${CFLAGS} ${INCFLAGS} -Aa +e \
				  -D_HPUX_SOURCE -D_2KCHANGES 

#
# Flags for the link-loader. Always link to the archive libraries.
# Specify local copy, since final copies are updated only After
# the programs have been linked.
#
LIBS			= -L$(LIBDIR) -llvmc -llvmraw -lIO

default: all
all:	build_install

#
# The target "build_install" will attempt to copy the libraries into
# their eventual homes "/lib" and "/usr/lib"
#
build_install: ${PROGRAMS} 

#
# The target "build_debug" will copy the libraries into the current 
# directory and add "-L." to the link path.
#
#
build_debug: libs_debug progs_debug

#
# Just make the all the libraries.
#
libs:
	cd $(LIBDIR); $(MAKE) all

#
# If a source file or header files are touched, recompile the objects. 
#
$(GEN_OBJS) $(MIR_OBJS): $(HDRS)

.SUFFIXES:
.SUFFIXES:	.o .s .c _m.o

#
# Make mirrored objects
#
.c_m.o: 
	$(CC) ${LVM_CFLAGS} -DHP_MIR_PRODUCT -c $< -o $@

#
# Make non-mirrored objects
#
.c.o: 
	$(CC) ${LVM_CFLAGS} -c $< -o $@

### PROGRAMS

#
# If an object or library has been remade, relink the objects.
#
lvchange: libs $(GEN_OBJS) 
	$(CC) -o $@ $(GEN_OBJS) $(LIBS) 
		

lvchange.mir: libs $(MIR_OBJS)
	$(CC) -o $@ $(MIR_OBJS) $(LIBS) 

lvmmigrate: libs lvmmigrate.o 
	$(CC) -o $@ lvmmigrate.o $(LIBS) 

lvmtabmig: libs lvmtabmig.o 
	$(CC) -o $@ lvmtabmig.o $(LIBS) 

###

#
# Remove the objects.
#
clean:;		@rm -f $(GEN_OBJS) $(M_OBJS:.o=_m.o) lvmtabmig.o lvmmigrate.o core
					@cd lib; $(MAKE) clean

#
# Remove the objects and executables.
#
clobber:	clean	
					@rm -f $(LVMMIRCMDS) lvchange.mir lvchange.nomir lvmtabmig lvmmigrate tags
					@cd lib; $(MAKE) clobber

#
# Building to use the lvm debug routines
#
libs_debug:
	cd lib; make debug
	cp -f lib/liblvmc.a .
	cp -f lib/liblvmraw.a .

progs_debug:
	$(MAKE) \
		LIBS="-L. -L./lib -L$(BE)/usr/lib -Wl,-a,archive,+n  -llvmc -llvmraw -lIO $(SH_LOAD_NLS)" \
		INCFLAGS="-Ih -I$(BE)/usr/include" \
		CFLAGS="-g -DDEBUG" lvchange lvchange.mir lvmmigrate lvmtabmig

#
# Link the various LVM commands to the main mirrored executable
#
LVMCMDS	= lvdisplay \
		lvlnboot \
		lvremove \
		lvrmboot \
		pvchange \
		pvcreate \
		pvdisplay \
		pvmove \
		sdstolvm \
		vgcfgbackup \
		vgcfgrestore \
		vgchange \
		vgcreate \
		vgdisplay \
		vgexport \
		vgextend \
		vgimport \
		vgreduce \
		vgremove \
		vgscan \
		lvchange \
		lvcreate \
		lvextend \
		lvreduce

MIR_ONLY = lvmerge \
		lvsplit \
		lvsync \
		nomwcsyncd \
		vgsync

LVMMIRCMDS	= $(LVMCMDS) $(MIR_ONLY)

mircmds: 
	-mv -f lvchange lvchange.nomir 
	-for Command in $(LVMMIRCMDS) ; do \
		ln -f lvchange.mir $$Command ; \
	done

cmds: 
	-mv -f lvchange lvchange.nomir 
	-for Command in $(LVMCMDS) ; do \
		ln -f lvchange.nomir $$Command ; \
	done


#
# Miscellaneous stuff
#
echo:;		@echo $(HDRS) $(SRCS)

index:;		@ctags -wx $(HDRS) $(SRCS)

print:;		@$(PRINT) $(HDRS) $(SRCS)

tags:     $(HDRS) $(SRCS)
					@cd lib; make tags
		 			@ctags -t -a lib/tags $(HDRS) $(SRCS)

