Skip to content

Commit

Permalink
add "cc.rkt" to compile "callbacks.c"
Browse files Browse the repository at this point in the history
Use some indirection to avoid a package dependency on `dynext-lib`,
since the intent is for "cc.rkt" to be used manually.
  • Loading branch information
LiberalArtist committed Aug 8, 2020
1 parent 77a03c8 commit 9b09c3f
Showing 1 changed file with 64 additions and 0 deletions.
64 changes: 64 additions & 0 deletions portaudio/lib/cc.rkt
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
#lang racket

;; Compile "callbacks.c" using Racket's suggested compiler and flags.

;; Heavily based on Sam Tobin-Hochstadt's bcrypt/private/install.rkt
;; https://github.com/samth/bcrypt.rkt

(require racket/file
racket/runtime-path
(for-syntax syntax/transformer))

(define-syntax-rule (require-without-pkg-dep lib name)
(begin (define tmp
(let* ([v #f]
[name (λ ()
(unless v
(set! v (dynamic-require 'lib 'name)))
v)])
name))
(define-syntax name
(make-variable-like-transformer #'(tmp)))))

(require-without-pkg-dep dynext/file append-extension-suffix)
(require-without-pkg-dep dynext/link current-use-mzdyn)
(require-without-pkg-dep dynext/link current-extension-linker-flags)
(require-without-pkg-dep dynext/link link-extension)

(define-runtime-path callbacks.c
"callbacks.c")

(define lib/
(path-only callbacks.c))

(define (so-path-elem)
(append-extension-suffix "callbacks"))

(define (cc [so-path (build-path lib/
(system-library-subpath #f)
(so-path-elem))]
#:overwrite? [overwrite? #t])
(parameterize ([current-use-mzdyn #f]
[current-extension-linker-flags
(if (eq? 'macosx (system-type 'os))
(list* "-mmacosx-version-min=10.5"
(current-extension-linker-flags))
(current-extension-linker-flags))])
(when (and overwrite? (file-exists? so-path))
(delete-file so-path))
(make-parent-directory* so-path)
(link-extension #f ;; not quiet
(list callbacks.c)
so-path)))

(define (cc/i386-macosx)
(unless (eq? 'macosx (system-type 'os))
(raise-arguments-error 'cc/i386-macosx
"unsupported system type"
"expected" 'macosx
"given" (system-type 'os)))
(parameterize ([current-extension-linker-flags
(list* "-arch"
"i386"
(current-extension-linker-flags))])
(cc (build-path lib/ "i386-macosx" (so-path-elem)))))

0 comments on commit 9b09c3f

Please sign in to comment.