# list all .c files that need to be compiled into object and linked in xschem
put /local/src {
 icon.c callback.c actions.c move.c check.c clip.c draw.c globals.c
 main.c netlist.c hash_iterator.c findnet.c scheduler.c store.c xinit.c
 select.c font.c editprop.c save.c paste.c token.c psprint.c node_hash.c
 hilight.c options.c vhdl_netlist.c svgdraw.c spice_netlist.c
 tedax_netlist.c verilog_netlist.c parselabel.c expandlabel.c
 in_memory_undo.c
}

# list all files that need to be installed in $(XSHAREDIR)
put /local/install_shares {
 keys.help xschem.help xschem.tcl break.awk convert_to_verilog2001.awk
 flatten.awk make_sym.awk order_labels.awk sort_labels.awk spice.awk
 tedax.awk verilog.awk vhdl.awk
 xschemrc
}

# generate a list of objects from the list of source files
put /local/obj [@@/local/src@ @]
gsub /local/obj {\n} { }
gsub /local/obj {[.]c } {.o }

print [@
###############################################################
#  Generated by scconfig - DO NOT EDIT - will be overwritten  #
#  Source: Makefile.in; to regenerate run ./configure         #
###############################################################

OBJ = @/local/obj@

all: xschem

include ../Makefile.conf

xschem: $(OBJ)
	$(CC) -o xschem $(OBJ) $(LDFLAGS)

parselabel.c: parselabel.l expandlabel.h
	flex -l -oparselabel.c  parselabel.l

expandlabel.c expandlabel.h: expandlabel.y
	bison -d -o expandlabel.c  expandlabel.y

parselabel.o: expandlabel.h

$(OBJ): xschem.h ../config.h Makefile

clean: FORCE
	rm -rf xschem *.o expandlabel.[ch] parselabel.c netlist netlist.spice netlist.vhdl netlist.v *.da gmon.out

# Explicit rule for each object:
@]

foreach /local/n in /local/src
	put /local/o /local/n
	sub /local/o {.c$} {.o}
	print [@
@/local/o@: @/local/n@
	$(CC) -c $(CFLAGS) -o @/local/o@ @/local/n@
@]
end

print [@

install: xschem FORCE
	mkdir -p $(BINDIR)
	mkdir -p $(XSHAREDIR)
	cp xschem $(BINDIR)/xschem
	cp -r systemlib $(XSHAREDIR)@]

foreach /local/n in /local/install_shares
	print [@
	cp @/local/n@  $(XSHAREDIR)@]
end

print [@

distclean: clean

uninstall: FORCE
	rm $(BINDIR)/xschem
	rm -rf $(XSHAREDIR)
	rm -rf $(XDOCDIR)

FORCE:

@]
