append /local/pcb/CFLAGS {-I. -I.. -I../src_3rd -I../src -I../src_3rd/liblihata }
append /local/pcb/LDFLAGS cc/ldflags
append /local/pcb/LDFLAGS cc/rdynamic
append /local/pcb/LDFLAGS ?/local/librnd/cflags_profile
put /local/pcb/DEPCFLAGS {}
put /local/librnd/OBJS_3RDLIB {}
put /local/librnd/OBJS_HIDLIB {}
put /local/librnd/OBJS_C99_HIDLIB_PLG {}
put /local/librnd/OBJS_HIDLIB_PLG {}

if ?libs/script/fungw/presents
then
	append /local/pcb/CFLAGS libs/script/fungw/cflags
	append /local/pcb/LDFLAGS libs/script/fungw/ldflags
	append /local/librnd/LIBRND_3RD_LDFLAGS libs/script/fungw/ldflags
	put /local/librnd/HDRS_GENHT {}
# TODO#GENHT temporary workaround for camv-rnd bug: Makefile.dep uses these
	put /local/librnd/HDRS_GENHT [@
	../src_3rd/genht/ht.h
	../src_3rd/genht/ht.c
	../src_3rd/genht/ht_inlines.h
	../src_3rd/genht/ht_utils.h
	../src_3rd/genht/siphash24.h
	../src_3rd/genht/version.h
	../src_3rd/genht/hash.h
	../src_3rd/genht/htsp.h
	../src_3rd/genht/htss.h
	../src_3rd/genht/htsi.h
	../src_3rd/genht/htpi.h
	../src_3rd/genht/htip.h
	../src_3rd/genht/htpp.h
	@]
else
# no system installed fungw means we need to use local genht
	append /local/librnd/OBJS_3RDLIB [@
	../src_3rd/genht/hash.o
	../src_3rd/genht/htsp.o
	../src_3rd/genht/htss.o
	../src_3rd/genht/htsi.o
	../src_3rd/genht/htpi.o
	../src_3rd/genht/htip.o
	../src_3rd/genht/htpp.o
	@]
# also install all the other headers
	put /local/librnd/HDRS_GENHT [@
	../src_3rd/genht/ht.h
	../src_3rd/genht/ht.c
	../src_3rd/genht/ht_inlines.h
	../src_3rd/genht/ht_utils.h
	../src_3rd/genht/siphash24.h
	../src_3rd/genht/version.h
	@]
# local compilation of fungw objects
	append /local/librnd/OBJS_3RDLIB [@
	../src_3rd/libfungw/fungw.o
	../src_3rd/libfungw/fungw_conv.o
	../src_3rd/libfungw/fungw_ptr.o
	../src_3rd/libfungw/fungw_debug.o
	../src_3rd/libfungw/fungw_call.o
	../src_3rd/libfungwbind/c/fungw_c.o
	@]
	put /local/librnd/LIBRND_3RD_LDFLAGS {}
end

# always install this one, pcb-rnd depends on it
append /local/librnd/HDRS_GENHT [@
	../src_3rd/libfungw/scconfig_hooks.h
@]

# These files are to be generated before make dep is run
put /local/pcb/DEPDEPS { $(LIBRND)/core/hidlib_conf_fields.h buildin.hidlib.c }

include {librnd/scconfig/template/debug.tmpasm}

# main: objects
# hidlib will be a library that provides:
#  - the plugin system
#  - the conf system
#  - some basic/generic types like pcb_coord_t
#  - the HID infra, including DAD
# but nothing else; in short the HID part of pcb-rnd for developing a
# GUI program based on pcb-rnd HIDs.

# These have constructs that are not c89 strictly speaking but are
# effectively c89; typical example is casting a function pointer to a
# data pointer for dlsym().
put /local/librnd/OBJS_C99_HIDLIB [@
	$(LIBRND)/core/fptr_cast.o
@]

append /local/librnd/OBJS_HIDLIB [@
	$(LIBRND)/core/actions.o
	$(LIBRND)/core/anyload.o
	$(LIBRND)/core/base64.o
	$(LIBRND)/core/box.o
	$(LIBRND)/core/box_isc.o
	$(LIBRND)/core/color.o
	$(LIBRND)/core/conf.o
	$(LIBRND)/core/conf_act.o
	$(LIBRND)/core/conf_hid.o
	$(LIBRND)/core/compat_fs.o
	$(LIBRND)/core/compat_lrealpath.o
	$(LIBRND)/core/compat_misc.o
	$(LIBRND)/core/error.o
	$(LIBRND)/core/event.o
	$(LIBRND)/core/file_loaded.o
	$(LIBRND)/core/funchash.o
	$(LIBRND)/core/grid.o
	$(LIBRND)/core/gui_act.o
	$(LIBRND)/core/heap.o
	$(LIBRND)/core/hid.o
	$(LIBRND)/core/hid_attrib.o
	$(LIBRND)/core/hid_cfg.o
	$(LIBRND)/core/hid_cfg_action.o
	$(LIBRND)/core/hid_cfg_input.o
	$(LIBRND)/core/hid_dlg.o
	$(LIBRND)/core/hid_dad.o
	$(LIBRND)/core/hid_dad_tree.o
	$(LIBRND)/core/hid_dad_spin.o
	$(LIBRND)/core/hid_dad_unit.o
	$(LIBRND)/core/hid_init.o
	$(LIBRND)/core/hid_menu.o
	$(LIBRND)/core/hid_nogui.o
	$(LIBRND)/core/hidlib.o
	$(LIBRND)/core/hidlib_conf.o
	$(LIBRND)/core/list_conf.o
	$(LIBRND)/core/main_act.o
	$(LIBRND)/core/misc_util.o
	$(LIBRND)/core/paths.o
	$(LIBRND)/core/rnd_bool.o
	$(LIBRND)/core/rnd_printf.o
	$(LIBRND)/core/plugins.o
	$(LIBRND)/core/pixmap.o
	$(LIBRND)/core/safe_fs.o
	$(LIBRND)/core/tool.o
	$(LIBRND)/core/unit.o
	$(LIBRND)/core/vtc0.o
	buildin.hidlib.o
@]

