#	Advanced System UI
#	Copyright (c) 2010-2011 Brand Huntsman <brand.huntsman@gmail.com>

CC = gcc
LD = $(CC)
NAME = advanced-systemui

DEPS = xft dbus-1 gconf-2.0
# conic

LIBS = -lX11 -lXpm -lm -lXrandr `pkg-config --libs $(DEPS)` -pthread -lesd
CFLAGS = -O2 -Wall -W -Wno-unused-parameter -I/usr/include/X11/Xft `pkg-config --cflags $(DEPS)` -pthread
LDFLAGS =
PROG = $(NAME)

#################### EDIT HERE

# test build
#include .makefile-test
#CFLAGS += -DTESTLOG

# debug build
#include .makefile-debug

####################

OBJS = main.o config.o window.o dialog.o draw.o text.o hardware.o services.o dbus.o powerbutton.o dsme.o secure.o alarm.o flashlight.o battery_graph.o process_viewer.o governor_dsp.o \
	button_lock.o button_flight_mode.o button_reboot_shutdown.o button_rotate.o button_audio_lock.o button_key_repeat.o button_screenshot.o \
	button_screen_stayslit.o button_screen_autolock.o button_sounds.o button_settings.o button_edit_buttons.o button_edit_widgets.o \
	widget_battery.o widget_brightness.o widget_volume.o widget_bluetooth.o widget_gps.o widget_wifi.o \
	widget_clock.o widget_audio.o widget_desktop.o widget_ssh.o widget_vpn.o widget_usb.o

all: $(PROG)
	$(POSTCMD)

cfg:
	@(cd settings ; make)

sb:
	@(cd statusbar ; make)

clean:
	rm -f $(NAME) $(NAME)-test $(NAME)-debug *.o core default-theme.inc images/white_*.xpm
	@(cd settings ; make clean)
	@(cd statusbar ; make clean)

