
put /local/camv/root {..}
put /local/camv/CFLAGS {-I.. -I../src }
put /local/rnd/DEPDEPS {conf_internal.c menu_internal.c }
put /local/rnd/DEPCFLAGS {-I$(LIBRND)/include/librnd/src_3rd}

# static librnd link: need to get all librnd ldlibs
if ?/local/camv/want_static_librnd
then
	put /local/camv/librnd_extra_ldlibs {$(LDFLAGS_LIBRND)}
	put /local/rnd/LDFLAGS_STATIC { $(LDFLAGS_LIBRND_STATIC) }
else
	put /local/camv/librnd_extra_ldlibs {}
	put /local/rnd/LDFLAGS_STATIC {}
end


include {template/cc.tmpasm}
include [@@/local/camv/librnd_template@/debug.tmpasm@]

put /local/camv/OBJS [@
 camv-rnd.o
 data.o
 event.o
 obj_any.o
 obj_arc.o
 obj_line.o
 obj_poly.o
 obj_grp.o
 obj_text.o
 gui_act.o
 draw.o
 export.o
 crosshair.o
 rtree.o
 plug_io.o
 plug_io_act.o
 conf_core.o
 main_act.o
 build_run.o
@]

# e.g.$(ROOT)/src_3rd/ttf2bbox/ttf_map.o
put /local/camv/LIBS_3RD [@
@]

uniq /local/camv/LIBS_3RD

put /local/camv/DEPDEPS {}


#---- modules ----#
# extra rules for modules
put /local/rnd/CLEANFILES {}
put /local/pcb/CLEANRULES {}
put /local/pcb/EXEDEPS {}
put /local/pcb/all {}
put /local/pcb/buildin_init {}
put /local/rnd/rules/install_ {}
put /local/rnd/rules/install {}
put /local/rnd/rules/linstall {}
put /local/rnd/rules/uninstall {}
put /local/rnd/mod/OBJS {}
put /local/rnd/mod/OBJS_C99 {}
put /local/rnd/mod/CONF {}
put /local/rnd/mod/LDFLAGS {}
put /local/rnd/mod/CFLAGS {}
put /local/rnd/mod/YACC {}
put /local/rnd/mod/LEX {}
put /local/rnd/mod/BYACCIC {}
put /local/rnd/mod/UREGLEX {}

put /local/camv/tmpasm/buildin         {../src_plugins/Buildin.tmpasm}
put /local/camv/tmpasm/plugin          {../src_plugins/Plugin.tmpasm}
put /local/camv/tmpasm/disable         {../src_plugins/Disable.tmpasm}
put /local/camv/tmpasm/common_enabled  {../src_plugins/Common_enabled.tmpasm}
put /local/camv/tmpasm/plugin_sphash   [@@/local/camv/librnd_template@/plugin_sphash.tmpasm@]
put /local/camv/tmpasm/plugin_conf     [@@/local/camv/librnd_template@/plugin_conf.tmpasm@]
put /local/camv/tmpasm/plugin_intconf  [@@/local/camv/librnd_template@/plugin_intconf.tmpasm@]
put /local/camv/tmpasm/plugin_intmenu  [@@/local/camv/librnd_template@/plugin_intmenu.tmpasm@]
put /local/camv/tmpasm/comp_var        [@@/local/camv/librnd_template@/comp_var.tmpasm@]

include {../src_plugins/plugins_ALL.tmpasm}

append /local/camv/OBJS ?/local/camv/MOD_OBJS

uniq /local/camv/OBJS

append /local/camv/CFLAGS ?/local/camv/MOD_CFLAGS
append /local/camv/CFLAGS ?/local/camv/librnd_extra_inc
append /local/camv/LDFLAGS ?/local/camv/MOD_LDFLAGS
append /local/camv/LDFLAGS ?/local/camv/librnd_extra_ldf

# workaround: lately gcc doesn't like -ansi and the ((unused)) attribute
# together, which happens in --debug for C99
put /local/camv/C99CFLAGS /local/camv/CFLAGS
append /local/camv/C99CFLAGS  ?/local/rnd/CFLAGS
sub /local/camv/C99CFLAGS {-ansi } {}

### Makefile ###

