#
# First attempt of Makefile.in for use with autoconf. There's still a
# lot todo, but at least it works, sort of... Things that need to be
# done is clean up the install target and add appropriate clean
# targets a la GNU. It also only works if you have gcc, but it might
# not compile with another compiler anyway. Should probably be better 
# to use automake.
#
# NOTE:	gentoo contains code that deals with 64-bit variables and expressions
#	in a couple of places (typically, to handle cumulative directory sizes).
#	This might pose a problem if your environment/compiler does not
#	support it... Sorry about that.
#

prefix		= /usr/local
exec_prefix	= ${prefix}
SHELL		= /bin/sh

# Where to put binary on 'make install'?
BIN	= ${exec_prefix}/bin

# Where to put icons on 'make install'? Note: if you change this,
# gentoo will not find the icons as it starts up. You're going to
# have to alter gentoo's icon path (in the config window, "Paths"
# tab) before it will work.
ICONS	= ${exec_prefix}/lib/gentoo/

#----------------------------------------- Hardcoding paths

# Paths defined here use single qoutes, in order to safely
# "contain" double ones. The double quotes are required to make
# the defined symbols proper C strings, of course.

# Where should gentoo look for the system-global config file?
PTH_CFG	= '"${prefix}/etc"'

# Where should gentoo look for icons, if no path is configured?
# This is typically just "icons", to look in the directory that
# gentoo is started from, followed by some system-wide location
# (which in my world is /usr/local/lib/gentoo/icons).
PTH_ICN = '"icons:${exec_prefix}/lib/gentoo/icons"'

# This path tells gentoo where to look for its GTK+ RC file.
# The name of the file is always ".gentoogtkrc" (with dot), but
# you can put in anywhere you like as long as you tell gentoo
# where to find it. The dollar is double to protect it from make.
PTH_GRC = '"$$HOME/"'

# ---------------------------------------------------------------

CMDS	= cmd_generic.o cmd_activate.o cmd_rescan.o cmd_parent.o cmd_select.o\
	  cmd_copy.o cmd_delete.o cmd_rename.o cmd_chmod.o cmd_move.o cmd_chown.o\
	  cmd_split.o cmd_swap.o cmd_mkdir.o cmd_direnter.o cmd_file.o cmd_copyas.o\
	  cmd_moveas.o cmd_getsize.o cmd_run.o cmd_about.o cmd_quit.o cmd_configure.o\
	  cmd_dpmisc.o cmd_info.o cmd_viewtext.o cmd_dpfocus.o cmd_symlink.o\
	  cmd_menupopup.o cmd_renamere.o cmd_join.o

CFGS	= cfg_gui.o cfg_dirpane.o cfg_shortcuts.o cfg_types.o\
	  cfg_styles.o cfg_paths.o cfg_buttons.o cfg_cmdseq.o\
	  cfg_mount.o cfg_windows.o cfg_controls.o cfg_cmdcfg.o

UTILS	= fileutil.o guiutil.o xmlutil.o strutil.o iconutil.o sizeutil.o

OBJS	= gentoo.o errors.o userinfo.o $(CMDS) $(UTILS) $(CFGS) dirpane.o\
	  dpformat.o dialog.o hash_dialog.o textview.o types.o\
	  styles.o style_dialog.o buttons.o overwrite.o file.o queue.o\
	  cmdseq.o cmdparse.o children.o cmdgrab.o cmdseq_dialog.o progress.o\
	  options.o dirhistory.o shortcuts.o mount.o mntent.o keyboard.o controls.o\
	  cmdseq_config.o color_dialog.o cmdarg.o colorutil.o icon_dialog.o events.o\
	  dpmenu.o window.o\
	  ../widgets/odemilbutton.o ../widgets/odscrolledbox.o ../widgets/odlabel.o

DEBUG	= -g -O2 #-Wno-unused

# Feel free to add any compiler-specific flags you need here.

CC	= gcc

# These flags should work even on files that contain code that deals with
# 64-bit stuff. Sorry for the possibly counter-intuitive name. :)
CFLAGS_64BIT = -Wall -Wmissing-prototypes $(DEBUG) `gtk-config --cflags`\
		-I/usr/X11R6/include -I../widgets -DGENTOO_PACKAGE='"gentoo"'\
		-DGENTOO_LOCALEDIR='"/home/emil/data/projects/gentoo/locale"'

