Skip to content

Commit

Permalink
Merge pull request cretz#15 from cretz/tor-0.3.5.x
Browse files Browse the repository at this point in the history
Tor 0.3.5.7 as latest stable version
  • Loading branch information
cretz committed Jan 22, 2019
2 parents 64e6b57 + b1d03f7 commit 97ab0ce
Show file tree
Hide file tree
Showing 4 changed files with 60 additions and 22 deletions.
26 changes: 9 additions & 17 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@ This project helps compile Tor into a static lib for use in other projects.
The dependencies are in this repository as submodules so this repository needs to be cloned with `--recursive`. The
submodules are:

* [OpenSSL](https://github.com/openssl/openssl/) - Checked out at tag `OpenSSL_1_0_2o`
* [OpenSSL](https://github.com/openssl/openssl/) - Checked out at tag `OpenSSL_1_0_2p`
* [Libevent](https://github.com/libevent/libevent) - Checked out at tag `release-2.1.8-stable`
* [zlib](https://github.com/madler/zlib) - Checked out at tag `v1.2.11`
* [XZ Utils](https://git.tukaani.org/?p=xz.git) - Checked out at tag `v5.2.4`
* [Tor](https://github.com/torproject/tor) - Checked out at tag `tor-0.3.3.7`
* [Tor](https://github.com/torproject/tor) - Checked out at tag `tor-0.3.5.7`

Many many bugs and quirks were hit while deriving these steps. Also many other repos, mailing lists, etc were leveraged
to get some of the pieces right. They are not listed here for brevity reasons.
Expand Down Expand Up @@ -73,21 +73,13 @@ are being run, add `-verbose` before the command.

## Using

Once the libs have been compiled, they can be used to link with your program. Below is the list of each dir (relative to
this repository root) and the library names inside the dirs. Library names are just the filenames without the "lib"
prefix of ".a" extension. When using something like `ld` or `LDFLAGS`, the directories (i.e. `-L<dir>`) and the libs
(i.e. `-l<libname>`) must be given in the order below:

* `tor/src/or` - `tor`
* `tor/src/common` - `or`, `or-crypto`, `curve25519_donna`, `or-ctime`, and `or-event`
* `tor/src/trunnel` - `or-trunnel`
* `tor/src/ext/keccak-tiny` - `keccak-tiny`
* `tor/src/ext/ed25519/ref10` - `ed25519_ref10`
* `tor/src/ext/ed25519/donna` - `ed25519_donna`
* `libevent/dist/lib` - `event`
* `xz/dist/lib` - `lzma`
* `zlib/dist/lib` - `z`
* `openssl/dist/lib` - `ssl`, and `crypto`
Once the libs have been compiled, they can be used to link with your program. Due to recent refactorings within the Tor
source, the libraries are not listed here but instead listed when executing:

go run build.go show-libs

This lists directories (relative, prefixed with `-L`) followed by lib names (file sans `lib` prefix and sans `.a`
extension, prefixed with `-l`) as might be used in `ld`.

The OS-specific system libs that have to be referenced (i.e. `-l<libname>`) are:

Expand Down
52 changes: 49 additions & 3 deletions build.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ func main() {
flag.StringVar(&autopointPath, "autopoint-path", "/usr/local/opt/gettext/bin", "OSX: Directory that contains autopoint binary")
flag.Parse()
if len(flag.Args()) != 1 {
log.Fatal("Missing command. Can be build-all, build-<folder>, clean-all, or clean-<folder>")
log.Fatal("Missing command. Can be build-all, build-<folder>, clean-all, clean-<folder>, or show-libs")
}
if err := run(flag.Args()[0]); err != nil {
log.Fatal(err)
Expand All @@ -39,8 +39,10 @@ func run(cmd string) error {
return build(cmd[6:])
} else if strings.HasPrefix(cmd, "clean-") {
return clean(cmd[6:])
} else if cmd == "show-libs" {
return showLibs()
}
return fmt.Errorf("Invalid command: %v. Should be build-all, build-<folder>, clean-all, or clean-<folder>", cmd)
return fmt.Errorf("Invalid command: %v. Should be build-all, build-<folder>, clean-all, clean-<folder>, or show-libs", cmd)
}

func getAbsCurrDir() string {
Expand Down Expand Up @@ -145,7 +147,7 @@ func build(folder string) error {
var env = []string{"LDFLAGS=-s"}
var torConf []string
if runtime.GOOS == "windows" {
env = append(env, "LIBS=-lcrypt32")
env = append(env, "LIBS=-lcrypt32 -lgdi32")
}
torConf = []string{"sh", "./configure", "--prefix=" + pwd + "/dist",
"--disable-gcc-hardening", "--disable-system-torrc", "--disable-asciidoc",
Expand Down Expand Up @@ -228,3 +230,47 @@ func runCmd(folder string, env []string, cmd string, args ...string) error {
}
return c.Run()
}

func showLibs() error {
// Ask Tor for their libs
cmd := exec.Command("make", "show-libs")
cmd.Dir = "tor"
out, err := cmd.CombinedOutput()
if err != nil {
return fmt.Errorf("Failed 'make show-libs' in tor: %v", err)
}
// Key is dir
libSets := [][]string{}
for _, lib := range strings.Split(strings.TrimSpace(string(out)), " ") {
dir, file := path.Split(lib)
dir = path.Join("tor", dir)
file = strings.TrimPrefix(strings.TrimSuffix(file, ".a"), "lib")
found := false
for i, libSet := range libSets {
if libSet[0] == dir {
libSets[i] = append(libSets[i], file)
found = true
break
}
}
if !found {
libSets = append(libSets, []string{dir, file})
}
}
// Add the rest of the known libs
libSets = append(libSets,
[]string{"libevent/dist/lib", "event"},
[]string{"xz/dist/lib", "lzma"},
[]string{"zlib/dist/lib", "z"},
[]string{"openssl/dist/lib", "ssl", "crypto"},
)
// Dump em
for _, libSet := range libSets {
fmt.Print("-L" + libSet[0])
for _, lib := range libSet[1:] {
fmt.Print(" -l" + lib)
}
fmt.Println()
}
return nil
}
2 changes: 1 addition & 1 deletion openssl
Submodule openssl updated 130 files
2 changes: 1 addition & 1 deletion tor
Submodule tor updated 977 files

0 comments on commit 97ab0ce

Please sign in to comment.