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 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 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 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213
|
# Desenvolvendo
Este documento descreve como configurar o ambiente de desenvolvimento local do
GPT usando as mesmas etapas utilizadas no pipeline do [GitHub
Actions](.github/workflows/build.yml) para GNU/Linux e Windows.
Dependências:
- g++
- make
- autoconf
- automake
- libtool
- pkg-config
- libantlr-dev (ANTLR 2.x)
- libpcre2-dev
- nasm
- wget
## Baixar o fonte
```shell
git clone https://github.com/gportugol/gpt.git
```
## GNU/Linux
O GPT pode ser compilado nativamente em distribuições GNU/Linux, como o
Debian/Ubuntu, usando os pacotes:
### 1. Instalar dependências no Debian/Ubuntu
```shell
sudo apt install -y \
build-essential autoconf automake libtool pkg-config \
libantlr-dev libpcre2-dev nasm
```
### 2. Configurar e compilar no Debian/Ubuntu
```shell
autoreconf -i
./configure --prefix=/usr/local
make -j$(nproc)
```
### 3. Testar no Debian/Ubuntu
#### Interpretador no Debian/Ubuntu
```shell
src/gpt -i exemplos/olamundo.gpt
```
#### Compilador no Debian/Ubuntu
```shell
src/gpt -o olamundo exemplos/olamundo.gpt
./olamundo
```
## Windows (MSYS2 / Mingw-w64)
O GPT é compilado no Windows usando MSYS2.
### 1. Instalar MSYS2
Baixar em <https://www.msys2.org> e instalar o MSYS2
### 2. Instalar dependências
Abra o terminal **MSYS2 MinGW 64-bit**.
```shell
pacman -Syu --noconfirm
pacman -S --noconfirm \
autoconf automake libtool make \
mingw-w64-x86_64-gcc mingw-w64-x86_64-gcc-libs \
mingw-w64-x86_64-pcre2 pkg-config \
tar unzip wget
```
### 3. Instalar Java (necessário para ANTLR 2.x)
```shell
wget https://download.java.net/java/GA/jdk25.0.1/2fbf10d8c78e40bd87641c434705079d/8/GPL/openjdk-25.0.1_windows-x64_bin.zip
unzip openjdk-25.0.1_windows-x64_bin.zip
export PATH=$PATH:$(pwd)/jdk-25.0.1/bin
```
### 4. Compilar ANTLR 2.7.7 no Windows (com patches aplicados)
O ANTLR 2 é muito antigo e não compila corretamente no `Mingw64` sem correções.
Precisamos aplicar dois patches usando o `sed`.
#### Baixar e extrair
```shell
wget http://www.antlr2.org/download/antlr-2.7.7.tar.gz
tar xvfz antlr-2.7.7.tar.gz
cd antlr-2.7.7
```
#### Patch 1 — incluir \_stricmp no Windows
Insere no topo de `CharScanner.hpp`:
```shell
sed -i \
'1i \
#ifdef _WIN32\n\
#include <string.h>\n\
#define strcasecmp _stricmp\n\
#endif' \
lib/cpp/antlr/CharScanner.hpp
```
#### Patch 2 — substituir binary_function obsoleto
```shell
sed -i \
's/struct CharScannerLiteralsLess : public binary_function<string, string, bool>/\
struct CharScannerLiteralsLess { \
bool operator()(const std::string& x, const std::string& y) const { \
return strcasecmp(x.c_str(), y.c_str()) < 0; \
} \
};/g' \
lib/cpp/antlr/CharScanner.hpp
```
Esses patches corrigem:
- Incompatibilidade com `binary_function` removido no C++17
- Ausência de `strcasecmp` no Windows
#### Compilar o ANTLR com flags estáticas
```shell
export CXXFLAGS="-O2 -std=gnu++14 -static -static-libgcc -static-libstdc++"
export LDFLAGS="-static -static-libgcc -static-libstdc++"
autoreconf -fi
./configure --prefix=/usr/local
make -j$(nproc)
make install
```
Criar o alias usado pelo GPT:
```shell
ln -s /usr/local/bin/antlr /usr/local/bin/runantlr || true
```
### 5. Instalar o NASM
```shell
wget https://www.nasm.us/pub/nasm/releasebuilds/0.99.06/nasm-0.99.06-win32.zip
unzip nasm-0.99.06-win32.zip
cp nasm-0.99.06/nasm.exe /mingw64/bin/
```
### 6. Compilar o GPT no Windows
```shell
export CXXFLAGS="-O2 -std=gnu++14 -static -static-libgcc -static-libstdc++"
export LDFLAGS="-static -static-libgcc -static-libstdc++"
autoreconf -i
./configure --prefix=/usr/local
make -j$(nproc)
make install
```
### 7. Testar no Windows
#### Interpretador no Windows
```shell
gpt.exe -i exemplos/olamundo.gpt
```
#### Compilador no Windows
```shell
gpt.exe -o olamundo.exe exemplos/olamundo.gpt
./olamundo.exe
```
## Documentação
Documentação na pasta [doc](doc) e o manual (LaTeX) em [doc/manual](doc/manual).
### Instalar dependências no Debian/Ubuntu
```shell
sudo apt install -y latex-make texlive-latex-base texlive-lang-portuguese latex2html
```
### Compilar o manual
Para PDF:
```shell
cd doc/manual
pdflatex manual.tex
```
Para HTML:
```shell
cd doc/manual
latex2html manual.tex
```
|