PREFIX    ?= /usr
GTK_VERSION ?= 3

# Iconos
APP_ICON           := ../images/simple_netaid.ico
BRAND_ICON         := ../images/SimpleNetaid.png
CONNECTED_ICON     := ../images/network-transmit-receive.ico
DISCONNECTED_ICON  := ../images/network-wired-disconnected.ico
VIEW_REFRESH_ICON  := ../images/view-refresh.png
WIRED_ICON         := ../images/wired.png

# Objetos
OBJECTS := userinfo.o netaid-config.o netaid-saved-wifis.o netaid-password-dialog.o \
	netaid-pixbuf.o netaid-active-wifis.o netaid-menu-bar.o netaid-toolbar.o netaid-notebook.o \
	netaid-status-icon.o netaid-window.o main.o

# Configuración de Flags según GTK_VERSION
ifeq ($(GTK_VERSION),2)
    VTE_PKG := vte
    GTK_PKG := gtk+-2.0
else
    VTE_PKG := vte-2.91
    GTK_PKG := gtk+-3.0
endif

# PKG_CONFIG acumulado
PKGS := $(VTE_PKG) glib-2.0 $(GTK_PKG) libubus libubox json-c gdk-x11-3.0 x11

CFLAGS  += `pkg-config --cflags $(PKGS)` \
			-Wno-deprecated-declarations \
			-D_GNU_SOURCE \
			-I..

LDLIBS  += `pkg-config --libs $(PKGS)` \
			-lnetaid -linih \
			 -lubox -lblobmsg_json -ljson-c

PROG := simple-netaid-gtk$(GTK_VERSION)

all: $(PROG)

# Generación de recursos (Pixbufs)
# Se generan antes de compilar netaid-pixbuf.o
netaid-pixbuf.o: netaid-pixbuf.c app_16x16 brand_16x16 connected_16x16 disconnected_16x16 view_refresh_16x16 wired_16x16  
	$(CC) $(CFLAGS) -c $< -o $@

# Regla específica para los csource (puedes añadir los demás iconos aquí)
app_16x16: $(APP_ICON)
	gdk-pixbuf-csource --raw --name=app_16x16 $(APP_ICON) > $@

brand_16x16: $(BRAND_ICON)
	gdk-pixbuf-csource --raw --name=brand_16x16 $(BRAND_ICON) > $@

connected_16x16: $(CONNECTED_ICON)
	gdk-pixbuf-csource --raw --name=connected_16x16 $(CONNECTED_ICON) > $@

disconnected_16x16: $(DISCONNECTED_ICON)
	gdk-pixbuf-csource --raw --name=disconnected_16x16 $(DISCONNECTED_ICON) > $@

view_refresh_16x16: $(VIEW_REFRESH_ICON)
	gdk-pixbuf-csource --raw --name=view_refresh_16x16 $(VIEW_REFRESH_ICON) > $@

wired_16x16: $(WIRED_ICON)
	gdk-pixbuf-csource --raw --name=wired_16x16 $(WIRED_ICON) > $@

# ... repetir para los demás iconos si es necesario ...

# Regla genérica para objetos
%.o: %.c
	$(CC) $(CFLAGS) -c $< -o $@

$(PROG): $(OBJECTS)
	$(CC) -o $@ $^ $(LDFLAGS) $(LDLIBS)

.PHONY: clean cleanall

clean:
	rm -f *.o *~ app_16x16 brand_16x16 connected_16x16 disconnected_16x16 view_refresh_16x16 wired_16x16

cleanall: clean
	rm -f simple-netaid-gtk2 simple-netaid-gtk3
