#An excerpt from the makefile I used to automatize generation of case-numbered .pof files based on ECO and other
# position and LC feature modifications to follow which bits change in the .pof file for what verilog changes:
#(This won't work but may give some ideas what tools and commandlines were used. Quartus is quite complicated, 
# if someone wants to design lowlevel and turn off automatic optimizations, a lot of settings should be done...)

RE_DIR=./reverse-engineered/MAXV-5M40ZE64/23-GNDout-vs-VCCout

define ECOscript1
package require ::quartus::chip_planner
package require ::quartus::project
load_chip_planner_utility_commands
project_open Xxx -revision Xxx
read_netlist
set had_failure 0

endef
export ECOscript1

define ECOscript2
set result [ add_new_cell -cell_name 
endef
export ECOscript2

define ECOscript2b
 ]

set node_properties [ node_properties_record #auto -node_name |Xxx|
endef
export ECOscript2b

define ECOscript2c
 -node_type LCELL -op_mode normal -data_to_lut_c "Data C" -sum_lut_mask 0000 -fanins [ list ] ]
set result [ set_lutmask_wrapper $$node_properties |Xxx|
endef
export ECOscript2c 
define ECOscript2d
 "Sum LUT Mask" 
endef
export ECOscript2d

define ECOscript2f
set node_id [ get_node_by_name -name |Xxx|regout ] 
set result [ set_node_info -node $$node_id -info "Open Drain" "true" ] 
endef
export ECOscript2f

define ECOscript3 

puts ""
set drc_result [check_netlist_and_save]
project_close
endef
export ECOscript3

#by default all unused IOs are  "As input tri-stated with weak pull-up", standard: "3.3-V LVTTL"
define PINscript 
#set_instance_assignment -name ENABLE_BUS_HOLD_CIRCUITRY ON -to clk
#set_instance_assignment -name WEAK_PULL_UP_RESISTOR ON -to clk
#set_instance_assignment -name IO_STANDARD "1.8 V" -to clk
#set_instance_assignment -name IO_STANDARD "3.3V SCHMITT TRIGGER INPUT" -to clk
#set_instance_assignment -name IO_STANDARD LVDS -to xxx
#set_instance_assignment -name SLEW_RATE 2 -to xxx
#set_instance_assignment -name SLEW_RATE 2 -to xxx
#set_instance_assignment -name SLOW_SLEW_RATE ON -to clk
#set_instance_assignment -name CURRENT_STRENGTH_NEW "MINIMUM CURRENT" -to xxx
#set_instance_assignment -name CURRENT_STRENGTH_NEW "MAX" -to xxx
#set_instance_assignment -name CURRENT_STRENGTH_NEW 8mA -to clk -comment 8mA/16mA
#set_instance_assignment -name PAD_TO_CORE_DELAY 0 -to regin
#set_instance_assignment -name AUTO_OPEN_DRAIN_PINS ON -to regout
#set_instance_assignment -name GLOBAL_SIGNAL value [-from xxx] -to xxx
#set_location_assignment -to regout
set_location_assignment -to xxx_osc
endef
export PINscript


iterate:
	$(PRINT) "$$XXX_PROJ_SCRIPT" > "$(XXX_PROJNAME).qsf"
	-$(MKDIR) $(RE_DIR)
	for pinNum in 1 2 3 4 5 7 9 10 11 12 13 18 19 20 21 22 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 40 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 58 59 60 61 62 63 64 ; do \
            echo "$${PINscript}" PIN_$${pinNum} > $(XXX_PINFILE); \
            $(XXX_SYNTH) $(XXX_SYNTH_ARGS) --source=$(SOURCES_DIR)/Xxx.v; \
            $(XXX_PROUTE) $(XXX_PAR_ARGS)  --tdc=on; \
            #echo "$$ECOscript1$$ECOscript2" TestLEX$${cellposX}_Y$${cellposY}_N$${cellNum} -arith -location IOE_PIN_$${pinNum}"$$ECOscript2b"TestLEX$${cellposX}_Y$${cellposY}_N$${cellNum}"$$ECOscript2c"TestLEX$${cellposX}_Y$${cellposY}_N$${cellNum}"$$ECOscript2d" $${LUTcnt} "$$ECOscript3" > ECOiterator.tcl; \
            #echo "$$ECOscript1$$ECOscript2f$$ECOscript3" > ECOiterator.tcl; \
            #$(XXX_CDB_IF) -t ECOiterator.tcl; \
            $(XXX_BITGEN) $(XXX_BITGEN_ARGS); \
            $(POFVIEW) $(XXX_PROJNAME).pof -debug > $(RE_DIR)/IOE_PIN_$${pinNum}-output-driven-by-GND.pof.txt ; \
            $(MOVE) $(XXX_PROJNAME).pof.bmp $(RE_DIR)/IOE_PIN_$${pinNum}-output-driven-by-GND.pof.bmp; \
            $(COPY) $(XXX_PROJNAME).pof $(RE_DIR)/IOE_PIN_$${pinNum}-output-driven-by-GND.pof; \
            $(XXX_TIMEAN) $(XXX_PROJNAME)   #need to run before netgen; \
            $(XXX_NETGEN) $(XXX_PROJNAME) --simulation=on -c Xxx --read_settings_files=on --write_settings_files=off --output_directory=./simulation --tool=modelsim_oem --format=verilog; \
            $(COPY) $(SIMUL_DIR)/$(XXX_PROJNAME).vo $(RE_DIR)/IOE_PIN_$${pinNum}-output-driven-by-GND.vo; \
          done; \


# echo "$$ECOscript1$$ECOscript2" TestLEX$${cellposX}_Y$${cellposY}_N$${cellNum} -arith -location IOE_PIN_$${pinNum}"$$ECOscript2b"|Xxx|TestLEX$${cellposX}_Y$${cellposY}_N$${cellNum}"$$ECOscript2c"|Xxx|TestLEX$${cellposX}_Y$${cellposY}_N$${cellNum}"Sum LUT Mask" D2B6 "$$ECOscript3" > ECOiterator.tcl; \

genxxx: $(SOURCES_DIR)/Xxx.v
	$(PRINT) "$$XXX_PROJ_SCRIPT" > "$(XXX_PROJNAME).qsf"
	$(XXX_SYNTH) $(XXX_SYNTH_ARGS) --source=$(SOURCES_DIR)/Xxx.v
	$(XXX_PROUTE) $(XXX_PAR_ARGS)  --tdc=on  #--fmax=100.00mhz
#	$(XXX_CDB_IF) -t ECOiterator.tcl; 
	$(XXX_BITGEN) $(XXX_BITGEN_ARGS)
	$(POFVIEW) $(XXX_PROJNAME).pof

netviewxxx:
	$(POFVIEW) $(XXX_PROJNAME).pof -debug > $(XXX_PROJNAME).pof.txt 
	gpicview $(XXX_PROJNAME).pof.bmp &
#	$(BINLOAD) --library-path $(QUARTUS_LIN_DIR) $(XXX_NETVIEW) \
#         $(XXX_PROJNAME) -c $(XXX_PROJNAME) \
#         --netlist_type=atom_fit #'atom_fit' = post-fit
         # / 'atom_map'=post-map / 'sgate'=RTL / 'sm_process'=state-machine

backannotate:
#	$(XXX_CDB_IF) $(XXX_CDB_IF_ARGS) --back_annotate=routing #/device/lc/lab
	$(XXX_CDB_IF) -t $(TOOLS_DIR)/quartus-back-annotate.tcl


################################################################################