put /local/librnd/OBJS_POLYLIB [@
	$(LIBRND)/poly/polyarea.o
	$(LIBRND)/poly/polygon1_gen.o
	$(LIBRND)/poly/offset.o
	$(LIBRND)/poly/self_isc.o
	$(LIBRND)/poly/rtree.o
@]

append /local/librnd/OBJS_3RDLIB [@
	../src_3rd/liblihata/parser.o
	../src_3rd/liblihata/dom.o
	../src_3rd/liblihata/dom_list.o
	../src_3rd/liblihata/dom_hash.o
	../src_3rd/liblihata/dom_table.o
	../src_3rd/liblihata/lihata.o
	../src_3rd/liblihata/hash_str.o
	../src_3rd/liblihata/tree.o
	../src_3rd/liblihata/tree_list.o
	../src_3rd/liblihata/tree_hash.o
	../src_3rd/liblihata/tree_table.o
	../src_3rd/liblihata/tree_symlink.o
	../src_3rd/liblihata/tree_path.o
	../src_3rd/liblhtpers/lhtpers.o
	../src_3rd/genvector/gds_char.o
	../src_3rd/genvector/vtp0.o
	../src_3rd/genvector/vtd0.o
	../src_3rd/genvector/vts0.o
	../src_3rd/genvector/vti0.o
	../src_3rd/genvector/vtl0.o
	../src_3rd/libulzw/libulzw_comp.o
	../src_3rd/libulzw/libulzw_decomp.o
	../src_3rd/genregex/regex_sei.o
	../src_3rd/genregex/regex_se.o
	../src_3rd/genregex/regex.o
	../src_3rd/ureglex/exec.o
	../src_3rd/ureglex/strtree_exec.o
	../src_3rd/genlist/genadlist.o
	../src_3rd/genlist/genlistalloc.o
	../src_3rd/libualloc/slab_impl.o
	../src_3rd/libualloc/slabap_impl.o
	../src_3rd/libualloc/stackd_impl.o
	../src_3rd/libualloc/stackdnp_impl.o
	../src_3rd/libualloc/stacks_impl.o
	../src_3rd/libualloc/mcache_impl.o
	../src_3rd/libualloc/acache_impl.o
	../src_3rd/libualloc/buddy_impl.o
	../src_3rd/libualloc/buddy_debug.o
	../src_3rd/libualloc/libualloc.o
@]

# these need special rules for compilation
append /local/librnd/OBJS_3RDLIB_NOAUTO [@
	../src_3rd/puplug/libpuplug.a
@]

put /local/librnd/OBJS_C99 /local/librnd/OBJS_C99_HIDLIB
put /local/librnd/OBJS /local/librnd/OBJS_HIDLIB
append /local/librnd/OBJS /local/librnd/OBJS_3RDLIB
append /local/librnd/OBJS /local/librnd/OBJS_POLYLIB


#---- modules ----#
# extra rules for modules
put /local/pcb/RULES {}
put /local/pcb/CLEANFILES {test-rnd$(EXE)}
put /local/librnd/CLEANRULES {}
put /local/librnd/all {}
put /local/librnd/buildin_init {}
put /local/pcb/rules/install_ {}
put /local/pcb/rules/install {}
put /local/pcb/rules/linstall {}
put /local/pcb/rules/uninstall {}
put /local/pcb/mod/OBJS {}
put /local/pcb/mod/OBJS_C99 {}
put /local/pcb/mod/CONF {}
put /local/pcb/mod/LDFLAGS {}
put /local/pcb/mod/CFLAGS {}
put /local/pcb/mod/YACC {}
put /local/pcb/mod/LEX {}
put /local/pcb/mod/BYACCIC {}
put /local/pcb/mod/UREGLEX {}

