我會使用GNAT Project工具和命令行gnatmake
。
我剛剛設置了一個小例子(所以我可以肯定我說的作品!)。我有3個目錄; teacher/
包含教師提供的源代碼,我假設您不想更改,並且可能無法寫入訪問權限,jacks_lib/
包含teacher.gpr
,它指向teacher/
(您也可以將自己的代碼庫代碼也包含在內)並且jack/
包含您的代碼代碼main.adb
和main.gpr
。
jacks_lib/teacher.gpr
:
project Teacher is
-- This project calls up the teacher-supplied source.
-- This is a list of paths, which can be absolute but
-- if relative are relative to the directory where this .gpr
-- is found.
for Source_Dirs use ("../teacher");
-- Keep the built objects (.ali, .o) out of the way. Use the -p
-- gnatmake flag to have directories like this built
-- automatically.
for Object_Dir use ".build";
end Teacher;
jack/main.gpr
:
-- teacher.gpr tells where to find library source and how to build it.
with "../jacks_lib/teacher";
project Main is
-- for Source_Dirs use ("."); (commented out because it's the default)
-- Keep built objects out of the way
for Object_Dir use ".build";
-- Build executables here rather than in Object_Dir
for Exec_Dir use ".";
-- What's the main program? (there can be more than one)
for Main use ("main.adb");
end Main;
jack/main.adb
:
with Foo;
procedure Main is
begin
null;
end Main;
然後,在jack/
,
$ gnatmake -p -P main.gpr
object directory "/Users/simon/tmp/jacks_lib/.build" created for project teacher
object directory "/Users/simon/tmp/jack/.build" created for project main
gcc -c -I- -gnatA /Users/simon/tmp/jack/main.adb
gcc -c -I- -gnatA /Users/simon/tmp/teacher/foo.ads
gnatbind -I- -x /Users/simon/tmp/jack/.build/main.ali
gnatlink /Users/simon/tmp/jack/.build/main.ali -o /Users/simon/tmp/jack/main
我應該補充說我在Mac OS X上使用GCC 4.7.0,但這對任何最近的GNAT都可以正常工作。
恐怕我們使用的是一個漂亮的骨頭文本編輯器,而不是GPS ......我想我可以編寫一個bash腳本來處理爲我設置命令行選項,或者什麼? –
如果你可以從命令行調用gnatmake,你可以同樣從腳本調用它。 –