Check-in [ff53d13ed7]
Overview
Comment:Updated to produce working shared objects and executables (might need more stuff for Windows)
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1: ff53d13ed7a11d4f9d5d49150aae458a9408f3a2
User & Date: rkeene on 2014-06-18 17:26:34
Other Links: manifest | tags
Context
2014-06-18
17:31
Updated to provide package version numbers check-in: 6ef06b043d user: rkeene tags: trunk
17:26
Updated to produce working shared objects and executables (might need more stuff for Windows) check-in: ff53d13ed7 user: rkeene tags: trunk
17:03
Updated to support output to exe check-in: 3c45d1d050 user: rkeene tags: trunk
Changes

Modified tcc4tcl.tcl from [54d1a42bf7] to [9fb3ac5d6d].

74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113

114
115
116
117

118
119
120




































121
122
123
124
125
126
127

128
129
130
131
132
133
134
		upvar #0 $handle state

		if {[info exists state(tk)]} {
			set state(code) "#include <tk.h>\n$state(code)"
		}
		set state(code) "#include <tcl.h>\n\n$state(code)"

		tcc4tcl $dir $state(type) tcc

		switch -- $state(type) {
			"memory" {
				tcc compile $state(code)

				foreach {procname cname} $state(procs) {
					tcc command $procname $cname
				}
			}
			"exe" {
				if {[info exists state(procs)] && [llength $state(procs)] > 0} {
					append state(code) "int _initProcs(Tcl_Interp *interp) \{\n"
					
					foreach {procname cname} $state(procs) {
						append state(code) "  Tcl_CreateObjCommand(interp, \"$procname\", $cname, NULL, NULL);"
					}

					append state(code) "\}"
				}

				tcc compile $state(code)

				tcc output_file $state(filename)
			}
			"dll" {
				append state(code) "int [string totitle $state(package)]_Init(Tcl_Interp *interp) \{\n"
				append state(code) "#ifdef USE_TCL_STUBS\n"
				append state(code) "  if (Tcl_InitStubs(interp, \"8.4\" , 0) == 0L) \{\n"
				append state(code) "    return TCL_ERROR;\n"
				append state(code) "  \}\n"
				append state(code) "#endif\n"


				foreach {procname cname} $state(procs) {
					append state(code) "  Tcl_CreateObjCommand(interp, \"$procname\", $cname, NULL, NULL);"
				}


				append state(code) "Tcl_PkgProvide(interp, \"$state(package)\", \"0.0\");\n"
				append state(code) "  return(TCL_OK);\n"
				append state(code) "\}"





































				tcc compile $state(code)

				tcc output_file $state(filename)
			}
		}


		rename $handle ""
		unset $handle
	}
}

proc ::tcc4tcl::checkname {n} {expr {[regexp {^[a-zA-Z0-9_]+$} $n] > 0}}
proc ::tcc4tcl::cleanname {n} {regsub -all {[^a-zA-Z0-9_]+} $n _}







<
|


<
|
<
<
<











<
<
<
<









>
|
|
|
|
>



>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>







>







74
75
76
77
78
79
80

81
82
83

84



85
86
87
88
89
90
91
92
93
94
95




96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
		upvar #0 $handle state

		if {[info exists state(tk)]} {
			set state(code) "#include <tk.h>\n$state(code)"
		}
		set state(code) "#include <tcl.h>\n\n$state(code)"


		# Append additional generated code to support the output type
		switch -- $state(type) {
			"memory" {

				# No additional code needed



			}
			"exe" {
				if {[info exists state(procs)] && [llength $state(procs)] > 0} {
					append state(code) "int _initProcs(Tcl_Interp *interp) \{\n"
					
					foreach {procname cname} $state(procs) {
						append state(code) "  Tcl_CreateObjCommand(interp, \"$procname\", $cname, NULL, NULL);"
					}

					append state(code) "\}"
				}




			}
			"dll" {
				append state(code) "int [string totitle $state(package)]_Init(Tcl_Interp *interp) \{\n"
				append state(code) "#ifdef USE_TCL_STUBS\n"
				append state(code) "  if (Tcl_InitStubs(interp, \"8.4\" , 0) == 0L) \{\n"
				append state(code) "    return TCL_ERROR;\n"
				append state(code) "  \}\n"
				append state(code) "#endif\n"

				if {[info exists state(procs)] && [llength $state(procs)] > 0} {
					foreach {procname cname} $state(procs) {
						append state(code) "  Tcl_CreateObjCommand(interp, \"$procname\", $cname, NULL, NULL);"
					}
				}

				append state(code) "Tcl_PkgProvide(interp, \"$state(package)\", \"0.0\");\n"
				append state(code) "  return(TCL_OK);\n"
				append state(code) "\}"
			}
		}

		# Generate output code
		tcc4tcl $dir $state(type) tcc

		switch -- $state(type) {
			"memory" {
				tcc compile $state(code)

				foreach {procname cname} $state(procs) {
					tcc command $procname $cname
				}
			}

			"dll" - "exe" {
				switch -glob -- $::tcl_platform(os)-$::tcl_platform(machine) {
					"Linux-x86_64" {
						tcc add_library_path "/lib64"
						tcc add_library_path "/usr/lib64"
						tcc add_library_path "/lib"
						tcc add_library_path "/usr/lib"
					}
					"Linux-*" {
						tcc add_library_path "/lib32"
						tcc add_library_path "/usr/lib32"
						tcc add_library_path "/lib"
						tcc add_library_path "/usr/lib"
					}
					default {
						if {$::tcl_platform(platform) == "unix"} {
							tcc add_library_path "/lib"
							tcc add_library_path "/usr/lib"
						}
					}
				}

				tcc compile $state(code)

				tcc output_file $state(filename)
			}
		}

		# Cleanup
		rename $handle ""
		unset $handle
	}
}

proc ::tcc4tcl::checkname {n} {expr {[regexp {^[a-zA-Z0-9_]+$} $n] > 0}}
proc ::tcc4tcl::cleanname {n} {regsub -all {[^a-zA-Z0-9_]+} $n _}