include ../../config.mak

VPATH=$(SRC_PATH)/Applications/Osmo4_wx

# NOTE: -I.. is needed to include config.h
CFLAGS= $(OPTFLAGS) -Wall -I.. -I$(SRC_PATH)/include

ifeq ($(DEBUGBUILD), yes)
CFLAGS+=-g
LDFLAGS+=-g
endif

#common obj
OBJS= wxOsmo4.o wxGPACControl.o fileprops.o

ifeq ($(BUILD_INSTALL), yes)
INSTALL_FLAGS=-DM4_PLUGIN_PATH=\"$(libdir)\"
else
INSTALL_FLAGS=
endif

LINKFLAGS=-L../../bin/gcc -lm4systems

ifeq ($(CONFIG_JS),no)
else
ifeq ($(CONFIG_JS),local)
LINKFLAGS+= -L../../extra_lib/lib/gcc
endif
LINKFLAGS+= -l$(JS_LIBS)
endif

ifeq ($(CONFIG_WIN32),yes)
EXE=.exe
PROG=Osmo4$(EXE)
else
LDFLAGS+= -lpthread -ldl
EXT=
PROG=Osmo4
endif


SRCS := $(OBJS:.o=.cpp) 

all: $(PROG)

#I added m4systems twice because gcc has trouble linking with libs using cross references
Osmo4$(EXE): $(OBJS)
	$(CC) $(LDFLAGS) -o ../../bin/gcc/$@ $(OBJS) $(LINKFLAGS) $(EXTRALIBS) $(WX_LFLAGS)

%.o: %.cpp
	$(CXX) $(CFLAGS) $(INSTALL_FLAGS) $(WX_CFLAGS) -c -o $@ $< 

clean: 
	rm -f $(OBJS) ../../bin/gcc/$(PROG)

install: clean
	make -override BUILD_INSTALL=yes all
	install -c -s -m 755 ../../bin/gcc/Osmo4 "$(bindir)"

uninstall:
	rm -rf $(bindir)/Osmo4

dep: depend

depend:
	rm -f .depend	
	$(CC) -MM $(CFLAGS) $(SRCS) 1>.depend

distclean: clean
	rm -f Makefile.bak .depend



# include dependency files if they exist
#
ifneq ($(wildcard .depend),)
include .depend
endif
