PmEnvironment.icl 10 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
34
	, target_bcprelink :: !String		// bytecode prelinker
Diederik van Arkel's avatar
Diederik van Arkel committed
35 36 37
	, target_link	:: !String		// static/eager linker
	, target_dynl	:: !String		// dynamic linker
	, target_vers	:: !Int			// abc version
38
	, env_64_bit_processor :: !Bool
Diederik van Arkel's avatar
Diederik van Arkel committed
39 40
	, target_redc	:: !Bool		// redirect console?
	, target_meth	:: !CompileMethod	// compile strategy
41
	, target_proc	:: !Processor		// object type
Diederik van Arkel's avatar
Diederik van Arkel committed
42 43 44 45 46 47
	}

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

Diederik van Arkel's avatar
Diederik van Arkel committed
49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71
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
72 73
openEnvironments :: !String !String !*env -> *([Target],*env) | FileEnv env
openEnvironments stup envpath env
Diederik van Arkel's avatar
Diederik van Arkel committed
74
	# ((targets,ok,_),env)		= accFiles (openEnvironment envpath) env
Diederik van Arkel's avatar
Diederik van Arkel committed
75 76
	| not ok
		#	targets				= emptyTargets
77
		#	(_,env)				= saveEnvironmentsStupArg stup envpath targets env
Diederik van Arkel's avatar
Diederik van Arkel committed
78 79 80 81
		#	targets				= map (fixAppPaths stup) targets
		= (targets,env)
	# targets				= map (fixAppPaths stup) targets
	= (targets,env)
Diederik van Arkel's avatar
Diederik van Arkel committed
82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97

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
98 99 100

saveEnvironments :: !String ![Target] !*env -> *(Bool,*env) | FileEnv env
saveEnvironments envpath targets env
101 102 103 104 105
	# (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
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
	# 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	= ""
137 138 139
	, target_abcopt	= ""
	, target_bcgen	= ""
	, target_bclink	= ""
140
	, target_bcstrip = ""
141
	, target_bcprelink = ""
Diederik van Arkel's avatar
Diederik van Arkel committed
142 143 144
	, target_link	= ""
	, target_dynl	= ""
	, target_vers	= 42
145
	, env_64_bit_processor = IF_INT_64_OR_32 True False
Diederik van Arkel's avatar
Diederik van Arkel committed
146 147
	, target_redc	= False
	, target_meth	= CompileSync
148
	, target_proc	= DefaultProcessor
Diederik van Arkel's avatar
Diederik van Arkel committed
149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171
	}

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})
172 173 174
	, 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})
175
	, SimpleOption	"EnvironmentByteCodeStrip"	(\a->a.target_bcstrip) (\v a->{a & target_bcstrip=v})
176
	, SimpleOption	"EnvironmentByteCodePrelink"	(\a->a.target_bcprelink) (\v a->{a & target_bcprelink=v})
Diederik van Arkel's avatar
Diederik van Arkel committed
177 178 179
	, 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})
180
	, 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
181
	, SimpleOption	"EnvironmentCompileMethod"	(\a->m2s a.target_meth) (\v a->{a & target_meth=s2m v})
182
	, SimpleOption	"EnvironmentProcessor"		(\a->toString a.target_proc) (\v a->{a & target_proc=fromString v})
183
	, 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
184 185 186 187
	}
where
	b2s True	= "True"
	b2s _		= "False"
188 189 190

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

202
t_StdEnv20 :: Target
203 204 205 206
t_StdEnv20
	# compiler_and_linker_directory
		= IF_WINDOWS ("Tools"+++DirSeparatorString+++"Clean System") ("lib"+++DirSeparatorString+++"exe")
	=
207
	{ target_name	= "StdEnv"
208 209
	, target_path = ("{Application}"+++DirSeparatorString+++IF_WINDOWS "Libraries" "lib"+++DirSeparatorString+++"StdEnv":! Nil)
	, target_libs	= Nil
Diederik van Arkel's avatar
Diederik van Arkel committed
210 211
	, target_objs	= Nil
	, target_stat	= Nil
212 213
	, target_comp	= compiler_and_linker_directory+++DirSeparatorString+++IF_WINDOWS "CleanCompiler.exe" "cocl"
	, target_cgen	= compiler_and_linker_directory+++DirSeparatorString+++IF_WINDOWS "CodeGenerator.exe" "cg"
214 215 216
	, 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"
217
	, target_bcstrip = compiler_and_linker_directory+++DirSeparatorString+++IF_WINDOWS "ByteCodeStripper.exe" "bcstrip"
218
	, target_bcprelink = compiler_and_linker_directory+++DirSeparatorString+++IF_WINDOWS "ByteCodePrelinker.exe" "bcprelink"
219
	, target_link	= IF_MACOSX "/usr/bin/gcc" (compiler_and_linker_directory+++DirSeparatorString+++IF_WINDOWS "StaticLinker.exe" "linker")
220
	, target_dynl	= "Tools"+++DirSeparatorString+++"Dynamics"+++DirSeparatorString+++"DynamicLinker.exe"
221
	, target_vers	= 920
222
	, env_64_bit_processor = IF_INT_64_OR_32 True False
Diederik van Arkel's avatar
Diederik van Arkel committed
223 224
	, target_redc	= False
	, target_meth	= CompilePers
225
	, target_proc	= DefaultProcessor
Diederik van Arkel's avatar
Diederik van Arkel committed
226 227
	}

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

Diederik van Arkel's avatar
Diederik van Arkel committed
240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256
//--

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
257