######################
# Builds the library #
######################
CC = g++
DEBUG =
AFLAGS = -fPIC
CFLAGS = -fPIC $(DEBUG) -pedantic -Wall -fomit-frame-pointer -O2
LDFLAGS = $(DEBUG)

#################
# Library stuff #
#################
LIBNAME = venus
INCDIR = /usr/include/$(LIBNAME)
LIBDIR = /usr/lib
LIBDYN = lib$(LIBNAME).so.0.5
LIBLD = lib$(LIBNAME).so.0
LIBLDD = lib$(LIBNAME).so
LIBSTA = lib$(LIBNAME).a

#####################################
# Internal includes for the library #
#####################################
INTS =

##############################
# Includes for user programs #
##############################
INCS =	addon.h binedit.h button.h cluster.h config.h desktop.h \
	dialogs.h editor.h fedit.h inpline.h label.h listbox.h \
	listview.h menubar.h progbar.h scrbar.h statline.h stattxt.h \
	window.h \
	venus.h

###################
# Library objects #
###################
OBJS =	addon.o binedit.o button.o cluster.o config.o desktop.o \
	dialogs.o editor.o fedit.o inpline.o label.o listbox.o \
	listview.o menubar.o progbar.o scrbar.o statline.o stattxt.o \
	window.o \
	common.o group.o program.o rect.o system.o view.o engine.o

########################
# All the source files #
########################
SRCS =	addon.cc binedit.cc button.cc cluster.cc config.cc desktop.cc \
	dialogs.cc editor.cc fedit.cc inpline.cc label.cc listbox.cc \
	listview.cc menubar.cc progbar.cc scrbar.cc statline.cc stattxt.cc \
	window.cc \
	common.cc group.cc program.cc rect.cc system.cc view.cc engine.S

####################################################################
# RCS files = library includes + internal includes + sources files #
####################################################################
RCS = $(INCS) $(INTS) $(SRCS)
DISTFILES = Makefile mkdepend $(RCS)

#######################
# Rules to make files #
#######################
.c.o:
	$(CC) $(CFLAGS) -c $<

.cc.o:
	$(CC) $(CFLAGS) -c $<

.S.o:
	$(CC) $(AFLAGS) -c $<

##################
# Files to build #
##################
all: $(LIBDYN) $(LIBSTA)

$(LIBDYN): $(OBJS)
	$(CC) -shared -Wl,-soname,$(LIBLD) -o $(LIBDYN) $(OBJS)

$(LIBSTA): $(OBJS)
	$(AR) rcs $(LIBSTA) $(OBJS)

##################################
# Library uninstalling procedure #
##################################
uninstall:
	rm -f $(LIBDIR)/{$(LIBDYN),$(LIBLD),$(LIBLDD),$(LIBSTA)}
	rm -f -r $(INCDIR)

################################
# Library installing procedure #
################################
install: all uninstall
	install -m 755 {$(LIBDYN),$(LIBSTA)} $(LIBDIR)
	ln -s $(LIBDYN) $(LIBDIR)/$(LIBLD)
	ln -s $(LIBDYN) $(LIBDIR)/$(LIBLDD)
	mkdir $(INCDIR)
	cp $(INCS) $(INCDIR)

.PHONY:	clean ciall coall dist

########################
# Remove garbage files #
########################
clean:
	rm -f $(LIBDYN) $(LIBSTA) *.bak *.o *~

###################
# Store revisions #
###################
ciall:
	ci Makefile $(RCS)

#####################
# Recover revisions #
#####################
coall:
	co $(RCS)

############################
# Package-making procedure #
############################
distdirx = ../$(distdir)/lib

dist: $(DISTFILES)
	@for file in $(DISTFILES); do \
	  ln $$file $(distdirx) \
	    || { echo copying $$f instead; cp -p $$file $(distdirx);}; \
	done

# Automatically generated dependencies
addon.o: addon.cc addon.h window.h venus.h button.h
binedit.o: binedit.cc binedit.h window.h venus.h button.h dialogs.h \
 inpline.h label.h scrbar.h
button.o: button.cc button.h venus.h
cluster.o: cluster.cc cluster.h venus.h
common.o: common.cc venus.h
config.o: config.cc config.h
desktop.o: desktop.cc desktop.h venus.h window.h
dialogs.o: dialogs.cc button.h venus.h dialogs.h window.h inpline.h \
 label.h listbox.h listview.h scrbar.h stattxt.h
editor.o: editor.cc button.h venus.h config.h dialogs.h window.h \
 editor.h cluster.h inpline.h label.h scrbar.h
fedit.o: fedit.cc dialogs.h window.h venus.h fedit.h editor.h \
 cluster.h inpline.h scrbar.h
group.o: group.cc venus.h
inpline.o: inpline.cc inpline.h venus.h
label.o: label.cc label.h venus.h
listbox.o: listbox.cc listbox.h listview.h venus.h
listview.o: listview.cc listview.h venus.h scrbar.h
menubar.o: menubar.cc desktop.h venus.h menubar.h
progbar.o: progbar.cc progbar.h venus.h
program.o: program.cc config.h desktop.h venus.h menubar.h statline.h \
 window.h
rect.o: rect.cc venus.h
scrbar.o: scrbar.cc scrbar.h venus.h
statline.o: statline.cc statline.h venus.h
stattxt.o: stattxt.cc stattxt.h venus.h
system.o: system.cc venus.h
view.o: view.cc button.h venus.h stattxt.h window.h
window.o: window.cc window.h venus.h
engine.o: engine.S
# Makefile ends here
