PmEnvironment.icl 9.75 KB
Newer Older
Diederik van Arkel's avatar
Diederik van Arkel committed
1 2
implementation module PmEnvironment

3 4
import StdArray, StdBool, StdFunc, StdList
import Directory
Diederik van Arkel's avatar
Diederik van Arkel committed
5 6 7 8 9 10
import UtilIO
import UtilOptions
import UtilStrictLists
import PmPath
import StdMaybe
import Platform
11
import PmTypes
Diederik van Arkel's avatar
Diederik van Arkel committed
12 13 14 15

EnvsFileName :== "IDEEnvs"

emptyTargets
16
	= IF_WINDOWS [t_StdEnv20,t_StdIO20] [t_StdEnv20]
Diederik van Arkel's avatar
Diederik van Arkel committed
17

18
t_StdEnv :: Target
Diederik van Arkel's avatar
Diederik van Arkel committed
19
t_StdEnv
20
	= t_StdEnv20
Diederik van Arkel's avatar
Diederik van Arkel committed
21 22 23 24 25 26 27 28 29

:: Target =
	{ target_name	:: !String		// environment identifier
	, target_path	:: !List String	// search paths
	, target_libs	:: !List String	// dynamic libraries
	, target_objs	:: !List String	// object files
	, target_stat	:: !List String	// static libraries
	, target_comp	:: !String		// compiler
	, target_cgen	:: !String		// code generator
30 31 32
	, target_abcopt	:: !String		// abc optimiser
	, target_bcgen	:: !String		// bytecode generator
	, target_bclink	:: !String		// bytecode linker
33
	, target_bcstrip :: !String			// bytecode stripper
Diederik van Arkel's avatar
Diederik van Arkel committed
34 35 36
	, target_link	:: !String		// static/eager linker
	, target_dynl	:: !String		// dynamic linker
	, target_vers	:: !Int			// abc version
37
	, env_64_bit_processor :: !Bool
Diederik van Arkel's avatar
Diederik van Arkel committed
38 39
	, target_redc	:: !Bool		// redirect console?
	, target_meth	:: !CompileMethod	// compile strategy
40
	, target_proc	:: !Processor		// object type
Diederik van Arkel's avatar
Diederik van Arkel committed
41 42 43 44 45 46
	}

:: CompileMethod
	= CompileSync
	| CompileAsync !Int
	| CompilePers
47

Diederik van Arkel's avatar
Diederik van Arkel committed
48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70
getEnvironments :: !String !String !*env -> *([Target],*env) | FileSystem, FileEnv env
getEnvironments stup envpath env
	# ((ok,path),env)		= pd_StringToPath envpath env
	# ((err,entries),env)	= getDirectoryContents path env
	| err <> NoDirError		= (map (fixAppPaths stup) emptyTargets,env)
	# eentries				= [fileName \\ {fileName} <- entries | size fileName > 4 && fileName%(size fileName - 4,size fileName) == ".env"]
//	# eentries				= [fileName%(size fileName - 4,size fileName) \\ {fileName} <- entries ]//| size fileName > 4 && fileName%(size fileName - 4,size fileName) == ".env"]
	| isEmpty eentries		= openEnvironments stup (MakeFullPathname envpath EnvsFileName) env
	# (ts,env)				= seqSt eentries env
	= case ts of
		[]					-> (map (fixAppPaths stup) emptyTargets,env)
		ts					-> (map (fixAppPaths stup) ts,env)
where
	seqSt [] e = ([],e)
	seqSt [e:es] env
		# ((t,ok,err),env)	= openEnvironment (MakeFullPathname envpath e) env
		# env = case ok of
				True -> env
//				_ -> trace_n` ("Error",err) env
				_ -> env
		# (ts,env)			= seqSt es env
		= (t++ts,env)

Diederik van Arkel's avatar
Diederik van Arkel committed
71 72
openEnvironments :: !String !String !*env -> *([Target],*env) | FileEnv env
openEnvironments stup envpath env
Diederik van Arkel's avatar
Diederik van Arkel committed
73
	# ((targets,ok,_),env)		= accFiles (openEnvironment envpath) env
Diederik van Arkel's avatar
Diederik van Arkel committed
74 75
	| not ok
		#	targets				= emptyTargets
76
		#	(_,env)				= saveEnvironmentsStupArg stup envpath targets env
Diederik van Arkel's avatar
Diederik van Arkel committed
77 78 79 80
		#	targets				= map (fixAppPaths stup) targets
		= (targets,env)
	# targets				= map (fixAppPaths stup) targets
	= (targets,env)
Diederik van Arkel's avatar
Diederik van Arkel committed
81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96