put /local/librnd/tmpasm/buildin         {../src/librnd/plugins/Buildin.tmpasm}
put /local/librnd/tmpasm/plugin          {../src/librnd/plugins/Plugin.tmpasm}
put /local/librnd/tmpasm/disable         {../src/librnd/plugins/Disable.tmpasm}
put /local/librnd/tmpasm/common_enabled  {../src/librnd/plugins/Common_enabled.tmpasm}
put /local/librnd/tmpasm/plugin_sphash   {librnd/scconfig/template/plugin_sphash.tmpasm}
put /local/librnd/tmpasm/plugin_conf     {librnd/scconfig/template/plugin_conf.tmpasm}
put /local/librnd/tmpasm/plugin_intconf  {librnd/scconfig/template/plugin_intconf.tmpasm}
put /local/librnd/tmpasm/plugin_intmenu  {librnd/scconfig/template/plugin_intmenu.tmpasm}

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

# Lesstif requires that -lXm is before -lXt or else there is a runtime BadWindow error
order /local/pcb/LDFLAGS {-lXm} {before} {-lXt}

# ---- logic ----


# Clean up variables
uniq /local/librnd/OBJS
uniq /local/librnd/OBJS_C99
uniq /local/librnd/OBJS_3RDLIB
uniq /local/librnd/OBJS_3RDLIB_NOAUTO
uniq /local/librnd/OBJS_POLYLIB
uniq /local/librnd/OBJS_HIDLIB
uniq /local/librnd/OBJS_C99_HIDLIB
uniq /local/librnd/OBJS_HIDLIB_PLG
uniq /local/librnd/OBJS_C99_HIDLIB_PLG
uniq /local/librnd/OBJS_UTIL
uniq /local/pcb/CFLAGS
uniq /local/librnd/CFLAGS_GENERIC
uniq /local/librnd/LIBS
uniq /local/librnd/LIBS_PRE
uniq /local/librnd/LIBS_3RD
uniq /local/pcb/CLEANFILES
uniq /local/pcb/DISTCLEANFILES
uniq /local/librnd/CLEANRULES
uniq /local/librnd/all
put /local/librnd/SRCS /local/librnd/OBJS 
append /local/librnd/SRCS ?/local/librnd/OBJS_C99
append /local/librnd/SRCS ?/local/librnd/OBJS_3RDLIB
append /local/librnd/SRCS ?/local/librnd/OBJS_POLYLIB
append /local/librnd/SRCS ?/local/librnd/OBJS_HIDLIB
gsub /local/librnd/SRCS {.o } {.c }

# apple requires multiple "-framework something" instead of -lsomething
# we need to keep all -frameworks but uniq would keep only the first if it
# is a word on its own
gsub /local/pcb/LDFLAGS {-framework } {-framework-}
uniq /local/pcb/LDFLAGS
gsub /local/pcb/LDFLAGS {-framework-} {-framework }


# dummy ranlib is echo
switch ?/target/fstools/ranlib
	case {^$}
		put /local/librnd/ranlib {echo}
		end
	default
		put /local/librnd/ranlib /target/fstools/ranlib
		end
end

