summaryrefslogtreecommitdiff
path: root/project2/ice/iceCompile.h
blob: c06f8b1dc3611958af58f53f0a9a9ef772b9fe7a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
#ifndef ICECOMPILE_H
#define ICECOMPILE_H

#include "options.h"
#include <string>
#include <set>
#include <boost/filesystem/path.hpp>
#include <boost/optional.hpp>

class IceCompile {
	public:
		INITOPTIONS;

		typedef std::shared_ptr<IceCompile> Ptr;
		typedef std::shared_ptr<const IceCompile> CPtr;
		typedef std::vector<Ptr> Deps;

		static std::string slice2cpp;
		static std::string slicer;
		static std::string cxx;
		static std::string linker;
		static std::string cxxopts;
		static std::string linkeropts;
		static boost::filesystem::path tmpdir;
		static boost::filesystem::path headerdir;
		static boost::filesystem::path slicerheaderdir;
		
		IceCompile(const boost::filesystem::path & slice);
		IceCompile(const boost::filesystem::path & slice, const Deps & deps);

		enum Steps {
			UpdateBuild = 0x1,
			UpdateCompile = 0x2,
			UpdateLink = 0x4,
		};
		/// Conditionally execute Build, Compile, Link as required
		void Update(int steps = UpdateBuild | UpdateCompile | UpdateLink);
		/// Source file path (e.g. /some/path/slice.ice)
		virtual boost::filesystem::path InputPath() const = 0;
		/// File name (no extension) in temporary directory (e.g. clientSlice)
		virtual boost::filesystem::path OutputName(const std::string & type) const = 0;

		typedef boost::shared_ptr<void> LibHandle;
		typedef std::set<LibHandle> LibHandles;
		LibHandles Open() const;

	protected:
		virtual unsigned int Build(const boost::filesystem::path & in, const boost::filesystem::path & out) const = 0;
		virtual unsigned int Count(const boost::filesystem::path & in) const = 0;
		void BuildInteral(const boost::filesystem::path & in, const boost::filesystem::path & out);
		void Compile(const boost::filesystem::path & in, const boost::filesystem::path & out);
		void Link(const boost::filesystem::path & in, const boost::filesystem::path & out);

		typedef void (IceCompile::*UpdateFunc)(const boost::filesystem::path & in, const boost::filesystem::path & out);
		typedef void (IceCompile::*CountFunc)(const boost::filesystem::path & in);
		void update(const boost::filesystem::path & in, const boost::filesystem::path & out, UpdateFunc func, CountFunc count = NULL);

		const boost::filesystem::path slice;

	private:
		void countComponents(const boost::filesystem::path & in);
		unsigned int components;
		LibHandle OpenLib() const;
		const Deps deps;
};

#endif