Ada: Unterschied zwischen den Versionen
Keine Bearbeitungszusammenfassung |
Keine Bearbeitungszusammenfassung |
||
Zeile 38: | Zeile 38: | ||
| | | | ||
0001: '''with''' Ada.Text_IO; | 0001: '''with''' Ada.Text_IO; | ||
0002: | 0002: '''with''' Greetings_Task; | ||
0003: '''procedure''' main '''is''' | 0003: | ||
0004: '''procedure''' main '''is''' | |||
0005: '''use''' Ada.Text_IO; | |||
0006: '''begin''' | |||
0007: Put_Line( "Hallo Welt!" ); | |||
0008: Greetings_Task.Goodby; | |||
0009: '''end''' main; | |||
0010: | |||
|} | |} | ||
=== ada_package/*. | {| class="wikitable" | ||
|+ | |||
|- | |||
! greetings_task.ads | |||
|- | |||
| | |||
0001: '''with''' Ada.Text_IO; | |||
0002: | |||
0003: '''package''' '''body''' Greetings_Task '''is''' | |||
0004: '''procedure''' Goodby '''is''' | |||
0005: '''begin''' | |||
0006: Ada.Text_IO.Put_Line("Goodby"); | |||
0007: '''end''' Goodby; | |||
0008: '''end''' Greetings_Task; | |||
0009: | |||
|} | |||
=== ada_package/*.ads: Paket-Header-Dateien === | |||
{| class="wikitable" | |||
|+ | |||
|- | |||
! greetings_task.ads | |||
|- | |||
| | |||
0001: '''package''' Greetings_Task '''is''' | |||
0002: '''procedure''' Goodby; | |||
0003: '''end''' Greetings_Task; | |||
0004: | |||
|} | |||
=== makefile === | |||
{| class="wikitable" | |||
|+ | |||
|- | |||
! makefile | |||
|- | |||
| | |||
0001: # ############################################################################ | |||
0001: # Copyright (C) 2022 by # | |||
0001: # Christoph Stadelmann, M.Sc. # | |||
0001: # # | |||
0001: # This file is free software; you can redistribute it and/or modify # | |||
0001: # it under the terms of the GNU General Public License as published by # | |||
0001: # the Free Software Foundation; either version 2 of the License, or # | |||
0001: # (at your option) any later version. # | |||
0001: # # | |||
0001: # This program is distributed in the hope that it will be useful, # | |||
0001: # but WITHOUT ANY WARRANTY; without even the implied warranty of # | |||
0001: # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # | |||
0001: # GNU General Public License for more details. # | |||
0001: # # | |||
0001: # You should have received a copy of the GNU General Public License # | |||
0001: # along with this program; if not, write to the # | |||
0001: # Free Software Foundation, Inc., # | |||
0001: # 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. # | |||
0001: # ############################################################################ | |||
0001: | |||
0001: PROJECT_NAME = ADA_PRGM_0000_hello_world | |||
0001: | |||
0001: TARGET_EXEC_NAME = hello_world.exec | |||
0001: | |||
0001: | |||
0001: # ############################################################################ | |||
0001: # all | |||
0001: # ############################################################################ | |||
0001: | |||
0001: GNAT = /usr/bin/i686-linux-gnu-gcc | |||
0001: GNATBIND = /usr/bin/i686-linux-gnu-gnatbind | |||
0001: GNATLINK = /usr/bin/i686-linux-gnu-gnatlink | |||
0001: | |||
0001: FOLDERS = work \ | |||
0001: ../BACKUP | |||
0001: | |||
0001: ADA_BODIES = $(shell cd ada_body; ls *.adb) | |||
0001: | |||
0001: .PHONY: all | |||
0001: all: $(FOLDERS) | |||
0001: cp $(shell pwd)/ada_body/*.adb $(shell pwd)/ada_package/*.ads $(shell pwd)/work | |||
0001: (cd $(shell pwd)/work; \ | |||
0001: for item in $(ADA_BODIES); do \ | |||
0001: $(GNAT) -c $$item; \ | |||
0001: done ; \ | |||
0001: $(GNATBIND) main; \ | |||
0001: $(GNATLINK) main; \ | |||
0001: cp main ../$(TARGET_EXEC_NAME)) | |||
0001: echo "all done" | |||
0001: echo "$(ADA_BODIES)" | |||
0001: | |||
0001: # ############################################################################ | |||
0001: # $(FOLDERS) | |||
0001: # ############################################################################ | |||
0001: | |||
0001: work: | |||
0001: mkdir -p $@ | |||
0001: | |||
0001: ../BACKUP: | |||
0001: mkdir -p $@ | |||
0001: | |||
0001: | |||
0001: # ############################################################################ | |||
0001: # edit, clean | |||
0001: # ############################################################################ | |||
0001: | |||
0001: .PHONY: edit | |||
0001: edit: | |||
0001: kate makefile ada_body/*.adb ada_package/*.ads & | |||
0001: echo "edit done" | |||
0001: | |||
0001: | |||
0001: .PHONY: clean | |||
0001: clean: | |||
0001: rm -f $(shell pwd)/*.exec | |||
0001: rm -f $(shell pwd)/work/* $(shell pwd)/work/*.* | |||
0001: echo "clean done" | |||
0001: | |||
0001: | |||
0001: # ############################################################################ | |||
0001: # backup | |||
0001: # ############################################################################ | |||
0001: | |||
0001: BACKUP_OBJECTS = makefile ada_body/*.adb ada_package/*.ads | |||
0001: | |||
0001: .PHONY: backup | |||
0001: backup: $(FOLDERS) | |||
0001: zip -r ../BACKUP/ZIP__$(PROJECT_NAME)__$$(date +"%Y_%m%d_%H%M%S" -u).zip $(BACKUP_OBJECTS) > | |||
../BACKUP/ZIP__$(PROJECT_NAME)__$$(date +"%Y_%m%d_%H%M%S" -u).txt | |||
0001: @echo "backup done" | |||
0001: | |||
|} | |||
Stand: | Stand: 2022_1202 |
Version vom 3. Dezember 2022, 00:14 Uhr
Ada
Framework
Zum Erstellen eines lauffähigen Programms unter Linux muss der Quelltext, welcher kompiliert werden soll, in ein Framework eingefügt werden. Dieses besteht im Wesentlichen aus einer flachen Ordnerstruktur, in welcher neben Paket-Header-Dateien (engl: *.ads) und Paket-Implementierungs-Dateien (engl: *.adb) temporäre Dateien sortiert sind. Zur Kompilierung und zur Dateiverwaltung unter Verwendung des Steuerprogramms "make" genügt eine Steuerdatei namens "makefile" im Wurzelverzeichnis. Die Bedienung des Frameworks erfolgt unter Verwendung der Kommandozeile.
Ordner "ada_package"
In diesem Ordner werden alle Paket-Header-Dateien (engl: *.ads) abgelegt.
Ordner "ada_body"
In diesem Ordner werden alle Paket-Implementierungs-Dateien (engl: *.adb) abgelegt.
Ordner "work"
Hier werden während des Kompiliervorgangs temporäre Dateien erzeugt. Der Inhalt des Ordners muss weder bearbeitet noch archiviert werden.
Ordner "../BACKUP"
Es besteht die Möglichkeit, unter Verwendung der Steuerdatei Zwischenstände abzuspeichern. Die Quelltexte in den Ordnern "ada_body" und "ada_package" werden in einer Zip-Datei archiviert. Der Name der Zip-Datei in der Steuerdatei unter Verwendung des Projektnamens, eines Datumstempels und eines Zeitstempels automatisch vergeben.
Erstes Programm: Hallo Welt!
Dieses Programm gibt die Zeichenkette "Hallo Welt!" unter Verwendung der Bibliothek "Ada.Text_IO" in der Kommandozeile aus.
ada_body/*.adb: Paket-Implementierungs-Dateien
main.adb |
---|
0001: with Ada.Text_IO; 0002: with Greetings_Task; 0003: 0004: procedure main is 0005: use Ada.Text_IO; 0006: begin 0007: Put_Line( "Hallo Welt!" ); 0008: Greetings_Task.Goodby; 0009: end main; 0010: |
greetings_task.ads |
---|
0001: with Ada.Text_IO; 0002: 0003: package body Greetings_Task is 0004: procedure Goodby is 0005: begin 0006: Ada.Text_IO.Put_Line("Goodby"); 0007: end Goodby; 0008: end Greetings_Task; 0009: |
ada_package/*.ads: Paket-Header-Dateien
greetings_task.ads |
---|
0001: package Greetings_Task is 0002: procedure Goodby; 0003: end Greetings_Task; 0004: |
makefile
makefile |
---|
0001: # ############################################################################ 0001: # Copyright (C) 2022 by # 0001: # Christoph Stadelmann, M.Sc. # 0001: # # 0001: # This file is free software; you can redistribute it and/or modify # 0001: # it under the terms of the GNU General Public License as published by # 0001: # the Free Software Foundation; either version 2 of the License, or # 0001: # (at your option) any later version. # 0001: # # 0001: # This program is distributed in the hope that it will be useful, # 0001: # but WITHOUT ANY WARRANTY; without even the implied warranty of # 0001: # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # 0001: # GNU General Public License for more details. # 0001: # # 0001: # You should have received a copy of the GNU General Public License # 0001: # along with this program; if not, write to the # 0001: # Free Software Foundation, Inc., # 0001: # 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. # 0001: # ############################################################################ 0001: 0001: PROJECT_NAME = ADA_PRGM_0000_hello_world 0001: 0001: TARGET_EXEC_NAME = hello_world.exec 0001: 0001: 0001: # ############################################################################ 0001: # all 0001: # ############################################################################ 0001: 0001: GNAT = /usr/bin/i686-linux-gnu-gcc 0001: GNATBIND = /usr/bin/i686-linux-gnu-gnatbind 0001: GNATLINK = /usr/bin/i686-linux-gnu-gnatlink 0001: 0001: FOLDERS = work \ 0001: ../BACKUP 0001: 0001: ADA_BODIES = $(shell cd ada_body; ls *.adb) 0001: 0001: .PHONY: all 0001: all: $(FOLDERS) 0001: cp $(shell pwd)/ada_body/*.adb $(shell pwd)/ada_package/*.ads $(shell pwd)/work 0001: (cd $(shell pwd)/work; \ 0001: for item in $(ADA_BODIES); do \ 0001: $(GNAT) -c $$item; \ 0001: done ; \ 0001: $(GNATBIND) main; \ 0001: $(GNATLINK) main; \ 0001: cp main ../$(TARGET_EXEC_NAME)) 0001: echo "all done" 0001: echo "$(ADA_BODIES)" 0001: 0001: # ############################################################################ 0001: # $(FOLDERS) 0001: # ############################################################################ 0001: 0001: work: 0001: mkdir -p $@ 0001: 0001: ../BACKUP: 0001: mkdir -p $@ 0001: 0001: 0001: # ############################################################################ 0001: # edit, clean 0001: # ############################################################################ 0001: 0001: .PHONY: edit 0001: edit: 0001: kate makefile ada_body/*.adb ada_package/*.ads & 0001: echo "edit done" 0001: 0001: 0001: .PHONY: clean 0001: clean: 0001: rm -f $(shell pwd)/*.exec 0001: rm -f $(shell pwd)/work/* $(shell pwd)/work/*.* 0001: echo "clean done" 0001: 0001: 0001: # ############################################################################ 0001: # backup 0001: # ############################################################################ 0001: 0001: BACKUP_OBJECTS = makefile ada_body/*.adb ada_package/*.ads 0001: 0001: .PHONY: backup 0001: backup: $(FOLDERS) 0001: zip -r ../BACKUP/ZIP__$(PROJECT_NAME)__$$(date +"%Y_%m%d_%H%M%S" -u).zip $(BACKUP_OBJECTS) > ../BACKUP/ZIP__$(PROJECT_NAME)__$$(date +"%Y_%m%d_%H%M%S" -u).txt 0001: @echo "backup done" 0001: |
Stand: 2022_1202