#
# Here's a simplistic makefile. I guess I really should grow up some day and
# start writing horribly complex makefiles like everybody else. Or use IMakefiles
# or autoconf or some other big thing. Writing simple makefiles by hand simply
# isn't geeky enough.
#
# The only things you should need to care about in here are the installation
# destinations, BIN and ICONS below. In some cases, you might be interested
# in controlling various paths that are built into the gentoo binary, like
# for example where to load system group and passwd files from. These are
# defined below, too.
#

# Where to put binary on 'make install'?
BIN	= /usr/local/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	= /usr/local/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	= '"/usr/local/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:/usr/local/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/"'

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

SRC	= ..
VPATH	= $(SRC)
CC	= gcc

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

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

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_possize.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 list_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 odemilbutton.o cmdarg.o colorutil.o\
	  odscrolledbox.o icon_dialog.o

# Clear this (or set it to -O2) to get a much smaller, faster executable.
# NOTE: There is at least one known bug which will occur if gentoo is compiled
# with level 2 optimization (-O2) (see dialog.c).
DEBUG	= -g #-Wno-unused

# Feel free to add any compiler-specific flags you need here.
CFLAGS	:= -ansi -pedantic -Wall -Wmissing-prototypes $(CFLAGS) $(DEBUG) `gtk-config --cflags`

# Add names of any required libraries here (only included in final link).
LIBS	= `gtk-config --libs`

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

gentoo-target:
		@mkdir -p obj
		@cd obj && $(MAKE) -f ../widgets/Makefile widgets
		@cd obj && $(MAKE) -f ../Makefile gentoo

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

gentoo:			$(OBJS) ../Makefile
			$(CC) -o $(SRC)/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_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


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_possize.o:		cfg_possize.c cfg_possize.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


dirpane.o:		dirpane.c dirpane.h graphics/icon_dirparent.xpm

dpformat.o:		dpformat.c dpformat.h

fileutil.o:		fileutil.c fileutil.h

dialog.o:		dialog.c dialog.h

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

list_dialog.o:		list_dialog.c list_dialog.h dialog.h

style_dialog.o:		style_dialog.c style_dialog.h list_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

sizeutil.o:		sizeutil.c sizeutil.h

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

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

# You're going to have to be root to do this!
install:	gentoo-target
		install ./gentoo $(BIN)
		cp gentoorc-example $(HOME)/.gentoorc
#		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));"
		@echo '* Copying gentoogtkrc-example to $$(HOME)/.gentoogtkrc.'

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

clean:
		cd widgets && make clean
		rm -rf gentoo obj core *~

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... ;^)
dist:
		@test -x ./gentoo || echo "Please '$(MAKE)' first!"
		@rm -rf $(DIST) $(DIST).tar.gz gentoo*rc-example
		@mkdir $(DIST)
		@grep -v defpath $(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!"
