gnu: Add libhx.
[jackhill/guix/guix.git] / gnu / packages / c.scm
1 ;;; GNU Guix --- Functional package management for GNU
2 ;;; Copyright © 2016, 2018 Ludovic Courtès <ludo@gnu.org>
3 ;;; Copyright © 2016, 2017, 2018, 2019 Ricardo Wurmus <rekado@elephly.net>
4 ;;; Copyright © 2018 Tobias Geerinckx-Rice <me@tobias.gr>
5 ;;; Copyright © 2018, 2019 Pierre Neidhardt <mail@ambrevar.xyz>
6 ;;; Copyright © 2019 Efraim Flashner <efraim@flashner.co.il>
7 ;;; Copyright © 2019 Guillaume Le Vaillant <glv@posteo.net>
8 ;;;
9 ;;; This file is part of GNU Guix.
10 ;;;
11 ;;; GNU Guix is free software; you can redistribute it and/or modify it
12 ;;; under the terms of the GNU General Public License as published by
13 ;;; the Free Software Foundation; either version 3 of the License, or (at
14 ;;; your option) any later version.
15 ;;;
16 ;;; GNU Guix is distributed in the hope that it will be useful, but
17 ;;; WITHOUT ANY WARRANTY; without even the implied warranty of
18 ;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 ;;; GNU General Public License for more details.
20 ;;;
21 ;;; You should have received a copy of the GNU General Public License
22 ;;; along with GNU Guix. If not, see <http://www.gnu.org/licenses/>.
23
24 (define-module (gnu packages c)
25 #:use-module ((guix licenses) #:prefix license:)
26 #:use-module (guix packages)
27 #:use-module (guix download)
28 #:use-module (guix git-download)
29 #:use-module (guix build-system gnu)
30 #:use-module (guix build-system trivial)
31 #:use-module (gnu packages bootstrap)
32 #:use-module (gnu packages bison)
33 #:use-module (gnu packages check)
34 #:use-module (gnu packages flex)
35 #:use-module (gnu packages perl)
36 #:use-module (gnu packages texinfo)
37 #:use-module (gnu packages guile)
38 #:use-module (gnu packages multiprecision)
39 #:use-module (gnu packages pcre)
40 #:use-module (gnu packages python)
41 #:use-module (gnu packages autotools)
42 #:use-module (gnu packages gettext)
43 #:use-module (gnu packages pkg-config)
44 #:use-module (gnu packages xml))
45
46 (define-public tcc
47 (package
48 (name "tcc") ;aka. "tinycc"
49 (version "0.9.27")
50 (source (origin
51 (method url-fetch)
52 (uri (string-append "mirror://savannah/tinycc/tcc-"
53 version ".tar.bz2"))
54 (sha256
55 (base32
56 "177bdhwzrnqgyrdv1dwvpd04fcxj68s5pm1dzwny6359ziway8yy"))))
57 (build-system gnu-build-system)
58 (native-inputs `(("perl" ,perl)
59 ("texinfo" ,texinfo)))
60 (arguments
61 `(#:configure-flags (list (string-append "--elfinterp="
62 (assoc-ref %build-inputs "libc")
63 ,(glibc-dynamic-linker))
64 (string-append "--crtprefix="
65 (assoc-ref %build-inputs "libc")
66 "/lib")
67 (string-append "--sysincludepaths="
68 (assoc-ref %build-inputs "libc")
69 "/include:"
70 (assoc-ref %build-inputs
71 "kernel-headers")
72 "/include:{B}/include")
73 (string-append "--libpaths="
74 (assoc-ref %build-inputs "libc")
75 "/lib")
76 ,@(if (string-prefix? "armhf-linux"
77 (or (%current-target-system)
78 (%current-system)))
79 `("--triplet=arm-linux-gnueabihf")
80 '()))
81 #:test-target "test"))
82 ;; Fails to build on MIPS: "Unsupported CPU"
83 (supported-systems (delete "mips64el-linux" %supported-systems))
84 (synopsis "Tiny and fast C compiler")
85 (description
86 "TCC, also referred to as \"TinyCC\", is a small and fast C compiler
87 written in C. It supports ANSI C with GNU and extensions and most of the C99
88 standard.")
89 (home-page "http://www.tinycc.org/")
90 ;; An attempt to re-licence tcc under the Expat licence is underway but not
91 ;; (if ever) complete. See the RELICENSING file for more information.
92 (license license:lgpl2.1+)))
93
94 (define-public tcc-wrapper
95 (package
96 (inherit tcc)
97 (name "tcc-wrapper")
98 (build-system trivial-build-system)
99 (native-inputs '())
100 (inputs `(("tcc" ,tcc)
101 ("guile" ,guile-2.2)))
102
103 ;; By default TCC does not honor any search path environment variable.
104 ;; This wrapper adds them.
105 ;;
106 ;; FIXME: TCC includes its own linker so our 'ld-wrapper' hack to set the
107 ;; RUNPATH is ineffective here. We should modify TCC itself.
108 (native-search-paths
109 (list (search-path-specification
110 (variable "TCC_CPATH")
111 (files '("include")))
112 (search-path-specification
113 (variable "TCC_LIBRARY_PATH")
114 (files '("lib" "lib64")))))
115
116 (arguments
117 '(#:builder
118 (let* ((out (assoc-ref %outputs "out"))
119 (bin (string-append out "/bin"))
120 (tcc (assoc-ref %build-inputs "tcc"))
121 (guile (assoc-ref %build-inputs "guile")))
122 (mkdir out)
123 (mkdir bin)
124 (call-with-output-file (string-append bin "/cc")
125 (lambda (port)
126 (format port "#!~a/bin/guile --no-auto-compile~%!#~%" guile)
127 (write
128 `(begin
129 (use-modules (ice-9 match)
130 (srfi srfi-26))
131
132 (define (split path)
133 (string-tokenize path (char-set-complement
134 (char-set #\:))))
135
136 (apply execl ,(string-append tcc "/bin/tcc")
137 ,(string-append tcc "/bin/tcc") ;argv[0]
138 (append (cdr (command-line))
139 (match (getenv "TCC_CPATH")
140 (#f '())
141 (str
142 (map (cut string-append "-I" <>)
143 (split str))))
144 (match (getenv "TCC_LIBRARY_PATH")
145 (#f '())
146 (str
147 (map (cut string-append "-L" <>)
148 (split str)))))))
149 port)
150 (chmod port #o777)))
151 #t)))
152 (synopsis "Wrapper providing the 'cc' command for TCC")))
153
154 (define-public pcc
155 (package
156 (name "pcc")
157 (version "20170109")
158 (source (origin
159 (method url-fetch)
160 (uri (string-append "http://pcc.ludd.ltu.se/ftp/pub/pcc/pcc-"
161 version ".tgz"))
162 (sha256
163 (base32
164 "1p34w496095mi0473f815w6wbi57zxil106mg7pj6sg6gzpjcgww"))))
165 (build-system gnu-build-system)
166 (arguments
167 `(#:phases
168 (modify-phases %standard-phases
169 (replace 'check
170 (lambda _ (invoke "make" "-C" "cc/cpp" "test") #t)))))
171 (native-inputs
172 `(("bison" ,bison)
173 ("flex" ,flex)))
174 (synopsis "Portable C compiler")
175 (description
176 "PCC is a portable C compiler. The project goal is to write a C99
177 compiler while still keeping it small, simple, fast and understandable.")
178 (home-page "http://pcc.ludd.ltu.se")
179 (supported-systems (delete "aarch64-linux" %supported-systems))
180 ;; PCC incorporates code under various BSD licenses; for new code bsd-2 is
181 ;; preferred. See http://pcc.ludd.ltu.se/licenses/ for more details.
182 (license (list license:bsd-2 license:bsd-3))))
183
184 (define-public libbytesize
185 (package
186 (name "libbytesize")
187 (version "2.1")
188 (source (origin
189 (method url-fetch)
190 (uri (string-append
191 "https://github.com/storaged-project/libbytesize/releases/"
192 "download/" version "/libbytesize-" version ".tar.gz"))
193 (sha256
194 (base32
195 "1bpz9cpb8s47kqplkkiz6ryfahas2ma95g9rh2axnfjp6w1d9ixc"))))
196 (build-system gnu-build-system)
197 (arguments
198 `(#:tests? #f))
199 (native-inputs
200 `(("gettext" ,gettext-minimal)
201 ("pkg-config" ,pkg-config)
202 ("python" ,python)))
203 (inputs
204 `(("mpfr" ,mpfr)
205 ("pcre2" ,pcre2)))
206 (home-page "https://github.com/storaged-project/libbytesize")
207 (synopsis "Tiny C library for working with arbitrary big sizes in bytes")
208 (description
209 "The goal of this project is to provide a tiny library that would
210 facilitate the common operations with sizes in bytes. Many projects need to
211 work with sizes in bytes (be it sizes of storage space, memory...) and all of
212 them need to deal with the same issues like:
213
214 @itemize
215 @item How to get a human-readable string for the given size?
216 @item How to store the given size so that no significant information is lost?
217 @item If we store the size in bytes, what if the given size gets over the
218 MAXUINT64 value?
219 @item How to interpret sizes entered by users according to their locale and
220 typing conventions?
221 @item How to deal with the decimal/binary units (MB versus MiB) ambiguity?
222 @end itemize
223
224 @code{libbytesize} offers a generally usable solution that could be used by
225 every project that needs to deal with sizes in bytes. It is written in the C
226 language with thin bindings for other languages.")
227 (license license:lgpl2.1+)))
228
229 (define-public udunits
230 (package
231 (name "udunits")
232 (version "2.2.26")
233 (source (origin
234 (method url-fetch)
235 (uri (string-append "ftp://ftp.unidata.ucar.edu/pub/udunits/"
236 "udunits-" version ".tar.gz"))
237 (sha256
238 (base32
239 "0v9mqw4drnkzkm57331ail6yvs9485jmi37s40lhvmf7r5lli3rn"))))
240 (build-system gnu-build-system)
241 (inputs
242 `(("expat" ,expat)))
243 (home-page "https://www.unidata.ucar.edu/software/udunits/")
244 (synopsis "C library for units of physical quantities and value-conversion utils")
245 (description
246 "The UDUNITS-2 package provides support for units of physical quantities.
247 Its three main components are:
248
249 @enumerate
250 @item @code{udunits2lib}, a C library for units of physical quantities;
251 @item @code{udunits2prog}, a utility for obtaining the definition of a unit
252 and for converting numeric values between compatible units; and
253 @item an extensive database of units.
254 @end enumerate\n")
255 ;; Like the BSD-3 license but with an extra anti patent clause.
256 (license (license:non-copyleft "file://COPYRIGHT"))))
257
258 (define-public libfixposix
259 (package
260 (name "libfixposix")
261 (version "0.4.3")
262 (home-page "https://github.com/sionescu/libfixposix")
263 (source
264 (origin
265 (method git-fetch)
266 (uri (git-reference
267 (url home-page)
268 (commit (string-append "v" version))))
269 (file-name (git-file-name name version))
270 (sha256
271 (base32
272 "1x4q6yspi5g2s98vq4qszw4z3zjgk9l5zs8471w4d4cs6l97w08j"))))
273 (build-system gnu-build-system)
274 (native-inputs
275 `(("autoconf" ,autoconf)
276 ("automake" ,automake)
277 ("libtool" ,libtool)
278 ("pkg-config" ,pkg-config)
279 ("check" ,check)))
280 (synopsis "Thin wrapper over POSIX syscalls")
281 (description
282 "The purpose of libfixposix is to offer replacements for parts of POSIX
283 whose behaviour is inconsistent across *NIX flavours.")
284 (license license:boost1.0)))
285
286 (define-public libhx
287 (package
288 (name "libhx")
289 (version "3.24")
290 (source
291 (origin
292 (method url-fetch)
293 (uri (string-append "mirror://sourceforge/libhx/libHX/"
294 "libHX-" version ".tar.xz"))
295 (sha256
296 (base32
297 "0i8v2464p830c15myknvvs6bhxaf663lrqgga95l94ygfynkw6x5"))))
298 (build-system gnu-build-system)
299 (home-page "http://libhx.sourceforge.net")
300 (synopsis "C library with common data structures and functions")
301 (description
302 "This is a C library (with some C++ bindings available) that provides data
303 structures and functions commonly needed, such as maps, deques, linked lists,
304 string formatting and autoresizing, option and config file parsing, type
305 checking casts and more.")
306 (license license:lgpl2.1+)))