top_builddir = ..
top_srcdir = @top_srcdir@
prefix = @prefix@
sysconfdir = @sysconfdir@
exec_prefix = @exec_prefix@
datadir = @datadir@
bindir = @bindir@
libdir = @libdir@
libexecdir = @libexecdir@

CC = @CC@
LIBTOOL = @LIBTOOL@
INSTALL = @INSTALL@

BINDIR = $(DESTDIR)$(bindir)

VPATH = $(top_srcdir)/xwindow/@GUI@:$(top_srcdir)/xwindow

OBJ1 = x_screen_manager.o x_event_source.o x_display.o x_window.o x_screen.o \
	x_xic.o x_color_manager.o x_font_manager.o x_picture.o x_font.o \
	x_color.o x_selection.o x_font_config.o x_main_config.o \
	x_shortcut.o x_bel_mode.o x_sb_mode.o x_mod_meta_mode.o x_font_cache.o \
	x_draw_str.o x_gc.o x_color_cache.o x_dnd.o x_scrollbar.o x_layout.o \
	x_sb_view_factory.o x_simple_sb_view.o x_imagelib.o x_connect_dialog.o \
	x_type_engine.o x_im.o x_im_candidate_screen.o

OBJ2_xlib = x_decsp_font.o x_xim.o x_im_status_screen.o @TYPE_LOADER_OBJ@

OBJ2_win32 = x_gdiobj_pool.o x.o x_im_status_screen.o

OBJ2_fb = x.o x_virtual_kbd.o x_im_status_screen.o

OBJ2_quartz = x.o cocoa.o x_im_status_screen-cocoa.o

OBJ2_console = x.o x_im_status_screen.o

RSOBJ_win32 = winrs.o

OBJ = $(OBJ1) $(OBJ2_@GUI@)

XDISPLAY_DEPENDS_fb = x_display_freebsd.c x_display_linux.c x_display_wscons.c x_display_x68kgrf.c

LIBNAME = libxwindow

# XDATADIR is to avoid conflicting with DATADIR structure in w32api/objidl.h.
CFLAGS = $(CFLAGS_LOCAL) @KIK_CFLAGS@ @MKF_CFLAGS@ @DEB_CFLAGS@ @MATH_CFLAGS@ \
	@IMAGELIB_CFLAGS@ @X_CFLAGS@ @GUI_CFLAGS@ @SSH2_CFLAGS@ @XUTF8_CFLAGS@ @DND_CFLAGS@ \
	@IM_CFLAGS@ @SB_CFLAGS@ @REGEX_CFLAGS@ @CTL_CFLAGS@ @TYPE_CFLAGS@ @FT_CFLAGS@ \
	@IMAGE_CFLAGS@ @TOOLS_CFLAGS@ @OT_LAYOUT_CFLAGS@ @SIXEL_CFLAGS@ @CFLAGS@ @CPPFLAGS@ \
	-DBINDIR=\"$(bindir)\" -DLIBDIR=\"$(libdir)\" -DSYSCONFDIR=\"$(sysconfdir)\" \
	-DLIBEXECDIR=\"$(libexecdir)\" -DXDATADIR=\"$(datadir)\"\
	-I$(top_srcdir)/mlterm -I$(top_srcdir)/xwindow/libotl -I/usr/local/include

LIBTOOL_CC = $(LIBTOOL) --mode=compile $(CC) $(CFLAGS)
LIBTOOL_LINK = $(LIBTOOL) --mode=link $(CC) @LDFLAGS@
LIBTOOL_INSTALL = $(LIBTOOL) --mode=install $(INSTALL)

all: $(LIBNAME).a

debug: $(LIBNAME).a

# If winrs.o is archived to libxwindow.a, connect dialog is not shown correctly.
$(LIBNAME).a: $(OBJ) $(RSOBJ_@GUI@)
	$(LIBTOOL_LINK) -o $(LIBNAME).a $(OBJ:.o=.lo)

.SUFFIXES: .c .o

.c.o:
	$(LIBTOOL_CC) -c $<

.m.o:
	$(LIBTOOL_CC) -c $<

x_display.o: x_display.c $(XDISPLAY_DEPENDS_@GUI@)
	$(LIBTOOL_CC) -c $<

winrs.o: winrs.rs
	cp $(top_srcdir)/contrib/icon/mlterm-icon-win32.ico .
	# windres-2.11.90(included in MSYS-DTK 1.0.1) doesn't accept '-I[DIR]' option.
	windres `echo "@KIK_CFLAGS@"|sed 's/-I/--include-dir /'` @GUI_CFLAGS@ @SSH2_CFLAGS@ $< winrs.o

install:

uninstall:

wc:
	find . -name "*.[ch]" -a \! -name "test_*" | xargs wc -l

clean:
	rm -rf *.a *.la $(OBJ) $(OBJ:.o=.lo) $(RSOBJ_win32) mlterm-icon-win32.ico .libs

distclean: clean
	rm -f Makefile