# Makefile, static
print [@
# *** DO NOT EDIT THIS FILE ***
# This file has been generated from Makefile.in by configure
# *** DO NOT EDIT THIS FILE ***

ROOT=..

# plugin source
LIBRND_PLUGDIR=$(ROOT)/src/librnd/plugins
PLUGDIR=$(LIBRND_PLUGDIR)

# plugin source install - so that pcb-rnd runs from source properly
PLUGIDIR=plugins

# src_3rd dir for the lib_ wrapper plugins
SRC_3RD_DIR=$(ROOT)/src_3rd

# where to install src_3rd files that are diverted
INST_DUMMY=/tmp/librnd-dummy

OBJS=@/local/librnd/OBJS@ @/local/librnd/OBJS_3RDLIB_NOAUTO@
OBJS_C99=@/local/librnd/OBJS_C99@
OBJS_POLYLIB=@/local/librnd/OBJS_POLYLIB@
OBJS_3RDLIB=@/local/librnd/OBJS_3RDLIB@ ../src_3rd/puplug/*.o
OBJS_HIDLIB=@/local/librnd/OBJS_HIDLIB@
OBJS_C99_HIDLIB=@/local/librnd/OBJS_C99_HIDLIB@
OBJS_HIDLIB_PLG=@/local/librnd/OBJS_HIDLIB_PLG@
OBJS_C99_HIDLIB_PLG=@/local/librnd/OBJS_C99_HIDLIB_PLG@
OBJS_UTIL=@/local/librnd/OBJS_UTIL@
SRCS=@/local/librnd/SRCS@
CFLAGS=@?cc/argstd/std_c99@ @/local/pcb/CFLAGS@
C89FLAGS=@/local/librnd/c89flags@ @/local/pcb/CFLAGS@
LDFLAGS=@/local/pcb/LDFLAGS@
LIBS_PRE=@/local/librnd/LIBS_PRE@
LIBS=@/local/librnd/LIBS@ @libs/socket/socket/ldflags@ -lm @?/target/libs/ldl@
LIBS_3RD=@/local/librnd/LIBS_3RD@
CLEANFILES=@/local/pcb/CLEANFILES@
CLEANRULES=@/local/librnd/CLEANRULES@
CC=@/target/cc/cc@
AR=@/target/fstools/ar@
RANLIB=@/local/librnd/ranlib@
HOSTCC=@/host/cc/cc@
CQUOTE=$(ROOT)/scconfig/cquote
ARU=$(ROOT)/scconfig/aru
SPHASH_PATH=$(ROOT)/src_3rd/sphash
SPHASH=$(SPHASH_PATH)/sphash
PUPLUG=$(ROOT)/src_3rd/puplug/util/puplug
GENLIST_CFLAGS=@/local/librnd/CFLAGS_GENERIC@
GENLIST_LDFLAGS=@cc/ldflags@
LIBRND=../src/librnd
LIBRND_LIBDIR=../src/librnd

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

include $(ROOT)/Makefile.conf

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

all_exe: $(SPHASH) test-rnd$(EXE) @/local/librnd/all@

test-rnd.o: $(LIBRND)/core/buildin.hidlib.h

test-rnd$(EXE): $(OBJS) test-rnd.o $(OBJS_C99) $(LIBS_3RD)
	$(CC) test-rnd.o $(OBJS) $(OBJS_C99) -o test-rnd$(EXE) $(LIBS_PRE) $(LDFLAGS) $(LIBS)

### librnd, hidlib ####

OBJS_HIDLIB_ALL = $(OBJS_HIDLIB_PLG) $(OBJS_C99_HIDLIB_PLG) $(OBJS_HIDLIB) $(OBJS_C99_HIDLIB)
DEPS_HIDLIB_ALL = $(OBJS_HIDLIB_ALL) $(LIBS_3RD) $(LIBRND)/core/buildin.hidlib.h
@]

switch cc/soname
	case {^$} print [@
SONAME_HID=
SONAME_3RD=
SONAME_POLY=
@]
	end;
	default print [@
SONAME_HID=@cc/soname@librnd-hid.so.$(PCB_RND_VER_MAJOR)
SONAME_3RD=@cc/soname@librnd-3rd.so.$(PCB_RND_VER_MAJOR)
SONAME_POLY=@cc/soname@librnd-poly.so.$(PCB_RND_VER_MAJOR)
@]
	end;
end

print [@

librnd-hid.a: $(DEPS_HIDLIB_ALL)
	$(ARU) $(AR) rvu librnd-hid.a $(OBJS_HIDLIB_ALL)
	$(RANLIB) librnd-hid.a

librnd-3rd.a: $(OBJS_3RDLIB)
	$(ARU) $(AR) rvu librnd-3rd.a $(OBJS_3RDLIB)
	$(RANLIB) librnd-3rd.a

librnd-poly.a: $(OBJS_POLYLIB)
	$(ARU) $(AR) rvu librnd-poly.a $(OBJS_POLYLIB)
	$(RANLIB) librnd-poly.a

# Note: .so depends on .a because $(ARU) renames some object files temporarily
# so building the .so and the .a shouldn't be done in parallel

librnd-hid.so.$(PCB_RND_VER): $(DEPS_HIDLIB_ALL) librnd-hid.a
	$(CC) @?cc/ldflags_dynlib@ @?cc/so_undefined@ $(SONAME_HID) -o librnd-hid.so.$(PCB_RND_VER) $(OBJS_HIDLIB_ALL) $(LDFLAGS)

librnd-3rd.so.$(PCB_RND_VER): $(OBJS_3RDLIB) librnd-3rd.a
	$(CC) @?cc/ldflags_dynlib@ @?cc/so_undefined@ $(SONAME_3RD) -o librnd-3rd.so.$(PCB_RND_VER) $(OBJS_3RDLIB) $(LDFLAGS) @/local/librnd/LIBRND_3RD_LDFLAGS@ @?libs/ldl@ -lm

librnd-poly.so.$(PCB_RND_VER): $(OBJS_POLYLIB) librnd-poly.a
	$(CC) @?cc/ldflags_dynlib@ @?cc/so_undefined@ $(SONAME_POLY) -o librnd-poly.so.$(PCB_RND_VER) $(OBJS_POLYLIB) $(LDFLAGS) -lm


# these are required in case librnd is used from source checkout in dynamic
# lib mode

librnd-hid.so: librnd-hid.so.$(PCB_RND_VER)
	$(SCCBOX) ln -f librnd-hid.so.$(PCB_RND_VER) librnd-hid.so
	$(SCCBOX) ln -f librnd-hid.so.$(PCB_RND_VER) librnd-hid.so.$(PCB_RND_VER_MAJOR)

librnd-3rd.so: librnd-3rd.so.$(PCB_RND_VER)
	$(SCCBOX) ln -f librnd-3rd.so.$(PCB_RND_VER) librnd-3rd.so
	$(SCCBOX) ln -f librnd-3rd.so.$(PCB_RND_VER) librnd-3rd.so.$(PCB_RND_VER_MAJOR)

librnd-poly.so: librnd-poly.so.$(PCB_RND_VER)
	$(SCCBOX) ln -f librnd-poly.so.$(PCB_RND_VER) librnd-poly.so
	$(SCCBOX) ln -f librnd-poly.so.$(PCB_RND_VER) librnd-poly.so.$(PCB_RND_VER_MAJOR)

@]


if /local/librnd/disable_so
then
	print [@
# .so files are disabled
HIDLIB_CLEAN_FILES_SO=
@]
else
	print [@
HIDLIB_CLEAN_FILES_SO=\
	librnd-hid.so.$(PCB_RND_VER) \
	librnd-3rd.so.$(PCB_RND_VER) \
	librnd-poly.so.$(PCB_RND_VER)

HIDLIB_CLEAN_FILES_SO_SY=\
	librnd-hid.so \
	librnd-3rd.so \
	librnd-poly.so
@]
end

print [@
HIDLIB_CLEAN_FILES_A=\
	librnd-hid.a \
	librnd-3rd.a \
	librnd-poly.a

HIDLIB_CLEAN_FILES=$(HIDLIB_CLEAN_FILES_A) $(HIDLIB_CLEAN_FILES_SO) $(HIDLIB_CLEAN_FILES_SO_SY)

librnd: $(HIDLIB_CLEAN_FILES) ../src_3rd/genht/version.h

librnd_a: $(HIDLIB_CLEAN_FILES_A) ../src_3rd/genht/version.h

../src_3rd/genht/version.h:
	cd ../src_3rd/genht && $(MAKE) version.h

### pcb-rnd infra ###

$(SPHASH): $(SPHASH_PATH)/sphash.c
	$(HOSTCC) $(SPHASH_PATH)/sphash.c -o $(SPHASH)

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

buildin.h: $(LIBRND_PLUGDIR)/.builtin.pups $(PUPLUG)
	$(PUPLUG) buildin.h > buildin.h

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

$(LIBRND)/core/buildin.hidlib.h: $(LIBRND_PLUGDIR)/.builtin.hidlib.pups $(PUPLUG)
	$(PUPLUG) buildin.h > $(LIBRND)/core/buildin.hidlib.h

@]

if sys/cross
then
print [@
../src_3rd/puplug/libpuplug.a $(PUPLUG):
	cd ../src_3rd/puplug && make libpuplug.a CC=$(CC)
	cd ../src_3rd/puplug && make util/puplug CC=$(HOSTCC) PUP_O_PREFIX=-host
@]
else
print [@
../src_3rd/puplug/libpuplug.a $(PUPLUG):
	cd ../src_3rd/puplug && make libpuplug.a util/puplug
@]
end

print [@
##### module rules begin #####

@/local/pcb/RULES@

##### module rules end #####

pcblib_DATA=
EXTRA_DIST=

../src/librnd/core/hidlib_conf_fields.h: $(LIBRND)/core/hidlib_conf.h $(ROOT)/doc/conf/tree/rc.html
	AWK=@/host/fstools/awk@ $(LIBRND)/scconfig/gen_conf.sh < $(LIBRND)/core/hidlib_conf.h > $(LIBRND)/core/hidlib_conf_fields.h

$(ROOT)/doc/conf/tree/rc.html: $(LIBRND)/core/hidlib_conf.h
	cat $(LIBRND)/core/hidlib_conf.h | AWK=@/host/fstools/awk@ $(LIBRND)/scconfig/gen_conf.sh $(ROOT)/doc/conf/tree > /dev/null

FORCE:

DISTCLEANFILES = librnd/config.h Makefile.depgen buildin.hidlib.c $(LIBRND)/core/buildin.hidlib.h $(LIBRND)/core/compat_inc.h $(LIBRND)/core/hidlib_conf_fields.h ../src/librnd/plugins/.builtin.pups ../src/librnd/plugins/.builtin.hidlib.pups $(LIBRND)/core/librnd.mak $(LIBRND)/plugin.state @/local/pcb/DISTCLEANFILES@

clean: $(CLEANRULES)
	$(SCCBOX) rm -f -q  pcb-rnd $(HIDLIB_CLEAN_FILES) $(OBJS) $(OBJS_C99) $(CLEANFILES)

distclean: FORCE
	$(SCCBOX) rm -f -q  $(DISTCLEANFILES) plugins

install_librnd: librnd
	$(MAKE) install_librnd_ LIBDIR=$(HL_LIBDIR)/librnd3

install_librnd_:
	$(SCCBOX) mkdir -p "$(HL_LIBDIR)/librnd3/plugins" "$(HL_LIBDIR)/librnd3/scconfig/template" "$(HL_INCDIR)/core" "$(HL_INCDIR)/poly" "$(HL_INCDIR)/scconfig" "$(HL_INCDIR)/src_3rd/liblihata" "$(HL_INCDIR)/src_3rd/libualloc" "$(HL_INCDIR)/src_3rd/liblhtpers" "$(HL_INCDIR)/src_3rd/puplug" "$(HL_INCDIR)/src_3rd/libfungw" "$(HL_INCDIR)/src_3rd/genvector" "$(HL_INCDIR)/src_3rd/genregex" "$(HL_INCDIR)/src_3rd/ureglex" "$(HL_INCDIR)/src_3rd/genrtree"  "$(HL_INCDIR)/src_3rd/libulzw"  "$(HL_INCDIR)/src_3rd/genht" "$(HL_INCDIR)/src_3rd/libfungwbind/c" "$(HL_SHAREDIR)" "$(HL_INCDIR)/plugins/lib_hid_common" "$(HL_INCDIR)/plugins/lib_wget" "$(HL_INCDIR)/plugins/lib_exp_text" "$(HL_INCDIR)/plugins/lib_exp_pixmap"
	$(SCCBOX) $(HOW) "librnd-hid.a" "$(HL_LIBDIR)/librnd-hid.a"
	$(SCCBOX) $(HOW) "librnd-3rd.a" "$(HL_LIBDIR)/librnd-3rd.a"
	$(SCCBOX) $(HOW) "librnd-poly.a" "$(HL_LIBDIR)/librnd-poly.a"
	$(SCCBOX) $(HOW) "$(LIBRND)/core/librnd.mak" "$(HL_SHAREDIR)/librnd.mak"
	$(SCCBOX) $(HOW) "$(LIBRND)/plugin.state" "$(HL_SHAREDIR)/plugin.state"
	$(SCCBOX) $(HOW) "../config.h" "$(HL_INCDIR)/core/config.h"
	$(SCCBOX) $(HOW) "../src_3rd/puplug/util/puplug" "$(HL_LIBDIR)/librnd3/puplug"
	$(SCCBOX) $(HOW) "$(SPHASH)" "$(HL_LIBDIR)/librnd3/sphash"
	$(SCCBOX) $(HOW) "librnd/scconfig/gen_conf.sh" "$(HL_LIBDIR)/librnd3/scconfig/gen_conf.sh"
	$(SCCBOX) $(HOW) "../scconfig/cquote"                              "$(HL_LIBDIR)/librnd3/scconfig/cquote"
	$(SCCBOX) $(HOW) "../scconfig/sccbox"                              "$(HL_LIBDIR)/librnd3/scconfig/sccbox"
	$(SCCBOX) $(HOW) "librnd/scconfig/template/cdep.tmpasm"            "$(HL_LIBDIR)/librnd3/scconfig/template/cdep.tmpasm"
	$(SCCBOX) $(HOW) "librnd/scconfig/template/comp_var.tmpasm"        "$(HL_LIBDIR)/librnd3/scconfig/template/comp_var.tmpasm"
	$(SCCBOX) $(HOW) "librnd/scconfig/template/compile.tmpasm"         "$(HL_LIBDIR)/librnd3/scconfig/template/compile.tmpasm"
	$(SCCBOX) $(HOW) "librnd/scconfig/template/debug.tmpasm"           "$(HL_LIBDIR)/librnd3/scconfig/template/debug.tmpasm"
	$(SCCBOX) $(HOW) "librnd/scconfig/template/plugin_conf.tmpasm"     "$(HL_LIBDIR)/librnd3/scconfig/template/plugin_conf.tmpasm"
	$(SCCBOX) $(HOW) "librnd/scconfig/template/plugin_intconf.tmpasm"  "$(HL_LIBDIR)/librnd3/scconfig/template/plugin_intconf.tmpasm"
	$(SCCBOX) $(HOW) "librnd/scconfig/template/plugin_intmenu.tmpasm"  "$(HL_LIBDIR)/librnd3/scconfig/template/plugin_intmenu.tmpasm"
	$(SCCBOX) $(HOW) "librnd/scconfig/template/plugin_sphash.tmpasm"   "$(HL_LIBDIR)/librnd3/scconfig/template/plugin_sphash.tmpasm"
	$(SCCBOX) $(HOW) "librnd/scconfig/hooks_common.h" "$(HL_INCDIR)/scconfig/hooks_common.h"
	$(SCCBOX) $(HOW) "librnd/scconfig/rnd_hook_detect.h" "$(HL_INCDIR)/scconfig/rnd_hook_detect.h"
	$(SCCBOX) $(HOW) "librnd/scconfig/plugin_3state.h" "$(HL_INCDIR)/scconfig/plugin_3state.h"
	$(SCCBOX) $(HOW) "$(LIBRND)/core/buildin.hidlib.h" "$(HL_INCDIR)/core/buildin.hidlib.h"
	$(SCCBOX) $(HOW) "librnd/plugins/map_plugins.sh" "$(HL_LIBDIR)/librnd3/plugins/map_plugins.sh"
	cd ../src_3rd/puplug && $(MAKE) install_hdr_ MKDR="../$(SCCBOX) mkdir -p" INST="../$(SCCBOX) $(HOW)" INCDIR="$(HL_INCDIR)/src_3rd/puplug"@/local/pcb/rules/install_@@]

if /local/librnd/disable_so
then
	print [@
@]
else
	print [@
	$(SCCBOX) $(HOW) "librnd-hid.so.$(PCB_RND_VER)" "$(HL_LIBDIR)/librnd-hid.so.$(PCB_RND_VER)"
	$(SCCBOX) $(HOW) "librnd-3rd.so.$(PCB_RND_VER)" "$(HL_LIBDIR)/librnd-3rd.so.$(PCB_RND_VER)"
	$(SCCBOX) $(HOW) "librnd-poly.so.$(PCB_RND_VER)" "$(HL_LIBDIR)/librnd-poly.so.$(PCB_RND_VER)"
@]
end

# rndlib: build a list of header files to be installed with the hidlib
put /local/librnd/HDRS_3RDLIB /local/librnd/OBJS_3RDLIB
put /local/librnd/HDRS_HIDLIB /local/librnd/OBJS_HIDLIB
append /local/librnd/HDRS_HIDLIB /local/librnd/OBJS_POLYLIB
uniq /local/librnd/HDRS_3RDLIB
uniq /local/librnd/HDRS_HIDLIB
gsub /local/librnd/HDRS_HIDLIB {.o } {.h }
gsub /local/librnd/HDRS_3RDLIB {.o } {.h }
append /local/librnd/HDRS_3RDLIB /local/librnd/HDRS_GENHT

# rndlib: corner case: some headers are not derived from the objects
sub /local/librnd/HDRS_HIDLIB {$(LIBRND)/core/hid_dlg.h } {}
sub /local/librnd/HDRS_HIDLIB {$(LIBRND)/core/conf_act.h } {}
sub /local/librnd/HDRS_HIDLIB {$(LIBRND)/core/gui_act.h } {}
sub /local/librnd/HDRS_HIDLIB {$(LIBRND)/core/main_act.h } {}
append /local/librnd/HDRS_HIDLIB {$(LIBRND)/config.h $(LIBRND)/core/global_typedefs.h $(LIBRND)/core/globalconst.h $(LIBRND)/core/math_helper.h $(LIBRND)/core/buildin.hidlib.h $(LIBRND)/core/hid_inlines.h $(LIBRND)/core/rotate.h $(LIBRND)/core/fptr_cast.h $(LIBRND)/core/safe_fs_dir.h $(LIBRND)/core/compat_inc.h $(LIBRND)/poly/rtree2_compat.h $(LIBRND)/core/color_cache.h }
append /local/librnd/HDRS_HIDLIB {$(LIBRND)/plugins/lib_hid_common/dialogs_conf.h $(LIBRND)/plugins/lib_hid_common/xpm.h $(LIBRND)/plugins/lib_hid_common/dlg_comm_m.h $(LIBRND)/plugins/lib_hid_common/place.h $(LIBRND)/plugins/lib_hid_common/toolbar.h $(LIBRND)/plugins/lib_hid_common/dlg_pref.h $(LIBRND)/plugins/lib_hid_common/zoompan.h $(LIBRND)/plugins/lib_hid_common/dlg_export.h }
append /local/librnd/HDRS_HIDLIB {$(LIBRND)/plugins/lib_wget/lib_wget.h }
append /local/librnd/HDRS_HIDLIB {$(LIBRND)/plugins/lib_exp_text/draw_eps.h }
append /local/librnd/HDRS_HIDLIB {$(LIBRND)/plugins/lib_exp_text/draw_ps.h }
append /local/librnd/HDRS_HIDLIB {$(LIBRND)/plugins/lib_exp_text/draw_svg.h }
append /local/librnd/HDRS_HIDLIB {$(LIBRND)/plugins/lib_exp_text/media.h }
append /local/librnd/HDRS_HIDLIB {$(LIBRND)/plugins/lib_exp_text/lpr_hid.h }
append /local/librnd/HDRS_HIDLIB {$(LIBRND)/plugins/lib_exp_pixmap/draw_pixmap.h }

# TODO: remove this in 4.0.0
append /local/librnd/HDRS_HIDLIB {$(LIBRND)/core/conf_multi_temp.h }

# extra core headers to install
append /local/librnd/HDRS_HIDLIB { $(LIBRND)/core/funchash_core.h $(LIBRND)/core/funchash_core_list.h }

gsub /local/librnd/HDRS_3RDLIB {../src_3rd/liblihata/dom_[^ ]*.h } {}
gsub /local/librnd/HDRS_3RDLIB {../src_3rd/liblihata/tree_[^ ]*.h } {}
gsub /local/librnd/HDRS_3RDLIB {../src_3rd/libulzw/libulzw_[^ ]*.h } {}
gsub /local/librnd/HDRS_3RDLIB {../src_3rd/ureglex/strtree_exec.h } {}
gsub /local/librnd/HDRS_3RDLIB {../src_3rd/libfungw/fungw_ptr.h ../src_3rd/libfungw/fungw_debug.h ../src_3rd/libfungw/fungw_call.h } {}
gsub /local/librnd/HDRS_3RDLIB {../src_3rd/genlist/[^ ]*.h } {}
append /local/librnd/HDRS_3RDLIB {../src_3rd/genvector/genvector_impl.h ../src_3rd/genvector/genvector_impl.c ../src_3rd/genvector/genvector_undef.h }
append /local/librnd/HDRS_3RDLIB {../src_3rd/genrtree/genrtree_api.h ../src_3rd/genrtree/genrtree_impl.h ../src_3rd/genrtree/genrtree_search.h ../src_3rd/genrtree/genrtree_delete.h ../src_3rd/genrtree/genrtree_debug.h }
append /local/librnd/HDRS_3RDLIB {../src_3rd/libulzw/libulzw.h }
append /local/librnd/HDRS_3RDLIB {../src_3rd/genregex/regex_templ.h }
append /local/librnd/HDRS_3RDLIB {../src_3rd/genlist/ }

sub /local/librnd/HDRS_HIDLIB {$(LIBRND)/core/buildin.hidlib.h } {}
sub /local/librnd/HDRS_HIDLIB {buildin.hidlib.h } {}

# dynamic part of install_pcbrnd: hidlib headers
foreach /local/h in /local/librnd/HDRS_HIDLIB
	put /local/hd /local/h
	switch /local/h
		case {^$(LIBRND)/}
			sub /local/hd {$(LIBRND)/} {}
			end
		case {^../}
			sub /local/hd {^[.][.]/} {}
			end
		default
			sub /local/hd {^} {core/}
			end
	end
	print [@	$(SCCBOX) $(HOW) "@/local/h@" "$(HL_INCDIR)/@/local/hd@"@] {\n}
end

# dynamic part of install_pcbrnd: 3rdlib headers
foreach /local/h in /local/librnd/HDRS_3RDLIB
	put /local/hd /local/h
	switch /local/h
		case {^../}
			sub /local/hd {^[.][.]/} {}
			end
		default
			sub /local/hd {^} {src_3rd/}
			end
	end

	switch /local/hd
		case {genlist/} end
		default
			print [@	$(SCCBOX) $(HOW) "@/local/h@" "$(HL_INCDIR)/@/local/hd@"@] {\n}
			end
	end
end

if /local/librnd/disable_so
then
print [@
install_librnd_sy:
@]
else
print [@
install_librnd_sy:
	$(SCCBOX) $(HOW) "$(HL_LIBDIR)/librnd-hid.so.$(PCB_RND_VER)" "$(HL_LIBDIR)/librnd-hid.so.$(PCB_RND_VER_MAJOR)"
	$(SCCBOX) $(HOW) "$(HL_LIBDIR)/librnd-hid.so.$(PCB_RND_VER)" "$(HL_LIBDIR)/librnd-hid.so"
	$(SCCBOX) $(HOW) "$(HL_LIBDIR)/librnd-3rd.so.$(PCB_RND_VER)" "$(HL_LIBDIR)/librnd-3rd.so.$(PCB_RND_VER_MAJOR)"
	$(SCCBOX) $(HOW) "$(HL_LIBDIR)/librnd-3rd.so.$(PCB_RND_VER)" "$(HL_LIBDIR)/librnd-3rd.so"
	$(SCCBOX) $(HOW) "$(HL_LIBDIR)/librnd-poly.so.$(PCB_RND_VER)" "$(HL_LIBDIR)/librnd-poly.so.$(PCB_RND_VER_MAJOR)"
	$(SCCBOX) $(HOW) "$(HL_LIBDIR)/librnd-poly.so.$(PCB_RND_VER)" "$(HL_LIBDIR)/librnd-poly.so"

@]
end

#gsub /local/librnd/plugin_rule_install {^[ 	]*$} {}

print [@

install:
	$(MAKE) install_librnd HOW="install -f"
	$(MAKE) install_librnd_sy HOW="ln -f --relative" LIBDIR=$(HL_LIBDIR)/librnd3
	cd ../src_3rd/genlist && $(MAKE) install_ CP="../$(SCCBOX) install -f -q" INCDIR=$(HL_INCDIR)/src_3rd/genlist LIBDIR=$(INST_DUMMY)
@/local/librnd/plugin_rule_install@

linstall:
	$(MAKE) install_librnd HOW="linstall -f"
	$(MAKE) install_librnd_sy HOW="ln -f --relative" LIBDIR=$(HL_LIBDIR)/librnd3
	cd ../src_3rd/genlist && $(MAKE) install_ CP="../$(SCCBOX) linstall -f -q" INCDIR=$(HL_INCDIR)/src_3rd/genlist LIBDIR=$(INST_DUMMY)
@/local/librnd/plugin_rule_linstall@

uninstall:
	$(MAKE) install_librnd_sy HOW="uninstall"
	$(MAKE) install_librnd_ HOW="uninstall" LIBDIR=$(HL_LIBDIR)/librnd3
	cd ../src_3rd/genlist && $(MAKE) install_ CP="../$(SCCBOX) uninstall -q" INCDIR=$(HL_INCDIR)/src_3rd/genlist LIBDIR=$(INST_DUMMY)
@/local/librnd/plugin_rule_uninstall@


map_plugins:
	cd librnd/plugins && INCLUDE_PREFIX=../src/librnd/plugins/ PUPLUG=../../../src_3rd/puplug/util/puplug ./map_plugins.sh "."
	mv librnd/scconfig/plugins.h ../scconfig

@]

# generate explicit rules for .c -> .o
put /local/comp/OBJS /local/librnd/OBJS
put /local/comp/OBJS_C99 ?/local/librnd/OBJS_C99
include {librnd/scconfig/template/compile.tmpasm}

print [@
# for extern utils:@]

put /local/comp/OBJS /local/librnd/OBJS_UTIL
include {librnd/scconfig/template/compile.tmpasm}

# generate deps
put /local/dep/CFLAGS /local/pcb/CFLAGS
put /local/dep/SRCS /local/librnd/SRCS

gsub /local/librnd/DEPSRCS {.o } {.c }
append /local/dep/SRCS /local/librnd/DEPSRCS
include {librnd/scconfig/template/cdep.tmpasm}

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

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

