
put /local/csch/root {../..}
put /local/csch/CFLAGS {-I. -I.. }
put /local/rnd/DEPDEPS {conf_internal.c defsheet_internal.c menu_default.c }
put /local/rnd/DEPCFLAGS {}

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

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

put /local/csch/OBJS [@
	buffer.o
	conf_core.o
	conf_internal.o
	crosshair.o
	defsheet_internal.o
	draw.o
	draw_xor.o
	emergency.o
	export.o
	extobj_act.o
	file_act.o
	font.o
	plug_io_act.o
	sch-rnd.o
	search.o
	select.o
	select_act.o
	operation.o
	build_run.o
	main_act.o
	menu_default.o
	multi.o
	project.o
	style.o
	sheet.o
	util_sheet.o
@]


put /local/csch/LIBS_3RD [@
	$(ROOT)/src_3rd/libminuid/libminuid.a
	$(ROOT)/src_3rd/libuundo/uundo.o
	$(ROOT)/src_3rd/libuundo/uundo_debug.o
	$(ROOT)/src_3rd/load_cache/load_cache.o
@]

uniq /local/csch/LIBS_3RD

put /local/csch/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/csch/tmpasm/buildin         {../src/plugins/Buildin.tmpasm}
put /local/csch/tmpasm/plugin          {../src/plugins/Plugin.tmpasm}
put /local/csch/tmpasm/disable         {../src/plugins/Disable.tmpasm}
put /local/csch/tmpasm/common_enabled  {../src/plugins/Common_enabled.tmpasm}
put /local/csch/tmpasm/plugin_sphash   [@@/local/csch/librnd_template@/plugin_sphash.tmpasm@]
put /local/csch/tmpasm/plugin_conf     [@@/local/csch/librnd_template@/plugin_conf.tmpasm@]
put /local/csch/tmpasm/plugin_intconf  [@@/local/csch/librnd_template@/plugin_intconf.tmpasm@]
put /local/csch/tmpasm/plugin_intmenu  [@@/local/csch/librnd_template@/plugin_intmenu.tmpasm@]
put /local/csch/tmpasm/comp_var        [@@/local/csch/librnd_template@/comp_var.tmpasm@]

include {../src/plugins/plugins_ALL.tmpasm}

append /local/csch/OBJS ?/local/csch/MOD_OBJS

uniq /local/csch/OBJS

append /local/csch/CFLAGS ?/local/csch/MOD_CFLAGS
append /local/csch/LDFLAGS ?/local/csch/MOD_LDFLAGS

### Makefile ###

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

RNDLIB_LDLIBS = -lrnd-hid -lrnd-font2 -lrnd-poly -lrnd-core -lrnd-3rd @libs/socket/socket/ldflags@
ROOT=@/local/csch/root@
CC=@cc/cc@
CFLAGS=-I. @/local/csch/CFLAGS@ @/local/csch/c89flags@ @?/local/rnd/CFLAGS@ $(CFLAGS_LIBRND) @?/local/csch/librnd_extra_inc@
C89FLAGS=$(CFLAGS)
CP=cp
MKDIR=mkdir -p
LDFLAGS=@/local/csch/LDFLAGS@ @?/local/rnd/LDFLAGS@ $(LDFLAGS_LIBRND) @?/local/csch/librnd_extra_ldf@
OBJS = @/local/csch/OBJS@
LDLIBS=$(RNDLIB_LDLIBS) $(LDFLAGS_LIBRND_FUNGW) @?libs/ldl@ @/local/sch/librnd_extra_ldlibs@ -lm
PLUGDIR=../plugins
PLUGIDIR=./plugins

SRC_3RD_DIR=$(LIBRND_INCDIR)/librnd/src_3rd

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

CLEAN_FILES = sch-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: sch-rnd @/local/pcb/all@

LIBCSCHEM=../libcschem
include $(LIBCSCHEM)/Makefile.objs

sch-rnd: $(OBJS) $(LIBCSCHEM_OBJS) @/local/csch/LIBS_3RD@
	$(CC) -o sch-rnd $(OBJS) $(LIBCSCHEM_OBJS) $(LDFLAGS) @/local/csch/LIBS_3RD@ $(LDLIBS)

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

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

conf_core.o: conf_core_fields.h

$(LIBCSCHEM_OBJS):
	cd $(ROOT)/src/libcschem && $(MAKE) libcschem.a


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

conf_internal.c: sch-rnd-conf.lht $(CQUOTE)
	$(CQUOTE) -n rnd_conf_internal < sch-rnd-conf.lht > conf_internal.c

defsheet_internal.c: default-sheet.lht
	$(CQUOTE) -n default_sheet_internal < default-sheet.lht > defsheet_internal.c

menu_default.c: menu-default.lht $(CQUOTE)
	$(CQUOTE) -n rnd_hidlib_default_embedded_menu <menu-default.lht > menu_default.c

### src_3rd explicit rules ###

$(ROOT)/src_3rd/libminuid/libminuid.a:
	cd $(ROOT)/src_3rd/libminuid && $(MAKE) "CC=$(CC)" LIBMINUID_CFLAGS="$(LIBMINUID_CFLAGS)" LIBMINUID_LDFLAGS="$(LIBMINUID_LDFLAGS)"

$(ROOT)/src_3rd/libuundo/uundo.o $(ROOT)/src_3rd/libuundo/uundo_debug.o:
	cd $(ROOT)/src_3rd/libuundo && $(MAKE) uundo.o uundo_debug.o "CC=$(CC)" "CFLAGS=$(CFLAGS)"

$(ROOT)/src_3rd/load_cache/load_cache.o:
	cd $(ROOT)/src_3rd/load_cache && $(MAKE) load_cache.o "CC=$(CC)" "CFLAGS=$(CFLAGS)"

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

clean:
	-rm $(OBJS) sch-rnd @/local/rnd/CLEANFILES@
	-cd $(ROOT)/src_3rd/libminuid && $(MAKE) clean
	-cd $(ROOT)/src_3rd/libuundo && $(MAKE) clean
	-cd $(ROOT)/src_3rd/load_cache && $(MAKE) clean

distclean: clean
	-rm buildin.c conf_core_fields.h ../plugins/.builtin.pups Makefile defsheet_internal.c conf_internal.c


install_schrnd:
	$(SCCBOX) mkdir -p "$(BINDIR)" "$(DATADIR)" "$(LIBDIR)" "$(LIBDIR)/plugins" "$(CONFDIR)"
	$(SCCBOX) $(HOW) "sch-rnd$(EXE)" "$(BINDIR)/sch-rnd$(EXE)"
	$(SCCBOX) $(HOW) "sch-rnd-conf.lht" "$(CONFDIR)/sch-rnd-conf.lht"
	$(SCCBOX) $(HOW) "menu-default.lht" "$(CONFDIR)/menu-default.lht"
	$(SCCBOX) $(HOW) "default-sheet.lht" "$(DATADIR)/default-sheet.lht"@/local/rnd/rules/install_@

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

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

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

@]


#---- rules ----#

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

put /local/csch/CFLAGS_RND3RD_DIR [@ -isystem $(SRC_3RD_DIR)@]

put /local/dep/OUTFN {../src/sch-rnd/Makefile.depgen}
put /local/dep/SRCS /local/csch/OBJS
put /local/dep/CFLAGS /local/csch/CFLAGS
append /local/dep/CFLAGS /local/csch/CFLAGS_RND3RD_DIR
gsub /local/dep/SRCS {.o } {.c }
include [@@/local/csch/librnd_template@/cdep.tmpasm@]

print [@

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

@]


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