# Most files compile with the flags that are 64-bit compliant, plus some
# more to ensure ANSI compatibility.
CFLAGS	+= $(CFLAGS_64BIT) -ansi -pedantic

# Add names of any required libraries here (only included in final link).
#LIBINTL	= -lintl
LIBS	= -L/usr/lib -L/usr/X11R6/lib `gtk-config --libs` -rdynamic -ldl -lXi -lXext -lX11 -lm $(LIBINTL)

# ----------------------------------------- Targets

gentoo-target:
#		@mkdir -p obj
		$(MAKE) gentoo

# ----------------------------------------- Regular stuff

gentoo:			$(OBJS) Makefile
			$(CC) -o gentoo $(OBJS) $(LIBS)

gentoo.o:		gentoo.c gentoo.h
			$(CC) $(CFLAGS) -DPTH_ICN=$(PTH_ICN) -DPTH_GRC=$(PTH_GRC) -DPTH_PWD=$(PTH_PWD) -DPTH_GRP=$(PTH_GRP) -c $<

errors.o:		errors.c errors.h

userinfo.o:		userinfo.c userinfo.h

buttons.o:		buttons.c buttons.h

cmdseq.o:		cmdseq.c cmdseq.h

cmdparse.o:		cmdparse.c cmdparse.h

cmdgrab.o:		cmdgrab.c cmdgrab.h

cmdarg.o:		cmdarg.c cmdarg.h

children.o:		children.c children.h

cmd_generic.o:		cmd_generic.c cmd_generic.h

cmdseq_dialog.o:	cmdseq_dialog.c cmdseq_dialog.h

cmd_activate.o:		cmd_activate.c cmd_activate.h

cmd_parent.o:		cmd_parent.c cmd_parent.h

cmd_rescan.o:		cmd_rescan.c cmd_rescan.h

cmd_select.o:		cmd_select.c cmd_select.h

cmd_copy.o:		cmd_copy.c

cmd_copyas.o:		cmd_copyas.c

cmd_delete.o:		cmd_delete.c cmd_delete.h cmd_generic.h

cmd_rename.o:		cmd_rename.c cmd_rename.h cmd_generic.h

cmd_renamere.o:		cmd_renamere.c cmd_renamere.h cmd_generic.h

cmd_chmod.o:		cmd_chmod.c cmd_chmod.h cmd_generic.h

cmd_move.o:		cmd_move.c cmd_move.h

cmd_moveas.o:		cmd_moveas.c cmd_moveas.h

cmd_chown.o:		cmd_chown.c cmd_chown.h

cmd_split.o:		cmd_split.c cmd_split.h

cmd_swap.o:		cmd_swap.c cmd_swap.h

cmd_mkdir.o:		cmd_mkdir.c cmd_mkdir.h

cmd_direnter.o:		cmd_direnter.c cmd_direnter.h

cmd_file.o:		cmd_file.c cmd_file.h

cmd_getsize.o:		cmd_getsize.c cmd_getsize.h

cmd_run.o:		cmd_run.c cmd_run.h

cmd_about.o:		cmd_about.c cmd_about.h gentoo.h graphics/icon_gentoo.xpm

cmd_quit.o:		cmd_quit.c cmd_quit.h

cmd_configure.o:	cmd_configure.c cmd_configure.h

cmd_dpmisc.o:		cmd_dpmisc.c cmd_dpmisc.h

cmd_viewtext.o:		cmd_viewtext.c cmd_viewtext.h

cmd_dpfocus.o:		cmd_dpfocus.c cmd_dpfocus.h

cmd_symlink.o:		cmd_symlink.c cmd_symlink.h

cmd_menupopup.o:	cmd_menupopup.c cmd_menupopup.h

cfg_gui.o:		cfg_gui.c cfg_gui.h cfg_module.h gentoo.h
			$(CC) $(CFLAGS) -DPTH_CFG=$(PTH_CFG) -c $<

cfg_dirpane.o:		cfg_dirpane.c cfg_dirpane.h

cfg_buttons.o:		cfg_buttons.c cfg_buttons.h

cfg_shortcuts.o:	cfg_shortcuts.c cfg_shortcuts.h

cfg_types.o:		cfg_types.c cfg_types.h cfg_module.h types.h

cfg_styles.o:		cfg_styles.c cfg_styles.h cfg_module.h styles.h

cfg_paths.o:		cfg_paths.c cfg_paths.h cfg_module.h