openEnvironment :: !String *a -> *(([Target],.Bool,{#Char}),*a) | FileSystem a
openEnvironment envpath env
	# (opened, file, env)		= fopen envpath FReadData env
	| not opened
		= (([],False,"The file \"" +++  envpath +++ "\" could not be opened."),env)
	# (version, file)			= ReadVersion file
	| version <> EnvFileVersion
		# (_, env)				= fclose file env
		= (([],False,"The file \"" +++  envpath +++ "\" has the wrong version."+++version+++"<<<"),env)
	#! 	(options, file)			= ReadOptionsFile file
		targets					= REO options
		(closed, env)			= fclose file env
	| not closed
		=	((targets, True,"The file \"" +++ envpath +++ "\" clould not be closed."), env)	// warning genereren of zo?
	=	((targets, True,""), env)
Diederik van Arkel's avatar
Diederik van Arkel committed
97 98 99

saveEnvironments :: !String ![Target] !*env -> *(Bool,*env) | FileEnv env
saveEnvironments envpath targets env
100 101 102 103 104
	# (stup,env) = accFiles GetFullApplicationPath env
	= saveEnvironmentsStupArg stup envpath targets env

saveEnvironmentsStupArg :: !String !String ![Target] !*env -> *(Bool,*env) | FileEnv env
saveEnvironmentsStupArg stup envpath targets env
Diederik van Arkel's avatar
Diederik van Arkel committed
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
	# targets		= map (unfixAppPaths stup) targets
	# (err,env)		= accFiles (saveEnvironments envpath targets) env
	# ok			= isNothing err
	= (ok,env)
where
	saveEnvironments :: !String [.Target] *a -> *(Maybe .[{#Char}],*a) | FileSystem a
	saveEnvironments envpath targets env
		# (opened, file, env)		= fopen envpath FWriteText env
		| not opened
			=	(Just ["Fatal open environments..."],env)
		#! options					= WEO targets
		#! file						= WriteOptionsFile EnvFileVersion options file
		# (closed,env)				= fclose file env
		| not closed
			= (Just ["Fatal close environments..."],env)
		= (Nothing,env)

/* Variant die in dir zoekt naar alle *.env bestanden?
 * Eerst beginnen met targets in leesbare variant weg te schrijven...
 * Rekening houden met exemplaren oude variant...
 */

EnvFileVersion :== "1.0"
emptyTarget =
	{ target_name	= ""
	, target_path	= Nil
	, target_libs	= Nil
	, target_objs	= Nil
	, target_stat	= Nil
	, target_comp	= ""
	, target_cgen	= ""
136 137 138
	, target_abcopt	= ""
	, target_bcgen	= ""
	, target_bclink	= ""
139
	, target_bcstrip = ""
Diederik van Arkel's avatar
Diederik van Arkel committed
140 141 142
	, target_link	= ""
	, target_dynl	= ""
	, target_vers	= 42
143
	, env_64_bit_processor = IF_INT_64_OR_32 True False
Diederik van Arkel's avatar
Diederik van Arkel committed
144 145
	, target_redc	= False
	, target_meth	= CompileSync
146
	, target_proc	= DefaultProcessor
Diederik van Arkel's avatar
Diederik van Arkel committed
147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169
	}

WEO prefs
	= PutOptions TargetsTable prefs

REO options
	= GetOptions TargetsTable options []

TargetsTable =
	{ ListOption "Environments" (TargetTableOption) emptyTarget (\a->ListToStrictList a) (\v a->StrictListToList v)
	}

TargetTableOption = GroupedOption "Environment" TargetTable id const

TargetTable :: OptionsTable Target
TargetTable =
	{ SimpleOption	"EnvironmentName"			(\a->a.target_name) (\v a->{a & target_name=v})
	, ListOption	"EnvironmentPaths"			(PathOption) "" (\a-> a.target_path) (\v a->{a & target_path= v})
	, ListOption	"EnvironmentDynamicLibs"	(PathOption) "" (\a-> a.target_libs) (\v a->{a & target_libs= v})
	, ListOption	"EnvironmentObjects"		(PathOption) "" (\a-> a.target_objs) (\v a->{a & target_objs= v})
	, ListOption	"EnvironmentStaticLibs"		(PathOption) "" (\a-> a.target_stat) (\v a->{a & target_stat= v})
	, SimpleOption	"EnvironmentCompiler"		(\a->a.target_comp) (\v a->{a & target_comp=v})
	, SimpleOption	"EnvironmentCodeGen"		(\a->a.target_cgen) (\v a->{a & target_cgen=v})
170 171 172
	, SimpleOption	"EnvironmentABCOptimise"	(\a->a.target_abcopt) (\v a->{a & target_abcopt=v})
	, SimpleOption	"EnvironmentByteCodeGen"	(\a->a.target_bcgen) (\v a->{a & target_bcgen=v})
	, SimpleOption	"EnvironmentByteCodeLink"	(\a->a.target_bclink) (\v a->{a & target_bclink=v})
173
	, SimpleOption	"EnvironmentByteCodeStrip"	(\a->a.target_bcstrip) (\v a->{a & target_bcstrip=v})
Diederik van Arkel's avatar
Diederik van Arkel committed
174 175 176
	, SimpleOption	"EnvironmentLinker"			(\a->a.target_link) (\v a->{a & target_link=v})
	, SimpleOption	"EnvironmentDynLink"		(\a->a.target_dynl) (\v a->{a & target_dynl=v})
	, SimpleOption	"EnvironmentVersion"		(\a->toString a.target_vers) (\v a->{a & target_vers=toInt v})
177
	, SimpleOption	"EnvironmentRedirect"		(\a->b2s a.target_redc) (\v a->{a & target_redc=string_to_bool v})
Diederik van Arkel's avatar
Diederik van Arkel committed
178
	, SimpleOption	"EnvironmentCompileMethod"	(\a->m2s a.target_meth) (\v a->{a & target_meth=s2m v})
179
	, SimpleOption	"EnvironmentProcessor"		(\a->toString a.target_proc) (\v a->{a & target_proc=fromString v})
180
	, SimpleOption	"Environment64BitProcessor" (\a->toString a.env_64_bit_processor) (\v a->{a & env_64_bit_processor=string_to_bool v})
Diederik van Arkel's avatar
Diederik van Arkel committed
181 182 183 184
	}
where
	b2s True	= "True"
	b2s _		= "False"
185 186 187

	string_to_bool "True"	= True
	string_to_bool  _		= False
Diederik van Arkel's avatar
Diederik van Arkel committed
188 189 190 191 192 193 194 195 196
	
	m2s CompileSync			= "Sync"
	m2s CompilePers			= "Pers"
	m2s (CompileAsync n)	= toString n
	
	s2m "Sync"	= CompileSync
	s2m "Pers"	= CompilePers
	s2m n		= CompileAsync (toInt n)
	
197
PathOption = SimpleWithStringConversionOption convert_path_separators "Path" id const
Diederik van Arkel's avatar
Diederik van Arkel committed
198

199
t_StdEnv20 :: Target
200 201 202 203
t_StdEnv20
	# compiler_and_linker_directory
		= IF_WINDOWS ("Tools"+++DirSeparatorString+++"Clean System") ("lib"+++DirSeparatorString+++"exe")
	=
204
	{ target_name	= "StdEnv"
205 206
	, target_path = ("{Application}"+++DirSeparatorString+++IF_WINDOWS "Libraries" "lib"+++DirSeparatorString+++"StdEnv":! Nil)
	, target_libs	= Nil
Diederik van Arkel's avatar
Diederik van Arkel committed
207 208
	, target_objs	= Nil
	, target_stat	= Nil
209 210
	, target_comp	= compiler_and_linker_directory+++DirSeparatorString+++IF_WINDOWS "CleanCompiler.exe" "cocl"
	, target_cgen	= compiler_and_linker_directory+++DirSeparatorString+++IF_WINDOWS "CodeGenerator.exe" "cg"
211 212 213
	, target_abcopt	= compiler_and_linker_directory+++DirSeparatorString+++IF_WINDOWS "ABCOptimiser.exe" "abcopt"
	, target_bcgen	= compiler_and_linker_directory+++DirSeparatorString+++IF_WINDOWS "ByteCodeGenerator.exe" "bcgen"
	, target_bclink	= compiler_and_linker_directory+++DirSeparatorString+++IF_WINDOWS "ByteCodeLinker.exe" "bclink"
214
	, target_bcstrip = compiler_and_linker_directory+++DirSeparatorString+++IF_WINDOWS "ByteCodeStripper.exe" "bcstrip"
215
	, target_link	= IF_MACOSX "/usr/bin/gcc" (compiler_and_linker_directory+++DirSeparatorString+++IF_WINDOWS "StaticLinker.exe" "linker")
216
	, target_dynl	= "Tools"+++DirSeparatorString+++"Dynamics"+++DirSeparatorString+++"DynamicLinker.exe"
John van Groningen's avatar
John van Groningen committed
217
	, target_vers	= 920
218
	, env_64_bit_processor = IF_INT_64_OR_32 True False
Diederik van Arkel's avatar
Diederik van Arkel committed
219 220
	, target_redc	= False
	, target_meth	= CompilePers
221
	, target_proc	= DefaultProcessor
Diederik van Arkel's avatar
Diederik van Arkel committed
222 223
	}

224 225 226 227
t_StdIO20 =
	{ t_StdEnv20
	& target_name	= "Object IO"
	, target_path	=
228 229 230 231
		(	"{Application}\\Libraries\\StdEnv"
		:!	"{Application}\\Libraries\\StdLib"
		:!	"{Application}\\Libraries\\ObjectIO ObjectIO"
		:!	"{Application}\\Libraries\\ObjectIO ObjectIO\\OS Windows"
232 233 234 235
		:!	Nil
		)
	}

Diederik van Arkel's avatar
Diederik van Arkel committed
236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252
//--

fixAppPaths stup target=:{target_path = path, target_libs = libs, target_objs=objs, target_stat=stat}
	= {target & target_path = path`, target_libs = libs`, target_objs=objs`, target_stat = stat`}
where
	path` = fulAppPaths stup path
	libs` = fulAppPaths stup libs
	objs` = fulAppPaths stup objs
	stat` = fulAppPaths stup stat

unfixAppPaths stup target=:{target_path = path, target_libs = libs, target_objs=objs, target_stat=stat}
	= {target & target_path = path`, target_libs = libs`, target_objs=objs`, target_stat=stat`}
where
	path` = symAppPaths stup path
	libs` = symAppPaths stup libs
	objs` = symAppPaths stup objs
	stat` = symAppPaths stup stat
253