print [@
ROOT=@/local/camv/root@
include $(ROOT)/Makefile.conf

RNDLIB_LDLIBS = -lrnd-hid -lrnd-poly -lrnd-font -lrnd-core -lrnd-3rd
CC=@cc/cc@
CFLAGS= @/local/camv/C99CFLAGS@ $(CFLAGS_LIBRND)
C89FLAGS=@/local/camv/c89flags@ @/local/rnd/CFLAGS@ @/local/camv/CFLAGS@ $(CFLAGS_LIBRND)
CP=cp
MKDIR=mkdir -p
LDFLAGS=@/local/camv/LDFLAGS@ @?/local/rnd/LDFLAGS@ $(LDFLAGS_LIBRND)
OBJS = @/local/camv/OBJS@
LDLIBS=$(RNDLIB_LDLIBS) @libs/socket/socket/ldflags@ $(LDFLAGS_LIBRND_FUNGW) @/local/camv/librnd_extra_ldlibs@ @/local/rnd/LDFLAGS_STATIC@ @?libs/ldl@ -lm
PLUGDIR=../src_plugins
PLUGIDIR=./plugins

LIBMINUID_CFLAGS=@/local/camv/CFLAGS@ @?/local/rnd/CFLAGS@
LIBMINUID_LDFLAGS=@/local/camv/LDFLAGS@ @?/local/rnd/LDFLAGS@

CLEAN_FILES = camv-rnd conf_core_fields.h buildin.c

all:
	$(MAKE) revcheck
	$(MAKE) all_exe

include $(ROOT)/Makefile.conf

revcheck:
	cd $(ROOT)/scconfig && ./revtest Rev.stamp < Rev.tab

all_exe: camv-rnd @/local/pcb/all@

camv-rnd: $(OBJS) @/local/camv/LIBS_3RD@
	$(CC) -o camv-rnd $(OBJS) $(LDFLAGS) @/local/camv/LIBS_3RD@ $(LDLIBS)

buildin.c: $(PLUGDIR)/.builtin.pups $(PUPLUG)
	cd $(PLUGDIR) && $(PUPLUG) buildin.c "-" < $(PLUGDIR)/.builtin.pups > ../src/buildin.c

conf_core_fields.h: conf_core.h
	$(GENCONF) < conf_core.h > conf_core_fields.h

conf_core.o: conf_core_fields.h


### embedded (internal) version of configs and data files ###

conf_internal.c: conf_core.lht $(CQUOTE)
	$(CQUOTE) -n camv_conf_internal < conf_core.lht > conf_internal.c

menu_internal.c: menu.lht $(CQUOTE)
	$(CQUOTE) -n camv_menu_internal < menu.lht > menu_internal.c

### src_3rd explicit rules ###

### misc ###
map_plugins:
	cd ../src_plugins && ./map_plugins.sh

clean:
	-rm $(OBJS) camv-rnd @/local/rnd/CLEANFILES@

distclean: clean
	-rm buildin.c conf_core_fields.h ../src_plugins/.builtin.pups Makefile conf_internal.c ../config.h ../config.sh ../src_plugins/import_gcode/conf_internal.c Makefile.depgen menu_internal.c ../Makefile.conf

install_camvrnd:
	$(SCCBOX) mkdir -p "$(BINDIR)" "$(LIBDIR)/plugins" "$(CONFDIR)"
	$(SCCBOX) $(HOW) "camv-rnd$(EXE)" "$(BINDIR)/camv-rnd$(EXE)"
	$(SCCBOX) $(HOW) "conf_core.lht" "$(CONFDIR)/conf_core.lht"
	$(SCCBOX) $(HOW) "menu.lht" "$(CONFDIR)/menu.lht"
@/local/rnd/rules/install_@

install:
	$(MAKE) install_camvrnd HOW="install -f"

linstall:
	$(MAKE) install_camvrnd HOW="linstall -f"

uninstall:
	$(MAKE) install_camvrnd HOW="uninstall"

@]


#---- rules ----#

put /local/comp/OBJS_C89 /local/camv/OBJS
put /local/comp/C89FLAGS {$(C89FLAGS)}
include [@@/local/camv/librnd_template@/compile.tmpasm@]

put /local/dep/OUTFN {../src/Makefile.depgen}
put /local/dep/SRCS /local/camv/OBJS
put /local/dep/CFLAGS [@@/local/camv/CFLAGS@ -I@/local/camv/librnd_prefix@/include/librnd/src_3rd@]
gsub /local/dep/SRCS {.o } {.c }
include [@@/local/camv/librnd_template@/cdep.tmpasm@]

print [@

# --- Extra rules from modules ---
@?/local/camv/MOD_RULES@
@?/local/rnd/RULES@

@]


redir {../src_plugins/.builtin.pups}
print [@# Autogenerated by ./configure - do NOT edit - contains the list of buildins
@?/local/camv/buildin_pups@
@]
