# tmpasm script for compiling a plugin_src/ module as a plugin
# Requires variables before the include:
#  /local/rnd/mod       basename of the module (e.g. autoplace)
#  /local/rnd/mod/OBJS  full path of all object files
#  /local/rnd/mod/OBJS_C99  full path of all object files for non-c89

# clean up input vars
uniq /local/rnd/mod/OBJS
uniq /local/rnd/mod/OBJS_C99
uniq /local/rnd/mod/CFLAGS
uniq /local/rnd/mod/LDFLAGS
uniq /local/rnd/mod/LIBS

# generate .c -> .o rules in /local/comp/output
put /local/comp/OBJS_C89 ?/local/rnd/mod/OBJS
put /local/comp/OBJS_C99 ?/local/rnd/mod/OBJS_C99
put /local/comp/C89FLAGS [@ $(C89FLAGS) @/local/rnd/mod/CFLAGS@ @]
put /local/comp/C99FLAGS [@ $(CFLAGS) @/local/rnd/mod/CFLAGS@ @]
include [@@/local/pcb/librnd_template@/comp_var.tmpasm@]

append /local/pcb/all   [@ $(PLUGIDIR)/@/local/rnd/mod@.so @]

append /local/rnd/rules/install_ [@
	$(SCCBOX) $(HOW) "$(PLUGDIR)/@/local/rnd/mod@/@/local/rnd/mod@.so" "$(LIBDIR)/plugins/@/local/rnd/mod@.so"
	$(SCCBOX) $(HOW) "$(PLUGDIR)/@/local/rnd/mod@/@/local/rnd/mod@.pup" "$(LIBDIR)/plugins/@/local/rnd/mod@.pup"@]

append /local/rnd/CLEANFILES [@ $(PLUGDIR)/@/local/rnd/mod@/@/local/rnd/mod@.so $(PLUGIDIR)/@/local/rnd/mod@.so $(PLUGIDIR)/@/local/rnd/mod@.pup @/local/rnd/mod/OBJS@  @/local/rnd/mod/OBJS_C99@ @]

append /local/rnd/RULES [@

### Module @/local/rnd/mod@: plugin ###

$(PLUGDIR)/@/local/rnd/mod@/@/local/rnd/mod@.so: @/local/rnd/mod/OBJS@ @/local/rnd/mod/OBJS_C99@
	$(CC) -shared @cc/rdynamic@ -o $(PLUGDIR)/@/local/rnd/mod@/@/local/rnd/mod@.so @/local/rnd/mod/OBJS@ @/local/rnd/mod/OBJS_C99@  $(LDFLAGS) @/local/rnd/mod/LDFLAGS@

mod_@/local/rnd/mod@: $(PLUGIDIR)/@/local/rnd/mod@.so

$(PLUGIDIR)/@/local/rnd/mod@.so: $(PLUGDIR)/@/local/rnd/mod@/@/local/rnd/mod@.so
	$(MKDIR) $(PLUGIDIR)
	$(CP) $(PLUGDIR)/@/local/rnd/mod@/@/local/rnd/mod@.so $(PLUGIDIR)/@/local/rnd/mod@.so
	$(CP) $(PLUGDIR)/@/local/rnd/mod@/@/local/rnd/mod@.pup $(PLUGIDIR)/@/local/rnd/mod@.pup

# module .c -> .o rules
@/local/comp/output@

### Module @/local/rnd/mod@ end ###
@]

include /local/pcb/tmpasm/common_enabled