cfg_cmdseq.o:		cfg_cmdseq.c cfg_cmdseq.h cfg_module.h

cfg_mount.o:		cfg_mount.c cfg_mount.h cfg_module.h

cfg_windows.o:		cfg_windows.c cfg_windows.h cfg_module.h

cfg_controls.o:		cfg_controls.c cfg_controls.h cfg_module.h

cfg_cmdcfg.o:		cfg_cmdcfg.c cfg_cmdcfg.h cfg_module.h


dpformat.o:		dpformat.c dpformat.h

dpmenu.o:		dpmenu.c dpmenu.h

fileutil.o:		fileutil.c fileutil.h

dialog.o:		dialog.c dialog.h

hash_dialog.o:		hash_dialog.c hash_dialog.h dialog.h

style_dialog.o:		style_dialog.c style_dialog.h dialog.h

icon_dialog.o:		icon_dialog.c icon_dialog.h dialog.h

textview.o:		textview.c textview.h

guiutil.o:		guiutil.c guiutil.h graphics/icon_details.xpm

xmlutil.o:		xmlutil.c xmlutil.h

strutil.o:		strutil.c strutil.h

iconutil.o:		iconutil.c iconutil.h graphics/icon_failed.xpm graphics/icon_empty.xpm

types.o:		types.c types.h

styles.o:		styles.c styles.h

overwrite.o:		overwrite.c overwrite.h

file.o:			file.c file.h

queue.o:		queue.c queue.h

progress.o:		progress.c progress.h

options.o:		options.c options.h gentoo.h

dirhistory.o:		dirhistory.c dirhistory.h

shortcuts.o:		shortcuts.c shortcuts.h

mount.o:		mount.c mount.h

mntent.o:		mntent.c mntent.h

keyboard.o:		keyboard.c keyboard.h

controls.o:		controls.c controls.h

cmdseq_config.o:	cmdseq_config.c cmdseq_config.h

color_dialog.o:		color_dialog.c color_dialog.h dialog.h

colorutil.o:		colorutil.c colorutil.h

events.o:		events.c events.h

window.o:		window.c window.h


# These two files contain 64-bit fiddling, and cannot be compiled with the
# usual CFLAGS, which include -ansi -pedantic. Explicit 64-bit variables
# and code is not, of course, very ANSI compliant (yet -- C9X is coming up).
dirpane.o:		dirpane.c dirpane.h graphics/icon_dirparent.xpm
			$(CC) $(CFLAGS_64BIT) -c ./dirpane.c

sizeutil.o:		sizeutil.c sizeutil.h
			$(CC) $(CFLAGS_64BIT) -c ./sizeutil.c

cmd_info.o:		cmd_info.c cmd_info.h
			$(CC) $(CFLAGS_64BIT) -c ./cmd_info.c

# ----------------------------------------- Installation

# You're going to have to be root to do this!
install:	gentoo-target
		install ./gentoo ${exec_prefix}/bin
		if test ! -r $(HOME)/.gentoorc ; then echo "Installing config to ~/.gentoorc" && cp gentoorc-example $(HOME)/.gentoorc ; fi
#		install icons $(ICONS)
		@echo "No icons or GTK+ RC files installed! Please do so manually by:"
		@echo "* Copying the icons/ subdir to somewhere in $(shell echo $(PTH_ICN));"

# ----------------------------------------- Maintenance

clean:
		rm -rf *.o *~

DIST	= gentoo-$(shell ./gentoo --version)

# I use this to build the release archive. It's really very crude, ugly
# and inefficient, so hopefully you won't have to use it. Just leave the
# pain to me. :)
dist:
		@test -x ./gentoo || echo "Please '$(MAKE)' first!"
		@rm -rf $(DIST) $(DIST).tar.gz gentoo*rc-example
		@mkdir $(DIST)
		@cp $(HOME)/.gentoorc    gentoorc-example
		@cp $(HOME)/.gentoogtkrc gentoogtkrc-example
		@for f in *; do\
			if test $$f != 'obj' && test $$f != 'gentoo' && test $$f != $(DIST); then cp -r $$f $(DIST); fi\
		;done
		@tar -cf $(DIST).tar $(DIST)
		@gzip $(DIST).tar
		@rm -rf $(DIST)
		@echo "Distribution created in $(DIST).tar.gz - don't forget to create diff!"
