=== modified file 'stagebuilder.prolog' --- stagebuilder.prolog 2011-11-09 00:42:32 +0000 +++ stagebuilder.prolog 2011-10-31 20:42:42 +0000 @@ -1,393 +1,316 @@ -% vim: ft=prolog textwidth=80 tabstop=4 softtabstop=4 shiftwidth=4 expandtab - -% operator definition +% vim: ft=prolog tw=80 ts=4 sts=4 noet + +gentoo_mirror('ftp://ftp.sh.cvut.cz/MIRRORS/gentoo'). + :- op(400, yfx, +/+). -% -% Settings -% - -gentoo_mirror('ftp://ftp.sh.cvut.cz/MIRRORS/gentoo'). work_dir('/home/ccx/bzr/prosys'). -site_conf_dir(Work +/+ conf ) :- work_dir(Work). -downloads_dir(Work +/+ downloads) :- work_dir(Work). - stages_dir(Work +/+ stages ) :- work_dir(Work). - -% -% Generic predicates and shell stuff -% - -maplist(_Pred,[ ]). -maplist( Pred,[A|As]) :- - call(Pred,A), - maplist(Pred,As). - -maplist(_Pred,[ ],[ ]). -maplist( Pred,[A|As],[B|Bs]) :- - call(Pred,A,B), - maplist(Pred,As,Bs). - -prepend(List, List0, List1) :- append(List, List1, List0). - -concat([ ], [ ]). -concat([Head|Tail], String) :- - ( atom(Head) -> name(Head, HString) ; HString = Head ), - append(HString, Rest, String), - concat(Tail, Rest). - -concat_n(List, Name) :- concat(List, String), name(Name, String). - -str_join(_ , [ ], [ ]). -str_join(_ , [X ], X ). -str_join(Sep, [A, B|Rest], Result) :- - concat([A, Sep, B], Start), - str_join(Sep, [Start|Rest], Result). - -join(_ , [ ], [ ]). -join(_ , [X ], X ). -join(Sep, [A, B|Rest], A + Sep + Result) :- - join(Sep, [B|Rest], Result). - -l_strip(_ , [ ], [ ]). -l_strip(Strip, [Head|Tail], Out) :- - ( member(Head, Strip) - -> l_strip(Strip, Tail, Out) - ; Out = [Head|Tail] - ). - -r_strip(_, [ ], []). -r_strip(Strip, [Head|Tail], Out) :- - r_strip(Strip, Tail, Out0), - ( Out0 = [], - member(Head, Strip) - -> Out = [ ] - ; Out = [Head|Out0] - ). - -escape_backslashes([ ], [ ]). -escape_backslashes([UnescapedChar|UnescapedChars], Escaped) :- - ( member(UnescapedChar, "\n") - -> append("'\n'", Escaped0, Escaped) - ; member(UnescapedChar, " \t()[]{}&;$#!?*=<>'\"`") - -> concat(["\\", [UnescapedChar], Escaped0], Escaped) - ; Escaped = [UnescapedChar|Escaped0] - ), - escape_backslashes(UnescapedChars, Escaped0). - -% not_in(_, [ ]). -% not_in(A, [B|Bs]) :- A =\= B, not_in(A, Bs). - -% not_in(A, Bs) :- \+ member(A, Bs). - -str(X, String) :- - ( is_list(X) -> X = String - ; atom(X) -> name(X, String) - ; str_aux(X, String) - ). -str_aux(A + B, String) :- - str(A, AString), - append(AString, BString, String), - str(B, BString). -str_aux(A +/+ B, String) :- - str(A, AString), - str(B, BString), - r_strip("/", AString, AStripped), - l_strip("/", BString, BStripped), - concat([AStripped, "/", BStripped], String). - -escape(Unescaped, Escaped) :- - ( str(Unescaped, UnescapedString) - -> ( member(UnescapedChar, UnescapedString), - member(UnescapedChar, " \n\t()[]{}&;$#!?*=<>\"`"), - [Quote] = "'", \+ member(Quote, UnescapedString) - -> concat(["'", UnescapedString, "'"], Escaped) - ; escape_backslashes(UnescapedString, Escaped) - ) - ; escape_aux(Unescaped, Escaped) - ). -escape_aux(variable(Name), Escaped) :- - concat(["${", Name, "}"], Escaped). -escape_aux(A + B , Escaped) :- - escape(A, AEscaped), - append(AEscaped, BEscaped, Escaped), - escape(B, BEscaped). -escape_aux(A +/+ B , Escaped) :- - escape(A, AEscaped), - escape(B, BEscaped), % (can't make this into a tail-call - % because the l_strinp/3 call needs to - % run afterwards) - r_strip("/", AEscaped, AStripped), - l_strip("/", BEscaped, BStripped), - concat([AStripped, "/", BStripped], Escaped). - -escape_n(X, Name) :- escape(X, String), name(Name, String). - -% list_escape(Unescapeds,Escapeds) :- -% maplist(escape,Unescapeds,Escapeds) - -cmd_tokens(run(List) , Escaped) :- - maplist(escape, List, Escaped). -cmd_tokens( run_append(List, File) , Escaped) :- - maplist(escape, List, Escaped0), - append(Escaped0, [">>", FileEscaped], Escaped), - escape(File, FileEscaped). -cmd_tokens(run_replace(List, File) , Escaped) :- - maplist(escape, List, Escaped0), - append(Escaped0, [">", FileEscaped], Escaped), - escape(File, FileEscaped). -cmd_tokens( run_outvar(List, Var) , Escaped) :- - maplist(escape, List, Escaped0), - concat([Var, "=$("], Pre), - concat([[Pre], Escaped0, [")"]], Escaped). -cmd_tokens( echo_append(String, File), Escaped) :- - cmd_tokens( run_append([echo, String], File), Escaped). -cmd_tokens(echo_replace(String, File), Escaped) :- - cmd_tokens(run_replace([echo, String], File), Escaped). -cmd_tokens(chroot(Dir, Args) , Escaped) :- - cmd_tokens(run([Dir +/+ 'chroot.sh'|Args]) , Escaped). - -format_cmd(Cmd, String) :- - cmd_tokens(Cmd, Tokens), - str_join(" ", Tokens, String). - -% format_cmds(Cmds, Strings) :- -% maplist(format_cmd, Cmds, Strings). - -print_cmds([ ]). +site_conf_dir(Wrk +/+ conf) :- work_dir(Wrk). +downloads_dir(Wrk +/+ downloads) :- work_dir(Wrk). +stages_dir(Wrk +/+ stages) :- work_dir(Wrk). + +concat([], []). +concat([H|T], String) :- + (atom(H) -> name(H, HS); HS = H), + concat(T, Rest), + append(HS, Rest, String). + +concatn(L, N) :- concat(L, S), name(N, S). + +strjoin(_, [], []). +strjoin(_, [X], X). +strjoin(Sep, [A, B|R], Result) :- + concat([A, Sep, B], Start), + strjoin(Sep, [Start|R], Result). + +join(_, [], []). +join(_, [X], X). +join(Sep, [A, B|R], A + Sep + Result) :- + join(Sep, [B|R], Result). + +lstrip(_, [], []). +lstrip(S, [H|T], O) :- + member(H, S) -> lstrip(S, T, O); O = [H|T]. + +rstrip(_, [], []). +rstrip(S, [H|T], O) :- + rstrip(S, T, Out), + (length(Out, 0), member(H, S) -> O = []; O = [H|Out]). + +escape_backslashes([], []). +escape_backslashes([UC|UR], E) :- + escape_backslashes(UR, ER), ( + member(UC, "\n") -> append("'\n'", ER, E); + member(UC, " \t()[]{}&;$#!?*=<>'\"`") -> concat(["\\", [UC], ER], E); + E = [UC|ER] + ). + +not_in(_, []). +not_in(A, [B|R]) :- A =\= B, not_in(A, R). + +str(X, S) :- + is_list(X) -> X = S; + atom(X) -> name(X, S). + +str(A + B, S) :- + str(A, AS), + str(B, BS), + append(AS, BS, S). + +str(A +/+ B, E) :- + str(A, AS), + str(B, BS), + rstrip("/", AS, AP), + lstrip("/", BS, BP), + concat([AP, "/", BP], E). + +escape(U, ES) :- + str(U, US), + (( + member(UC, US), + member(UC, " \n\t()[]{}&;$#!?*=<>\"`"), + not_in(39, US) + ) -> + concat(["'", US, "'"], ES); + escape_backslashes(US, ES) + ). + +escape(variable(Name), E) :- + concat(["${", Name, "}"], E). + +escape(A+B, E) :- + escape(A, AE), + escape(B, BE), + concat([AE, BE], E). + +escape(A +/+ B, E) :- + escape(A, AE), + escape(B, BE), + rstrip("/", AE, AP), + lstrip("/", BE, BP), + concat([AP, "/", BP], E). + +escape_n(X, N) :- escape(X, S), name(N, S). + +list_escape([], []). +list_escape([U|UR], [E|ER]) :- escape(U, E), list_escape(UR, ER). + +cmd_tokens(run(L), E) :- list_escape(L, E). + +cmd_tokens(run_append(L, F), T) :- + list_escape(L, E), + escape(F, FE), + append(E, [">>", FE], T). + +cmd_tokens(run_replace(L, F), T) :- + list_escape(L, E), + escape(F, FE), + append(E, [">", FE], T). + +cmd_tokens(run_outvar(L, V), T) :- + list_escape(L, E), + concat([V, "=$("], Pre), + concat([[Pre], E, [")"]], T). + +cmd_tokens(echo_append(String, File), E) :- + cmd_tokens(run_append([echo, String], File), E). +cmd_tokens(echo_replace(String, File), E) :- + cmd_tokens(run_replace([echo, String], File), E). +cmd_tokens(chroot(Dir, Args), E) :- + cmd_tokens(run([Dir +/+ 'chroot.sh'|Args]), E). + +format_cmds([], []). +format_cmds([Cmd|R], [S|SR]) :- + cmd_tokens(Cmd, Tokens), + strjoin(" ", Tokens, S), + format_cmds(R, SR). + +print_cmds([]). print_cmds(Commands) :- - flat_cmds(Commands, CmdList), - maplist(format_cmd, CmdList, Lines), !, - str_join("\n", Lines, String), - name(Name,String), - write(Name). - -print_solution(Solution) :- - str_join('\n', Solution, String), name(Text, String), - write(Text), - nl, nl. - -% print_solutions(Solutions) :- -% maplist(print_solution, Solutions). - -cmd_repr(Command) :- - write('representation of: '), write(Command), write(' ::'), nl, - setof(Lines , maplist(format_cmd, [Command], Lines), Solutions), - maplist(print_solution, Solutions). - -% cmds_repr(Commands) :- -% maplist(cmd_repr, Commands). - -flat_cmds(X, List) :- - ( list(X) - -> List = X - ; X = A + B - -> flat_cmds(A, AList), - flat_cmds(B, BList), - append(AList, BList, List) - ; functor(X, _Name, _), - arg(1, X, List), - ( list(List) - -> true - ; throw('functor does not have command list as first argument:' + X) - ) - ). - -% -% Gentoo stuff below -% + format_cmds(Commands, Lines), + strjoin("\n", Lines, S), + name(N,S), + write(N). site_conf_file(Name, Dir +/+ Name) :- site_conf_dir(Dir). -unpack_tarball(Tarball, Dir) --> - [run([tar, '-xpf', Tarball, '-C', Dir])]. - -create_tarball(Tarball, Dir, AddOpts) --> - [run([tar|Opts])], - {append(AddOpts, ['-cpf', Tarball, '-C', Dir, '.'], Opts)}. - -create_stage(Name, Dir) --> - {stages_dir(Stages)}, - create_tarball(Stages +/+ Name + '.tar.xz', Dir, ['--xz']). - -http_glob(variable(uri), Uri) --> - [run_outvar([http_glob, Uri], uri)]. - -digest_download(variable(downloaded), Uri) --> - [run_outvar([digest_download, Uri], downloaded)]. - -download_gentoo_stage(File, Mirror, Arch, Subarch, Subdir) --> - http_glob(Uri - ,Mirror + '/releases/' + Arch + '/current-stage3/' - + Subdir +'stage3-' + Subarch + '-*.DIGESTS.asc' - ), - digest_download(File, Uri). - -gentoo_stage(amd64 , amd64, amd64, '' ). -gentoo_stage(amd64_hardened, amd64, amd64, hardened). -gentoo_stage( i486 , x86 , i486, '' ). -gentoo_stage( i686 , x86 , i686, '' ). -gentoo_stage( i686_hardened, x86 , i686, hardened). - -download_gentoo_stage(File, Name) --> - { gentoo_stage(Name, Arch, Subarch, Subdir), - gentoo_mirror(Mirror) - }, - download_gentoo_stage(File, Mirror, Arch, Subarch, Subdir). - -gentoo_package(portage22 - ,[package_keywords('sys-apps/portage **') - ,package_mask('=sys-apps/portage-9999') - ]). -gentoo_package(nopy3k - ,[package_mask('=dev-lang/python-3') - ,package_mask('net-zope/zope-fixers') - ]). -gentoo_package(mc - ,[package_use('app-misc/mc slang -ncurses') - ,package_world('app-misc/mc') - ]). -gentoo_package(portage_utilities - ,[package_world('ccx-meta/portage-utilities') - ]). - -gentoo_package(vim - ,[package_world('app-editors/vim') - ] - ,['vim', 'vim-pager', 'vim-syntax']). - -gentoo_package(zsh - ,[package_world('app-shells/zsh') - ,package_world('app-shells/zsh-completion') - ] - ,['zsh-completion']). -gentoo_package(base_utilities - ,[package_world('ccx-meta/base-utilities') - ] - ,['zsh-completion', unicode]). -gentoo_package(base_system - ,[package_world('ccx-meta/base-system') - ] - ,[caps, xattrs, acl]). -gentoo_package(base_network - ,[package_world('ccx-meta/base-network') - ] - ,[ipv6]). -gentoo_package(filesystem_utilities - ,[package_world('ccx-meta/filesystem-utilities') - ] - ,['device-mapper', xfs]). -gentoo_package(network_utilities - ,[package_world('ccx-meta/network-utilities') - ] - ,[ssl,ipv6]). +unpack_tarball(Tarball, Dir, [run([tar, '-xpf', Tarball, '-C', Dir])]). + +create_tarball(Tarball, Dir, AddOpts, [run([tar | Opts])]) :- + append(AddOpts, ['-cpf', Tarball, '-C', Dir, '.'], Opts). + +create_stage(Name, Dir, Commands) :- + stages_dir(Stages), + create_tarball(Stages +/+ Name + '.tar.xz', Dir, ['--xz'], Commands). + +http_glob(Uri, [run_outvar([http_glob, Uri], uri)], variable(uri)). + +digest_download(Uri, + [run_outvar([digest_download, Uri], downloaded)], + variable(downloaded)). + +download_gentoo_stage(Mirror, Arch, Subarch, Subdir, Commands, File) :- + http_glob( + Mirror + '/releases/' + Arch + '/current-stage3/' + + Subdir +'stage3-' + Subarch + '-*.DIGESTS.asc', + GlobCommands, Uri), + digest_download(Uri, DownloadCommands, File), + append(GlobCommands, DownloadCommands, Commands). + +gentoo_stage(amd64, "amd64", "amd64", ""). +gentoo_stage(amd64_hardened, "amd64", "amd64", "hardened"). +gentoo_stage(i486, "x86", "i486", ""). +gentoo_stage(i686, "x86", "i686", ""). +gentoo_stage(i686_hardened, "x86", "i686", "hardened"). + +download_gentoo_stage(Name, Commands, File) :- + gentoo_stage(Name, Arch, Subarch, Subdir), + gentoo_mirror(Mirror), + download_gentoo_stage(Mirror, Arch, Subarch, Subdir, Commands, File). + +gentoo_package(portage22, [ + package_keywords('sys-apps/portage **'), + package_mask('=sys-apps/portage-9999')]). + +gentoo_package(nopy3k, [ + package_mask('=dev-lang/python-3'), + package_mask('net-zope/zope-fixers')]). + +gentoo_package(mc, [ + package_use('app-misc/mc slang -ncurses'), + package_world('app-misc/mc')]). + +gentoo_package(portage_utilities, [ + package_world('ccx-meta/portage-utilities')]). + +gentoo_package(vim, [package_world('app-editors/vim')], [ + 'vim', 'vim-pager', 'vim-syntax']). + +gentoo_package(zsh, [ + package_world('app-shells/zsh'), + package_world('app-shells/zsh-completion') + ],['zsh-completion']). + +gentoo_package(base_utilities, [ + package_world('ccx-meta/base-utilities') + ],['zsh-completion', unicode]). + +gentoo_package(base_system, [ + package_world('ccx-meta/base-system') + ],[caps, xattrs, acl]). + +gentoo_package(base_network, [ + package_world('ccx-meta/base-network') + ],[ipv6]). + +gentoo_package(filesystem_utilities, [ + package_world('ccx-meta/filesystem-utilities') + ],['device-mapper', xfs]). + +gentoo_package(network_utilities, [ + package_world('ccx-meta/network-utilities') + ],[ssl,ipv6]). gentoo_package(Name, Echos, []) :- gentoo_package(Name, Echos). - -gentoo_package(Name, Echos, UseEnabled, []) :- - gentoo_package(Name, Echos, UseEnabled). - -aggregate_gentoo_packages([ ], [ ], [ ], [ ]). -aggregate_gentoo_packages([PkgName|PkgNames], Echos, UseEnabled, UseDisabled) :- - gentoo_package(PkgName, PkgEchos, PkgUseEnabled, PkgUseDisabled), - aggregate_gentoo_packages(PkgNames, AggEchos - ,AggUseEnabled, AggUseDisabled), - append(PkgEchos, AggEchos, Echos), - append(PkgUseEnabled , AggUseEnabled , MergedUseEnabled) , - sort(MergedUseEnabled , UseEnabled ), - append(PkgUseDisabled, AggUseDisabled, MergedUseDisabled), - sort(MergedUseDisabled, UseDisabled). - -echo_package( package_mask(String), '/etc/portage/package.mask' , String). -echo_package( package_unmask(String), '/etc/portage/package.unmask' , String). -echo_package( package_use(String), '/etc/portage/package.use' , String). +gentoo_package(Name, Echos, UseE, []) :- gentoo_package(Name, Echos, UseE). + +aggregate_gentoo_packages([], [], [], []). +aggregate_gentoo_packages([PkgName|PR], Echos, UseE, UseD) :- + gentoo_package(PkgName, PkgEchos, PkgUseE, PkgUseD), + aggregate_gentoo_packages(PR, AggEchos, AggUseE, AggUseD), + append(PkgEchos, AggEchos, Echos), + append(PkgUseE, AggUseE, MergedUseE), sort(MergedUseE, UseE), + append(PkgUseD, AggUseD, MergedUseD), sort(MergedUseD, UseD). + +echo_package(package_mask(String), '/etc/portage/package.mask', String). +echo_package(package_unmask(String), '/etc/portage/package.unmask', String). +echo_package(package_use(String), '/etc/portage/package.use', String). echo_package(package_keywords(String), '/etc/portage/package.keywords', String). -echo_package( package_world(String), '/root/prosys/world' , String). - -echo_package_dir(Dir, echo_append(String, Dir +/+ Tail), Echo) :- - echo_package(Echo, Tail, String). - -% echo_packages(Commands, Echos, Dir) :- -% maplist(echo_package_dir(Dir), Commands, Echos). - -disabled_use(Use, '-' + Use). - -% disabled_uses(Uses, DisabledUses) :- -% maplist(disabled_use, Uses, DisabledUses). +echo_package(package_world(String), '/root/prosys/world', String). + +echo_packages(_, [], []). +echo_packages(Dir, [E|Echos], [echo_append(String, Dir +/+ Tail)|Commands]) :- + echo_package(E, Tail, String), + echo_packages(Dir, Echos, Commands). + +disabled_uses([], []). +disabled_uses([U|UR], [D|DR]) :- + str(U, US), + append("-", US, D), + disabled_uses(UR, DR). + +enabled_uses([], []). +enabled_uses([U|UR], [US|SR]) :- + str(U, US), + enabled_uses(UR, SR). dir_make_conf(Dir, Dir +/+ 'etc/make.conf'). -configure_gentoo_packages(Dir, Packages) --> - [echo_append('USE="' + JoinedUse + '"', Make_conf)], - { aggregate_gentoo_packages(Packages, Echos, UseEnabled, UseDisabled), - maplist(echo_package_dir(Dir), Commands, Echos) - }, - prepend(Commands), - { maplist(disabled_use, UseDisabled, UseDisabledMinus), - append(UseEnabled, UseDisabledMinus, MergedUse), - join(' ', MergedUse, JoinedUse), - dir_make_conf(Dir, Make_conf) - }. - -reset_make_conf(Dir, CFLAGS, CXXFLAGS, CHOST) --> - [echo_replace('#Autogenerated make.conf by ProSys\n' - + 'CFLGAGS="' + CFLAGS + '"\n' - + 'CXXFLAGS="' + CXXFLAGS + '"\n' - + 'CHOST="' + CHOST + '"\n' - ,Make_conf - )], - {dir_make_conf(Dir, Make_conf)}. - -append_site_make_conf(Dir) --> - [run_append([cat, Src], Dst)], - { site_conf_file('make.conf', Src), - dir_make_conf(Dir, Dst) - }. - -create_chroot_script(Dir, Arch) --> - [run([cp, '-Lp', '--', Conf + '/chroot.sh-' + Arch - , Dir +/+ 'chroot.sh' - ])], - {site_conf_dir(Conf)}. - -create_gentoo_builddir(Name, Dir) --> - {gentoo_stage(Name, _, ArchName, _)}, - download_gentoo_stage(Tarball, Name), - unpack_tarball(Tarball, Dir), - create_chroot_script(Dir, ArchName), - {work_dir(Work)}, - [run([rsync, '-a', Work +/+ 'overlay/' - , Dir +/+ 'var/portage/ccx-autobuild' - ])]. - -gentoo_build_stage4(Name, Dir) --> - [chroot(Dir, ['/root/prosys/rebuild_stage3.sh'])], - create_stage(Name + '_stage3', Dir), - [chroot(Dir, ['emerge -uDN $( cat /root/prosys/world )'])], - create_stage(Name + '_stage4', Dir). - -target(i686_hardened_stage3, Dir) --> - create_gentoo_builddir(i686_hardened, Dir), - reset_make_conf(Dir, - '-O2 -pipe -march=i686 -mtune=pentium4 -fomit-frame-pointer', - '${CFLAGS}', - 'i686-pc-linux-gnu'), - append_site_make_conf(Dir), - configure_gentoo_packages(Dir, [portage22, nopy3k, mc, vim]), - [chroot(Dir, ['/root/prosys/rebuild_stage3.sh'])], - create_stage(i686_hardened_stage3, Dir). -target(amd64_hardened_vshost, Dir) --> - create_gentoo_builddir(amd64_hardened, Dir), - {dir_make_conf(Dir, Make_conf)}, - reset_make_conf(Dir, '-O2 -pipe', '${CFLAGS}' - ,'amd64-pc-linux-gnu'), - [echo_append('ACCEPT_KEYWORDS="~amd64"', Make_conf)], - append_site_make_conf(Dir), - configure_gentoo_packages(Dir - ,[portage22, nopy3k, - base_utilities, base_system, base_network, - network_utilities, filesystem_utilities - ]), - gentoo_build_stage4(amd64_hardened_vshost, Dir). - -target(Commands, Foo, Dir) :- - phrase(target(Foo, Dir), Commands). +configure_gentoo_packages(Dir, Packages, Commands) :- + aggregate_gentoo_packages(Packages, Echos, UseE, UseD), + echo_packages(Dir, Echos, C1), + enabled_uses(UseE, UseES), + disabled_uses(UseD, UseDS), + append(UseES, UseDS, MergedUse), + join(' ', MergedUse, JoinedUse), + dir_make_conf(Dir, Make_conf), + Commands = [ echo_append('USE="' + JoinedUse + '"', Make_conf) | C1 ]. + +reset_make_conf(Dir, CFLAGS, CXXFLAGS, CHOST, [echo_replace( + '#Autogenerated make.conf by ProSys\n' + + 'CFLGAGS="' + CFLAGS + '"\n' + + 'CXXFLAGS="' + CXXFLAGS + '"\n' + + 'CHOST="' + CHOST + '"\n', + Make_conf )]) :- dir_make_conf(Dir, Make_conf). + +append_site_make_conf(Dir, [run_append([cat, Src], Dst)]) :- + site_conf_file('make.conf', Src), + dir_make_conf(Dir, Dst). + +create_chroot_script(Dir, Arch, [run([ + cp, '-Lp', '--', Conf + '/chroot.sh-' + Arch, Dir +/+ 'chroot.sh' + ])]) :- + site_conf_dir(Conf). + +create_gentoo_builddir(Name, Dir, Commands) :- + gentoo_stage(Name, _, ArchName, _), + download_gentoo_stage(Name, C1, Tarball), + unpack_tarball(Tarball, Dir, C2), + create_chroot_script(Dir, ArchName, C3), + work_dir(Wrk), + concat([C1, C2, C3, [ + run([rsync, '-a', Wrk +/+ 'overlay/', Dir +/+ 'var/portage/ccx-autobuild']) + ]], Commands). + +target(i686_hardened_stage3, Dir, Commands) :- + create_gentoo_builddir(i686_hardened, Dir, C1), + reset_make_conf(Dir, + "-O2 -pipe -march=i686 -mtune=pentium4 -fomit-frame-pointer", + "${CFLAGS}", + "i686-pc-linux-gnu", + C2), + append_site_make_conf(Dir, C3), + configure_gentoo_packages(Dir, [portage22, nopy3k, mc, vim], C4), + C5 = [chroot(Dir, ['/root/prosys/rebuild_stage3.sh'])], + create_stage(i686_hardened_stage3, Dir, C6), + concat([C1, C2, C3, C4, C5, C6], Commands). + +target(amd64_hardened_vshost, Dir, Commands) :- + create_gentoo_builddir(amd64_hardened, Dir, C1), + reset_make_conf(Dir, '-O2 -pipe', '${CFLAGS}', 'amd64-pc-linux-gnu', C2), + C3 = [echo_append('ACCEPT_KEYWORDS="~amd64"')], + append_site_make_conf(Dir, C4), + configure_gentoo_packages(Dir, [ + portage22, nopy3k + ], C5), + C6 = [chroot(Dir, ['/root/prosys/rebuild_stage3.sh'])], + create_stage(amd64_hardened_vshost_stage3, Dir, C7), + C8 = [chroot(Dir, ['emerge -uDN $( cat /root/prosys/world )'])], + create_stage(amd64_hardened_vshost_stage4, Dir, C9), + concat([C1, C2, C3, C4, C5, C6, C7, C8, C9], Commands). + +cmds_repr([]). +cmds_repr([Command|R]) :- + write('representation of: '), write(Command), write('\n'), + setof( ,format_cmds([Command]), Solutions), + cmds_repr(R).