# If you don't use CC 
CC       = gcc

# Edit this line if you don't want sithwm to install under /usr.
# Note that $(DESTDIR) is used by the Debian build process.
prefix = $(DESTDIR)/usr

XROOT    = /usr/X11R6
INCLUDES = -I$(XROOT)/include
LDPATH   = -L$(XROOT)/lib
LIBS     = -lX11

DEFINES  = $(EXTRA_DEFINES)
# Configure sithwm by editing the following DEFINES lines.  You can also
# add options by setting EXTRA_DEFINES on the make(1) command line,
# e.g., make EXTRA_DEFINES="-DDEBUG".

# Print debugging messages.
# DEFINES += -DDEBUG	# miscellaneous debugging

CNF=DEATHSTAR
CNFDEATHSTAR= -DDEATHSTAR
CNFSTORMTROOPER= -DSTORMTROOPER
CNFDEV= -DDO_EVENT_LOG

DEFINES += $(CNF$(CNF))

# ----- You shouldn't need to change anything under this line ------ #

confdir=$(prefix)/share/sithwm

version = 1.2.3

distname = sithwm-$(version)

DEFINES += -DVERSION=\"$(version),\ Maul\" $(DEBIAN) -DCONFDIR=\"$(confdir)\" 

OPT_$(CC) = -Os
OPT_cc  = -xO2

EXDEFS= $(OPT_$(CC))
EXDEFS_d = -g

CFLAGS_$(CC) = -std=c99 -Wall
CFLAGS_cc  = 
CFLAGS += $(CFLAGS_$(CC)) $(INCLUDES) $(DEFINES) $(EXDEFS$(D))

LDFLAGS += $(LDPATH) $(LIBS)

HEADERS  = sithwm.h
SRCS     = menu.c client.c events.c main.c misc.c screen.c
OBJS     = $(SRCS:.c=.o)

.PHONY: all install dist debuild clean

all: sithwm

sithwm: $(OBJS)
	$(CC) $(CFLAGS) $(OBJS) -o $@ $(LDFLAGS)

%.o: %.c $(HEADERS)
	$(CC) $(CFLAGS) -c $<

install: sithwm
	if [ -f sithwm.exe ]; then mv sithwm.exe sithwm; fi
	mkdir -p $(prefix)/bin $(prefix)/share/man/man1 $(confdir)
	install -s sithwm $(prefix)/bin
	install sithwm.1 $(prefix)/share/man/man1
	install default.sithwmrc $(confdir)
	@if test -x /usr/bin/update-menus; then \
		echo -------------------------------------------------------------------------;\
		echo 'This appears to be a debian system, trying to install menus, this is a bit of a';\
		echo 'hack (I think), errors after this point may safely be ignored.';\
		cp sithwm.menu-method /etc/menu-methods/sithwm; update-menus; fi

debuild: dist
	-cd ..; rm -rf $(distname)/ $(distname).orig/
	cd ..; mv $(distname).tar.gz sithwm_$(version).orig.tar.gz
	cd ..; tar xfz sithwm_$(version).orig.tar.gz
	cp -a debian ../$(distname)/
	rm -rf ../$(distname)/debian/_darcs/
	cd ../$(distname); debuild

clean:
	rm -f sithwm sithwm.exe $(OBJS)

DISTRDIR=~/www/sithwm/sn
distr:
	cd ..; rm -f $(distname); ln -s sithwm $(distname); tar chvfz $(DISTRDIR)/$(distname).tgz --exclude=TAGS --exclude=CVS --exclude='*.o' --exclude=sithwm $(distname) ; rm -f $(distname)