install: $(NAME)
	strip $(NAME)
	install -o root -g root -m 755 $(NAME) $(DESTDIR)/usr/bin/

	# autobuilder doesn't support -T
	# install -o root -g root -m 755 -T scripts/asui.sh $(DESTDIR)/usr/bin/asui
	cp scripts/asui.sh $(DESTDIR)/usr/bin/asui ; chown root.root $(DESTDIR)/usr/bin/asui ; chmod 755 $(DESTDIR)/usr/bin/asui

	# autobuilder doesn't support -T
	# install -o root -g root -m 755 -T scripts/$(NAME).init.d $(DESTDIR)/etc/init.d/$(NAME)
	cp scripts/$(NAME).init.d $(DESTDIR)/etc/init.d/$(NAME) ; chown root.root $(DESTDIR)/etc/init.d/$(NAME) ; chmod 755 $(DESTDIR)/etc/init.d/$(NAME)
	# install -o root -g root -m 755 -T scripts/$(NAME)-early.init.d $(DESTDIR)/etc/init.d/$(NAME)-early
	cp scripts/$(NAME)-early.init.d $(DESTDIR)/etc/init.d/$(NAME)-early ; chown root.root $(DESTDIR)/etc/init.d/$(NAME)-early ; chmod 755 $(DESTDIR)/etc/init.d/$(NAME)-early

	install -o root -g root -m 644 scripts/$(NAME)*.desktop $(DESTDIR)/usr/share/applications/hildon/
	install -o root -g root -m 644 scripts/asui*_icon.png $(DESTDIR)/usr/share/icons/hicolor/64x64/hildon/
	install -o root -g root -m 644 scripts/$(NAME).sudoers $(DESTDIR)/etc/sudoers.d/

	install -o root -g root -m 644 themes/* $(DESTDIR)/etc/asui-themes/

	install -o root -g root -m 644 scripts/install-notice.txt $(DESTDIR)/usr/share/asui/

	@(cd settings ; make install)
	@(cd statusbar ; make install)

$(PROG): $(OBJS)
	@echo "linking $(PROG)"
	@$(LD) -o $(PROG) $(OBJS) $(LDFLAGS) $(LIBS)

images/white_reboot.xpm: images/make_white.sh images/reboot.xpm images/shutdown.xpm
	@echo "generating white images"
	@(cd images ; ./make_white.sh)

default-theme.inc: themes/default.bw Makefile
	@echo "generating default theme"
	@awk '{first=substr($$0, 0, 1); if(first >= "a" && first <= "z") printf("x_get_color(\"#%s\", \"#%s\"); // %s\n", $$3, $$4, $$1);}' themes/default.bw > default-theme.inc

.c.o:
	@echo "compiling $<"
	@$(CC) $(CFLAGS) -o $@ -c $< -DARCH_$(SBOX_DPKG_INST_ARCH) -DBINNAME="\"$(PROG)\""

main.o: Makefile main.c powerbutton.h							window.h main.h draw.h text.h config.h services.h hardware.h dialog.h dbus.h dsme.h secure.h alarm.h flashlight.h widget_battery.h widget_clock.h widget_brightness.h widget_volume.h button_rotate.h button_reboot_shutdown.h button_screenshot.h
config.o: Makefile config.c										         main.h               config.h            hardware.h
window.o: Makefile window.c default-theme.inc					window.h main.h        text.h config.h services.h hardware.h dialog.h dbus.h dsme.h          alarm.h flashlight.h widget_battery.h widget_clock.h                                     images/*.xpm images/white_reboot.xpm button_audio_lock.h
dialog.o: Makefile dialog.c										window.h main.h draw.h text.h                                dialog.h
draw.o: Makefile draw.c											window.h        draw.h text.h config.h
text.o: Makefile text.c											window.h main.h        text.h
hardware.o: Makefile hardware.c									window.h main.h               config.h services.h hardware.h dialog.h dbus.h dsme.h
services.o: Makefile services.c									         main.h draw.h        config.h services.h hardware.h
dbus.o: Makefile dbus.c											window.h main.h               config.h            hardware.h dialog.h dbus.h dsme.h          alarm.h                                                                                  button_audio_lock.h
powerbutton.o: Makefile powerbutton.c powerbutton.h				window.h main.h               config.h            hardware.h dialog.h dbus.h dsme.h          alarm.h                                                                                  button_audio_lock.h
dsme.o: Makefile dsme.c											window.h main.h               config.h            hardware.h dialog.h dbus.h dsme.h
secure.o: Makefile secure.c										window.h main.h draw.h text.h config.h            hardware.h dialog.h        dsme.h secure.h         flashlight.h widget_battery.h widget_clock.h
alarm.o: Makefile alarm.c										         main.h draw.h text.h config.h services.h hardware.h dialog.h dbus.h                 alarm.h
flashlight.o: Makefile flashlight.c								         main.h draw.h                            hardware.h dialog.h        dsme.h                  flashlight.h
battery_graph.o: Makefile battery_graph.c						window.h main.h draw.h text.h config.h            hardware.h dialog.h                                                                                                                 battery_graph.h
process_viewer.o: Makefile process_viewer.c						window.h main.h draw.h text.h          services.h            dialog.h                                                                                                                 process_viewer.h
governor_dsp.o: Makefile governor_dsp.c							window.h main.h draw.h text.h                     hardware.h dialog.h                                                                                                                 governor_dsp.h

button_lock.o: Makefile button_lock.c							         main.h draw.h text.h config.h            hardware.h          dbus.h
button_flight_mode.o: Makefile button_flight_mode.c				         main.h draw.h text.h config.h services.h hardware.h
button_reboot_shutdown.o: Makefile button_reboot_shutdown.c		window.h main.h draw.h text.h config.h            hardware.h dialog.h                                                                                                                 button_reboot_shutdown.h
button_rotate.o: Makefile button_rotate.c						window.h main.h draw.h        config.h            hardware.h                                                                                                                          button_rotate.h
button_audio_lock.o: Makefile button_audio_lock.c				window.h main.h draw.h text.h config.h            hardware.h                                                                                                                          button_audio_lock.h
button_key_repeat.o: Makefile button_key_repeat.c				window.h main.h draw.h text.h config.h            hardware.h
button_screenshot.o: Makefile button_screenshot.c				window.h main.h draw.h text.h config.h
button_screen_stayslit.o: Makefile button_screen_stayslit.c		window.h main.h draw.h text.h config.h            hardware.h
button_screen_autolock.o: Makefile button_screen_autolock.c		window.h main.h draw.h text.h config.h            hardware.h
button_sounds.o: Makefile button_sounds.c						window.h main.h draw.h text.h config.h
button_settings.o: Makefile button_settings.c					window.h main.h draw.h text.h config.h
button_edit_buttons.o: Makefile button_edit_buttons.c			         main.h draw.h text.h config.h
button_edit_widgets.o: Makefile button_edit_widgets.c			         main.h draw.h text.h config.h

widget_battery.o: Makefile widget_battery.c						window.h main.h draw.h text.h config.h services.h hardware.h dialog.h                                             widget_battery.h                                                    battery_graph.h process_viewer.h governor_dsp.h
widget_brightness.o: Makefile widget_brightness.c				window.h main.h draw.h text.h config.h            hardware.h                                                                                      widget_brightness.h
widget_volume.o: Makefile widget_volume.c						window.h main.h draw.h text.h config.h            hardware.h                                                                                                          widget_volume.h
widget_bluetooth.o: Makefile widget_bluetooth.c					window.h main.h draw.h text.h config.h services.h hardware.h
widget_gps.o: Makefile widget_gps.c								window.h main.h draw.h text.h config.h services.h hardware.h
widget_wifi.o: Makefile widget_wifi.c							window.h main.h draw.h text.h config.h services.h hardware.h
widget_clock.o: Makefile widget_clock.c							window.h main.h draw.h text.h config.h            hardware.h dialog.h        dsme.h                  flashlight.h                  widget_clock.h
widget_audio.o: Makefile widget_audio.c							window.h main.h draw.h text.h config.h services.h
widget_desktop.o: Makefile widget_desktop.c						window.h main.h draw.h text.h config.h services.h
widget_ssh.o: Makefile widget_ssh.c								window.h main.h draw.h text.h config.h services.h
widget_vpn.o: Makefile widget_vpn.c								window.h main.h draw.h text.h config.h services.h
widget_usb.o: Makefile widget_usb.c								window.h main.h draw.h text.h config.h            hardware.h
