├── .bzrignore ├── .gitattributes ├── .gitignore ├── .quickly ├── .travis.yml ├── AUTHORS ├── COPYING ├── Makefile.am ├── README.md ├── configure.ac ├── debian ├── README.Debian ├── changelog ├── compat ├── control ├── copyright ├── docs ├── rules └── source │ └── format ├── eatmydata.in ├── eatmydata.sh.in ├── fsynctest.result ├── libeatmydata.spec.in ├── libeatmydata ├── libeatmydata.c ├── portability.h ├── test │ ├── eatmydatatest.c │ ├── eatmydatatest_largefile.c │ ├── fcntltest.c │ ├── fsynctest.c │ ├── syncfstest.c │ ├── tst-cancel4.c │ ├── tst-invalidfd.c │ └── tst-key4.c └── visibility.h ├── m4 ├── acx_pthread.m4 ├── ax_tls.m4 ├── gettext.m4 ├── iconv.m4 ├── lib-ld.m4 ├── lib-link.m4 ├── lib-prefix.m4 ├── po.m4 └── progtest.m4 ├── start_suspended.sh └── test_run.sh /.bzrignore: -------------------------------------------------------------------------------- 1 | fsynctest 2 | libeatmydata.so 3 | libeatmydata.so.1 4 | libeatmydata.so.1.0 5 | .deps 6 | .libs 7 | Makefile 8 | Makefile.in 9 | config.h 10 | fsynctest_eatmydata 11 | config.log 12 | autom4te.cache 13 | -------------------------------------------------------------------------------- /.gitattributes: -------------------------------------------------------------------------------- 1 | /m4/* linguist-vendored 2 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | Makefile 2 | Makefile.in 3 | aclocal.m4 4 | autom4te.cache/ 5 | compile 6 | config.h 7 | config.h.in 8 | config.h.in~ 9 | config.log 10 | config.status 11 | config/ 12 | configure 13 | depcomp 14 | eatmydata 15 | eatmydata.sh 16 | install-sh 17 | libeatmydata-*.tar.gz 18 | libeatmydata.la 19 | libeatmydata.spec 20 | .deps/ 21 | .dirstamp 22 | .libs/ 23 | *.o 24 | *.lo 25 | libeatmydata/test/eatmydatatest 26 | libeatmydata/test/eatmydatatest.log 27 | libeatmydata/test/eatmydatatest.o 28 | libeatmydata/test/eatmydatatest.trs 29 | libeatmydata/test/eatmydatatest_largefile 30 | libeatmydata/test/eatmydatatest_largefile.log 31 | libeatmydata/test/eatmydatatest_largefile.trs 32 | libeatmydata/test/fcntltest 33 | libeatmydata/test/fcntltest.log 34 | libeatmydata/test/fcntltest.trs 35 | libeatmydata/test/fsynctest 36 | libeatmydata/test/fsynctest.log 37 | libeatmydata/test/fsynctest.trs 38 | libeatmydata/test/tst-cancel4 39 | libeatmydata/test/tst-cancel4.log 40 | libeatmydata/test/tst-cancel4.trs 41 | libeatmydata/test/tst-invalidfd 42 | libeatmydata/test/tst-invalidfd.log 43 | libeatmydata/test/tst-invalidfd.trs 44 | libeatmydata/test/tst-key4 45 | libeatmydata/test/tst-key4.log 46 | libeatmydata/test/tst-key4.trs 47 | libtool 48 | m4/ 49 | missing 50 | stamp-h1 51 | test-driver 52 | test-suite.log 53 | -------------------------------------------------------------------------------- /.quickly: -------------------------------------------------------------------------------- 1 | project = libeatmydata 2 | version = 0.4.2 3 | template = pandora-build 4 | project-type = library 5 | pandora-version = 0.176 6 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: c 2 | 3 | sudo: required 4 | 5 | addons: 6 | apt: 7 | packages: 8 | - strace 9 | 10 | compiler: 11 | - clang 12 | - gcc 13 | 14 | before_script: 15 | autoreconf -i 16 | -------------------------------------------------------------------------------- /AUTHORS: -------------------------------------------------------------------------------- 1 | Copyright: 2007-2021 Stewart Smith 2 | 2014-2020 Mattia Rizzolo 3 | 2020 Sam Thursfield 4 | 2019 Alberto Bertogli 5 | 2013 Alexey Bychko 6 | 2012 Blair Zajac 7 | 2012 Phillip Susi 8 | 2011 Modestas Vainius 9 | 2010-2011 Monty Taylor 10 | 2010 Olly Betts 11 | 2010 Pavel Pushkarev 12 | 2010 Elliot Murphy 13 | 2009 Eric Wong 14 | 2009 Tamas TEVESZ 15 | 2009 Joachim Berdal Haga 16 | 2008 Mohsen Hariri 17 | 18 | -------------------------------------------------------------------------------- /COPYING: -------------------------------------------------------------------------------- 1 | GNU GENERAL PUBLIC LICENSE 2 | Version 3, 29 June 2007 3 | 4 | Copyright (C) 2007 Free Software Foundation, Inc. 5 | Everyone is permitted to copy and distribute verbatim copies 6 | of this license document, but changing it is not allowed. 7 | 8 | Preamble 9 | 10 | The GNU General Public License is a free, copyleft license for 11 | software and other kinds of works. 12 | 13 | The licenses for most software and other practical works are designed 14 | to take away your freedom to share and change the works. By contrast, 15 | the GNU General Public License is intended to guarantee your freedom to 16 | share and change all versions of a program--to make sure it remains free 17 | software for all its users. We, the Free Software Foundation, use the 18 | GNU General Public License for most of our software; it applies also to 19 | any other work released this way by its authors. You can apply it to 20 | your programs, too. 21 | 22 | When we speak of free software, we are referring to freedom, not 23 | price. Our General Public Licenses are designed to make sure that you 24 | have the freedom to distribute copies of free software (and charge for 25 | them if you wish), that you receive source code or can get it if you 26 | want it, that you can change the software or use pieces of it in new 27 | free programs, and that you know you can do these things. 28 | 29 | To protect your rights, we need to prevent others from denying you 30 | these rights or asking you to surrender the rights. Therefore, you have 31 | certain responsibilities if you distribute copies of the software, or if 32 | you modify it: responsibilities to respect the freedom of others. 33 | 34 | For example, if you distribute copies of such a program, whether 35 | gratis or for a fee, you must pass on to the recipients the same 36 | freedoms that you received. You must make sure that they, too, receive 37 | or can get the source code. And you must show them these terms so they 38 | know their rights. 39 | 40 | Developers that use the GNU GPL protect your rights with two steps: 41 | (1) assert copyright on the software, and (2) offer you this License 42 | giving you legal permission to copy, distribute and/or modify it. 43 | 44 | For the developers' and authors' protection, the GPL clearly explains 45 | that there is no warranty for this free software. For both users' and 46 | authors' sake, the GPL requires that modified versions be marked as 47 | changed, so that their problems will not be attributed erroneously to 48 | authors of previous versions. 49 | 50 | Some devices are designed to deny users access to install or run 51 | modified versions of the software inside them, although the manufacturer 52 | can do so. This is fundamentally incompatible with the aim of 53 | protecting users' freedom to change the software. The systematic 54 | pattern of such abuse occurs in the area of products for individuals to 55 | use, which is precisely where it is most unacceptable. Therefore, we 56 | have designed this version of the GPL to prohibit the practice for those 57 | products. If such problems arise substantially in other domains, we 58 | stand ready to extend this provision to those domains in future versions 59 | of the GPL, as needed to protect the freedom of users. 60 | 61 | Finally, every program is threatened constantly by software patents. 62 | States should not allow patents to restrict development and use of 63 | software on general-purpose computers, but in those that do, we wish to 64 | avoid the special danger that patents applied to a free program could 65 | make it effectively proprietary. To prevent this, the GPL assures that 66 | patents cannot be used to render the program non-free. 67 | 68 | The precise terms and conditions for copying, distribution and 69 | modification follow. 70 | 71 | TERMS AND CONDITIONS 72 | 73 | 0. Definitions. 74 | 75 | "This License" refers to version 3 of the GNU General Public License. 76 | 77 | "Copyright" also means copyright-like laws that apply to other kinds of 78 | works, such as semiconductor masks. 79 | 80 | "The Program" refers to any copyrightable work licensed under this 81 | License. Each licensee is addressed as "you". "Licensees" and 82 | "recipients" may be individuals or organizations. 83 | 84 | To "modify" a work means to copy from or adapt all or part of the work 85 | in a fashion requiring copyright permission, other than the making of an 86 | exact copy. The resulting work is called a "modified version" of the 87 | earlier work or a work "based on" the earlier work. 88 | 89 | A "covered work" means either the unmodified Program or a work based 90 | on the Program. 91 | 92 | To "propagate" a work means to do anything with it that, without 93 | permission, would make you directly or secondarily liable for 94 | infringement under applicable copyright law, except executing it on a 95 | computer or modifying a private copy. Propagation includes copying, 96 | distribution (with or without modification), making available to the 97 | public, and in some countries other activities as well. 98 | 99 | To "convey" a work means any kind of propagation that enables other 100 | parties to make or receive copies. Mere interaction with a user through 101 | a computer network, with no transfer of a copy, is not conveying. 102 | 103 | An interactive user interface displays "Appropriate Legal Notices" 104 | to the extent that it includes a convenient and prominently visible 105 | feature that (1) displays an appropriate copyright notice, and (2) 106 | tells the user that there is no warranty for the work (except to the 107 | extent that warranties are provided), that licensees may convey the 108 | work under this License, and how to view a copy of this License. If 109 | the interface presents a list of user commands or options, such as a 110 | menu, a prominent item in the list meets this criterion. 111 | 112 | 1. Source Code. 113 | 114 | The "source code" for a work means the preferred form of the work 115 | for making modifications to it. "Object code" means any non-source 116 | form of a work. 117 | 118 | A "Standard Interface" means an interface that either is an official 119 | standard defined by a recognized standards body, or, in the case of 120 | interfaces specified for a particular programming language, one that 121 | is widely used among developers working in that language. 122 | 123 | The "System Libraries" of an executable work include anything, other 124 | than the work as a whole, that (a) is included in the normal form of 125 | packaging a Major Component, but which is not part of that Major 126 | Component, and (b) serves only to enable use of the work with that 127 | Major Component, or to implement a Standard Interface for which an 128 | implementation is available to the public in source code form. A 129 | "Major Component", in this context, means a major essential component 130 | (kernel, window system, and so on) of the specific operating system 131 | (if any) on which the executable work runs, or a compiler used to 132 | produce the work, or an object code interpreter used to run it. 133 | 134 | The "Corresponding Source" for a work in object code form means all 135 | the source code needed to generate, install, and (for an executable 136 | work) run the object code and to modify the work, including scripts to 137 | control those activities. However, it does not include the work's 138 | System Libraries, or general-purpose tools or generally available free 139 | programs which are used unmodified in performing those activities but 140 | which are not part of the work. For example, Corresponding Source 141 | includes interface definition files associated with source files for 142 | the work, and the source code for shared libraries and dynamically 143 | linked subprograms that the work is specifically designed to require, 144 | such as by intimate data communication or control flow between those 145 | subprograms and other parts of the work. 146 | 147 | The Corresponding Source need not include anything that users 148 | can regenerate automatically from other parts of the Corresponding 149 | Source. 150 | 151 | The Corresponding Source for a work in source code form is that 152 | same work. 153 | 154 | 2. Basic Permissions. 155 | 156 | All rights granted under this License are granted for the term of 157 | copyright on the Program, and are irrevocable provided the stated 158 | conditions are met. This License explicitly affirms your unlimited 159 | permission to run the unmodified Program. The output from running a 160 | covered work is covered by this License only if the output, given its 161 | content, constitutes a covered work. This License acknowledges your 162 | rights of fair use or other equivalent, as provided by copyright law. 163 | 164 | You may make, run and propagate covered works that you do not 165 | convey, without conditions so long as your license otherwise remains 166 | in force. You may convey covered works to others for the sole purpose 167 | of having them make modifications exclusively for you, or provide you 168 | with facilities for running those works, provided that you comply with 169 | the terms of this License in conveying all material for which you do 170 | not control copyright. Those thus making or running the covered works 171 | for you must do so exclusively on your behalf, under your direction 172 | and control, on terms that prohibit them from making any copies of 173 | your copyrighted material outside their relationship with you. 174 | 175 | Conveying under any other circumstances is permitted solely under 176 | the conditions stated below. Sublicensing is not allowed; section 10 177 | makes it unnecessary. 178 | 179 | 3. Protecting Users' Legal Rights From Anti-Circumvention Law. 180 | 181 | No covered work shall be deemed part of an effective technological 182 | measure under any applicable law fulfilling obligations under article 183 | 11 of the WIPO copyright treaty adopted on 20 December 1996, or 184 | similar laws prohibiting or restricting circumvention of such 185 | measures. 186 | 187 | When you convey a covered work, you waive any legal power to forbid 188 | circumvention of technological measures to the extent such circumvention 189 | is effected by exercising rights under this License with respect to 190 | the covered work, and you disclaim any intention to limit operation or 191 | modification of the work as a means of enforcing, against the work's 192 | users, your or third parties' legal rights to forbid circumvention of 193 | technological measures. 194 | 195 | 4. Conveying Verbatim Copies. 196 | 197 | You may convey verbatim copies of the Program's source code as you 198 | receive it, in any medium, provided that you conspicuously and 199 | appropriately publish on each copy an appropriate copyright notice; 200 | keep intact all notices stating that this License and any 201 | non-permissive terms added in accord with section 7 apply to the code; 202 | keep intact all notices of the absence of any warranty; and give all 203 | recipients a copy of this License along with the Program. 204 | 205 | You may charge any price or no price for each copy that you convey, 206 | and you may offer support or warranty protection for a fee. 207 | 208 | 5. Conveying Modified Source Versions. 209 | 210 | You may convey a work based on the Program, or the modifications to 211 | produce it from the Program, in the form of source code under the 212 | terms of section 4, provided that you also meet all of these conditions: 213 | 214 | a) The work must carry prominent notices stating that you modified 215 | it, and giving a relevant date. 216 | 217 | b) The work must carry prominent notices stating that it is 218 | released under this License and any conditions added under section 219 | 7. This requirement modifies the requirement in section 4 to 220 | "keep intact all notices". 221 | 222 | c) You must license the entire work, as a whole, under this 223 | License to anyone who comes into possession of a copy. This 224 | License will therefore apply, along with any applicable section 7 225 | additional terms, to the whole of the work, and all its parts, 226 | regardless of how they are packaged. This License gives no 227 | permission to license the work in any other way, but it does not 228 | invalidate such permission if you have separately received it. 229 | 230 | d) If the work has interactive user interfaces, each must display 231 | Appropriate Legal Notices; however, if the Program has interactive 232 | interfaces that do not display Appropriate Legal Notices, your 233 | work need not make them do so. 234 | 235 | A compilation of a covered work with other separate and independent 236 | works, which are not by their nature extensions of the covered work, 237 | and which are not combined with it such as to form a larger program, 238 | in or on a volume of a storage or distribution medium, is called an 239 | "aggregate" if the compilation and its resulting copyright are not 240 | used to limit the access or legal rights of the compilation's users 241 | beyond what the individual works permit. Inclusion of a covered work 242 | in an aggregate does not cause this License to apply to the other 243 | parts of the aggregate. 244 | 245 | 6. Conveying Non-Source Forms. 246 | 247 | You may convey a covered work in object code form under the terms 248 | of sections 4 and 5, provided that you also convey the 249 | machine-readable Corresponding Source under the terms of this License, 250 | in one of these ways: 251 | 252 | a) Convey the object code in, or embodied in, a physical product 253 | (including a physical distribution medium), accompanied by the 254 | Corresponding Source fixed on a durable physical medium 255 | customarily used for software interchange. 256 | 257 | b) Convey the object code in, or embodied in, a physical product 258 | (including a physical distribution medium), accompanied by a 259 | written offer, valid for at least three years and valid for as 260 | long as you offer spare parts or customer support for that product 261 | model, to give anyone who possesses the object code either (1) a 262 | copy of the Corresponding Source for all the software in the 263 | product that is covered by this License, on a durable physical 264 | medium customarily used for software interchange, for a price no 265 | more than your reasonable cost of physically performing this 266 | conveying of source, or (2) access to copy the 267 | Corresponding Source from a network server at no charge. 268 | 269 | c) Convey individual copies of the object code with a copy of the 270 | written offer to provide the Corresponding Source. This 271 | alternative is allowed only occasionally and noncommercially, and 272 | only if you received the object code with such an offer, in accord 273 | with subsection 6b. 274 | 275 | d) Convey the object code by offering access from a designated 276 | place (gratis or for a charge), and offer equivalent access to the 277 | Corresponding Source in the same way through the same place at no 278 | further charge. You need not require recipients to copy the 279 | Corresponding Source along with the object code. If the place to 280 | copy the object code is a network server, the Corresponding Source 281 | may be on a different server (operated by you or a third party) 282 | that supports equivalent copying facilities, provided you maintain 283 | clear directions next to the object code saying where to find the 284 | Corresponding Source. Regardless of what server hosts the 285 | Corresponding Source, you remain obligated to ensure that it is 286 | available for as long as needed to satisfy these requirements. 287 | 288 | e) Convey the object code using peer-to-peer transmission, provided 289 | you inform other peers where the object code and Corresponding 290 | Source of the work are being offered to the general public at no 291 | charge under subsection 6d. 292 | 293 | A separable portion of the object code, whose source code is excluded 294 | from the Corresponding Source as a System Library, need not be 295 | included in conveying the object code work. 296 | 297 | A "User Product" is either (1) a "consumer product", which means any 298 | tangible personal property which is normally used for personal, family, 299 | or household purposes, or (2) anything designed or sold for incorporation 300 | into a dwelling. In determining whether a product is a consumer product, 301 | doubtful cases shall be resolved in favor of coverage. For a particular 302 | product received by a particular user, "normally used" refers to a 303 | typical or common use of that class of product, regardless of the status 304 | of the particular user or of the way in which the particular user 305 | actually uses, or expects or is expected to use, the product. A product 306 | is a consumer product regardless of whether the product has substantial 307 | commercial, industrial or non-consumer uses, unless such uses represent 308 | the only significant mode of use of the product. 309 | 310 | "Installation Information" for a User Product means any methods, 311 | procedures, authorization keys, or other information required to install 312 | and execute modified versions of a covered work in that User Product from 313 | a modified version of its Corresponding Source. The information must 314 | suffice to ensure that the continued functioning of the modified object 315 | code is in no case prevented or interfered with solely because 316 | modification has been made. 317 | 318 | If you convey an object code work under this section in, or with, or 319 | specifically for use in, a User Product, and the conveying occurs as 320 | part of a transaction in which the right of possession and use of the 321 | User Product is transferred to the recipient in perpetuity or for a 322 | fixed term (regardless of how the transaction is characterized), the 323 | Corresponding Source conveyed under this section must be accompanied 324 | by the Installation Information. But this requirement does not apply 325 | if neither you nor any third party retains the ability to install 326 | modified object code on the User Product (for example, the work has 327 | been installed in ROM). 328 | 329 | The requirement to provide Installation Information does not include a 330 | requirement to continue to provide support service, warranty, or updates 331 | for a work that has been modified or installed by the recipient, or for 332 | the User Product in which it has been modified or installed. Access to a 333 | network may be denied when the modification itself materially and 334 | adversely affects the operation of the network or violates the rules and 335 | protocols for communication across the network. 336 | 337 | Corresponding Source conveyed, and Installation Information provided, 338 | in accord with this section must be in a format that is publicly 339 | documented (and with an implementation available to the public in 340 | source code form), and must require no special password or key for 341 | unpacking, reading or copying. 342 | 343 | 7. Additional Terms. 344 | 345 | "Additional permissions" are terms that supplement the terms of this 346 | License by making exceptions from one or more of its conditions. 347 | Additional permissions that are applicable to the entire Program shall 348 | be treated as though they were included in this License, to the extent 349 | that they are valid under applicable law. If additional permissions 350 | apply only to part of the Program, that part may be used separately 351 | under those permissions, but the entire Program remains governed by 352 | this License without regard to the additional permissions. 353 | 354 | When you convey a copy of a covered work, you may at your option 355 | remove any additional permissions from that copy, or from any part of 356 | it. (Additional permissions may be written to require their own 357 | removal in certain cases when you modify the work.) You may place 358 | additional permissions on material, added by you to a covered work, 359 | for which you have or can give appropriate copyright permission. 360 | 361 | Notwithstanding any other provision of this License, for material you 362 | add to a covered work, you may (if authorized by the copyright holders of 363 | that material) supplement the terms of this License with terms: 364 | 365 | a) Disclaiming warranty or limiting liability differently from the 366 | terms of sections 15 and 16 of this License; or 367 | 368 | b) Requiring preservation of specified reasonable legal notices or 369 | author attributions in that material or in the Appropriate Legal 370 | Notices displayed by works containing it; or 371 | 372 | c) Prohibiting misrepresentation of the origin of that material, or 373 | requiring that modified versions of such material be marked in 374 | reasonable ways as different from the original version; or 375 | 376 | d) Limiting the use for publicity purposes of names of licensors or 377 | authors of the material; or 378 | 379 | e) Declining to grant rights under trademark law for use of some 380 | trade names, trademarks, or service marks; or 381 | 382 | f) Requiring indemnification of licensors and authors of that 383 | material by anyone who conveys the material (or modified versions of 384 | it) with contractual assumptions of liability to the recipient, for 385 | any liability that these contractual assumptions directly impose on 386 | those licensors and authors. 387 | 388 | All other non-permissive additional terms are considered "further 389 | restrictions" within the meaning of section 10. If the Program as you 390 | received it, or any part of it, contains a notice stating that it is 391 | governed by this License along with a term that is a further 392 | restriction, you may remove that term. If a license document contains 393 | a further restriction but permits relicensing or conveying under this 394 | License, you may add to a covered work material governed by the terms 395 | of that license document, provided that the further restriction does 396 | not survive such relicensing or conveying. 397 | 398 | If you add terms to a covered work in accord with this section, you 399 | must place, in the relevant source files, a statement of the 400 | additional terms that apply to those files, or a notice indicating 401 | where to find the applicable terms. 402 | 403 | Additional terms, permissive or non-permissive, may be stated in the 404 | form of a separately written license, or stated as exceptions; 405 | the above requirements apply either way. 406 | 407 | 8. Termination. 408 | 409 | You may not propagate or modify a covered work except as expressly 410 | provided under this License. Any attempt otherwise to propagate or 411 | modify it is void, and will automatically terminate your rights under 412 | this License (including any patent licenses granted under the third 413 | paragraph of section 11). 414 | 415 | However, if you cease all violation of this License, then your 416 | license from a particular copyright holder is reinstated (a) 417 | provisionally, unless and until the copyright holder explicitly and 418 | finally terminates your license, and (b) permanently, if the copyright 419 | holder fails to notify you of the violation by some reasonable means 420 | prior to 60 days after the cessation. 421 | 422 | Moreover, your license from a particular copyright holder is 423 | reinstated permanently if the copyright holder notifies you of the 424 | violation by some reasonable means, this is the first time you have 425 | received notice of violation of this License (for any work) from that 426 | copyright holder, and you cure the violation prior to 30 days after 427 | your receipt of the notice. 428 | 429 | Termination of your rights under this section does not terminate the 430 | licenses of parties who have received copies or rights from you under 431 | this License. If your rights have been terminated and not permanently 432 | reinstated, you do not qualify to receive new licenses for the same 433 | material under section 10. 434 | 435 | 9. Acceptance Not Required for Having Copies. 436 | 437 | You are not required to accept this License in order to receive or 438 | run a copy of the Program. Ancillary propagation of a covered work 439 | occurring solely as a consequence of using peer-to-peer transmission 440 | to receive a copy likewise does not require acceptance. However, 441 | nothing other than this License grants you permission to propagate or 442 | modify any covered work. These actions infringe copyright if you do 443 | not accept this License. Therefore, by modifying or propagating a 444 | covered work, you indicate your acceptance of this License to do so. 445 | 446 | 10. Automatic Licensing of Downstream Recipients. 447 | 448 | Each time you convey a covered work, the recipient automatically 449 | receives a license from the original licensors, to run, modify and 450 | propagate that work, subject to this License. You are not responsible 451 | for enforcing compliance by third parties with this License. 452 | 453 | An "entity transaction" is a transaction transferring control of an 454 | organization, or substantially all assets of one, or subdividing an 455 | organization, or merging organizations. If propagation of a covered 456 | work results from an entity transaction, each party to that 457 | transaction who receives a copy of the work also receives whatever 458 | licenses to the work the party's predecessor in interest had or could 459 | give under the previous paragraph, plus a right to possession of the 460 | Corresponding Source of the work from the predecessor in interest, if 461 | the predecessor has it or can get it with reasonable efforts. 462 | 463 | You may not impose any further restrictions on the exercise of the 464 | rights granted or affirmed under this License. For example, you may 465 | not impose a license fee, royalty, or other charge for exercise of 466 | rights granted under this License, and you may not initiate litigation 467 | (including a cross-claim or counterclaim in a lawsuit) alleging that 468 | any patent claim is infringed by making, using, selling, offering for 469 | sale, or importing the Program or any portion of it. 470 | 471 | 11. Patents. 472 | 473 | A "contributor" is a copyright holder who authorizes use under this 474 | License of the Program or a work on which the Program is based. The 475 | work thus licensed is called the contributor's "contributor version". 476 | 477 | A contributor's "essential patent claims" are all patent claims 478 | owned or controlled by the contributor, whether already acquired or 479 | hereafter acquired, that would be infringed by some manner, permitted 480 | by this License, of making, using, or selling its contributor version, 481 | but do not include claims that would be infringed only as a 482 | consequence of further modification of the contributor version. For 483 | purposes of this definition, "control" includes the right to grant 484 | patent sublicenses in a manner consistent with the requirements of 485 | this License. 486 | 487 | Each contributor grants you a non-exclusive, worldwide, royalty-free 488 | patent license under the contributor's essential patent claims, to 489 | make, use, sell, offer for sale, import and otherwise run, modify and 490 | propagate the contents of its contributor version. 491 | 492 | In the following three paragraphs, a "patent license" is any express 493 | agreement or commitment, however denominated, not to enforce a patent 494 | (such as an express permission to practice a patent or covenant not to 495 | sue for patent infringement). To "grant" such a patent license to a 496 | party means to make such an agreement or commitment not to enforce a 497 | patent against the party. 498 | 499 | If you convey a covered work, knowingly relying on a patent license, 500 | and the Corresponding Source of the work is not available for anyone 501 | to copy, free of charge and under the terms of this License, through a 502 | publicly available network server or other readily accessible means, 503 | then you must either (1) cause the Corresponding Source to be so 504 | available, or (2) arrange to deprive yourself of the benefit of the 505 | patent license for this particular work, or (3) arrange, in a manner 506 | consistent with the requirements of this License, to extend the patent 507 | license to downstream recipients. "Knowingly relying" means you have 508 | actual knowledge that, but for the patent license, your conveying the 509 | covered work in a country, or your recipient's use of the covered work 510 | in a country, would infringe one or more identifiable patents in that 511 | country that you have reason to believe are valid. 512 | 513 | If, pursuant to or in connection with a single transaction or 514 | arrangement, you convey, or propagate by procuring conveyance of, a 515 | covered work, and grant a patent license to some of the parties 516 | receiving the covered work authorizing them to use, propagate, modify 517 | or convey a specific copy of the covered work, then the patent license 518 | you grant is automatically extended to all recipients of the covered 519 | work and works based on it. 520 | 521 | A patent license is "discriminatory" if it does not include within 522 | the scope of its coverage, prohibits the exercise of, or is 523 | conditioned on the non-exercise of one or more of the rights that are 524 | specifically granted under this License. You may not convey a covered 525 | work if you are a party to an arrangement with a third party that is 526 | in the business of distributing software, under which you make payment 527 | to the third party based on the extent of your activity of conveying 528 | the work, and under which the third party grants, to any of the 529 | parties who would receive the covered work from you, a discriminatory 530 | patent license (a) in connection with copies of the covered work 531 | conveyed by you (or copies made from those copies), or (b) primarily 532 | for and in connection with specific products or compilations that 533 | contain the covered work, unless you entered into that arrangement, 534 | or that patent license was granted, prior to 28 March 2007. 535 | 536 | Nothing in this License shall be construed as excluding or limiting 537 | any implied license or other defenses to infringement that may 538 | otherwise be available to you under applicable patent law. 539 | 540 | 12. No Surrender of Others' Freedom. 541 | 542 | If conditions are imposed on you (whether by court order, agreement or 543 | otherwise) that contradict the conditions of this License, they do not 544 | excuse you from the conditions of this License. If you cannot convey a 545 | covered work so as to satisfy simultaneously your obligations under this 546 | License and any other pertinent obligations, then as a consequence you may 547 | not convey it at all. For example, if you agree to terms that obligate you 548 | to collect a royalty for further conveying from those to whom you convey 549 | the Program, the only way you could satisfy both those terms and this 550 | License would be to refrain entirely from conveying the Program. 551 | 552 | 13. Use with the GNU Affero General Public License. 553 | 554 | Notwithstanding any other provision of this License, you have 555 | permission to link or combine any covered work with a work licensed 556 | under version 3 of the GNU Affero General Public License into a single 557 | combined work, and to convey the resulting work. The terms of this 558 | License will continue to apply to the part which is the covered work, 559 | but the special requirements of the GNU Affero General Public License, 560 | section 13, concerning interaction through a network will apply to the 561 | combination as such. 562 | 563 | 14. Revised Versions of this License. 564 | 565 | The Free Software Foundation may publish revised and/or new versions of 566 | the GNU General Public License from time to time. Such new versions will 567 | be similar in spirit to the present version, but may differ in detail to 568 | address new problems or concerns. 569 | 570 | Each version is given a distinguishing version number. If the 571 | Program specifies that a certain numbered version of the GNU General 572 | Public License "or any later version" applies to it, you have the 573 | option of following the terms and conditions either of that numbered 574 | version or of any later version published by the Free Software 575 | Foundation. If the Program does not specify a version number of the 576 | GNU General Public License, you may choose any version ever published 577 | by the Free Software Foundation. 578 | 579 | If the Program specifies that a proxy can decide which future 580 | versions of the GNU General Public License can be used, that proxy's 581 | public statement of acceptance of a version permanently authorizes you 582 | to choose that version for the Program. 583 | 584 | Later license versions may give you additional or different 585 | permissions. However, no additional obligations are imposed on any 586 | author or copyright holder as a result of your choosing to follow a 587 | later version. 588 | 589 | 15. Disclaimer of Warranty. 590 | 591 | THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY 592 | APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT 593 | HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY 594 | OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, 595 | THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 596 | PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM 597 | IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF 598 | ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 599 | 600 | 16. Limitation of Liability. 601 | 602 | IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING 603 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS 604 | THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY 605 | GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE 606 | USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF 607 | DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD 608 | PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), 609 | EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF 610 | SUCH DAMAGES. 611 | 612 | 17. Interpretation of Sections 15 and 16. 613 | 614 | If the disclaimer of warranty and limitation of liability provided 615 | above cannot be given local legal effect according to their terms, 616 | reviewing courts shall apply local law that most closely approximates 617 | an absolute waiver of all civil liability in connection with the 618 | Program, unless a warranty or assumption of liability accompanies a 619 | copy of the Program in return for a fee. 620 | 621 | END OF TERMS AND CONDITIONS 622 | 623 | How to Apply These Terms to Your New Programs 624 | 625 | If you develop a new program, and you want it to be of the greatest 626 | possible use to the public, the best way to achieve this is to make it 627 | free software which everyone can redistribute and change under these terms. 628 | 629 | To do so, attach the following notices to the program. It is safest 630 | to attach them to the start of each source file to most effectively 631 | state the exclusion of warranty; and each file should have at least 632 | the "copyright" line and a pointer to where the full notice is found. 633 | 634 | 635 | Copyright (C) 636 | 637 | This program is free software: you can redistribute it and/or modify 638 | it under the terms of the GNU General Public License as published by 639 | the Free Software Foundation, either version 3 of the License, or 640 | (at your option) any later version. 641 | 642 | This program is distributed in the hope that it will be useful, 643 | but WITHOUT ANY WARRANTY; without even the implied warranty of 644 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 645 | GNU General Public License for more details. 646 | 647 | You should have received a copy of the GNU General Public License 648 | along with this program. If not, see . 649 | 650 | Also add information on how to contact you by electronic and paper mail. 651 | 652 | If the program does terminal interaction, make it output a short 653 | notice like this when it starts in an interactive mode: 654 | 655 | Copyright (C) 656 | This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'. 657 | This is free software, and you are welcome to redistribute it 658 | under certain conditions; type `show c' for details. 659 | 660 | The hypothetical commands `show w' and `show c' should show the appropriate 661 | parts of the General Public License. Of course, your program's commands 662 | might be different; for a GUI interface, you would use an "about box". 663 | 664 | You should also get your employer (if you work as a programmer) or school, 665 | if any, to sign a "copyright disclaimer" for the program, if necessary. 666 | For more information on this, and how to apply and follow the GNU GPL, see 667 | . 668 | 669 | The GNU General Public License does not permit incorporating your program 670 | into proprietary programs. If your program is a subroutine library, you 671 | may consider it more useful to permit linking proprietary applications with 672 | the library. If this is what you want to do, use the GNU Lesser General 673 | Public License instead of this License. But first, please read 674 | . 675 | -------------------------------------------------------------------------------- /Makefile.am: -------------------------------------------------------------------------------- 1 | # 2 | # Libeatmydata 3 | # 4 | ### BEGIN LICENSE 5 | # Copyright (C) 2008-2021 Stewart Smith 6 | # This program is free software: you can redistribute it and/or modify it 7 | # under the terms of the GNU General Public License version 3, as published 8 | # by the Free Software Foundation. 9 | # 10 | # This program is distributed in the hope that it will be useful, but 11 | # WITHOUT ANY WARRANTY; without even the implied warranties of 12 | # MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR 13 | # PURPOSE. See the GNU General Public License for more details. 14 | # 15 | # You should have received a copy of the GNU General Public License along 16 | # with this program. If not, see . 17 | ### END LICENSE 18 | 19 | ACLOCAL_AMFLAGS = -I m4 20 | #LDADD = libeatmydata.la 21 | 22 | AUTOMAKE_OPTIONS = parallel-tests 23 | 24 | bin_PROGRAMS = 25 | check_PROGRAMS = 26 | noinst_PROGRAMS = 27 | lib_LTLIBRARIES = 28 | noinst_LTLIBRARIES = 29 | nobase_include_HEADERS = 30 | noinst_HEADERS = 31 | CLEANFILES = $(bin_SCRIPTS) $(libexec_SCRIPTS) 32 | DISTCLEANFILES = config/top.h 33 | EXTRA_DIST = \ 34 | README.md \ 35 | AUTHORS \ 36 | fsynctest.result \ 37 | test_run.sh \ 38 | eatmydata.in \ 39 | eatmydata.sh.in \ 40 | debian/changelog \ 41 | debian/compat \ 42 | debian/control \ 43 | debian/copyright \ 44 | debian/docs \ 45 | debian/README.Debian \ 46 | debian/rules \ 47 | debian/source \ 48 | libeatmydata.spec \ 49 | start_suspended.sh 50 | 51 | 52 | bin_SCRIPTS = eatmydata 53 | libexec_SCRIPTS = eatmydata.sh 54 | 55 | do_subst = @SED@ \ 56 | -e 's!@''libdir''@!$(libdir)!g' \ 57 | -e 's!@''libexecdir''@!$(libexecdir)!g' 58 | 59 | eatmydata: eatmydata.in Makefile 60 | $(do_subst) $(srcdir)/eatmydata.in > $@ 61 | chmod +x eatmydata 62 | 63 | eatmydata.sh: eatmydata.sh.in Makefile 64 | $(do_subst) $(srcdir)/eatmydata.sh.in > $@ 65 | 66 | # 67 | # libeatmydata 68 | # 69 | 70 | lib_LTLIBRARIES += libeatmydata.la 71 | 72 | libeatmydata_la_SOURCES = \ 73 | libeatmydata/libeatmydata.c 74 | 75 | noinst_HEADERS += \ 76 | libeatmydata/portability.h \ 77 | libeatmydata/visibility.h 78 | 79 | libeatmydata_la_CFLAGS = \ 80 | $(AM_CFLAGS) \ 81 | $(NO_WERROR) \ 82 | -DBUILDING_LIBEATMYDATA 83 | 84 | libeatmydata_la_LIBADD = $(LIBDL_LIBS) -ldl 85 | libeatmydata_la_LDFLAGS = $(AM_LDFLAGS) -avoid-version 86 | 87 | #install-exec-hook: 88 | # find $(DESTDIR)$(libdir) -type f -name \*.la |xargs rm -f 89 | 90 | check_PROGRAMS += \ 91 | libeatmydata/test/fsynctest \ 92 | libeatmydata/test/tst-key4 \ 93 | libeatmydata/test/tst-invalidfd \ 94 | libeatmydata/test/eatmydatatest \ 95 | libeatmydata/test/eatmydatatest_largefile \ 96 | libeatmydata/test/syncfstest \ 97 | libeatmydata/test/fcntltest 98 | 99 | if HAVE_PTHREAD_BARRIERS 100 | check_PROGRAMS += libeatmydata/test/tst-cancel4 101 | endif 102 | 103 | libeatmydata_test_tst_cancel4_LDADD= -lpthread 104 | 105 | libeatmydata_test_tst_key4_LDADD= -lpthread 106 | 107 | # 108 | # Simple libeatmydata application 109 | # 110 | 111 | TESTS = $(check_PROGRAMS) 112 | 113 | LOG_COMPILER = ${top_srcdir}/test_run.sh 114 | 115 | test: distcheck 116 | 117 | check-verbose: 118 | @LIBEATMYDATA_TEST_ARGS="v" make check 119 | 120 | check-debug: 121 | @LIBEATMYDATA_TEST_ARGS="vvv" make check 122 | 123 | check-valgrind: 124 | @LIBEATMYDATA_TEST_PREFIX="valgrind -q --leak-check=full --show-reachable=yes --suppressions=valgrind.suppressions" make check 125 | 126 | check-valgrind-debug: 127 | @LIBEATMYDATA_TEST_PREFIX="valgrind -q --leak-check=full --show-reachable=yes --suppressions=valgrind.suppressions" LIBEATMYDATA_TEST_ARGS="vvv" make check 128 | 129 | check-gdb: 130 | @LIBEATMYDATA_TEST_PREFIX="gdb -q" make check 131 | 132 | check-time: 133 | @LIBEATMYDATA_TEST_PREFIX="/usr/bin/time" make check 134 | 135 | check-strace: 136 | @LIBEATMYDATA_TEST_PREFIX="strace -c" make check 137 | 138 | check-truss: 139 | @LIBEATMYDATA_TEST_PREFIX="truss -c" make check 140 | 141 | lcov: lcov-clean check 142 | @echo 143 | @echo "------------------------------------------------------" 144 | @echo "Make sure ./configure was run with '--enable-coverage'" 145 | @echo "------------------------------------------------------" 146 | @echo 147 | cd libeatmydata && lcov --directory . --base-directory .. --capture --output-file lcov.out 148 | cd libeatmydata && lcov --directory . --base-directory .. --extract lcov.out `pwd`/\* --output-file lcov_extract.out 149 | genhtml -o lcov -t libeatmydata libeatmydata/lcov_extract.out 150 | 151 | lcov-clean: clean 152 | find . -name '*.gcno' -exec rm {} \; 153 | find . -name '*.gcda' -exec rm {} \; 154 | find . -name 'lcov*.out' -exec rm {} \; 155 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | libeatmydata 2 | ============ 3 | 4 | An LD_PRELOAD library that disables all forms of writing data safely to disk. 5 | fsync() becomes a NO-OP, O_SYNC is removed etc. 6 | 7 | The idea is to use in testing to get faster test runs where real durability is 8 | not required. 9 | 10 | ***DO NOT*** use libeatmydata on software where you care about what it stores. It's called lib***EAT-MY-DATA*** for a *reason*. 11 | 12 | see http://www.flamingspork.com/projects/libeatmydata 13 | 14 | Installing 15 | ------------ 16 | 17 | Debian/Ubuntu and friends: 18 | ``` 19 | apt install eatmydata 20 | ``` 21 | 22 | To build from source, you will need `autoconf`, `autoconf-archive`, `automake`, `libtool`, and a compiler (say, `gcc`). 23 | 24 | Then, build and install like so: 25 | ``` 26 | git clone https://github.com/stewartsmith/libeatmydata.git # (or extract from source tarball) 27 | cd libeatmydata 28 | autoreconf -i # (if building from git only) 29 | ./configure 30 | make 31 | make check 32 | sudo make install 33 | ``` 34 | 35 | 36 | Usage 37 | ----- 38 | 39 | ``` 40 | eatmydata foo 41 | ``` 42 | 43 | Performance Improvements 44 | ------------------------ 45 | 46 | When running part of the MySQL test suite in 2007 on my laptop: 47 | 48 | ``` 49 | TEST RESULT TIME (ms) TIME (with libeatmydata) 50 | ---------------------------------------------------------------------------------- 51 | 52 | main.innodb-lock [ pass ] 4523 4323 53 | main.innodb-replace [ pass ] 102 56 54 | main.innodb-ucs2 [ pass ] 5786 1084 55 | main.innodb [ pass ] 78306 24900 56 | main.innodb_gis [ pass ] 2647 1544 57 | main.innodb_mysql [ pass ] 86810 68579 58 | main.innodb_notembedded [ pass ] 198 150 59 | main.innodb_timeout_rollback [ pass ] 2990 2750 60 | main.innodb_trx_weight [ pass ] 1608 841 61 | --------------------------------------------------------------- 62 | Stopping All Servers 63 | All 9 tests were successful. 64 | The servers were restarted 7 times 65 | 66 | WITHOUT: Spent 182.97 seconds actually executing testcases 67 | WITH : Spent 104.227 seconds actually executing testcases 68 | 69 | WITHOUT: WITH: 70 | real 3m36.053s real 2m10.610s 71 | user 0m42.323s user 0m41.939s 72 | sys 0m2.844s sys 0m2.356s 73 | ``` 74 | 75 | 76 | Talks/Video 77 | ----------- 78 | 79 | libeatmydata was the product of a talk I gave back at linux.conf.au 2007, titled 80 | "Eat My Data: How Everybody gets File IO Wrong" - I also gave this talk at OSCON. 81 | This talk went over the common mistakes people make when using POSIX file IO 82 | routines. 83 | 84 | You can watch a video recording of this talk at: 85 | 86 | - https://youtu.be/LMe7hf2G1po 87 | - [http://www.linux.org.au/conf/2007/talk/278.html](https://web.archive.org/web/20130504133047/http://www.linux.org.au/conf/2007/talk/278.html) 88 | 89 | Copyright 90 | --------- 91 | 92 | (C)2007-2022 Stewart Smith 93 | and other contributors (see AUTHORS) 94 | See LICENSE for full text of GPLv3 95 | -------------------------------------------------------------------------------- /configure.ac: -------------------------------------------------------------------------------- 1 | # 2 | # Libeatmydata 3 | # 4 | # Build infrastructure: 5 | # Copyright (C) 2009-2010 Monty Taylor, Eric Day 6 | # Copyright (C) 2010-2021 Stewart Smith 7 | # All rights reserved. 8 | # 9 | # Use and distribution licensed under the BSD license. See 10 | # the COPYING file in this directory for full text. 11 | # 12 | 13 | 14 | AC_INIT([libeatmydata],[131], [http://www.flamingspork.com/projects/libeatmydata]) 15 | AC_CONFIG_SRCDIR([libeatmydata/libeatmydata.c]) 16 | AC_CONFIG_AUX_DIR([config]) 17 | AC_CONFIG_MACRO_DIR([m4]) 18 | 19 | AC_CANONICAL_TARGET 20 | AC_ARG_PROGRAM 21 | AC_USE_SYSTEM_EXTENSIONS 22 | 23 | AM_INIT_AUTOMAKE([-Wall -Werror -Wno-portability subdir-objects foreign tar-ustar]) 24 | 25 | AC_PREREQ([2.63]) 26 | 27 | LT_PREREQ([2.2]) 28 | LT_INIT 29 | LT_LANG([C]) 30 | 31 | AC_CONFIG_HEADERS([config.h]) 32 | 33 | m4_ifdef([AM_SILENT_RULES], [AM_SILENT_RULES([yes])]) 34 | 35 | AC_CHECK_HEADERS_ONCE(pthread.h) 36 | 37 | AC_CHECK_SIZEOF(mode_t) 38 | AC_CHECK_SIZEOF(int) 39 | 40 | AC_CHECK_TYPE(pthread_barrier_t,,,[ 41 | #ifdef HAVE_PTHREAD_H 42 | #include 43 | #endif 44 | ]) 45 | 46 | AM_CONDITIONAL(HAVE_PTHREAD_BARRIERS, [test "x$ac_cv_type_pthread_barrier_t" = xyes]) 47 | 48 | AC_CHECK_DECLS(fdatasync) 49 | AC_CHECK_FUNCS(fdatasync) 50 | AC_CHECK_DECLS(sync_file_range) 51 | AC_CHECK_FUNCS(sync_file_range) 52 | AC_CHECK_FUNCS(open64) 53 | AC_CHECK_FUNCS(syncfs) 54 | 55 | AX_TLS(:,:) 56 | 57 | AC_CONFIG_FILES(Makefile libeatmydata.spec) 58 | 59 | AC_OUTPUT 60 | 61 | -------------------------------------------------------------------------------- /debian/README.Debian: -------------------------------------------------------------------------------- 1 | libeatmydata for Debian 2 | ----------------------- 3 | 4 | The debian packaging of libeatmydata is pretty simple. We have the LD_PRELOAD library along with the eatmydata wrapper. 5 | 6 | -- Stewart Smith Tue, 14 May 2013 16:03:33 +1000 7 | -------------------------------------------------------------------------------- /debian/changelog: -------------------------------------------------------------------------------- 1 | libeatmydata (79-1) unstable; urgency=low 2 | 3 | * new libeatmydata version 4 | * Use libeatmydata version number for package 5 | 6 | -- Stewart Smith Fri, 18 May 2013 16:25:33 +1000 7 | 8 | libeatmydata (0.1-1) unstable; urgency=low 9 | 10 | * Initial release (Closes: #JEN-16) 11 | 12 | -- Alexey Bychko Mon, 13 May 2013 01:33:33 -0400 13 | -------------------------------------------------------------------------------- /debian/compat: -------------------------------------------------------------------------------- 1 | 8 2 | -------------------------------------------------------------------------------- /debian/control: -------------------------------------------------------------------------------- 1 | Source: libeatmydata 2 | Section: main 3 | Priority: extra 4 | Maintainer: Stewart Smith 5 | Build-Depends: debhelper (>= 8.0.0) 6 | Standards-Version: 3.9.2 7 | Homepage: https://launchpad.net/libeatmydata 8 | 9 | Package: eatmydata 10 | Architecture: any 11 | Depends: ${shlibs:Depends}, ${misc:Depends} 12 | Description: library and utilities designed to disable fsync and friends 13 | This package contains a small LD_PRELOAD library (libeatmydata) and a couple of helper utilities designed to transparently disable fsync and friends (like open(O_SYNC)). 14 | This has two side-effects: making software that writes data safely to disk a lot quicker and making this software no longer crash safe.. 15 | -------------------------------------------------------------------------------- /debian/copyright: -------------------------------------------------------------------------------- 1 | Format: http://dep.debian.net/deps/dep5 2 | Upstream-Name: libeatmydata 3 | Source: 4 | 5 | Files: * 6 | Copyright: 2008-2013 Stewart Smith 7 | 2013 Alexey Bychko 8 | 2012 Blair Zajac 9 | 2012 Phillip Susi 10 | 2011 Modestas Vainius 11 | 2010-2011 Monty Taylor 12 | 2010 Olly Betts 13 | 2010 Pavel Pushkarev 14 | 2010 Elliot Murphy 15 | 2009 Eric Wong 16 | 2009 Tamas TEVESZ 17 | 2009 Joachim Berdal Haga 18 | 2008 Mohsen Hariri 19 | License: GPL v3 20 | This package is free software; you can redistribute it and/or modify 21 | it under the terms of the GNU General Public License as published by 22 | the Free Software Foundation; either version 2 of the License, or 23 | (at your option) any later version. 24 | . 25 | This package is distributed in the hope that it will be useful, 26 | but WITHOUT ANY WARRANTY; without even the implied warranty of 27 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 28 | GNU General Public License for more details. 29 | . 30 | You should have received a copy of the GNU General Public License 31 | along with this program. If not, see 32 | . 33 | On Debian systems, the complete text of the GNU General 34 | Public License version 2 can be found in "/usr/share/common-licenses/GPL-2". 35 | 36 | -------------------------------------------------------------------------------- /debian/docs: -------------------------------------------------------------------------------- 1 | README 2 | -------------------------------------------------------------------------------- /debian/rules: -------------------------------------------------------------------------------- 1 | #!/usr/bin/make -f 2 | # -*- makefile -*- 3 | # Sample debian/rules that uses debhelper. 4 | # This file was originally written by Joey Hess and Craig Small. 5 | # As a special exception, when this file is copied by dh-make into a 6 | # dh-make output file, you may use that output file without restriction. 7 | # This special exception was added by Craig Small in version 0.37 of dh-make. 8 | 9 | # Uncomment this to turn on verbose mode. 10 | #export DH_VERBOSE=1 11 | 12 | %: 13 | dh $@ 14 | -------------------------------------------------------------------------------- /debian/source/format: -------------------------------------------------------------------------------- 1 | 1.0 2 | -------------------------------------------------------------------------------- /eatmydata.in: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | # Copyright ©: 2010, Modestas Vainius 4 | # 5 | # This program is free software: you can redistribute it and/or modify 6 | # it under the terms of the GNU General Public License as published by 7 | # the Free Software Foundation, either version 3 of the License, or 8 | # (at your option) any later version. 9 | # 10 | # This program is distributed in the hope that it will be useful, 11 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | # GNU General Public License for more details. 14 | # 15 | # You should have received a copy of the GNU General Public License 16 | # along with this program. If not, see . 17 | 18 | shlib="@libexecdir@/eatmydata.sh" 19 | if [ -f "$shlib" ]; then 20 | . "$shlib" 21 | else 22 | echo "Unable to locate eatmydata shell library, it was not enabled" >&2 23 | exec "$@" 24 | fi 25 | 26 | usage() 27 | { 28 | echo "usage: $0 [--] command [ command arguments ... ]" >&2 29 | exit 2 30 | } 31 | 32 | # Detect operation mode. If this script is run via symlink, look for basename 33 | # in the PATH and execute it. 34 | cmd= 35 | if [ -L "$0" ]; then 36 | # Symlink mode. Get command to execute from the basename of $0. 37 | cmd="`basename "$0"`" 38 | if [ "$cmd" = "eatmydata" ] ; then 39 | # Don't engage symlink mode for a symlink from "eatmydata" though as 40 | # that breaks with how homebrew installs each package in its own 41 | # prefix and symlinks the binaries into a common "bin" directory. 42 | cmd= 43 | fi 44 | fi 45 | 46 | if [ -n "$cmd" ] ; then 47 | set -- "$cmd" "$@" 48 | else 49 | # Normal mode 50 | if [ "$1" = "--" ]; then 51 | shift 52 | fi 53 | 54 | if [ "$#" -eq 0 ]; then 55 | usage 56 | fi 57 | fi 58 | 59 | eatmydata_exec "$@" 60 | -------------------------------------------------------------------------------- /eatmydata.sh.in: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | # 3 | # Copyright ©: 2010, Modestas Vainius 4 | # 5 | # This program is free software: you can redistribute it and/or modify 6 | # it under the terms of the GNU General Public License as published by 7 | # the Free Software Foundation, either version 3 of the License, or 8 | # (at your option) any later version. 9 | # 10 | # This program is distributed in the hope that it will be useful, 11 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | # GNU General Public License for more details. 14 | # 15 | # You should have received a copy of the GNU General Public License 16 | # along with this program. If not, see . 17 | 18 | libeatmydata="@libdir@/libeatmydata" 19 | name="eatmydata" 20 | 21 | if [ "x`uname`" = "xDarwin" ]; then 22 | libeatmydata="$libeatmydata.dylib" 23 | else 24 | libeatmydata="$libeatmydata.so" 25 | fi 26 | 27 | eatmydata_error() 28 | { 29 | echo "$name error: $1" >&2 30 | exit 1 31 | } 32 | 33 | eatmydata_exec() 34 | { 35 | local cmd 36 | cmd="$1" 37 | if [ "${cmd#*/*}" = "${cmd}" ]; then 38 | # $cmd does not contain '/'. Look in $PATH avoiding loops with self. 39 | local self save_ifs path exe ok 40 | 41 | self="`readlink -f "$0"`" 42 | save_ifs="$IFS" 43 | IFS=":" 44 | ok="" 45 | for path in $PATH; do 46 | exe="${path}/$cmd" 47 | # Avoid loops with self 48 | if [ -x "$exe" ] && [ "`readlink -f "$exe"`" != "$self" ]; then 49 | ok="yes" 50 | break 51 | fi 52 | done 53 | IFS="$save_ifs" 54 | if [ -n "$ok" ]; then 55 | cmd="$exe" 56 | else 57 | eatmydata_error "unable to find '$cmd' in PATH" 58 | fi 59 | fi 60 | 61 | # Preload libeatmydata 62 | if [ `uname` = "Darwin" ]; then 63 | export DYLD_FORCE_FLAT_NAMESPACE=1 64 | export DYLD_INSERT_LIBRARIES="$libeatmydata" 65 | else 66 | if [ -n "$LD_PRELOAD" ]; then 67 | export LD_PRELOAD="$libeatmydata $LD_PRELOAD" 68 | else 69 | export LD_PRELOAD="$libeatmydata" 70 | fi 71 | fi 72 | 73 | # Execute requested command 74 | shift 75 | exec "$cmd" "$@" 76 | } 77 | 78 | # Verify environment 79 | if [ ! -f "$libeatmydata" ]; then 80 | eatmydata_error "could not find $name library $libeatmydata" 81 | fi 82 | -------------------------------------------------------------------------------- /fsynctest.result: -------------------------------------------------------------------------------- 1 | execve("./fsynctest", ["./fsynctest"], [/* */]) = 0 2 | open("./fsynctest", O_RDONLY) = 3 3 | -------------------------------------------------------------------------------- /libeatmydata.spec.in: -------------------------------------------------------------------------------- 1 | Name: libeatmydata 2 | Version: @PACKAGE_VERSION@ 3 | Release: 1%{?dist} 4 | Group: Development/Tools 5 | License: GPLv3 6 | Summary: Library and utilities designed to disable fsync and friends 7 | BuildRoot: %{_tmppath}/%{name}-%{version}-root 8 | BuildRequires: autoconf, automake, make, libtool, strace 9 | Source: https://www.flamingspork.com/projects/libeatmydata/%{name}-%{version}.tar.gz 10 | URL: https://www.flamingspork.com/projects/libeatmydata/ 11 | 12 | %description 13 | This package contains a small LD_PRELOAD library (libeatmydata) and a couple 14 | of helper utilities designed to transparently disable fsync and friends 15 | (like open(O_SYNC)). This has two side-effects: making software that writes 16 | data safely to disk a lot quicker and making this software no longer 17 | crash safe.. 18 | 19 | 20 | %prep 21 | 22 | %setup -q 23 | 24 | %build 25 | autoreconf --force --install 26 | 27 | %configure 28 | %{__make} 29 | 30 | %install 31 | rm -fr %{buildroot} 32 | 33 | %makeinstall 34 | find %{buildroot} -name "*.la" -print0 | xargs -0 rm -f 35 | 36 | %check 37 | %{__make} check 38 | 39 | %clean 40 | rm -fr %{buildroot} 41 | # 42 | %files 43 | %defattr(-,root,root) 44 | %attr(755,-,-) %{_bindir}/eatmydata 45 | %{_libdir}/* 46 | %{_libexecdir}/* 47 | 48 | %doc README.md AUTHORS 49 | # 50 | 51 | %post -p /sbin/ldconfig 52 | %postun -p /sbin/ldconfig 53 | 54 | %changelog 55 | * Sun Oct 10 2021 Stewart Smith - 130-1 56 | - version 130, add syncfs() wrapper 57 | * Sat Apr 10 2021 Stewart Smith - 129-1 58 | - Version 129, as always, bug fix release 59 | * Fri Jul 26 2013 Jaroslav Kortus - 82-1 60 | - Version 82, bug fix release 61 | - spec file changed to meet fedora packaging guidelines 62 | * Fri May 18 2013 Stewart Smith - 79 63 | - Version 79, bug fix release 64 | * Fri Mar 08 2013 Alexey Bychko - 0.1 65 | - Version 0.1, initial package for RPM-based systems 66 | 67 | 68 | -------------------------------------------------------------------------------- /libeatmydata/libeatmydata.c: -------------------------------------------------------------------------------- 1 | /* BEGIN LICENSE 2 | * Copyright (C) 2008-2014 Stewart Smith 3 | * This program is free software: you can redistribute it and/or modify it 4 | * under the terms of the GNU General Public License version 3, as published 5 | * by the Free Software Foundation. 6 | * 7 | * This program is distributed in the hope that it will be useful, but 8 | * WITHOUT ANY WARRANTY; without even the implied warranties of 9 | * MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR 10 | * PURPOSE. See the GNU General Public License for more details. 11 | * 12 | * You should have received a copy of the GNU General Public License along 13 | * with this program. If not, see . 14 | * END LICENSE */ 15 | 16 | #include "config.h" 17 | #include "libeatmydata/portability.h" 18 | #include "libeatmydata/visibility.h" 19 | 20 | #undef _FILE_OFFSET_BITS // Hack to get open and open64 on 32bit 21 | #undef __USE_FILE_OFFSET64 22 | #include 23 | #include 24 | #include 25 | #include 26 | #include 27 | #include 28 | #include 29 | #include 30 | #ifdef HAVE_PTHREAD_H 31 | #include 32 | #endif 33 | 34 | /* 35 | #define CHECK_FILE "/tmp/eatmydata" 36 | */ 37 | 38 | typedef int (*libc_open_t)(const char*, int, ...); 39 | #ifdef HAVE_OPEN64 40 | typedef int (*libc_open64_t)(const char*, int, ...); 41 | #endif 42 | typedef int (*libc_fsync_t)(int); 43 | typedef int (*libc_sync_t)(void); 44 | typedef int (*libc_fdatasync_t)(int); 45 | typedef int (*libc_msync_t)(void*, size_t, int); 46 | #ifdef HAVE_SYNC_FILE_RANGE 47 | typedef int (*libc_sync_file_range_t)(int, off64_t, off64_t, unsigned int); 48 | #endif 49 | #ifdef HAVE_SYNCFS 50 | typedef int (*libc_syncfs_t)(int); 51 | #endif 52 | #if defined(F_FULLFSYNC) && defined(__APPLE__) 53 | typedef int (*libc_fcntl_t)(int, int, ...); 54 | #endif 55 | 56 | /* All the following are thread-local, to avoid initialization races between 57 | * threads. */ 58 | static TLS int init_running = 0; 59 | static TLS int init_complete = 0; 60 | static TLS libc_open_t libc_open= NULL; 61 | #ifdef HAVE_OPEN64 62 | static TLS libc_open64_t libc_open64= NULL; 63 | #endif 64 | static TLS libc_fsync_t libc_fsync= NULL; 65 | static TLS libc_sync_t libc_sync= NULL; 66 | static TLS libc_fdatasync_t libc_fdatasync= NULL; 67 | static TLS libc_msync_t libc_msync= NULL; 68 | #ifdef HAVE_SYNC_FILE_RANGE 69 | static TLS libc_sync_file_range_t libc_sync_file_range= NULL; 70 | #endif 71 | #ifdef HAVE_SYNCFS 72 | static TLS libc_syncfs_t libc_syncfs= NULL; 73 | #endif 74 | #if defined(F_FULLFSYNC) && defined(__APPLE__) 75 | static TLS libc_fcntl_t libc_fcntl= NULL; 76 | #endif 77 | 78 | #define ASSIGN_DLSYM_OR_DIE(name) \ 79 | libc_##name = (libc_##name##_##t)(intptr_t)dlsym(RTLD_NEXT, #name); \ 80 | if (!libc_##name) \ 81 | { \ 82 | const char *dlerror_str = dlerror(); \ 83 | fprintf(stderr, "libeatmydata init error for %s: %s\n", #name,\ 84 | dlerror_str ? dlerror_str : "(null)"); \ 85 | _exit(1); \ 86 | } 87 | 88 | #define ASSIGN_DLSYM_IF_EXIST(name) \ 89 | libc_##name = (libc_##name##_##t)(intptr_t)dlsym(RTLD_NEXT, #name); \ 90 | dlerror(); 91 | 92 | #pragma weak pthread_testcancel 93 | 94 | int LIBEATMYDATA_API msync(void *addr, size_t length, int flags); 95 | 96 | void __attribute__ ((constructor)) eatmydata_init(void); 97 | 98 | void __attribute__ ((constructor)) eatmydata_init(void) 99 | { 100 | init_running++; 101 | ASSIGN_DLSYM_OR_DIE(open); 102 | #ifdef HAVE_OPEN64 103 | ASSIGN_DLSYM_OR_DIE(open64); 104 | #endif 105 | ASSIGN_DLSYM_OR_DIE(fsync); 106 | ASSIGN_DLSYM_OR_DIE(sync); 107 | ASSIGN_DLSYM_OR_DIE(fdatasync); 108 | ASSIGN_DLSYM_OR_DIE(msync); 109 | #ifdef HAVE_SYNC_FILE_RANGE 110 | ASSIGN_DLSYM_IF_EXIST(sync_file_range); 111 | #endif 112 | #ifdef HAVE_SYNCFS 113 | ASSIGN_DLSYM_IF_EXIST(syncfs); 114 | #endif 115 | #if defined(F_FULLFSYNC) && defined(__APPLE__) 116 | ASSIGN_DLSYM_OR_DIE(fcntl); 117 | #endif 118 | init_running--; 119 | init_complete++; 120 | } 121 | 122 | static int eatmydata_is_hungry(void) 123 | { 124 | /* Init here, as it is called before any libc functions */ 125 | if(!init_complete) 126 | eatmydata_init(); 127 | 128 | #ifdef CHECK_FILE 129 | static struct stat buf; 130 | int old_errno, stat_ret; 131 | 132 | old_errno= errno; 133 | stat_ret= stat(CHECK_FILE, &buf); 134 | errno= old_errno; 135 | 136 | /* Treat any error as if file doesn't exist, for safety */ 137 | return !stat_ret; 138 | #else 139 | /* Always hungry! */ 140 | return 1; 141 | #endif 142 | } 143 | 144 | int LIBEATMYDATA_API fsync(int fd) 145 | { 146 | if (eatmydata_is_hungry()) { 147 | if (pthread_testcancel) 148 | pthread_testcancel(); 149 | if (fcntl(fd, F_GETFD) == -1) { 150 | return -1; 151 | } 152 | errno= 0; 153 | return 0; 154 | } 155 | 156 | return (*libc_fsync)(fd); 157 | } 158 | 159 | /* no errors are defined for this function */ 160 | void LIBEATMYDATA_API sync(void) 161 | { 162 | if (eatmydata_is_hungry()) { 163 | return; 164 | } 165 | 166 | (*libc_sync)(); 167 | } 168 | 169 | int LIBEATMYDATA_API open(const char* pathname, int flags, ...) 170 | { 171 | va_list ap; 172 | mode_t mode; 173 | 174 | va_start(ap, flags); 175 | #if SIZEOF_MODE_T < SIZEOF_INT 176 | mode= (mode_t) va_arg(ap, int); 177 | #else 178 | mode= va_arg(ap, mode_t); 179 | #endif 180 | va_end(ap); 181 | 182 | /* If we get called recursively during initialization (which should 183 | * be rare but might happen), just fail. */ 184 | if (init_running > 0) { 185 | errno = EFAULT; 186 | return -1; 187 | } 188 | 189 | if (eatmydata_is_hungry()) 190 | flags &= ~(O_SYNC|O_DSYNC); 191 | 192 | return (*libc_open)(pathname,flags,mode); 193 | } 194 | 195 | #if !defined(__USE_FILE_OFFSET64) && defined(HAVE_OPEN64) 196 | 197 | /* 198 | * Musl libc does this in `fcntl.h`: 199 | * 200 | * #define open64 open 201 | * 202 | * It's hard to detect this situation, but we can avoid a compile failure 203 | * by undefining it. 204 | */ 205 | #undef open64 206 | 207 | int LIBEATMYDATA_API open64(const char* pathname, int flags, ...) 208 | { 209 | va_list ap; 210 | mode_t mode; 211 | 212 | va_start(ap, flags); 213 | #if SIZEOF_MODE_T < SIZEOF_INT 214 | mode= (mode_t) va_arg(ap, int); 215 | #else 216 | mode= va_arg(ap, mode_t); 217 | #endif 218 | va_end(ap); 219 | 220 | /* If we get called recursively during initialization (which should 221 | * be rare but might happen), just fail. */ 222 | if (init_running > 0) { 223 | errno = EFAULT; 224 | return -1; 225 | } 226 | 227 | if (eatmydata_is_hungry()) 228 | flags &= ~(O_SYNC|O_DSYNC); 229 | 230 | return (*libc_open64)(pathname,flags,mode); 231 | } 232 | #endif 233 | 234 | int LIBEATMYDATA_API fdatasync(int fd) 235 | { 236 | if (eatmydata_is_hungry()) { 237 | if (pthread_testcancel) 238 | pthread_testcancel(); 239 | if (fcntl(fd, F_GETFD) == -1) { 240 | return -1; 241 | } 242 | errno= 0; 243 | return 0; 244 | } 245 | 246 | return (*libc_fdatasync)(fd); 247 | } 248 | 249 | int LIBEATMYDATA_API msync(void *addr, size_t length, int flags) 250 | { 251 | if (eatmydata_is_hungry()) { 252 | if (pthread_testcancel) 253 | pthread_testcancel(); 254 | errno= 0; 255 | return 0; 256 | } 257 | 258 | return (*libc_msync)(addr, length, flags); 259 | } 260 | 261 | #ifdef HAVE_SYNC_FILE_RANGE 262 | int LIBEATMYDATA_API sync_file_range(int fd, off64_t offset, off64_t nbytes, 263 | unsigned int flags) 264 | { 265 | if (eatmydata_is_hungry()) { 266 | if (pthread_testcancel) 267 | pthread_testcancel(); 268 | if (fcntl(fd, F_GETFD) == -1) { 269 | return -1; 270 | } 271 | errno= 0; 272 | return 0; 273 | } 274 | 275 | return (libc_sync_file_range)(fd, offset, nbytes, flags); 276 | } 277 | #endif 278 | 279 | #ifdef HAVE_SYNCFS 280 | int LIBEATMYDATA_API syncfs(int fd) 281 | { 282 | if (eatmydata_is_hungry()) { 283 | if (pthread_testcancel) 284 | pthread_testcancel(); 285 | if (fcntl(fd, F_GETFD) == -1) { 286 | errno= EBADF; 287 | return -1; 288 | } 289 | errno= 0; 290 | return 0; 291 | } 292 | 293 | return (*libc_syncfs)(fd); 294 | } 295 | #endif 296 | 297 | #if defined(F_FULLFSYNC) && defined(__APPLE__) 298 | 299 | /* fcntl does not have a va_list version. We have to trust this one seen in 300 | public Darwin sources: 301 | int __FCNTL(int, int, void *); */ 302 | 303 | int LIBEATMYDATA_API fcntl(int fd, int cmd, ...) 304 | { 305 | if ((eatmydata_is_hungry() && (cmd == F_FULLFSYNC))) { 306 | if (fcntl(fd, F_GETFD) == -1) { 307 | return -1; 308 | } 309 | errno= 0; 310 | return 0; 311 | } else { 312 | 313 | va_list args; 314 | va_start(args, cmd); 315 | void * arg= va_arg(args, void *); 316 | va_end(args); 317 | return ((libc_fcntl)(fd, cmd, arg)); 318 | } 319 | } 320 | 321 | #endif 322 | -------------------------------------------------------------------------------- /libeatmydata/portability.h: -------------------------------------------------------------------------------- 1 | /* BEGIN LICENSE 2 | * Copyright (C) 2017 Stewart Smith 3 | * This program is free software: you can redistribute it and/or modify it 4 | * under the terms of the GNU General Public License version 3, as published 5 | * by the Free Software Foundation. 6 | * 7 | * This program is distributed in the hope that it will be useful, but 8 | * WITHOUT ANY WARRANTY; without even the implied warranties of 9 | * MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR 10 | * PURPOSE. See the GNU General Public License for more details. 11 | * 12 | * You should have received a copy of the GNU General Public License along 13 | * with this program. If not, see . 14 | * END LICENSE */ 15 | 16 | /** 17 | * @file 18 | * @brief libeatmydata portability abstraction header 19 | */ 20 | 21 | #ifndef LIBEATMYDATA_PORTABILITY_H 22 | #define LIBEATMYDATA_PORTABILITY_H 23 | 24 | #include "config.h" 25 | 26 | /* 27 | * Mac OS X 10.7 doesn't declare fdatasync(). 28 | */ 29 | #if defined(HAVE_FDATASYNC) && HAVE_DECL_FDATASYNC == 0 30 | int fdatasync(int fd); 31 | #endif 32 | 33 | #endif 34 | -------------------------------------------------------------------------------- /libeatmydata/test/eatmydatatest.c: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (C): 2010, Modestas Vainius 3 | 4 | This program is free software: you can redistribute it and/or modify 5 | it under the terms of the GNU General Public License as published by 6 | the Free Software Foundation, either version 3 of the License, or 7 | (at your option) any later version. 8 | 9 | This program is distributed in the hope that it will be useful, 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | GNU General Public License for more details. 13 | 14 | You should have received a copy of the GNU General Public License 15 | along with this program. If not, see . 16 | */ 17 | #include 18 | #include 19 | #include 20 | #include 21 | #include 22 | #include 23 | 24 | int failed_tests = 0; 25 | 26 | #define DATAFILENAME "eatmydatatest.dat" 27 | #define TESTCASE(value, expected, desc) \ 28 | { errno=0; if (value != expected) { \ 29 | fprintf(stderr, "Test case failed: %s (err=%d).\n", desc, value); \ 30 | if (errno != 0) perror("-- System errno (if applicable)"); \ 31 | failed_tests++; \ 32 | } \ 33 | } 34 | 35 | // Returns true if file status flag was not filtered out. 36 | static int test_open_flag(int flag) 37 | { 38 | int fd, res; 39 | 40 | res = -1; 41 | fd = open(DATAFILENAME, O_CREAT|O_TRUNC|O_WRONLY|flag, S_IRUSR|S_IWUSR); 42 | if (fd != -1) { 43 | res = fcntl(fd, F_GETFL); 44 | } 45 | if (res == -1) { 46 | res = errno; 47 | close(fd); 48 | unlink(DATAFILENAME); 49 | errno = res; 50 | return -1; 51 | } 52 | close(fd); 53 | unlink(DATAFILENAME); 54 | return res & flag; 55 | } 56 | 57 | int main(int argc, char** argv) 58 | { 59 | int fd; 60 | (void)argc; 61 | (void)argv; 62 | 63 | TESTCASE(test_open_flag(O_SYNC), 0, "open(O_SYNC) flag was not filtered out"); 64 | TESTCASE(test_open_flag(O_DSYNC), 0, "open(O_DSYNC) flag was not filtered out"); 65 | 66 | // Open and close FD in order to make sure its invalid. 67 | fd = open(DATAFILENAME, O_CREAT|O_TRUNC|O_WRONLY, S_IRUSR|S_IWUSR); 68 | if (fd == -1) 69 | perror("unable to open " DATAFILENAME); 70 | 71 | // Now test fsync and friends by feeding them an invalid file descriptor. 72 | // System implementation should fail with EBADF while libeatmydata 73 | // implementation will succeed. 74 | TESTCASE(fsync(fd), 0, "system fsync() was not overridden"); 75 | TESTCASE(fdatasync(fd), 0, "system fdatasync() was not overridden"); 76 | TESTCASE(msync(0, 1, 1), 0, "system msync() was not overridden"); 77 | 78 | if (failed_tests > 0) { 79 | fprintf(stderr, "%d test cases failed\n", failed_tests); 80 | return 2; 81 | } 82 | if (close(fd) == -1) 83 | perror("unable to close " DATAFILENAME " file descriptor"); 84 | unlink(DATAFILENAME); 85 | 86 | return 0; 87 | } 88 | -------------------------------------------------------------------------------- /libeatmydata/test/eatmydatatest_largefile.c: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (C): 2013, Stewart Smith 3 | 4 | This program is free software: you can redistribute it and/or modify 5 | it under the terms of the GNU General Public License as published by 6 | the Free Software Foundation, either version 3 of the License, or 7 | (at your option) any later version. 8 | 9 | This program is distributed in the hope that it will be useful, 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | GNU General Public License for more details. 13 | 14 | You should have received a copy of the GNU General Public License 15 | along with this program. If not, see . 16 | */ 17 | 18 | /* This test exists to test exactly the same thing as eatmydatatest but 19 | while defining _FILE_OFFSET_BITS to 64 which should enforce large file 20 | support on 32bit systems */ 21 | #define _FILE_OFFSET_BITS 64 22 | #include "eatmydatatest.c" 23 | -------------------------------------------------------------------------------- /libeatmydata/test/fcntltest.c: -------------------------------------------------------------------------------- 1 | /* BEGIN LICENSE 2 | * Copyright (C) 2017 Stewart Smith 3 | * This program is free software: you can redistribute it and/or modify it 4 | * under the terms of the GNU General Public License version 3, as published 5 | * by the Free Software Foundation. 6 | * 7 | * This program is distributed in the hope that it will be useful, but 8 | * WITHOUT ANY WARRANTY; without even the implied warranties of 9 | * MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR 10 | * PURPOSE. See the GNU General Public License for more details. 11 | * 12 | * You should have received a copy of the GNU General Public License along 13 | * with this program. If not, see . 14 | * END LICENSE */ 15 | 16 | #include "config.h" 17 | 18 | #include "libeatmydata/portability.h" 19 | 20 | #include 21 | #include 22 | #include 23 | #include 24 | #include 25 | 26 | #define TESTFN "fcntltestdata" 27 | 28 | int main(void) 29 | { 30 | int fd, err; 31 | ssize_t write_ret; 32 | 33 | errno= 0; 34 | fd= open(TESTFN, O_CREAT | O_RDWR | O_SYNC | O_DSYNC | O_TRUNC, 0700); 35 | assert(fd > 0); 36 | assert(errno == 0); 37 | 38 | #ifdef F_FULLFSYNC 39 | err= fcntl(fd, F_FULLFSYNC, 0); 40 | assert(err != -1); 41 | assert(errno == 0); 42 | #endif 43 | 44 | write_ret= write(fd, "a", 1); 45 | assert(write_ret == 1); 46 | assert(errno == 0); 47 | 48 | err= close(fd); 49 | assert(err == 0); 50 | assert(errno == 0); 51 | 52 | err= unlink(TESTFN); 53 | assert(err == 0); 54 | assert(errno == 0); 55 | 56 | return 0; 57 | } 58 | -------------------------------------------------------------------------------- /libeatmydata/test/fsynctest.c: -------------------------------------------------------------------------------- 1 | /* BEGIN LICENSE 2 | * Copyright (C) 2008-2010 Stewart Smith 3 | * This program is free software: you can redistribute it and/or modify it 4 | * under the terms of the GNU General Public License version 3, as published 5 | * by the Free Software Foundation. 6 | * 7 | * This program is distributed in the hope that it will be useful, but 8 | * WITHOUT ANY WARRANTY; without even the implied warranties of 9 | * MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR 10 | * PURPOSE. See the GNU General Public License for more details. 11 | * 12 | * You should have received a copy of the GNU General Public License along 13 | * with this program. If not, see . 14 | * END LICENSE */ 15 | 16 | #include "config.h" 17 | 18 | #include "libeatmydata/portability.h" 19 | 20 | #include 21 | #include 22 | #include 23 | #include 24 | #include 25 | #include 26 | #include 27 | #include 28 | #include 29 | 30 | int main(int argc, char* argv[]) 31 | { 32 | (void)argc; (void)argv; 33 | int fd; 34 | int i; 35 | ssize_t ret; 36 | fd= open("fsynctestdata",O_CREAT|O_RDWR|O_SYNC|O_DSYNC|O_TRUNC, 0700); 37 | assert(fd > 0); 38 | assert(errno == 0); 39 | for (i = 0; i < 1000; ++i) { 40 | ret= write(fd, "a", 1); 41 | assert(errno == 0 && ret == 1); 42 | fsync(fd); 43 | assert(errno == 0); 44 | ret= write(fd, "a", 1); 45 | assert(errno == 0 && ret == 1); 46 | fdatasync(fd); 47 | assert(errno == 0); 48 | ret= write(fd, "a", 1); 49 | assert(errno == 0 && ret == 1); 50 | sync(); 51 | assert(errno == 0); 52 | } 53 | close(fd); 54 | unlink("fsynctestdata"); 55 | msync(0,0,0); 56 | assert(errno == 0); 57 | return 0; 58 | } 59 | -------------------------------------------------------------------------------- /libeatmydata/test/syncfstest.c: -------------------------------------------------------------------------------- 1 | /* BEGIN LICENSE 2 | * Copyright (C) 2008-2010 Stewart Smith 3 | * This program is free software: you can redistribute it and/or modify it 4 | * under the terms of the GNU General Public License version 3, as published 5 | * by the Free Software Foundation. 6 | * 7 | * This program is distributed in the hope that it will be useful, but 8 | * WITHOUT ANY WARRANTY; without even the implied warranties of 9 | * MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR 10 | * PURPOSE. See the GNU General Public License for more details. 11 | * 12 | * You should have received a copy of the GNU General Public License along 13 | * with this program. If not, see . 14 | * END LICENSE */ 15 | 16 | #include "config.h" 17 | 18 | #include "libeatmydata/portability.h" 19 | 20 | #include 21 | #include 22 | #include 23 | #include 24 | #include 25 | #include 26 | #include 27 | #include 28 | #include 29 | 30 | int main(int argc, char* argv[]) 31 | { 32 | (void)argc; (void)argv; 33 | #ifdef HAVE_SYNCFS 34 | int fd; 35 | int i; 36 | ssize_t ret; 37 | fd= open("syncfstestdata",O_CREAT|O_RDWR|O_SYNC|O_DSYNC|O_TRUNC, 0700); 38 | assert(fd > 0); 39 | assert(errno == 0); 40 | for (i = 0; i < 1000; ++i) { 41 | ret= write(fd, "a", 1); 42 | assert(errno == 0 && ret == 1); 43 | syncfs(fd); 44 | assert(errno == 0); 45 | } 46 | close(fd); 47 | unlink("syncfstestdata"); 48 | #endif 49 | return 0; 50 | } 51 | -------------------------------------------------------------------------------- /libeatmydata/test/tst-cancel4.c: -------------------------------------------------------------------------------- 1 | /* Copyright (C) 2002, 2003, 2004, 2006, 2007 Free Software Foundation, Inc. 2 | This file is part of the GNU C Library. 3 | Contributed by Ulrich Drepper , 2002. 4 | (C) 2013 Stewart Smith. 5 | 6 | The GNU C Library is free software; you can redistribute it and/or 7 | modify it under the terms of the GNU Lesser General Public 8 | License as published by the Free Software Foundation; either 9 | version 2.1 of the License, or (at your option) any later version. 10 | 11 | The GNU C Library is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | Lesser General Public License for more details. 15 | 16 | You should have received a copy of the GNU Lesser General Public 17 | License along with the GNU C Library; if not, see 18 | . */ 19 | 20 | /* NOTE: Modified from original to use mkostemp() instead of relying on 21 | Makefile being present */ 22 | 23 | /* NOTE: this tests functionality beyond POSIX. POSIX does not allow 24 | exit to be called more than once. */ 25 | 26 | #include "config.h" 27 | 28 | #define _GNU_SOURCE 29 | #include 30 | #include 31 | #include 32 | #ifdef HAVE_PTHREAD_H 33 | #include 34 | #endif 35 | #include 36 | #include 37 | #include 38 | #include 39 | #include 40 | #include 41 | #include 42 | #include 43 | #include 44 | #include 45 | #include 46 | #include 47 | #include 48 | #include 49 | 50 | //#include "pthreadP.h" 51 | 52 | 53 | /* Since STREAMS are not supported in the standard Linux kernel and 54 | there we don't advertise STREAMS as supported is no need to test 55 | the STREAMS related functions. This affects 56 | getmsg() getpmsg() putmsg() 57 | putpmsg() 58 | 59 | lockf() and fcntl() are tested in tst-cancel16. 60 | 61 | pthread_join() is tested in tst-join5. 62 | 63 | pthread_testcancel()'s only purpose is to allow cancellation. This 64 | is tested in several places. 65 | 66 | sem_wait() and sem_timedwait() are checked in tst-cancel1[2345] tests. 67 | 68 | mq_send(), mq_timedsend(), mq_receive() and mq_timedreceive() are checked 69 | in tst-mqueue8{,x} tests. 70 | 71 | aio_suspend() is tested in tst-cancel17. 72 | 73 | clock_nanosleep() is tested in tst-cancel18. 74 | */ 75 | 76 | /* Pipe descriptors. */ 77 | static int fds[2]; 78 | 79 | /* Temporary file descriptor, to be closed after each round. */ 80 | static int tempfd = -1; 81 | static int tempfd2 = -1; 82 | /* Name of temporary file to be removed after each round. */ 83 | static char *tempfname; 84 | /* Temporary message queue. */ 85 | static int tempmsg = -1; 86 | 87 | /* Often used barrier for two threads. */ 88 | static pthread_barrier_t b2; 89 | 90 | 91 | #ifndef IPC_ADDVAL 92 | # define IPC_ADDVAL 0 93 | #endif 94 | 95 | /* Cleanup handling test. */ 96 | static int cl_called; 97 | 98 | static void 99 | cl (void *arg) 100 | { 101 | (void)arg; 102 | ++cl_called; 103 | } 104 | 105 | 106 | 107 | static void * 108 | tf_fsync (void *arg) 109 | { 110 | if (arg == NULL) 111 | // XXX If somebody can provide a portable test case in which fsync() 112 | // blocks we can enable this test to run in both rounds. 113 | abort (); 114 | 115 | char *fname= strdup("/tmp/eatmydataXXXXXX"); 116 | 117 | tempfd = mkostemp(fname, O_RDONLY); 118 | if (tempfd == -1) 119 | { 120 | printf ("%s: cannot open %s\n", __func__, fname); 121 | exit (1); 122 | } 123 | 124 | int r = pthread_barrier_wait (&b2); 125 | if (r != 0 && r != PTHREAD_BARRIER_SERIAL_THREAD) 126 | { 127 | printf ("%s: barrier_wait failed\n", __func__); 128 | exit (1); 129 | } 130 | 131 | r = pthread_barrier_wait (&b2); 132 | if (r != 0 && r != PTHREAD_BARRIER_SERIAL_THREAD) 133 | { 134 | printf ("%s: 2nd barrier_wait failed\n", __func__); 135 | exit (1); 136 | } 137 | 138 | pthread_cleanup_push (cl, NULL); 139 | 140 | fsync (tempfd); 141 | 142 | pthread_cleanup_pop (0); 143 | 144 | printf ("%s: fsync returned\n", __func__); 145 | 146 | unlink(fname); 147 | free(fname); 148 | 149 | exit (1); 150 | } 151 | 152 | 153 | static void * 154 | tf_fdatasync (void *arg) 155 | { 156 | if (arg == NULL) 157 | // XXX If somebody can provide a portable test case in which fdatasync() 158 | // blocks we can enable this test to run in both rounds. 159 | abort (); 160 | 161 | char *fname= strdup("/tmp/eatmydataXXXXXX"); 162 | 163 | tempfd = mkostemp(fname, O_RDONLY); 164 | if (tempfd == -1) 165 | { 166 | printf ("%s: cannot open %s\n", __func__, fname); 167 | exit (1); 168 | } 169 | 170 | int r = pthread_barrier_wait (&b2); 171 | if (r != 0 && r != PTHREAD_BARRIER_SERIAL_THREAD) 172 | { 173 | printf ("%s: barrier_wait failed\n", __func__); 174 | exit (1); 175 | } 176 | 177 | r = pthread_barrier_wait (&b2); 178 | if (r != 0 && r != PTHREAD_BARRIER_SERIAL_THREAD) 179 | { 180 | printf ("%s: 2nd barrier_wait failed\n", __func__); 181 | exit (1); 182 | } 183 | 184 | pthread_cleanup_push (cl, NULL); 185 | 186 | fdatasync (tempfd); 187 | 188 | pthread_cleanup_pop (0); 189 | 190 | printf ("%s: fdatasync returned\n", __func__); 191 | 192 | unlink(fname); 193 | free(fname); 194 | 195 | exit (1); 196 | } 197 | 198 | 199 | static void * 200 | tf_msync (void *arg) 201 | { 202 | if (arg == NULL) 203 | // XXX If somebody can provide a portable test case in which msync() 204 | // blocks we can enable this test to run in both rounds. 205 | abort (); 206 | 207 | char *fname= strdup("/tmp/eatmydataXXXXXX"); 208 | 209 | tempfd = mkostemp(fname, O_RDONLY); 210 | if (tempfd == -1) 211 | { 212 | printf ("%s: cannot open %s\n", __func__, fname); 213 | exit (1); 214 | } 215 | 216 | void *p = mmap (NULL, 10, PROT_READ, MAP_SHARED, tempfd, 0); 217 | if (p == MAP_FAILED) 218 | { 219 | printf ("%s: mmap failed\n", __func__); 220 | exit (1); 221 | } 222 | 223 | int r = pthread_barrier_wait (&b2); 224 | if (r != 0 && r != PTHREAD_BARRIER_SERIAL_THREAD) 225 | { 226 | printf ("%s: barrier_wait failed\n", __func__); 227 | exit (1); 228 | } 229 | 230 | r = pthread_barrier_wait (&b2); 231 | if (r != 0 && r != PTHREAD_BARRIER_SERIAL_THREAD) 232 | { 233 | printf ("%s: 2nd barrier_wait failed\n", __func__); 234 | exit (1); 235 | } 236 | 237 | pthread_cleanup_push (cl, NULL); 238 | 239 | msync (p, 10, 0); 240 | 241 | pthread_cleanup_pop (0); 242 | 243 | printf ("%s: msync returned\n", __func__); 244 | 245 | unlink(fname); 246 | free(fname); 247 | 248 | exit (1); 249 | } 250 | 251 | 252 | static struct 253 | { 254 | const char *name; 255 | void *(*tf) (void *); 256 | int nb; 257 | int only_early; 258 | } tests[] = 259 | { 260 | #define ADD_TEST(name, nbar, early) { #name, tf_##name, nbar, early } 261 | ADD_TEST (fsync, 2, 1), 262 | ADD_TEST (fdatasync, 2, 1), 263 | ADD_TEST (msync, 2, 1), 264 | }; 265 | #define ntest_tf (sizeof (tests) / sizeof (tests[0])) 266 | 267 | 268 | static int 269 | do_test (void) 270 | { 271 | int val; 272 | socklen_t len; 273 | 274 | if (socketpair (AF_UNIX, SOCK_STREAM, PF_UNIX, fds) != 0) 275 | { 276 | perror ("socketpair"); 277 | exit (1); 278 | } 279 | 280 | val = 1; 281 | len = sizeof(val); 282 | setsockopt (fds[1], SOL_SOCKET, SO_SNDBUF, &val, sizeof(val)); 283 | if (getsockopt (fds[1], SOL_SOCKET, SO_SNDBUF, &val, &len) < 0) 284 | { 285 | perror ("getsockopt"); 286 | exit (1); 287 | } 288 | setsockopt (fds[1], SOL_SOCKET, SO_SNDBUF, &val, sizeof(val)); 289 | 290 | int result = 0; 291 | size_t cnt; 292 | for (cnt = 0; cnt < ntest_tf; ++cnt) 293 | { 294 | if (tests[cnt].only_early) 295 | continue; 296 | 297 | if (pthread_barrier_init (&b2, NULL, tests[cnt].nb) != 0) 298 | { 299 | puts ("b2 init failed"); 300 | exit (1); 301 | } 302 | 303 | /* Reset the counter for the cleanup handler. */ 304 | cl_called = 0; 305 | 306 | pthread_t th; 307 | if (pthread_create (&th, NULL, tests[cnt].tf, NULL) != 0) 308 | { 309 | printf ("create for '%s' test failed\n", tests[cnt].name); 310 | result = 1; 311 | continue; 312 | } 313 | 314 | int r = pthread_barrier_wait (&b2); 315 | if (r != 0 && r != PTHREAD_BARRIER_SERIAL_THREAD) 316 | { 317 | printf ("%s: barrier_wait failed\n", __func__); 318 | result = 1; 319 | continue; 320 | } 321 | 322 | struct timespec ts = { .tv_sec = 0, .tv_nsec = 100000000 }; 323 | while (nanosleep (&ts, &ts) != 0) 324 | continue; 325 | 326 | if (pthread_cancel (th) != 0) 327 | { 328 | printf ("cancel for '%s' failed\n", tests[cnt].name); 329 | result = 1; 330 | continue; 331 | } 332 | 333 | void *status; 334 | if (pthread_join (th, &status) != 0) 335 | { 336 | printf ("join for '%s' failed\n", tests[cnt].name); 337 | result = 1; 338 | continue; 339 | } 340 | if (status != PTHREAD_CANCELED) 341 | { 342 | printf ("thread for '%s' not canceled\n", tests[cnt].name); 343 | result = 1; 344 | continue; 345 | } 346 | 347 | if (pthread_barrier_destroy (&b2) != 0) 348 | { 349 | puts ("barrier_destroy failed"); 350 | result = 1; 351 | continue; 352 | } 353 | 354 | if (cl_called == 0) 355 | { 356 | printf ("cleanup handler not called for '%s'\n", tests[cnt].name); 357 | result = 1; 358 | continue; 359 | } 360 | if (cl_called > 1) 361 | { 362 | printf ("cleanup handler called more than once for '%s'\n", 363 | tests[cnt].name); 364 | result = 1; 365 | continue; 366 | } 367 | 368 | printf ("in-time cancel test of '%s' successful\n", tests[cnt].name); 369 | 370 | if (tempfd != -1) 371 | { 372 | close (tempfd); 373 | tempfd = -1; 374 | } 375 | if (tempfd2 != -1) 376 | { 377 | close (tempfd2); 378 | tempfd2 = -1; 379 | } 380 | if (tempfname != NULL) 381 | { 382 | unlink (tempfname); 383 | free (tempfname); 384 | tempfname = NULL; 385 | } 386 | if (tempmsg != -1) 387 | { 388 | msgctl (tempmsg, IPC_RMID, NULL); 389 | tempmsg = -1; 390 | } 391 | } 392 | 393 | for (cnt = 0; cnt < ntest_tf; ++cnt) 394 | { 395 | if (pthread_barrier_init (&b2, NULL, tests[cnt].nb) != 0) 396 | { 397 | puts ("b2 init failed"); 398 | exit (1); 399 | } 400 | 401 | /* Reset the counter for the cleanup handler. */ 402 | cl_called = 0; 403 | 404 | pthread_t th; 405 | if (pthread_create (&th, NULL, tests[cnt].tf, (void *) 1l) != 0) 406 | { 407 | printf ("create for '%s' test failed\n", tests[cnt].name); 408 | result = 1; 409 | continue; 410 | } 411 | 412 | int r = pthread_barrier_wait (&b2); 413 | if (r != 0 && r != PTHREAD_BARRIER_SERIAL_THREAD) 414 | { 415 | printf ("%s: barrier_wait failed\n", __func__); 416 | result = 1; 417 | continue; 418 | } 419 | 420 | if (pthread_cancel (th) != 0) 421 | { 422 | printf ("cancel for '%s' failed\n", tests[cnt].name); 423 | result = 1; 424 | continue; 425 | } 426 | 427 | r = pthread_barrier_wait (&b2); 428 | if (r != 0 && r != PTHREAD_BARRIER_SERIAL_THREAD) 429 | { 430 | printf ("%s: barrier_wait failed\n", __func__); 431 | result = 1; 432 | continue; 433 | } 434 | 435 | void *status; 436 | if (pthread_join (th, &status) != 0) 437 | { 438 | printf ("join for '%s' failed\n", tests[cnt].name); 439 | result = 1; 440 | continue; 441 | } 442 | if (status != PTHREAD_CANCELED) 443 | { 444 | printf ("thread for '%s' not canceled\n", tests[cnt].name); 445 | result = 1; 446 | continue; 447 | } 448 | 449 | if (pthread_barrier_destroy (&b2) != 0) 450 | { 451 | puts ("barrier_destroy failed"); 452 | result = 1; 453 | continue; 454 | } 455 | 456 | if (cl_called == 0) 457 | { 458 | printf ("cleanup handler not called for '%s'\n", tests[cnt].name); 459 | result = 2; 460 | continue; 461 | } 462 | if (cl_called > 1) 463 | { 464 | printf ("cleanup handler called more than once for '%s'\n", 465 | tests[cnt].name); 466 | result = 1; 467 | continue; 468 | } 469 | 470 | printf ("early cancel test of '%s' successful\n", tests[cnt].name); 471 | 472 | if (tempfd != -1) 473 | { 474 | close (tempfd); 475 | tempfd = -1; 476 | } 477 | if (tempfd2 != -1) 478 | { 479 | close (tempfd2); 480 | tempfd2 = -1; 481 | } 482 | if (tempfname != NULL) 483 | { 484 | unlink (tempfname); 485 | free (tempfname); 486 | tempfname = NULL; 487 | } 488 | if (tempmsg != -1) 489 | { 490 | msgctl (tempmsg, IPC_RMID, NULL); 491 | tempmsg = -1; 492 | } 493 | } 494 | 495 | return result; 496 | } 497 | 498 | #define TIMEOUT 60 499 | //#define TEST_FUNCTION do_test () 500 | 501 | int main(void) 502 | { 503 | return do_test(); 504 | } 505 | //#include "test-skeleton.c" 506 | -------------------------------------------------------------------------------- /libeatmydata/test/tst-invalidfd.c: -------------------------------------------------------------------------------- 1 | /* BEGIN LICENSE 2 | * Copyright (C) 2017 Yura Sorokin, Stewart Smith 3 | * This program is free software: you can redistribute it and/or modify it 4 | * under the terms of the GNU General Public License version 3, as published 5 | * by the Free Software Foundation. 6 | * 7 | * This program is distributed in the hope that it will be useful, but 8 | * WITHOUT ANY WARRANTY; without even the implied warranties of 9 | * MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR 10 | * PURPOSE. See the GNU General Public License for more details. 11 | * 12 | * You should have received a copy of the GNU General Public License along 13 | * with this program. If not, see . 14 | * END LICENSE */ 15 | 16 | #include "libeatmydata/portability.h" 17 | 18 | #include 19 | #include 20 | #include 21 | #include 22 | 23 | #ifdef HAVE_SYNC_FILE_RANGE 24 | #define _GNU_SOURCE 25 | #include 26 | #endif 27 | 28 | int main() 29 | { 30 | int fd = 42; 31 | int r = fdatasync(fd); 32 | assert(r == -1 && errno == EBADF); 33 | r = fsync(fd); 34 | assert(r == -1 && errno == EBADF); 35 | #ifdef HAVE_SYNC_FILE_RANGE 36 | r = sync_file_range(fd, 0, 0, 0); 37 | assert(r == -1 && errno == EBADF); 38 | #endif 39 | return 0; 40 | } 41 | -------------------------------------------------------------------------------- /libeatmydata/test/tst-key4.c: -------------------------------------------------------------------------------- 1 | /* Copyright (C) 2003, 2004 Free Software Foundation, Inc. 2 | This file is part of the GNU C Library. 3 | Contributed by Ulrich Drepper , 2003. 4 | 5 | The GNU C Library is free software; you can redistribute it and/or 6 | modify it under the terms of the GNU Lesser General Public 7 | License as published by the Free Software Foundation; either 8 | version 2.1 of the License, or (at your option) any later version. 9 | 10 | The GNU C Library is distributed in the hope that it will be useful, 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | Lesser General Public License for more details. 14 | 15 | You should have received a copy of the GNU Lesser General Public 16 | License along with the GNU C Library; if not, see 17 | . */ 18 | 19 | #include "config.h" 20 | 21 | #include 22 | #ifdef HAVE_PTHREAD_H 23 | #include 24 | #endif 25 | #include 26 | #include 27 | #include 28 | 29 | 30 | #ifdef PTHREAD_KEYS_MAX 31 | const int max = PTHREAD_KEYS_MAX - 1; // -1 is for libeatmydata 32 | #else 33 | const int max = _POSIX_THREAD_KEYS_MAX; 34 | #endif 35 | static pthread_key_t *keys; 36 | 37 | 38 | static void * 39 | tf1 (void *arg) 40 | { 41 | (void)arg; 42 | int i; 43 | for (i = 0; i < max; ++i) 44 | if (pthread_setspecific (keys[i], (void *) (long int) (i + 1)) != 0) 45 | { 46 | puts ("setspecific failed"); 47 | exit (1); 48 | } 49 | 50 | return NULL; 51 | } 52 | 53 | 54 | static void * 55 | tf2 (void *arg) 56 | { 57 | (void)arg; 58 | int i; 59 | for (i = 0; i < max; ++i) 60 | if (pthread_getspecific (keys[i]) != NULL) 61 | { 62 | printf ("getspecific for key %d not NULL\n", i); 63 | exit (1); 64 | } 65 | 66 | return NULL; 67 | } 68 | 69 | 70 | int main(int argc, char *argv[]) 71 | { 72 | (void)argc; 73 | (void)argv; 74 | keys = alloca (max * sizeof (pthread_key_t)); 75 | 76 | int i; 77 | for (i = 0; i < max; ++i) 78 | if (pthread_key_create (&keys[i], NULL) != 0) 79 | { 80 | printf("key_create %d failed\n", i); 81 | exit (1); 82 | } 83 | pthread_attr_t a; 84 | 85 | if (pthread_attr_init (&a) != 0) 86 | { 87 | puts ("attr_init failed"); 88 | exit (1); 89 | } 90 | 91 | if (pthread_attr_setstacksize (&a, 1 * 1024 * 1024) != 0) 92 | { 93 | puts ("attr_setstacksize failed"); 94 | return 1; 95 | } 96 | 97 | for (i = 0; i < 10; ++i) 98 | { 99 | int j; 100 | #define N 2 101 | pthread_t th[N]; 102 | for (j = 0; j < N; ++j) 103 | if (pthread_create (&th[j], NULL, tf1, NULL) != 0) 104 | { 105 | puts ("1st create failed"); 106 | exit (1); 107 | } 108 | 109 | for (j = 0; j < N; ++j) 110 | if (pthread_join (th[j], NULL) != 0) 111 | { 112 | puts ("1st join failed"); 113 | exit (1); 114 | } 115 | 116 | for (j = 0; j < N; ++j) 117 | if (pthread_create (&th[j], NULL, tf2, NULL) != 0) 118 | { 119 | puts ("2nd create failed"); 120 | exit (1); 121 | } 122 | 123 | for (j = 0; j < N; ++j) 124 | if (pthread_join (th[j], NULL) != 0) 125 | { 126 | puts ("2nd join failed"); 127 | exit (1); 128 | } 129 | } 130 | 131 | if (pthread_attr_destroy (&a) != 0) 132 | { 133 | puts ("attr_destroy failed"); 134 | exit (1); 135 | } 136 | 137 | return 0; 138 | } 139 | -------------------------------------------------------------------------------- /libeatmydata/visibility.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Libeatmydata 3 | * 4 | * Copyright (C) 2010 Eric Day (eday@oddments.org) 5 | * All rights reserved. 6 | * 7 | * Use and distribution licensed under the BSD license. See the 8 | * COPYING file in the root project directory for full text. 9 | */ 10 | 11 | /** 12 | * @file 13 | * @brief Common Macro Definitions 14 | */ 15 | 16 | #ifndef LIBEATMYDATA_VISIBILITY_H 17 | #define LIBEATMYDATA_VISIBILITY_H 18 | 19 | /** 20 | * Be sure to put LIBEATMYDATA_API in front of all public API symbols, or one of 21 | * the other macros as appropriate. The default visibility without a macro is 22 | * to be hidden (LIBEATMYDATA_LOCAL). 23 | */ 24 | 25 | #if defined(BUILDING_LIBEATMYDATA) && defined(HAVE_VISIBILITY) 26 | # if defined(__GNUC__) 27 | # define LIBEATMYDATA_API __attribute__ ((visibility("default"))) 28 | # define LIBEATMYDATA_INTERNAL_API __attribute__ ((visibility("hidden"))) 29 | # define LIBEATMYDATA_API_DEPRECATED __attribute__ ((deprecated,visibility("default"))) 30 | # define LIBEATMYDATA_LOCAL __attribute__ ((visibility("hidden"))) 31 | # elif (defined(__SUNPRO_C) && (__SUNPRO_C >= 0x550)) || (defined(__SUNPRO_CC) && (__SUNPRO_CC >= 0x550)) 32 | # define LIBEATMYDATA_API __global 33 | # define LIBEATMYDATA_INTERNAL_API __hidden 34 | # define LIBEATMYDATA_API_DEPRECATED __global 35 | # define LIBEATMYDATA_LOCAL __hidden 36 | # elif defined(_MSC_VER) 37 | # define LIBEATMYDATA_API extern __declspec(dllexport) 38 | # define LIBEATMYDATA_INTERNAL_API extern __declspec(dllexport) 39 | # define LIBEATMYDATA_DEPRECATED_API extern __declspec(dllexport) 40 | # define LIBEATMYDATA_LOCAL 41 | # endif 42 | #else /* defined(BUILDING_LIBEATMYDATA) && defined(HAVE_VISIBILITY) */ 43 | # if defined(_MSC_VER) 44 | # define SCALESTACK_API extern __declspec(dllimport) 45 | # define LIBEATMYDATA_INTERNAL_API extern __declspec(dllimport) 46 | # define LIBEATMYDATA_API_DEPRECATED extern __declspec(dllimport) 47 | # define LIBEATMYDATA_LOCAL 48 | # else 49 | # define LIBEATMYDATA_API 50 | # define LIBEATMYDATA_INTERNAL_API 51 | # define LIBEATMYDATA_API_DEPRECATED 52 | # define LIBEATMYDATA_LOCAL 53 | # endif /* defined(_MSC_VER) */ 54 | #endif /* defined(BUILDING_LIBEATMYDATA) && defined(HAVE_VISIBILITY) */ 55 | 56 | 57 | #endif /* LIBEATMYDATA_VISIBILITY_H */ 58 | -------------------------------------------------------------------------------- /m4/acx_pthread.m4: -------------------------------------------------------------------------------- 1 | # =========================================================================== 2 | # http://autoconf-archive.cryp.to/acx_pthread.html 3 | # =========================================================================== 4 | # 5 | # SYNOPSIS 6 | # 7 | # ACX_PTHREAD([ACTION-IF-FOUND[, ACTION-IF-NOT-FOUND]]) 8 | # 9 | # DESCRIPTION 10 | # 11 | # This macro figures out how to build C programs using POSIX threads. It 12 | # sets the PTHREAD_LIBS output variable to the threads library and linker 13 | # flags, and the PTHREAD_CFLAGS output variable to any special C compiler 14 | # flags that are needed. (The user can also force certain compiler 15 | # flags/libs to be tested by setting these environment variables.) 16 | # 17 | # Also sets PTHREAD_CC to any special C compiler that is needed for 18 | # multi-threaded programs (defaults to the value of CC otherwise). (This 19 | # is necessary on AIX to use the special cc_r compiler alias.) 20 | # 21 | # NOTE: You are assumed to not only compile your program with these flags, 22 | # but also link it with them as well. e.g. you should link with 23 | # $PTHREAD_CC $CFLAGS $PTHREAD_CFLAGS $LDFLAGS ... $PTHREAD_LIBS $LIBS 24 | # 25 | # If you are only building threads programs, you may wish to use these 26 | # variables in your default LIBS, CFLAGS, and CC: 27 | # 28 | # LIBS="$PTHREAD_LIBS $LIBS" 29 | # CFLAGS="$CFLAGS $PTHREAD_CFLAGS" 30 | # CC="$PTHREAD_CC" 31 | # 32 | # In addition, if the PTHREAD_CREATE_JOINABLE thread-attribute constant 33 | # has a nonstandard name, defines PTHREAD_CREATE_JOINABLE to that name 34 | # (e.g. PTHREAD_CREATE_UNDETACHED on AIX). 35 | # 36 | # ACTION-IF-FOUND is a list of shell commands to run if a threads library 37 | # is found, and ACTION-IF-NOT-FOUND is a list of commands to run it if it 38 | # is not found. If ACTION-IF-FOUND is not specified, the default action 39 | # will define HAVE_PTHREAD. 40 | # 41 | # Please let the authors know if this macro fails on any platform, or if 42 | # you have any other suggestions or comments. This macro was based on work 43 | # by SGJ on autoconf scripts for FFTW (http://www.fftw.org/) (with help 44 | # from M. Frigo), as well as ac_pthread and hb_pthread macros posted by 45 | # Alejandro Forero Cuervo to the autoconf macro repository. We are also 46 | # grateful for the helpful feedback of numerous users. 47 | # 48 | # LICENSE 49 | # 50 | # Copyright (c) 2008 Steven G. Johnson 51 | # 52 | # This program is free software: you can redistribute it and/or modify it 53 | # under the terms of the GNU General Public License as published by the 54 | # Free Software Foundation, either version 3 of the License, or (at your 55 | # option) any later version. 56 | # 57 | # This program is distributed in the hope that it will be useful, but 58 | # WITHOUT ANY WARRANTY; without even the implied warranty of 59 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General 60 | # Public License for more details. 61 | # 62 | # You should have received a copy of the GNU General Public License along 63 | # with this program. If not, see . 64 | # 65 | # As a special exception, the respective Autoconf Macro's copyright owner 66 | # gives unlimited permission to copy, distribute and modify the configure 67 | # scripts that are the output of Autoconf when processing the Macro. You 68 | # need not follow the terms of the GNU General Public License when using 69 | # or distributing such scripts, even though portions of the text of the 70 | # Macro appear in them. The GNU General Public License (GPL) does govern 71 | # all other use of the material that constitutes the Autoconf Macro. 72 | # 73 | # This special exception to the GPL applies to versions of the Autoconf 74 | # Macro released by the Autoconf Archive. When you make and distribute a 75 | # modified version of the Autoconf Macro, you may extend this special 76 | # exception to the GPL to apply to your modified version as well. 77 | 78 | AC_DEFUN([ACX_PTHREAD], [ 79 | AC_REQUIRE([AC_CANONICAL_HOST]) 80 | AC_LANG_SAVE 81 | AC_LANG_C 82 | acx_pthread_ok=no 83 | 84 | # We used to check for pthread.h first, but this fails if pthread.h 85 | # requires special compiler flags (e.g. on True64 or Sequent). 86 | # It gets checked for in the link test anyway. 87 | 88 | # First of all, check if the user has set any of the PTHREAD_LIBS, 89 | # etcetera environment variables, and if threads linking works using 90 | # them: 91 | if test x"$PTHREAD_LIBS$PTHREAD_CFLAGS" != x; then 92 | save_CFLAGS="$CFLAGS" 93 | CFLAGS="$CFLAGS $PTHREAD_CFLAGS" 94 | save_LIBS="$LIBS" 95 | LIBS="$PTHREAD_LIBS $LIBS" 96 | AC_MSG_CHECKING([for pthread_join in LIBS=$PTHREAD_LIBS with CFLAGS=$PTHREAD_CFLAGS]) 97 | AC_TRY_LINK_FUNC(pthread_join, acx_pthread_ok=yes) 98 | AC_MSG_RESULT($acx_pthread_ok) 99 | if test x"$acx_pthread_ok" = xno; then 100 | PTHREAD_LIBS="" 101 | PTHREAD_CFLAGS="" 102 | fi 103 | LIBS="$save_LIBS" 104 | CFLAGS="$save_CFLAGS" 105 | fi 106 | 107 | # We must check for the threads library under a number of different 108 | # names; the ordering is very important because some systems 109 | # (e.g. DEC) have both -lpthread and -lpthreads, where one of the 110 | # libraries is broken (non-POSIX). 111 | 112 | # Create a list of thread flags to try. Items starting with a "-" are 113 | # C compiler flags, and other items are library names, except for "none" 114 | # which indicates that we try without any flags at all, and "pthread-config" 115 | # which is a program returning the flags for the Pth emulation library. 116 | 117 | acx_pthread_flags="pthreads none -Kthread -kthread lthread -pthread -pthreads -mthreads pthread --thread-safe -mt pthread-config" 118 | 119 | # The ordering *is* (sometimes) important. Some notes on the 120 | # individual items follow: 121 | 122 | # pthreads: AIX (must check this before -lpthread) 123 | # none: in case threads are in libc; should be tried before -Kthread and 124 | # other compiler flags to prevent continual compiler warnings 125 | # -Kthread: Sequent (threads in libc, but -Kthread needed for pthread.h) 126 | # -kthread: FreeBSD kernel threads (preferred to -pthread since SMP-able) 127 | # lthread: LinuxThreads port on FreeBSD (also preferred to -pthread) 128 | # -pthread: Linux/gcc (kernel threads), BSD/gcc (userland threads) 129 | # -pthreads: Solaris/gcc 130 | # -mthreads: Mingw32/gcc, Lynx/gcc 131 | # -mt: Sun Workshop C (may only link SunOS threads [-lthread], but it 132 | # doesn't hurt to check since this sometimes defines pthreads too; 133 | # also defines -D_REENTRANT) 134 | # ... -mt is also the pthreads flag for HP/aCC 135 | # pthread: Linux, etcetera 136 | # --thread-safe: KAI C++ 137 | # pthread-config: use pthread-config program (for GNU Pth library) 138 | 139 | case "${host_cpu}-${host_os}" in 140 | *solaris*) 141 | 142 | # On Solaris (at least, for some versions), libc contains stubbed 143 | # (non-functional) versions of the pthreads routines, so link-based 144 | # tests will erroneously succeed. (We need to link with -pthreads/-mt/ 145 | # -lpthread.) (The stubs are missing pthread_cleanup_push, or rather 146 | # a function called by this macro, so we could check for that, but 147 | # who knows whether they'll stub that too in a future libc.) So, 148 | # we'll just look for -pthreads and -lpthread first: 149 | 150 | acx_pthread_flags="-pthreads pthread -mt -pthread $acx_pthread_flags" 151 | ;; 152 | esac 153 | 154 | if test x"$acx_pthread_ok" = xno; then 155 | for flag in $acx_pthread_flags; do 156 | 157 | case $flag in 158 | none) 159 | AC_MSG_CHECKING([whether pthreads work without any flags]) 160 | ;; 161 | 162 | -*) 163 | AC_MSG_CHECKING([whether pthreads work with $flag]) 164 | PTHREAD_CFLAGS="$flag" 165 | ;; 166 | 167 | pthread-config) 168 | AC_CHECK_PROG(acx_pthread_config, pthread-config, yes, no) 169 | if test x"$acx_pthread_config" = xno; then continue; fi 170 | PTHREAD_CFLAGS="`pthread-config --cflags`" 171 | PTHREAD_LIBS="`pthread-config --ldflags` `pthread-config --libs`" 172 | ;; 173 | 174 | *) 175 | AC_MSG_CHECKING([for the pthreads library -l$flag]) 176 | PTHREAD_LIBS="-l$flag" 177 | ;; 178 | esac 179 | 180 | save_LIBS="$LIBS" 181 | save_CFLAGS="$CFLAGS" 182 | LIBS="$PTHREAD_LIBS $LIBS" 183 | CFLAGS="$CFLAGS $PTHREAD_CFLAGS" 184 | 185 | # Check for various functions. We must include pthread.h, 186 | # since some functions may be macros. (On the Sequent, we 187 | # need a special flag -Kthread to make this header compile.) 188 | # We check for pthread_join because it is in -lpthread on IRIX 189 | # while pthread_create is in libc. We check for pthread_attr_init 190 | # due to DEC craziness with -lpthreads. We check for 191 | # pthread_cleanup_push because it is one of the few pthread 192 | # functions on Solaris that doesn't have a non-functional libc stub. 193 | # We try pthread_create on general principles. 194 | AC_TRY_LINK([#include ], 195 | [pthread_t th; pthread_join(th, 0); 196 | pthread_attr_init(0); pthread_cleanup_push(0, 0); 197 | pthread_create(0,0,0,0); pthread_cleanup_pop(0); ], 198 | [acx_pthread_ok=yes]) 199 | 200 | LIBS="$save_LIBS" 201 | CFLAGS="$save_CFLAGS" 202 | 203 | AC_MSG_RESULT($acx_pthread_ok) 204 | if test "x$acx_pthread_ok" = xyes; then 205 | break; 206 | fi 207 | 208 | PTHREAD_LIBS="" 209 | PTHREAD_CFLAGS="" 210 | done 211 | fi 212 | 213 | # Various other checks: 214 | if test "x$acx_pthread_ok" = xyes; then 215 | save_LIBS="$LIBS" 216 | LIBS="$PTHREAD_LIBS $LIBS" 217 | save_CFLAGS="$CFLAGS" 218 | CFLAGS="$CFLAGS $PTHREAD_CFLAGS" 219 | 220 | # Detect AIX lossage: JOINABLE attribute is called UNDETACHED. 221 | AC_MSG_CHECKING([for joinable pthread attribute]) 222 | attr_name=unknown 223 | for attr in PTHREAD_CREATE_JOINABLE PTHREAD_CREATE_UNDETACHED; do 224 | AC_TRY_LINK([#include ], [int attr=$attr; return attr;], 225 | [attr_name=$attr; break]) 226 | done 227 | AC_MSG_RESULT($attr_name) 228 | if test "$attr_name" != PTHREAD_CREATE_JOINABLE; then 229 | AC_DEFINE_UNQUOTED(PTHREAD_CREATE_JOINABLE, $attr_name, 230 | [Define to necessary symbol if this constant 231 | uses a non-standard name on your system.]) 232 | fi 233 | 234 | AC_MSG_CHECKING([if more special flags are required for pthreads]) 235 | flag=no 236 | case "${host_cpu}-${host_os}" in 237 | *-aix* | *-freebsd* | *-darwin*) flag="-D_THREAD_SAFE";; 238 | *solaris* | *-osf* | *-hpux*) flag="-D_REENTRANT";; 239 | esac 240 | AC_MSG_RESULT(${flag}) 241 | if test "x$flag" != xno; then 242 | PTHREAD_CFLAGS="$flag $PTHREAD_CFLAGS" 243 | fi 244 | 245 | LIBS="$save_LIBS" 246 | CFLAGS="$save_CFLAGS" 247 | 248 | # More AIX lossage: must compile with xlc_r or cc_r 249 | if test x"$GCC" != xyes; then 250 | AC_CHECK_PROGS(PTHREAD_CC, xlc_r cc_r, ${CC}) 251 | else 252 | PTHREAD_CC=$CC 253 | fi 254 | else 255 | PTHREAD_CC="$CC" 256 | fi 257 | 258 | AC_SUBST(PTHREAD_LIBS) 259 | AC_SUBST(PTHREAD_CFLAGS) 260 | AC_SUBST(PTHREAD_CC) 261 | 262 | # Finally, execute ACTION-IF-FOUND/ACTION-IF-NOT-FOUND: 263 | if test x"$acx_pthread_ok" = xyes; then 264 | ifelse([$1],,AC_DEFINE(HAVE_PTHREAD,1,[Define if you have POSIX threads libraries and header files.]),[$1]) 265 | : 266 | else 267 | acx_pthread_ok=no 268 | $2 269 | fi 270 | AC_LANG_RESTORE 271 | ])dnl ACX_PTHREAD 272 | -------------------------------------------------------------------------------- /m4/ax_tls.m4: -------------------------------------------------------------------------------- 1 | # =========================================================================== 2 | # https://www.gnu.org/software/autoconf-archive/ax_tls.html 3 | # =========================================================================== 4 | # 5 | # SYNOPSIS 6 | # 7 | # AX_TLS([action-if-found], [action-if-not-found]) 8 | # 9 | # DESCRIPTION 10 | # 11 | # Provides a test for the compiler support of thread local storage (TLS) 12 | # extensions. Defines TLS if it is found. Currently knows about C++11, 13 | # GCC/ICC, and MSVC. I think SunPro uses the same as GCC, and Borland 14 | # apparently supports either. 15 | # 16 | # LICENSE 17 | # 18 | # Copyright (c) 2008 Alan Woodland 19 | # Copyright (c) 2010 Diego Elio Petteno` 20 | # 21 | # This program is free software: you can redistribute it and/or modify it 22 | # under the terms of the GNU General Public License as published by the 23 | # Free Software Foundation, either version 3 of the License, or (at your 24 | # option) any later version. 25 | # 26 | # This program is distributed in the hope that it will be useful, but 27 | # WITHOUT ANY WARRANTY; without even the implied warranty of 28 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General 29 | # Public License for more details. 30 | # 31 | # You should have received a copy of the GNU General Public License along 32 | # with this program. If not, see . 33 | # 34 | # As a special exception, the respective Autoconf Macro's copyright owner 35 | # gives unlimited permission to copy, distribute and modify the configure 36 | # scripts that are the output of Autoconf when processing the Macro. You 37 | # need not follow the terms of the GNU General Public License when using 38 | # or distributing such scripts, even though portions of the text of the 39 | # Macro appear in them. The GNU General Public License (GPL) does govern 40 | # all other use of the material that constitutes the Autoconf Macro. 41 | # 42 | # This special exception to the GPL applies to versions of the Autoconf 43 | # Macro released by the Autoconf Archive. When you make and distribute a 44 | # modified version of the Autoconf Macro, you may extend this special 45 | # exception to the GPL to apply to your modified version as well. 46 | 47 | #serial 14 48 | 49 | AC_DEFUN([AX_TLS], [ 50 | AC_MSG_CHECKING([for thread local storage (TLS) class]) 51 | AC_CACHE_VAL([ac_cv_tls], 52 | [for ax_tls_keyword in thread_local _Thread_local __thread '__declspec(thread)' none; do 53 | AS_CASE([$ax_tls_keyword], 54 | [none], [ac_cv_tls=none ; break], 55 | [AC_TRY_COMPILE( 56 | [#include 57 | static void 58 | foo(void) { 59 | static ] $ax_tls_keyword [ int bar; 60 | exit(1); 61 | }], 62 | [], 63 | [ac_cv_tls=$ax_tls_keyword ; break], 64 | ac_cv_tls=none 65 | )]) 66 | done 67 | ]) 68 | AC_MSG_RESULT([$ac_cv_tls]) 69 | 70 | AS_IF([test "$ac_cv_tls" != "none"], 71 | [AC_DEFINE_UNQUOTED([TLS],[$ac_cv_tls],[If the compiler supports a TLS storage class define it to that here]) 72 | m4_ifnblank([$1],[$1])], 73 | [m4_ifnblank([$2],[$2])]) 74 | ]) 75 | -------------------------------------------------------------------------------- /m4/gettext.m4: -------------------------------------------------------------------------------- 1 | # gettext.m4 serial 60 (gettext-0.17) 2 | dnl Copyright (C) 1995-2007 Free Software Foundation, Inc. 3 | dnl This file is free software; the Free Software Foundation 4 | dnl gives unlimited permission to copy and/or distribute it, 5 | dnl with or without modifications, as long as this notice is preserved. 6 | dnl 7 | dnl This file can can be used in projects which are not available under 8 | dnl the GNU General Public License or the GNU Library General Public 9 | dnl License but which still want to provide support for the GNU gettext 10 | dnl functionality. 11 | dnl Please note that the actual code of the GNU gettext library is covered 12 | dnl by the GNU Library General Public License, and the rest of the GNU 13 | dnl gettext package package is covered by the GNU General Public License. 14 | dnl They are *not* in the public domain. 15 | 16 | dnl Authors: 17 | dnl Ulrich Drepper , 1995-2000. 18 | dnl Bruno Haible , 2000-2006. 19 | 20 | dnl Macro to add for using GNU gettext. 21 | 22 | dnl Usage: AM_GNU_GETTEXT([INTLSYMBOL], [NEEDSYMBOL], [INTLDIR]). 23 | dnl INTLSYMBOL can be one of 'external', 'no-libtool', 'use-libtool'. The 24 | dnl default (if it is not specified or empty) is 'no-libtool'. 25 | dnl INTLSYMBOL should be 'external' for packages with no intl directory, 26 | dnl and 'no-libtool' or 'use-libtool' for packages with an intl directory. 27 | dnl If INTLSYMBOL is 'use-libtool', then a libtool library 28 | dnl $(top_builddir)/intl/libintl.la will be created (shared and/or static, 29 | dnl depending on --{enable,disable}-{shared,static} and on the presence of 30 | dnl AM-DISABLE-SHARED). If INTLSYMBOL is 'no-libtool', a static library 31 | dnl $(top_builddir)/intl/libintl.a will be created. 32 | dnl If NEEDSYMBOL is specified and is 'need-ngettext', then GNU gettext 33 | dnl implementations (in libc or libintl) without the ngettext() function 34 | dnl will be ignored. If NEEDSYMBOL is specified and is 35 | dnl 'need-formatstring-macros', then GNU gettext implementations that don't 36 | dnl support the ISO C 99 formatstring macros will be ignored. 37 | dnl INTLDIR is used to find the intl libraries. If empty, 38 | dnl the value `$(top_builddir)/intl/' is used. 39 | dnl 40 | dnl The result of the configuration is one of three cases: 41 | dnl 1) GNU gettext, as included in the intl subdirectory, will be compiled 42 | dnl and used. 43 | dnl Catalog format: GNU --> install in $(datadir) 44 | dnl Catalog extension: .mo after installation, .gmo in source tree 45 | dnl 2) GNU gettext has been found in the system's C library. 46 | dnl Catalog format: GNU --> install in $(datadir) 47 | dnl Catalog extension: .mo after installation, .gmo in source tree 48 | dnl 3) No internationalization, always use English msgid. 49 | dnl Catalog format: none 50 | dnl Catalog extension: none 51 | dnl If INTLSYMBOL is 'external', only cases 2 and 3 can occur. 52 | dnl The use of .gmo is historical (it was needed to avoid overwriting the 53 | dnl GNU format catalogs when building on a platform with an X/Open gettext), 54 | dnl but we keep it in order not to force irrelevant filename changes on the 55 | dnl maintainers. 56 | dnl 57 | AC_DEFUN([AM_GNU_GETTEXT], 58 | [ 59 | dnl Argument checking. 60 | ifelse([$1], [], , [ifelse([$1], [external], , [ifelse([$1], [no-libtool], , [ifelse([$1], [use-libtool], , 61 | [errprint([ERROR: invalid first argument to AM_GNU_GETTEXT 62 | ])])])])]) 63 | ifelse([$2], [], , [ifelse([$2], [need-ngettext], , [ifelse([$2], [need-formatstring-macros], , 64 | [errprint([ERROR: invalid second argument to AM_GNU_GETTEXT 65 | ])])])]) 66 | dnl Hardcode this, because the previous ifdef just wasn't working 67 | define([gt_included_intl],[no]) 68 | define([gt_libtool_suffix_prefix], ifelse([$1], [use-libtool], [l], [])) 69 | gt_NEEDS_INIT 70 | AM_GNU_GETTEXT_NEED([$2]) 71 | 72 | AC_REQUIRE([AM_PO_SUBDIRS])dnl 73 | dnl ifelse(gt_included_intl, yes, [ 74 | dnl AC_REQUIRE([AM_INTL_SUBDIR])dnl 75 | dnl ]) 76 | 77 | dnl Prerequisites of AC_LIB_LINKFLAGS_BODY. 78 | AC_REQUIRE([AC_LIB_PREPARE_PREFIX]) 79 | AC_REQUIRE([AC_LIB_RPATH]) 80 | 81 | dnl Sometimes libintl requires libiconv, so first search for libiconv. 82 | dnl Ideally we would do this search only after the 83 | dnl if test "$USE_NLS" = "yes"; then 84 | dnl if { eval "gt_val=\$$gt_func_gnugettext_libc"; test "$gt_val" != "yes"; }; then 85 | dnl tests. But if configure.in invokes AM_ICONV after AM_GNU_GETTEXT 86 | dnl the configure script would need to contain the same shell code 87 | dnl again, outside any 'if'. There are two solutions: 88 | dnl - Invoke AM_ICONV_LINKFLAGS_BODY here, outside any 'if'. 89 | dnl - Control the expansions in more detail using AC_PROVIDE_IFELSE. 90 | dnl Since AC_PROVIDE_IFELSE is only in autoconf >= 2.52 and not 91 | dnl documented, we avoid it. 92 | ifelse(gt_included_intl, yes, , [ 93 | AC_REQUIRE([AM_ICONV_LINKFLAGS_BODY]) 94 | ]) 95 | 96 | dnl Sometimes, on MacOS X, libintl requires linking with CoreFoundation. 97 | gt_INTL_MACOSX 98 | 99 | dnl Set USE_NLS. 100 | AC_REQUIRE([AM_NLS]) 101 | 102 | ifelse(gt_included_intl, yes, [ 103 | BUILD_INCLUDED_LIBINTL=no 104 | USE_INCLUDED_LIBINTL=no 105 | ]) 106 | LIBINTL= 107 | LTLIBINTL= 108 | POSUB= 109 | 110 | dnl Add a version number to the cache macros. 111 | case " $gt_needs " in 112 | *" need-formatstring-macros "*) gt_api_version=3 ;; 113 | *" need-ngettext "*) gt_api_version=2 ;; 114 | *) gt_api_version=1 ;; 115 | esac 116 | gt_func_gnugettext_libc="gt_cv_func_gnugettext${gt_api_version}_libc" 117 | gt_func_gnugettext_libintl="gt_cv_func_gnugettext${gt_api_version}_libintl" 118 | 119 | dnl If we use NLS figure out what method 120 | if test "$USE_NLS" = "yes"; then 121 | gt_use_preinstalled_gnugettext=no 122 | ifelse(gt_included_intl, yes, [ 123 | AC_MSG_CHECKING([whether included gettext is requested]) 124 | AC_ARG_WITH(included-gettext, 125 | [ --with-included-gettext use the GNU gettext library included here], 126 | nls_cv_force_use_gnu_gettext=$withval, 127 | nls_cv_force_use_gnu_gettext=no) 128 | AC_MSG_RESULT($nls_cv_force_use_gnu_gettext) 129 | 130 | nls_cv_use_gnu_gettext="$nls_cv_force_use_gnu_gettext" 131 | if test "$nls_cv_force_use_gnu_gettext" != "yes"; then 132 | ]) 133 | dnl User does not insist on using GNU NLS library. Figure out what 134 | dnl to use. If GNU gettext is available we use this. Else we have 135 | dnl to fall back to GNU NLS library. 136 | 137 | if test $gt_api_version -ge 3; then 138 | gt_revision_test_code=' 139 | #ifndef __GNU_GETTEXT_SUPPORTED_REVISION 140 | #define __GNU_GETTEXT_SUPPORTED_REVISION(major) ((major) == 0 ? 0 : -1) 141 | #endif 142 | changequote(,)dnl 143 | typedef int array [2 * (__GNU_GETTEXT_SUPPORTED_REVISION(0) >= 1) - 1]; 144 | changequote([,])dnl 145 | ' 146 | else 147 | gt_revision_test_code= 148 | fi 149 | if test $gt_api_version -ge 2; then 150 | gt_expression_test_code=' + * ngettext ("", "", 0)' 151 | else 152 | gt_expression_test_code= 153 | fi 154 | 155 | AC_CACHE_CHECK([for GNU gettext in libc], [$gt_func_gnugettext_libc], 156 | [AC_TRY_LINK([#include 157 | $gt_revision_test_code 158 | extern int _nl_msg_cat_cntr; 159 | extern int *_nl_domain_bindings;], 160 | [bindtextdomain ("", ""); 161 | return * gettext ("")$gt_expression_test_code + _nl_msg_cat_cntr + *_nl_domain_bindings], 162 | [eval "$gt_func_gnugettext_libc=yes"], 163 | [eval "$gt_func_gnugettext_libc=no"])]) 164 | 165 | if { eval "gt_val=\$$gt_func_gnugettext_libc"; test "$gt_val" != "yes"; }; then 166 | dnl Sometimes libintl requires libiconv, so first search for libiconv. 167 | ifelse(gt_included_intl, yes, , [ 168 | AM_ICONV_LINK 169 | ]) 170 | dnl Search for libintl and define LIBINTL, LTLIBINTL and INCINTL 171 | dnl accordingly. Don't use AC_LIB_LINKFLAGS_BODY([intl],[iconv]) 172 | dnl because that would add "-liconv" to LIBINTL and LTLIBINTL 173 | dnl even if libiconv doesn't exist. 174 | AC_LIB_LINKFLAGS_BODY([intl]) 175 | AC_CACHE_CHECK([for GNU gettext in libintl], 176 | [$gt_func_gnugettext_libintl], 177 | [gt_save_CPPFLAGS="$CPPFLAGS" 178 | CPPFLAGS="$CPPFLAGS $INCINTL" 179 | gt_save_LIBS="$LIBS" 180 | LIBS="$LIBS $LIBINTL" 181 | dnl Now see whether libintl exists and does not depend on libiconv. 182 | AC_TRY_LINK([#include 183 | $gt_revision_test_code 184 | extern int _nl_msg_cat_cntr; 185 | extern 186 | #ifdef __cplusplus 187 | "C" 188 | #endif 189 | const char *_nl_expand_alias (const char *);], 190 | [bindtextdomain ("", ""); 191 | return * gettext ("")$gt_expression_test_code + _nl_msg_cat_cntr + *_nl_expand_alias ("")], 192 | [eval "$gt_func_gnugettext_libintl=yes"], 193 | [eval "$gt_func_gnugettext_libintl=no"]) 194 | dnl Now see whether libintl exists and depends on libiconv. 195 | if { eval "gt_val=\$$gt_func_gnugettext_libintl"; test "$gt_val" != yes; } && test -n "$LIBICONV"; then 196 | LIBS="$LIBS $LIBICONV" 197 | AC_TRY_LINK([#include 198 | $gt_revision_test_code 199 | extern int _nl_msg_cat_cntr; 200 | extern 201 | #ifdef __cplusplus 202 | "C" 203 | #endif 204 | const char *_nl_expand_alias (const char *);], 205 | [bindtextdomain ("", ""); 206 | return * gettext ("")$gt_expression_test_code + _nl_msg_cat_cntr + *_nl_expand_alias ("")], 207 | [LIBINTL="$LIBINTL $LIBICONV" 208 | LTLIBINTL="$LTLIBINTL $LTLIBICONV" 209 | eval "$gt_func_gnugettext_libintl=yes" 210 | ]) 211 | fi 212 | CPPFLAGS="$gt_save_CPPFLAGS" 213 | LIBS="$gt_save_LIBS"]) 214 | fi 215 | 216 | dnl If an already present or preinstalled GNU gettext() is found, 217 | dnl use it. But if this macro is used in GNU gettext, and GNU 218 | dnl gettext is already preinstalled in libintl, we update this 219 | dnl libintl. (Cf. the install rule in intl/Makefile.in.) 220 | if { eval "gt_val=\$$gt_func_gnugettext_libc"; test "$gt_val" = "yes"; } \ 221 | || { { eval "gt_val=\$$gt_func_gnugettext_libintl"; test "$gt_val" = "yes"; } \ 222 | && test "$PACKAGE" != gettext-runtime \ 223 | && test "$PACKAGE" != gettext-tools; }; then 224 | gt_use_preinstalled_gnugettext=yes 225 | else 226 | dnl Reset the values set by searching for libintl. 227 | LIBINTL= 228 | LTLIBINTL= 229 | INCINTL= 230 | fi 231 | 232 | ifelse(gt_included_intl, yes, [ 233 | if test "$gt_use_preinstalled_gnugettext" != "yes"; then 234 | dnl GNU gettext is not found in the C library. 235 | dnl Fall back on included GNU gettext library. 236 | nls_cv_use_gnu_gettext=yes 237 | fi 238 | fi 239 | 240 | if test "$nls_cv_use_gnu_gettext" = "yes"; then 241 | dnl Mark actions used to generate GNU NLS library. 242 | BUILD_INCLUDED_LIBINTL=yes 243 | USE_INCLUDED_LIBINTL=yes 244 | LIBINTL="ifelse([$3],[],\${top_builddir}/intl,[$3])/libintl.[]gt_libtool_suffix_prefix[]a $LIBICONV $LIBTHREAD" 245 | LTLIBINTL="ifelse([$3],[],\${top_builddir}/intl,[$3])/libintl.[]gt_libtool_suffix_prefix[]a $LTLIBICONV $LTLIBTHREAD" 246 | LIBS=`echo " $LIBS " | sed -e 's/ -lintl / /' -e 's/^ //' -e 's/ $//'` 247 | fi 248 | 249 | CATOBJEXT= 250 | if test "$gt_use_preinstalled_gnugettext" = "yes" \ 251 | || test "$nls_cv_use_gnu_gettext" = "yes"; then 252 | dnl Mark actions to use GNU gettext tools. 253 | CATOBJEXT=.gmo 254 | fi 255 | ]) 256 | 257 | if test -n "$INTL_MACOSX_LIBS"; then 258 | if test "$gt_use_preinstalled_gnugettext" = "yes" \ 259 | || test "$nls_cv_use_gnu_gettext" = "yes"; then 260 | dnl Some extra flags are needed during linking. 261 | LIBINTL="$LIBINTL $INTL_MACOSX_LIBS" 262 | LTLIBINTL="$LTLIBINTL $INTL_MACOSX_LIBS" 263 | fi 264 | fi 265 | 266 | if test "$gt_use_preinstalled_gnugettext" = "yes" \ 267 | || test "$nls_cv_use_gnu_gettext" = "yes"; then 268 | AC_DEFINE(ENABLE_NLS, 1, 269 | [Define to 1 if translation of program messages to the user's native language 270 | is requested.]) 271 | else 272 | USE_NLS=no 273 | fi 274 | fi 275 | 276 | AC_MSG_CHECKING([whether to use NLS]) 277 | AC_MSG_RESULT([$USE_NLS]) 278 | if test "$USE_NLS" = "yes"; then 279 | AC_MSG_CHECKING([where the gettext function comes from]) 280 | if test "$gt_use_preinstalled_gnugettext" = "yes"; then 281 | if { eval "gt_val=\$$gt_func_gnugettext_libintl"; test "$gt_val" = "yes"; }; then 282 | gt_source="external libintl" 283 | else 284 | gt_source="libc" 285 | fi 286 | else 287 | gt_source="included intl directory" 288 | fi 289 | AC_MSG_RESULT([$gt_source]) 290 | fi 291 | 292 | if test "$USE_NLS" = "yes"; then 293 | 294 | if test "$gt_use_preinstalled_gnugettext" = "yes"; then 295 | if { eval "gt_val=\$$gt_func_gnugettext_libintl"; test "$gt_val" = "yes"; }; then 296 | AC_MSG_CHECKING([how to link with libintl]) 297 | AC_MSG_RESULT([$LIBINTL]) 298 | AC_LIB_APPENDTOVAR([CPPFLAGS], [$INCINTL]) 299 | fi 300 | 301 | dnl For backward compatibility. Some packages may be using this. 302 | AC_DEFINE(HAVE_GETTEXT, 1, 303 | [Define if the GNU gettext() function is already present or preinstalled.]) 304 | AC_DEFINE(HAVE_DCGETTEXT, 1, 305 | [Define if the GNU dcgettext() function is already present or preinstalled.]) 306 | fi 307 | 308 | dnl We need to process the po/ directory. 309 | POSUB=po 310 | fi 311 | 312 | ifelse(gt_included_intl, yes, [ 313 | dnl If this is used in GNU gettext we have to set BUILD_INCLUDED_LIBINTL 314 | dnl to 'yes' because some of the testsuite requires it. 315 | if test "$PACKAGE" = gettext-runtime || test "$PACKAGE" = gettext-tools; then 316 | BUILD_INCLUDED_LIBINTL=yes 317 | fi 318 | 319 | dnl Make all variables we use known to autoconf. 320 | AC_SUBST(BUILD_INCLUDED_LIBINTL) 321 | AC_SUBST(USE_INCLUDED_LIBINTL) 322 | AC_SUBST(CATOBJEXT) 323 | 324 | dnl For backward compatibility. Some configure.ins may be using this. 325 | nls_cv_header_intl= 326 | nls_cv_header_libgt= 327 | 328 | dnl For backward compatibility. Some Makefiles may be using this. 329 | DATADIRNAME=share 330 | AC_SUBST(DATADIRNAME) 331 | 332 | dnl For backward compatibility. Some Makefiles may be using this. 333 | INSTOBJEXT=.mo 334 | AC_SUBST(INSTOBJEXT) 335 | 336 | dnl For backward compatibility. Some Makefiles may be using this. 337 | GENCAT=gencat 338 | AC_SUBST(GENCAT) 339 | 340 | dnl For backward compatibility. Some Makefiles may be using this. 341 | INTLOBJS= 342 | if test "$USE_INCLUDED_LIBINTL" = yes; then 343 | INTLOBJS="\$(GETTOBJS)" 344 | fi 345 | AC_SUBST(INTLOBJS) 346 | 347 | dnl Enable libtool support if the surrounding package wishes it. 348 | INTL_LIBTOOL_SUFFIX_PREFIX=gt_libtool_suffix_prefix 349 | AC_SUBST(INTL_LIBTOOL_SUFFIX_PREFIX) 350 | ]) 351 | 352 | dnl For backward compatibility. Some Makefiles may be using this. 353 | INTLLIBS="$LIBINTL" 354 | AC_SUBST(INTLLIBS) 355 | 356 | dnl Make all documented variables known to autoconf. 357 | AC_SUBST(LIBINTL) 358 | AC_SUBST(LTLIBINTL) 359 | AC_SUBST(POSUB) 360 | ]) 361 | 362 | 363 | dnl gt_NEEDS_INIT ensures that the gt_needs variable is initialized. 364 | m4_define([gt_NEEDS_INIT], 365 | [ 366 | m4_divert_text([DEFAULTS], [gt_needs=]) 367 | m4_define([gt_NEEDS_INIT], []) 368 | ]) 369 | 370 | 371 | dnl Usage: AM_GNU_GETTEXT_NEED([NEEDSYMBOL]) 372 | AC_DEFUN([AM_GNU_GETTEXT_NEED], 373 | [ 374 | m4_divert_text([INIT_PREPARE], [gt_needs="$gt_needs $1"]) 375 | ]) 376 | 377 | 378 | dnl Usage: AM_GNU_GETTEXT_VERSION([gettext-version]) 379 | AC_DEFUN([AM_GNU_GETTEXT_VERSION], []) 380 | -------------------------------------------------------------------------------- /m4/iconv.m4: -------------------------------------------------------------------------------- 1 | # iconv.m4 serial 11 (gettext-0.18.1) 2 | dnl Copyright (C) 2000-2002, 2007-2010 Free Software Foundation, Inc. 3 | dnl This file is free software; the Free Software Foundation 4 | dnl gives unlimited permission to copy and/or distribute it, 5 | dnl with or without modifications, as long as this notice is preserved. 6 | 7 | dnl From Bruno Haible. 8 | 9 | AC_DEFUN([AM_ICONV_LINKFLAGS_BODY], 10 | [ 11 | dnl Prerequisites of AC_LIB_LINKFLAGS_BODY. 12 | AC_REQUIRE([AC_LIB_PREPARE_PREFIX]) 13 | AC_REQUIRE([AC_LIB_RPATH]) 14 | 15 | dnl Search for libiconv and define LIBICONV, LTLIBICONV and INCICONV 16 | dnl accordingly. 17 | AC_LIB_LINKFLAGS_BODY([iconv]) 18 | ]) 19 | 20 | AC_DEFUN([AM_ICONV_LINK], 21 | [ 22 | dnl Some systems have iconv in libc, some have it in libiconv (OSF/1 and 23 | dnl those with the standalone portable GNU libiconv installed). 24 | AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles 25 | 26 | dnl Search for libiconv and define LIBICONV, LTLIBICONV and INCICONV 27 | dnl accordingly. 28 | AC_REQUIRE([AM_ICONV_LINKFLAGS_BODY]) 29 | 30 | dnl Add $INCICONV to CPPFLAGS before performing the following checks, 31 | dnl because if the user has installed libiconv and not disabled its use 32 | dnl via --without-libiconv-prefix, he wants to use it. The first 33 | dnl AC_TRY_LINK will then fail, the second AC_TRY_LINK will succeed. 34 | am_save_CPPFLAGS="$CPPFLAGS" 35 | AC_LIB_APPENDTOVAR([CPPFLAGS], [$INCICONV]) 36 | 37 | AC_CACHE_CHECK([for iconv], [am_cv_func_iconv], [ 38 | am_cv_func_iconv="no, consider installing GNU libiconv" 39 | am_cv_lib_iconv=no 40 | AC_TRY_LINK([#include 41 | #include ], 42 | [iconv_t cd = iconv_open("",""); 43 | iconv(cd,NULL,NULL,NULL,NULL); 44 | iconv_close(cd);], 45 | [am_cv_func_iconv=yes]) 46 | if test "$am_cv_func_iconv" != yes; then 47 | am_save_LIBS="$LIBS" 48 | LIBS="$LIBS $LIBICONV" 49 | AC_TRY_LINK([#include 50 | #include ], 51 | [iconv_t cd = iconv_open("",""); 52 | iconv(cd,NULL,NULL,NULL,NULL); 53 | iconv_close(cd);], 54 | [am_cv_lib_iconv=yes] 55 | [am_cv_func_iconv=yes]) 56 | LIBS="$am_save_LIBS" 57 | fi 58 | ]) 59 | if test "$am_cv_func_iconv" = yes; then 60 | AC_CACHE_CHECK([for working iconv], [am_cv_func_iconv_works], [ 61 | dnl This tests against bugs in AIX 5.1, HP-UX 11.11, Solaris 10. 62 | am_save_LIBS="$LIBS" 63 | if test $am_cv_lib_iconv = yes; then 64 | LIBS="$LIBS $LIBICONV" 65 | fi 66 | AC_TRY_RUN([ 67 | #include 68 | #include 69 | int main () 70 | { 71 | /* Test against AIX 5.1 bug: Failures are not distinguishable from successful 72 | returns. */ 73 | { 74 | iconv_t cd_utf8_to_88591 = iconv_open ("ISO8859-1", "UTF-8"); 75 | if (cd_utf8_to_88591 != (iconv_t)(-1)) 76 | { 77 | static const char input[] = "\342\202\254"; /* EURO SIGN */ 78 | char buf[10]; 79 | const char *inptr = input; 80 | size_t inbytesleft = strlen (input); 81 | char *outptr = buf; 82 | size_t outbytesleft = sizeof (buf); 83 | size_t res = iconv (cd_utf8_to_88591, 84 | (char **) &inptr, &inbytesleft, 85 | &outptr, &outbytesleft); 86 | if (res == 0) 87 | return 1; 88 | } 89 | } 90 | /* Test against Solaris 10 bug: Failures are not distinguishable from 91 | successful returns. */ 92 | { 93 | iconv_t cd_ascii_to_88591 = iconv_open ("ISO8859-1", "646"); 94 | if (cd_ascii_to_88591 != (iconv_t)(-1)) 95 | { 96 | static const char input[] = "\263"; 97 | char buf[10]; 98 | const char *inptr = input; 99 | size_t inbytesleft = strlen (input); 100 | char *outptr = buf; 101 | size_t outbytesleft = sizeof (buf); 102 | size_t res = iconv (cd_ascii_to_88591, 103 | (char **) &inptr, &inbytesleft, 104 | &outptr, &outbytesleft); 105 | if (res == 0) 106 | return 1; 107 | } 108 | } 109 | #if 0 /* This bug could be worked around by the caller. */ 110 | /* Test against HP-UX 11.11 bug: Positive return value instead of 0. */ 111 | { 112 | iconv_t cd_88591_to_utf8 = iconv_open ("utf8", "iso88591"); 113 | if (cd_88591_to_utf8 != (iconv_t)(-1)) 114 | { 115 | static const char input[] = "\304rger mit b\366sen B\374bchen ohne Augenma\337"; 116 | char buf[50]; 117 | const char *inptr = input; 118 | size_t inbytesleft = strlen (input); 119 | char *outptr = buf; 120 | size_t outbytesleft = sizeof (buf); 121 | size_t res = iconv (cd_88591_to_utf8, 122 | (char **) &inptr, &inbytesleft, 123 | &outptr, &outbytesleft); 124 | if ((int)res > 0) 125 | return 1; 126 | } 127 | } 128 | #endif 129 | /* Test against HP-UX 11.11 bug: No converter from EUC-JP to UTF-8 is 130 | provided. */ 131 | if (/* Try standardized names. */ 132 | iconv_open ("UTF-8", "EUC-JP") == (iconv_t)(-1) 133 | /* Try IRIX, OSF/1 names. */ 134 | && iconv_open ("UTF-8", "eucJP") == (iconv_t)(-1) 135 | /* Try AIX names. */ 136 | && iconv_open ("UTF-8", "IBM-eucJP") == (iconv_t)(-1) 137 | /* Try HP-UX names. */ 138 | && iconv_open ("utf8", "eucJP") == (iconv_t)(-1)) 139 | return 1; 140 | return 0; 141 | }], [am_cv_func_iconv_works=yes], [am_cv_func_iconv_works=no], 142 | [case "$host_os" in 143 | aix* | hpux*) am_cv_func_iconv_works="guessing no" ;; 144 | *) am_cv_func_iconv_works="guessing yes" ;; 145 | esac]) 146 | LIBS="$am_save_LIBS" 147 | ]) 148 | case "$am_cv_func_iconv_works" in 149 | *no) am_func_iconv=no am_cv_lib_iconv=no ;; 150 | *) am_func_iconv=yes ;; 151 | esac 152 | else 153 | am_func_iconv=no am_cv_lib_iconv=no 154 | fi 155 | if test "$am_func_iconv" = yes; then 156 | AC_DEFINE([HAVE_ICONV], [1], 157 | [Define if you have the iconv() function and it works.]) 158 | fi 159 | if test "$am_cv_lib_iconv" = yes; then 160 | AC_MSG_CHECKING([how to link with libiconv]) 161 | AC_MSG_RESULT([$LIBICONV]) 162 | else 163 | dnl If $LIBICONV didn't lead to a usable library, we don't need $INCICONV 164 | dnl either. 165 | CPPFLAGS="$am_save_CPPFLAGS" 166 | LIBICONV= 167 | LTLIBICONV= 168 | fi 169 | AC_SUBST([LIBICONV]) 170 | AC_SUBST([LTLIBICONV]) 171 | ]) 172 | 173 | dnl Define AM_ICONV using AC_DEFUN_ONCE for Autoconf >= 2.64, in order to 174 | dnl avoid warnings like 175 | dnl "warning: AC_REQUIRE: `AM_ICONV' was expanded before it was required". 176 | dnl This is tricky because of the way 'aclocal' is implemented: 177 | dnl - It requires defining an auxiliary macro whose name ends in AC_DEFUN. 178 | dnl Otherwise aclocal's initial scan pass would miss the macro definition. 179 | dnl - It requires a line break inside the AC_DEFUN_ONCE and AC_DEFUN expansions. 180 | dnl Otherwise aclocal would emit many "Use of uninitialized value $1" 181 | dnl warnings. 182 | m4_define([gl_iconv_AC_DEFUN], 183 | m4_version_prereq([2.64], 184 | [[AC_DEFUN_ONCE( 185 | [$1], [$2])]], 186 | [[AC_DEFUN( 187 | [$1], [$2])]])) 188 | gl_iconv_AC_DEFUN([AM_ICONV], 189 | [ 190 | AM_ICONV_LINK 191 | if test "$am_cv_func_iconv" = yes; then 192 | AC_MSG_CHECKING([for iconv declaration]) 193 | AC_CACHE_VAL([am_cv_proto_iconv], [ 194 | AC_TRY_COMPILE([ 195 | #include 196 | #include 197 | extern 198 | #ifdef __cplusplus 199 | "C" 200 | #endif 201 | #if defined(__STDC__) || defined(__cplusplus) 202 | size_t iconv (iconv_t cd, char * *inbuf, size_t *inbytesleft, char * *outbuf, size_t *outbytesleft); 203 | #else 204 | size_t iconv(); 205 | #endif 206 | ], [], [am_cv_proto_iconv_arg1=""], [am_cv_proto_iconv_arg1="const"]) 207 | am_cv_proto_iconv="extern size_t iconv (iconv_t cd, $am_cv_proto_iconv_arg1 char * *inbuf, size_t *inbytesleft, char * *outbuf, size_t *outbytesleft);"]) 208 | am_cv_proto_iconv=`echo "[$]am_cv_proto_iconv" | tr -s ' ' | sed -e 's/( /(/'` 209 | AC_MSG_RESULT([ 210 | $am_cv_proto_iconv]) 211 | AC_DEFINE_UNQUOTED([ICONV_CONST], [$am_cv_proto_iconv_arg1], 212 | [Define as const if the declaration of iconv() needs const.]) 213 | fi 214 | ]) 215 | -------------------------------------------------------------------------------- /m4/lib-ld.m4: -------------------------------------------------------------------------------- 1 | # lib-ld.m4 serial 3 (gettext-0.13) 2 | dnl Copyright (C) 1996-2003 Free Software Foundation, Inc. 3 | dnl This file is free software; the Free Software Foundation 4 | dnl gives unlimited permission to copy and/or distribute it, 5 | dnl with or without modifications, as long as this notice is preserved. 6 | 7 | dnl Subroutines of libtool.m4, 8 | dnl with replacements s/AC_/AC_LIB/ and s/lt_cv/acl_cv/ to avoid collision 9 | dnl with libtool.m4. 10 | 11 | dnl From libtool-1.4. Sets the variable with_gnu_ld to yes or no. 12 | AC_DEFUN([AC_LIB_PROG_LD_GNU], 13 | [AC_CACHE_CHECK([if the linker ($LD) is GNU ld], acl_cv_prog_gnu_ld, 14 | [# I'd rather use --version here, but apparently some GNU ld's only accept -v. 15 | case `$LD -v 2>&1 conf$$.sh 35 | echo "exit 0" >>conf$$.sh 36 | chmod +x conf$$.sh 37 | if (PATH="/nonexistent;."; conf$$.sh) >/dev/null 2>&1; then 38 | PATH_SEPARATOR=';' 39 | else 40 | PATH_SEPARATOR=: 41 | fi 42 | rm -f conf$$.sh 43 | fi 44 | ac_prog=ld 45 | if test "$GCC" = yes; then 46 | # Check if gcc -print-prog-name=ld gives a path. 47 | AC_MSG_CHECKING([for ld used by GCC]) 48 | case $host in 49 | *-*-mingw*) 50 | # gcc leaves a trailing carriage return which upsets mingw 51 | ac_prog=`($CC -print-prog-name=ld) 2>&5 | tr -d '\015'` ;; 52 | *) 53 | ac_prog=`($CC -print-prog-name=ld) 2>&5` ;; 54 | esac 55 | case $ac_prog in 56 | # Accept absolute paths. 57 | [[\\/]* | [A-Za-z]:[\\/]*)] 58 | [re_direlt='/[^/][^/]*/\.\./'] 59 | # Canonicalize the path of ld 60 | ac_prog=`echo $ac_prog| sed 's%\\\\%/%g'` 61 | while echo $ac_prog | grep "$re_direlt" > /dev/null 2>&1; do 62 | ac_prog=`echo $ac_prog| sed "s%$re_direlt%/%"` 63 | done 64 | test -z "$LD" && LD="$ac_prog" 65 | ;; 66 | "") 67 | # If it fails, then pretend we aren't using GCC. 68 | ac_prog=ld 69 | ;; 70 | *) 71 | # If it is relative, then search for the first ld in PATH. 72 | with_gnu_ld=unknown 73 | ;; 74 | esac 75 | elif test "$with_gnu_ld" = yes; then 76 | AC_MSG_CHECKING([for GNU ld]) 77 | else 78 | AC_MSG_CHECKING([for non-GNU ld]) 79 | fi 80 | AC_CACHE_VAL(acl_cv_path_LD, 81 | [if test -z "$LD"; then 82 | IFS="${IFS= }"; ac_save_ifs="$IFS"; IFS="${IFS}${PATH_SEPARATOR-:}" 83 | for ac_dir in $PATH; do 84 | test -z "$ac_dir" && ac_dir=. 85 | if test -f "$ac_dir/$ac_prog" || test -f "$ac_dir/$ac_prog$ac_exeext"; then 86 | acl_cv_path_LD="$ac_dir/$ac_prog" 87 | # Check to see if the program is GNU ld. I'd rather use --version, 88 | # but apparently some GNU ld's only accept -v. 89 | # Break only if it was the GNU/non-GNU ld that we prefer. 90 | case `"$acl_cv_path_LD" -v 2>&1 < /dev/null` in 91 | *GNU* | *'with BFD'*) 92 | test "$with_gnu_ld" != no && break ;; 93 | *) 94 | test "$with_gnu_ld" != yes && break ;; 95 | esac 96 | fi 97 | done 98 | IFS="$ac_save_ifs" 99 | else 100 | acl_cv_path_LD="$LD" # Let the user override the test with a path. 101 | fi]) 102 | LD="$acl_cv_path_LD" 103 | if test -n "$LD"; then 104 | AC_MSG_RESULT($LD) 105 | else 106 | AC_MSG_RESULT(no) 107 | fi 108 | test -z "$LD" && AC_MSG_ERROR([no acceptable ld found in \$PATH]) 109 | AC_LIB_PROG_LD_GNU 110 | ]) 111 | -------------------------------------------------------------------------------- /m4/lib-link.m4: -------------------------------------------------------------------------------- 1 | # lib-link.m4 serial 18 (gettext-0.18) 2 | dnl Copyright (C) 2001-2009 Free Software Foundation, Inc. 3 | dnl This file is free software; the Free Software Foundation 4 | dnl gives unlimited permission to copy and/or distribute it, 5 | dnl with or without modifications, as long as this notice is preserved. 6 | 7 | dnl From Bruno Haible. 8 | 9 | AC_PREREQ([2.54]) 10 | 11 | dnl AC_LIB_LINKFLAGS(name [, dependencies]) searches for libname and 12 | dnl the libraries corresponding to explicit and implicit dependencies. 13 | dnl Sets and AC_SUBSTs the LIB${NAME} and LTLIB${NAME} variables and 14 | dnl augments the CPPFLAGS variable. 15 | dnl Sets and AC_SUBSTs the LIB${NAME}_PREFIX variable to nonempty if libname 16 | dnl was found in ${LIB${NAME}_PREFIX}/$acl_libdirstem. 17 | AC_DEFUN([AC_LIB_LINKFLAGS], 18 | [ 19 | AC_REQUIRE([AC_LIB_PREPARE_PREFIX]) 20 | AC_REQUIRE([AC_LIB_RPATH]) 21 | pushdef([Name],[translit([$1],[./-], [___])]) 22 | pushdef([NAME],[translit([$1],[abcdefghijklmnopqrstuvwxyz./-], 23 | [ABCDEFGHIJKLMNOPQRSTUVWXYZ___])]) 24 | AC_CACHE_CHECK([how to link with lib[]$1], [ac_cv_lib[]Name[]_libs], [ 25 | AC_LIB_LINKFLAGS_BODY([$1], [$2]) 26 | ac_cv_lib[]Name[]_libs="$LIB[]NAME" 27 | ac_cv_lib[]Name[]_ltlibs="$LTLIB[]NAME" 28 | ac_cv_lib[]Name[]_cppflags="$INC[]NAME" 29 | ac_cv_lib[]Name[]_prefix="$LIB[]NAME[]_PREFIX" 30 | ]) 31 | LIB[]NAME="$ac_cv_lib[]Name[]_libs" 32 | LTLIB[]NAME="$ac_cv_lib[]Name[]_ltlibs" 33 | INC[]NAME="$ac_cv_lib[]Name[]_cppflags" 34 | LIB[]NAME[]_PREFIX="$ac_cv_lib[]Name[]_prefix" 35 | AC_LIB_APPENDTOVAR([CPPFLAGS], [$INC]NAME) 36 | AC_SUBST([LIB]NAME) 37 | AC_SUBST([LTLIB]NAME) 38 | AC_SUBST([LIB]NAME[_PREFIX]) 39 | dnl Also set HAVE_LIB[]NAME so that AC_LIB_HAVE_LINKFLAGS can reuse the 40 | dnl results of this search when this library appears as a dependency. 41 | HAVE_LIB[]NAME=yes 42 | popdef([NAME]) 43 | popdef([Name]) 44 | ]) 45 | 46 | dnl AC_LIB_HAVE_LINKFLAGS(name, dependencies, includes, testcode, [system]) 47 | dnl searches for libname and the libraries corresponding to explicit and 48 | dnl implicit dependencies, together with the specified include files and 49 | dnl the ability to compile and link the specified testcode. If found, it 50 | dnl sets and AC_SUBSTs HAVE_LIB${NAME}=yes and the LIB${NAME} and 51 | dnl LTLIB${NAME} variables and augments the CPPFLAGS variable, and 52 | dnl #defines HAVE_LIB${NAME} to 1. Otherwise, it sets and AC_SUBSTs 53 | dnl HAVE_LIB${NAME}=no and LIB${NAME} and LTLIB${NAME} to empty. 54 | dnl Sets and AC_SUBSTs the LIB${NAME}_PREFIX variable to nonempty if libname 55 | dnl was found in ${LIB${NAME}_PREFIX}/$acl_libdirstem. 56 | AC_DEFUN([AC_LIB_HAVE_LINKFLAGS], 57 | [ 58 | AC_REQUIRE([AC_LIB_PREPARE_PREFIX]) 59 | AC_REQUIRE([AC_LIB_RPATH]) 60 | pushdef([Name],[translit([$1],[./-], [___])]) 61 | pushdef([NAME],[translit([$1],[abcdefghijklmnopqrstuvwxyz./-], 62 | [ABCDEFGHIJKLMNOPQRSTUVWXYZ___])]) 63 | 64 | dnl Search for lib[]Name and define LIB[]NAME, LTLIB[]NAME and INC[]NAME 65 | dnl accordingly. 66 | AC_LIB_LINKFLAGS_BODY([$1], [$2], [$5]) 67 | 68 | dnl Add $INC[]NAME to CPPFLAGS before performing the following checks, 69 | dnl because if the user has installed lib[]Name and not disabled its use 70 | dnl via --without-lib[]Name-prefix, he wants to use it. 71 | ac_save_CPPFLAGS="$CPPFLAGS" 72 | AC_LIB_APPENDTOVAR([CPPFLAGS], [$INC]NAME) 73 | 74 | AC_CACHE_CHECK([for lib[]$1], [ac_cv_lib[]Name], [ 75 | ac_save_LIBS="$LIBS" 76 | LIBS="$LIBS $LIB[]NAME" 77 | AC_TRY_LINK([$3], [$4], [ac_cv_lib[]Name=yes], [ac_cv_lib[]Name=no]) 78 | LIBS="$ac_save_LIBS" 79 | ]) 80 | if test "$ac_cv_lib[]Name" = yes; then 81 | HAVE_LIB[]NAME=yes 82 | AC_DEFINE([HAVE_LIB]NAME, 1, [Define if you have the $1 library.]) 83 | AC_MSG_CHECKING([how to link with lib[]$1]) 84 | AC_MSG_RESULT([$LIB[]NAME]) 85 | else 86 | HAVE_LIB[]NAME=no 87 | dnl If $LIB[]NAME didn't lead to a usable library, we don't need 88 | dnl $INC[]NAME either. 89 | CPPFLAGS="$ac_save_CPPFLAGS" 90 | LIB[]NAME= 91 | LTLIB[]NAME= 92 | LIB[]NAME[]_PREFIX= 93 | fi 94 | AC_SUBST([HAVE_LIB]NAME) 95 | AC_SUBST([LIB]NAME) 96 | AC_SUBST([LTLIB]NAME) 97 | AC_SUBST([LIB]NAME[_PREFIX]) 98 | popdef([NAME]) 99 | popdef([Name]) 100 | ]) 101 | 102 | dnl Determine the platform dependent parameters needed to use rpath: 103 | dnl acl_libext, 104 | dnl acl_shlibext, 105 | dnl acl_hardcode_libdir_flag_spec, 106 | dnl acl_hardcode_libdir_separator, 107 | dnl acl_hardcode_direct, 108 | dnl acl_hardcode_minus_L. 109 | AC_DEFUN([AC_LIB_RPATH], 110 | [ 111 | dnl Tell automake >= 1.10 to complain if config.rpath is missing. 112 | m4_ifdef([AC_REQUIRE_AUX_FILE], [AC_REQUIRE_AUX_FILE([config.rpath])]) 113 | AC_REQUIRE([AC_PROG_CC]) dnl we use $CC, $GCC, $LDFLAGS 114 | AC_REQUIRE([AC_LIB_PROG_LD]) dnl we use $LD, $with_gnu_ld 115 | AC_REQUIRE([AC_CANONICAL_HOST]) dnl we use $host 116 | AC_REQUIRE([AC_CONFIG_AUX_DIR_DEFAULT]) dnl we use $ac_aux_dir 117 | AC_CACHE_CHECK([for shared library run path origin], [acl_cv_rpath], [ 118 | CC="$CC" GCC="$GCC" LDFLAGS="$LDFLAGS" LD="$LD" with_gnu_ld="$with_gnu_ld" \ 119 | ${CONFIG_SHELL-/bin/sh} "$ac_aux_dir/config.rpath" "$host" > conftest.sh 120 | . ./conftest.sh 121 | rm -f ./conftest.sh 122 | acl_cv_rpath=done 123 | ]) 124 | wl="$acl_cv_wl" 125 | acl_libext="$acl_cv_libext" 126 | acl_shlibext="$acl_cv_shlibext" 127 | acl_libname_spec="$acl_cv_libname_spec" 128 | acl_library_names_spec="$acl_cv_library_names_spec" 129 | acl_hardcode_libdir_flag_spec="$acl_cv_hardcode_libdir_flag_spec" 130 | acl_hardcode_libdir_separator="$acl_cv_hardcode_libdir_separator" 131 | acl_hardcode_direct="$acl_cv_hardcode_direct" 132 | acl_hardcode_minus_L="$acl_cv_hardcode_minus_L" 133 | dnl Determine whether the user wants rpath handling at all. 134 | AC_ARG_ENABLE([rpath], 135 | [ --disable-rpath do not hardcode runtime library paths], 136 | :, enable_rpath=yes) 137 | ]) 138 | 139 | dnl AC_LIB_FROMPACKAGE(name, package) 140 | dnl declares that libname comes from the given package. The configure file 141 | dnl will then not have a --with-libname-prefix option but a 142 | dnl --with-package-prefix option. Several libraries can come from the same 143 | dnl package. This declaration must occur before an AC_LIB_LINKFLAGS or similar 144 | dnl macro call that searches for libname. 145 | AC_DEFUN([AC_LIB_FROMPACKAGE], 146 | [ 147 | pushdef([NAME],[translit([$1],[abcdefghijklmnopqrstuvwxyz./-], 148 | [ABCDEFGHIJKLMNOPQRSTUVWXYZ___])]) 149 | define([acl_frompackage_]NAME, [$2]) 150 | popdef([NAME]) 151 | pushdef([PACK],[$2]) 152 | pushdef([PACKUP],[translit(PACK,[abcdefghijklmnopqrstuvwxyz./-], 153 | [ABCDEFGHIJKLMNOPQRSTUVWXYZ___])]) 154 | define([acl_libsinpackage_]PACKUP, 155 | m4_ifdef([acl_libsinpackage_]PACKUP, [acl_libsinpackage_]PACKUP[[, ]],)[lib$1]) 156 | popdef([PACKUP]) 157 | popdef([PACK]) 158 | ]) 159 | 160 | dnl AC_LIB_LINKFLAGS_BODY(name [, dependencies, system]) searches for 161 | dnl libname and the libraries corresponding to explicit and implicit 162 | dnl dependencies. 163 | dnl Sets the LIB${NAME}, LTLIB${NAME} and INC${NAME} variables. 164 | dnl Also, sets the LIB${NAME}_PREFIX variable to nonempty if libname was found 165 | dnl in ${LIB${NAME}_PREFIX}/$acl_libdirstem. 166 | dnl If system==system, -isystem is used instead of -I 167 | AC_DEFUN([AC_LIB_LINKFLAGS_BODY], 168 | [ 169 | AC_REQUIRE([AC_LIB_PREPARE_MULTILIB]) 170 | pushdef([NAME],[translit([$1],[abcdefghijklmnopqrstuvwxyz./-], 171 | [ABCDEFGHIJKLMNOPQRSTUVWXYZ___])]) 172 | pushdef([PACK],[m4_ifdef([acl_frompackage_]NAME, [acl_frompackage_]NAME, lib[$1])]) 173 | pushdef([PACKUP],[translit(PACK,[abcdefghijklmnopqrstuvwxyz./-], 174 | [ABCDEFGHIJKLMNOPQRSTUVWXYZ___])]) 175 | pushdef([PACKLIBS],[m4_ifdef([acl_frompackage_]NAME, [acl_libsinpackage_]PACKUP, lib[$1])]) 176 | dnl Autoconf >= 2.61 supports dots in --with options. 177 | pushdef([P_A_C_K],[m4_if(m4_version_compare(m4_defn([m4_PACKAGE_VERSION]),[2.61]),[-1],[translit(PACK,[.],[_])],PACK)]) 178 | dnl By default, look in $includedir and $libdir. 179 | use_additional=yes 180 | if test "x$GCC" = "xyes" -a "x$3" = "xsystem" 181 | then 182 | i_system="-isystem " 183 | else 184 | i_system="-I" 185 | fi 186 | 187 | AC_LIB_WITH_FINAL_PREFIX([ 188 | eval additional_includedir=\"$includedir\" 189 | eval additional_libdir=\"$libdir\" 190 | ]) 191 | AC_ARG_WITH(P_A_C_K[-prefix], 192 | [[ --with-]]P_A_C_K[[-prefix[=DIR] search for ]PACKLIBS[ in DIR/include and DIR/lib 193 | --without-]]P_A_C_K[[-prefix don't search for ]PACKLIBS[ in includedir and libdir]], 194 | [ 195 | if test "X$withval" = "Xno"; then 196 | use_additional=no 197 | else 198 | if test "X$withval" = "X"; then 199 | AC_LIB_WITH_FINAL_PREFIX([ 200 | eval additional_includedir=\"$includedir\" 201 | eval additional_libdir=\"$libdir\" 202 | ]) 203 | else 204 | additional_includedir="$withval/include" 205 | additional_libdir="$withval/$acl_libdirstem" 206 | if test "$acl_libdirstem2" != "$acl_libdirstem" \ 207 | && ! test -d "$withval/$acl_libdirstem"; then 208 | additional_libdir="$withval/$acl_libdirstem2" 209 | fi 210 | fi 211 | fi 212 | ]) 213 | dnl Search the library and its dependencies in $additional_libdir and 214 | dnl $LDFLAGS. Using breadth-first-seach. 215 | LIB[]NAME= 216 | LTLIB[]NAME= 217 | INC[]NAME= 218 | LIB[]NAME[]_PREFIX= 219 | rpathdirs= 220 | ltrpathdirs= 221 | names_already_handled= 222 | names_next_round='$1 $2' 223 | while test -n "$names_next_round"; do 224 | names_this_round="$names_next_round" 225 | names_next_round= 226 | for name in $names_this_round; do 227 | already_handled= 228 | for n in $names_already_handled; do 229 | if test "$n" = "$name"; then 230 | already_handled=yes 231 | break 232 | fi 233 | done 234 | if test -z "$already_handled"; then 235 | names_already_handled="$names_already_handled $name" 236 | dnl See if it was already located by an earlier AC_LIB_LINKFLAGS 237 | dnl or AC_LIB_HAVE_LINKFLAGS call. 238 | uppername=`echo "$name" | sed -e 'y|abcdefghijklmnopqrstuvwxyz./-|ABCDEFGHIJKLMNOPQRSTUVWXYZ___|'` 239 | eval value=\"\$HAVE_LIB$uppername\" 240 | if test -n "$value"; then 241 | if test "$value" = yes; then 242 | eval value=\"\$LIB$uppername\" 243 | test -z "$value" || LIB[]NAME="${LIB[]NAME}${LIB[]NAME:+ }$value" 244 | eval value=\"\$LTLIB$uppername\" 245 | test -z "$value" || LTLIB[]NAME="${LTLIB[]NAME}${LTLIB[]NAME:+ }$value" 246 | else 247 | dnl An earlier call to AC_LIB_HAVE_LINKFLAGS has determined 248 | dnl that this library doesn't exist. So just drop it. 249 | : 250 | fi 251 | else 252 | dnl Search the library lib$name in $additional_libdir and $LDFLAGS 253 | dnl and the already constructed $LIBNAME/$LTLIBNAME. 254 | found_dir= 255 | found_la= 256 | found_so= 257 | found_a= 258 | eval libname=\"$acl_libname_spec\" # typically: libname=lib$name 259 | if test -n "$acl_shlibext"; then 260 | shrext=".$acl_shlibext" # typically: shrext=.so 261 | else 262 | shrext= 263 | fi 264 | if test $use_additional = yes; then 265 | dir="$additional_libdir" 266 | dnl The same code as in the loop below: 267 | dnl First look for a shared library. 268 | if test -n "$acl_shlibext"; then 269 | if test -f "$dir/$libname$shrext"; then 270 | found_dir="$dir" 271 | found_so="$dir/$libname$shrext" 272 | else 273 | if test "$acl_library_names_spec" = '$libname$shrext$versuffix'; then 274 | ver=`(cd "$dir" && \ 275 | for f in "$libname$shrext".*; do echo "$f"; done \ 276 | | sed -e "s,^$libname$shrext\\\\.,," \ 277 | | sort -t '.' -n -r -k1,1 -k2,2 -k3,3 -k4,4 -k5,5 \ 278 | | sed 1q ) 2>/dev/null` 279 | if test -n "$ver" && test -f "$dir/$libname$shrext.$ver"; then 280 | found_dir="$dir" 281 | found_so="$dir/$libname$shrext.$ver" 282 | fi 283 | else 284 | eval library_names=\"$acl_library_names_spec\" 285 | for f in $library_names; do 286 | if test -f "$dir/$f"; then 287 | found_dir="$dir" 288 | found_so="$dir/$f" 289 | break 290 | fi 291 | done 292 | fi 293 | fi 294 | fi 295 | dnl Then look for a static library. 296 | if test "X$found_dir" = "X"; then 297 | if test -f "$dir/$libname.$acl_libext"; then 298 | found_dir="$dir" 299 | found_a="$dir/$libname.$acl_libext" 300 | fi 301 | fi 302 | if test "X$found_dir" != "X"; then 303 | if test -f "$dir/$libname.la"; then 304 | found_la="$dir/$libname.la" 305 | fi 306 | fi 307 | fi 308 | if test "X$found_dir" = "X"; then 309 | for x in $LDFLAGS $LTLIB[]NAME; do 310 | AC_LIB_WITH_FINAL_PREFIX([eval x=\"$x\"]) 311 | case "$x" in 312 | -L*) 313 | dir=`echo "X$x" | sed -e 's/^X-L//'` 314 | dnl First look for a shared library. 315 | if test -n "$acl_shlibext"; then 316 | if test -f "$dir/$libname$shrext"; then 317 | found_dir="$dir" 318 | found_so="$dir/$libname$shrext" 319 | else 320 | if test "$acl_library_names_spec" = '$libname$shrext$versuffix'; then 321 | ver=`(cd "$dir" && \ 322 | for f in "$libname$shrext".*; do echo "$f"; done \ 323 | | sed -e "s,^$libname$shrext\\\\.,," \ 324 | | sort -t '.' -n -r -k1,1 -k2,2 -k3,3 -k4,4 -k5,5 \ 325 | | sed 1q ) 2>/dev/null` 326 | if test -n "$ver" && test -f "$dir/$libname$shrext.$ver"; then 327 | found_dir="$dir" 328 | found_so="$dir/$libname$shrext.$ver" 329 | fi 330 | else 331 | eval library_names=\"$acl_library_names_spec\" 332 | for f in $library_names; do 333 | if test -f "$dir/$f"; then 334 | found_dir="$dir" 335 | found_so="$dir/$f" 336 | break 337 | fi 338 | done 339 | fi 340 | fi 341 | fi 342 | dnl Then look for a static library. 343 | if test "X$found_dir" = "X"; then 344 | if test -f "$dir/$libname.$acl_libext"; then 345 | found_dir="$dir" 346 | found_a="$dir/$libname.$acl_libext" 347 | fi 348 | fi 349 | if test "X$found_dir" != "X"; then 350 | if test -f "$dir/$libname.la"; then 351 | found_la="$dir/$libname.la" 352 | fi 353 | fi 354 | ;; 355 | esac 356 | if test "X$found_dir" != "X"; then 357 | break 358 | fi 359 | done 360 | fi 361 | if test "X$found_dir" != "X"; then 362 | dnl Found the library. 363 | LTLIB[]NAME="${LTLIB[]NAME}${LTLIB[]NAME:+ }-L$found_dir -l$name" 364 | if test "X$found_so" != "X"; then 365 | dnl Linking with a shared library. We attempt to hardcode its 366 | dnl directory into the executable's runpath, unless it's the 367 | dnl standard /usr/lib. 368 | if test "$enable_rpath" = no \ 369 | || test "X$found_dir" = "X/usr/$acl_libdirstem" \ 370 | || test "X$found_dir" = "X/usr/$acl_libdirstem2"; then 371 | dnl No hardcoding is needed. 372 | LIB[]NAME="${LIB[]NAME}${LIB[]NAME:+ }$found_so" 373 | else 374 | dnl Use an explicit option to hardcode DIR into the resulting 375 | dnl binary. 376 | dnl Potentially add DIR to ltrpathdirs. 377 | dnl The ltrpathdirs will be appended to $LTLIBNAME at the end. 378 | haveit= 379 | for x in $ltrpathdirs; do 380 | if test "X$x" = "X$found_dir"; then 381 | haveit=yes 382 | break 383 | fi 384 | done 385 | if test -z "$haveit"; then 386 | ltrpathdirs="$ltrpathdirs $found_dir" 387 | fi 388 | dnl The hardcoding into $LIBNAME is system dependent. 389 | if test "$acl_hardcode_direct" = yes; then 390 | dnl Using DIR/libNAME.so during linking hardcodes DIR into the 391 | dnl resulting binary. 392 | LIB[]NAME="${LIB[]NAME}${LIB[]NAME:+ }$found_so" 393 | else 394 | if test -n "$acl_hardcode_libdir_flag_spec" && test "$acl_hardcode_minus_L" = no; then 395 | dnl Use an explicit option to hardcode DIR into the resulting 396 | dnl binary. 397 | LIB[]NAME="${LIB[]NAME}${LIB[]NAME:+ }$found_so" 398 | dnl Potentially add DIR to rpathdirs. 399 | dnl The rpathdirs will be appended to $LIBNAME at the end. 400 | haveit= 401 | for x in $rpathdirs; do 402 | if test "X$x" = "X$found_dir"; then 403 | haveit=yes 404 | break 405 | fi 406 | done 407 | if test -z "$haveit"; then 408 | rpathdirs="$rpathdirs $found_dir" 409 | fi 410 | else 411 | dnl Rely on "-L$found_dir". 412 | dnl But don't add it if it's already contained in the LDFLAGS 413 | dnl or the already constructed $LIBNAME 414 | haveit= 415 | for x in $LDFLAGS $LIB[]NAME; do 416 | AC_LIB_WITH_FINAL_PREFIX([eval x=\"$x\"]) 417 | if test "X$x" = "X-L$found_dir"; then 418 | haveit=yes 419 | break 420 | fi 421 | done 422 | if test -z "$haveit"; then 423 | LIB[]NAME="${LIB[]NAME}${LIB[]NAME:+ }-L$found_dir" 424 | fi 425 | if test "$acl_hardcode_minus_L" != no; then 426 | dnl FIXME: Not sure whether we should use 427 | dnl "-L$found_dir -l$name" or "-L$found_dir $found_so" 428 | dnl here. 429 | LIB[]NAME="${LIB[]NAME}${LIB[]NAME:+ }$found_so" 430 | else 431 | dnl We cannot use $acl_hardcode_runpath_var and LD_RUN_PATH 432 | dnl here, because this doesn't fit in flags passed to the 433 | dnl compiler. So give up. No hardcoding. This affects only 434 | dnl very old systems. 435 | dnl FIXME: Not sure whether we should use 436 | dnl "-L$found_dir -l$name" or "-L$found_dir $found_so" 437 | dnl here. 438 | LIB[]NAME="${LIB[]NAME}${LIB[]NAME:+ }-l$name" 439 | fi 440 | fi 441 | fi 442 | fi 443 | else 444 | if test "X$found_a" != "X"; then 445 | dnl Linking with a static library. 446 | LIB[]NAME="${LIB[]NAME}${LIB[]NAME:+ }$found_a" 447 | else 448 | dnl We shouldn't come here, but anyway it's good to have a 449 | dnl fallback. 450 | LIB[]NAME="${LIB[]NAME}${LIB[]NAME:+ }-L$found_dir -l$name" 451 | fi 452 | fi 453 | dnl Assume the include files are nearby. 454 | additional_includedir= 455 | case "$found_dir" in 456 | */$acl_libdirstem | */$acl_libdirstem/) 457 | basedir=`echo "X$found_dir" | sed -e 's,^X,,' -e "s,/$acl_libdirstem/"'*$,,'` 458 | if test "$name" = '$1'; then 459 | LIB[]NAME[]_PREFIX="$basedir" 460 | fi 461 | additional_includedir="$basedir/include" 462 | ;; 463 | */$acl_libdirstem2 | */$acl_libdirstem2/) 464 | basedir=`echo "X$found_dir" | sed -e 's,^X,,' -e "s,/$acl_libdirstem2/"'*$,,'` 465 | if test "$name" = '$1'; then 466 | LIB[]NAME[]_PREFIX="$basedir" 467 | fi 468 | additional_includedir="$basedir/include" 469 | ;; 470 | esac 471 | if test "X$additional_includedir" != "X"; then 472 | dnl Potentially add $additional_includedir to $INCNAME. 473 | dnl But don't add it 474 | dnl 1. if it's the standard /usr/include, 475 | dnl 2. if it's /usr/local/include and we are using GCC on Linux, 476 | dnl 3. if it's already present in $CPPFLAGS or the already 477 | dnl constructed $INCNAME, 478 | dnl 4. if it doesn't exist as a directory. 479 | if test "X$additional_includedir" != "X/usr/include"; then 480 | haveit= 481 | if test "X$additional_includedir" = "X/usr/local/include"; then 482 | if test -n "$GCC"; then 483 | case $host_os in 484 | linux* | gnu* | k*bsd*-gnu) haveit=yes;; 485 | esac 486 | fi 487 | fi 488 | if test -z "$haveit"; then 489 | for x in $CPPFLAGS $INC[]NAME; do 490 | AC_LIB_WITH_FINAL_PREFIX([eval x=\"$x\"]) 491 | if test "X$x" = "X${i_system}$additional_includedir"; then 492 | haveit=yes 493 | break 494 | fi 495 | done 496 | if test -z "$haveit"; then 497 | if test -d "$additional_includedir"; then 498 | dnl Really add $additional_includedir to $INCNAME. 499 | INC[]NAME="${INC[]NAME}${INC[]NAME:+ }${i_system}$additional_includedir" 500 | fi 501 | fi 502 | fi 503 | fi 504 | fi 505 | dnl Look for dependencies. 506 | if test -n "$found_la"; then 507 | dnl Read the .la file. It defines the variables 508 | dnl dlname, library_names, old_library, dependency_libs, current, 509 | dnl age, revision, installed, dlopen, dlpreopen, libdir. 510 | save_libdir="$libdir" 511 | case "$found_la" in 512 | */* | *\\*) . "$found_la" ;; 513 | *) . "./$found_la" ;; 514 | esac 515 | libdir="$save_libdir" 516 | dnl We use only dependency_libs. 517 | for dep in $dependency_libs; do 518 | case "$dep" in 519 | -L*) 520 | additional_libdir=`echo "X$dep" | sed -e 's/^X-L//'` 521 | dnl Potentially add $additional_libdir to $LIBNAME and $LTLIBNAME. 522 | dnl But don't add it 523 | dnl 1. if it's the standard /usr/lib, 524 | dnl 2. if it's /usr/local/lib and we are using GCC on Linux, 525 | dnl 3. if it's already present in $LDFLAGS or the already 526 | dnl constructed $LIBNAME, 527 | dnl 4. if it doesn't exist as a directory. 528 | if test "X$additional_libdir" != "X/usr/$acl_libdirstem" \ 529 | && test "X$additional_libdir" != "X/usr/$acl_libdirstem2"; then 530 | haveit= 531 | if test "X$additional_libdir" = "X/usr/local/$acl_libdirstem" \ 532 | || test "X$additional_libdir" = "X/usr/local/$acl_libdirstem2"; then 533 | if test -n "$GCC"; then 534 | case $host_os in 535 | linux* | gnu* | k*bsd*-gnu) haveit=yes;; 536 | esac 537 | fi 538 | fi 539 | if test -z "$haveit"; then 540 | haveit= 541 | for x in $LDFLAGS $LIB[]NAME; do 542 | AC_LIB_WITH_FINAL_PREFIX([eval x=\"$x\"]) 543 | if test "X$x" = "X-L$additional_libdir"; then 544 | haveit=yes 545 | break 546 | fi 547 | done 548 | if test -z "$haveit"; then 549 | if test -d "$additional_libdir"; then 550 | dnl Really add $additional_libdir to $LIBNAME. 551 | LIB[]NAME="${LIB[]NAME}${LIB[]NAME:+ }-L$additional_libdir" 552 | fi 553 | fi 554 | haveit= 555 | for x in $LDFLAGS $LTLIB[]NAME; do 556 | AC_LIB_WITH_FINAL_PREFIX([eval x=\"$x\"]) 557 | if test "X$x" = "X-L$additional_libdir"; then 558 | haveit=yes 559 | break 560 | fi 561 | done 562 | if test -z "$haveit"; then 563 | if test -d "$additional_libdir"; then 564 | dnl Really add $additional_libdir to $LTLIBNAME. 565 | LTLIB[]NAME="${LTLIB[]NAME}${LTLIB[]NAME:+ }-L$additional_libdir" 566 | fi 567 | fi 568 | fi 569 | fi 570 | ;; 571 | -R*) 572 | dir=`echo "X$dep" | sed -e 's/^X-R//'` 573 | if test "$enable_rpath" != no; then 574 | dnl Potentially add DIR to rpathdirs. 575 | dnl The rpathdirs will be appended to $LIBNAME at the end. 576 | haveit= 577 | for x in $rpathdirs; do 578 | if test "X$x" = "X$dir"; then 579 | haveit=yes 580 | break 581 | fi 582 | done 583 | if test -z "$haveit"; then 584 | rpathdirs="$rpathdirs $dir" 585 | fi 586 | dnl Potentially add DIR to ltrpathdirs. 587 | dnl The ltrpathdirs will be appended to $LTLIBNAME at the end. 588 | haveit= 589 | for x in $ltrpathdirs; do 590 | if test "X$x" = "X$dir"; then 591 | haveit=yes 592 | break 593 | fi 594 | done 595 | if test -z "$haveit"; then 596 | ltrpathdirs="$ltrpathdirs $dir" 597 | fi 598 | fi 599 | ;; 600 | -l*) 601 | dnl Handle this in the next round. 602 | names_next_round="$names_next_round "`echo "X$dep" | sed -e 's/^X-l//'` 603 | ;; 604 | *.la) 605 | dnl Handle this in the next round. Throw away the .la's 606 | dnl directory; it is already contained in a preceding -L 607 | dnl option. 608 | names_next_round="$names_next_round "`echo "X$dep" | sed -e 's,^X.*/,,' -e 's,^lib,,' -e 's,\.la$,,'` 609 | ;; 610 | *) 611 | dnl Most likely an immediate library name. 612 | LIB[]NAME="${LIB[]NAME}${LIB[]NAME:+ }$dep" 613 | LTLIB[]NAME="${LTLIB[]NAME}${LTLIB[]NAME:+ }$dep" 614 | ;; 615 | esac 616 | done 617 | fi 618 | else 619 | dnl Didn't find the library; assume it is in the system directories 620 | dnl known to the linker and runtime loader. (All the system 621 | dnl directories known to the linker should also be known to the 622 | dnl runtime loader, otherwise the system is severely misconfigured.) 623 | LIB[]NAME="${LIB[]NAME}${LIB[]NAME:+ }-l$name" 624 | LTLIB[]NAME="${LTLIB[]NAME}${LTLIB[]NAME:+ }-l$name" 625 | fi 626 | fi 627 | fi 628 | done 629 | done 630 | if test "X$rpathdirs" != "X"; then 631 | if test -n "$acl_hardcode_libdir_separator"; then 632 | dnl Weird platform: only the last -rpath option counts, the user must 633 | dnl pass all path elements in one option. We can arrange that for a 634 | dnl single library, but not when more than one $LIBNAMEs are used. 635 | alldirs= 636 | for found_dir in $rpathdirs; do 637 | alldirs="${alldirs}${alldirs:+$acl_hardcode_libdir_separator}$found_dir" 638 | done 639 | dnl Note: acl_hardcode_libdir_flag_spec uses $libdir and $wl. 640 | acl_save_libdir="$libdir" 641 | libdir="$alldirs" 642 | eval flag=\"$acl_hardcode_libdir_flag_spec\" 643 | libdir="$acl_save_libdir" 644 | LIB[]NAME="${LIB[]NAME}${LIB[]NAME:+ }$flag" 645 | else 646 | dnl The -rpath options are cumulative. 647 | for found_dir in $rpathdirs; do 648 | acl_save_libdir="$libdir" 649 | libdir="$found_dir" 650 | eval flag=\"$acl_hardcode_libdir_flag_spec\" 651 | libdir="$acl_save_libdir" 652 | LIB[]NAME="${LIB[]NAME}${LIB[]NAME:+ }$flag" 653 | done 654 | fi 655 | fi 656 | if test "X$ltrpathdirs" != "X"; then 657 | dnl When using libtool, the option that works for both libraries and 658 | dnl executables is -R. The -R options are cumulative. 659 | for found_dir in $ltrpathdirs; do 660 | LTLIB[]NAME="${LTLIB[]NAME}${LTLIB[]NAME:+ }-R$found_dir" 661 | done 662 | fi 663 | popdef([P_A_C_K]) 664 | popdef([PACKLIBS]) 665 | popdef([PACKUP]) 666 | popdef([PACK]) 667 | popdef([NAME]) 668 | ]) 669 | 670 | dnl AC_LIB_APPENDTOVAR(VAR, CONTENTS) appends the elements of CONTENTS to VAR, 671 | dnl unless already present in VAR. 672 | dnl Works only for CPPFLAGS, not for LIB* variables because that sometimes 673 | dnl contains two or three consecutive elements that belong together. 674 | AC_DEFUN([AC_LIB_APPENDTOVAR], 675 | [ 676 | for element in [$2]; do 677 | haveit= 678 | for x in $[$1]; do 679 | AC_LIB_WITH_FINAL_PREFIX([eval x=\"$x\"]) 680 | if test "X$x" = "X$element"; then 681 | haveit=yes 682 | break 683 | fi 684 | done 685 | if test -z "$haveit"; then 686 | [$1]="${[$1]}${[$1]:+ }$element" 687 | fi 688 | done 689 | ]) 690 | 691 | dnl For those cases where a variable contains several -L and -l options 692 | dnl referring to unknown libraries and directories, this macro determines the 693 | dnl necessary additional linker options for the runtime path. 694 | dnl AC_LIB_LINKFLAGS_FROM_LIBS([LDADDVAR], [LIBSVALUE], [USE-LIBTOOL]) 695 | dnl sets LDADDVAR to linker options needed together with LIBSVALUE. 696 | dnl If USE-LIBTOOL evaluates to non-empty, linking with libtool is assumed, 697 | dnl otherwise linking without libtool is assumed. 698 | AC_DEFUN([AC_LIB_LINKFLAGS_FROM_LIBS], 699 | [ 700 | AC_REQUIRE([AC_LIB_RPATH]) 701 | AC_REQUIRE([AC_LIB_PREPARE_MULTILIB]) 702 | $1= 703 | if test "$enable_rpath" != no; then 704 | if test -n "$acl_hardcode_libdir_flag_spec" && test "$acl_hardcode_minus_L" = no; then 705 | dnl Use an explicit option to hardcode directories into the resulting 706 | dnl binary. 707 | rpathdirs= 708 | next= 709 | for opt in $2; do 710 | if test -n "$next"; then 711 | dir="$next" 712 | dnl No need to hardcode the standard /usr/lib. 713 | if test "X$dir" != "X/usr/$acl_libdirstem" \ 714 | && test "X$dir" != "X/usr/$acl_libdirstem2"; then 715 | rpathdirs="$rpathdirs $dir" 716 | fi 717 | next= 718 | else 719 | case $opt in 720 | -L) next=yes ;; 721 | -L*) dir=`echo "X$opt" | sed -e 's,^X-L,,'` 722 | dnl No need to hardcode the standard /usr/lib. 723 | if test "X$dir" != "X/usr/$acl_libdirstem" \ 724 | && test "X$dir" != "X/usr/$acl_libdirstem2"; then 725 | rpathdirs="$rpathdirs $dir" 726 | fi 727 | next= ;; 728 | *) next= ;; 729 | esac 730 | fi 731 | done 732 | if test "X$rpathdirs" != "X"; then 733 | if test -n ""$3""; then 734 | dnl libtool is used for linking. Use -R options. 735 | for dir in $rpathdirs; do 736 | $1="${$1}${$1:+ }-R$dir" 737 | done 738 | else 739 | dnl The linker is used for linking directly. 740 | if test -n "$acl_hardcode_libdir_separator"; then 741 | dnl Weird platform: only the last -rpath option counts, the user 742 | dnl must pass all path elements in one option. 743 | alldirs= 744 | for dir in $rpathdirs; do 745 | alldirs="${alldirs}${alldirs:+$acl_hardcode_libdir_separator}$dir" 746 | done 747 | acl_save_libdir="$libdir" 748 | libdir="$alldirs" 749 | eval flag=\"$acl_hardcode_libdir_flag_spec\" 750 | libdir="$acl_save_libdir" 751 | $1="$flag" 752 | else 753 | dnl The -rpath options are cumulative. 754 | for dir in $rpathdirs; do 755 | acl_save_libdir="$libdir" 756 | libdir="$dir" 757 | eval flag=\"$acl_hardcode_libdir_flag_spec\" 758 | libdir="$acl_save_libdir" 759 | $1="${$1}${$1:+ }$flag" 760 | done 761 | fi 762 | fi 763 | fi 764 | fi 765 | fi 766 | AC_SUBST([$1]) 767 | ]) 768 | -------------------------------------------------------------------------------- /m4/lib-prefix.m4: -------------------------------------------------------------------------------- 1 | # lib-prefix.m4 serial 6 (gettext-0.18) 2 | dnl Copyright (C) 2001-2005, 2008 Free Software Foundation, Inc. 3 | dnl This file is free software; the Free Software Foundation 4 | dnl gives unlimited permission to copy and/or distribute it, 5 | dnl with or without modifications, as long as this notice is preserved. 6 | 7 | dnl From Bruno Haible. 8 | 9 | dnl AC_LIB_ARG_WITH is synonymous to AC_ARG_WITH in autoconf-2.13, and 10 | dnl similar to AC_ARG_WITH in autoconf 2.52...2.57 except that is doesn't 11 | dnl require excessive bracketing. 12 | ifdef([AC_HELP_STRING], 13 | [AC_DEFUN([AC_LIB_ARG_WITH], [AC_ARG_WITH([$1],[[$2]],[$3],[$4])])], 14 | [AC_DEFUN([AC_][LIB_ARG_WITH], [AC_ARG_WITH([$1],[$2],[$3],[$4])])]) 15 | 16 | dnl AC_LIB_PREFIX adds to the CPPFLAGS and LDFLAGS the flags that are needed 17 | dnl to access previously installed libraries. The basic assumption is that 18 | dnl a user will want packages to use other packages he previously installed 19 | dnl with the same --prefix option. 20 | dnl This macro is not needed if only AC_LIB_LINKFLAGS is used to locate 21 | dnl libraries, but is otherwise very convenient. 22 | AC_DEFUN([AC_LIB_PREFIX], 23 | [ 24 | AC_BEFORE([$0], [AC_LIB_LINKFLAGS]) 25 | AC_REQUIRE([AC_PROG_CC]) 26 | AC_REQUIRE([AC_CANONICAL_HOST]) 27 | AC_REQUIRE([AC_LIB_PREPARE_MULTILIB]) 28 | AC_REQUIRE([AC_LIB_PREPARE_PREFIX]) 29 | dnl By default, look in $includedir and $libdir. 30 | use_additional=yes 31 | AC_LIB_WITH_FINAL_PREFIX([ 32 | eval additional_includedir=\"$includedir\" 33 | eval additional_libdir=\"$libdir\" 34 | ]) 35 | AC_LIB_ARG_WITH([lib-prefix], 36 | [ --with-lib-prefix[=DIR] search for libraries in DIR/include and DIR/lib 37 | --without-lib-prefix don't search for libraries in includedir and libdir], 38 | [ 39 | if test "X$withval" = "Xno"; then 40 | use_additional=no 41 | else 42 | if test "X$withval" = "X"; then 43 | AC_LIB_WITH_FINAL_PREFIX([ 44 | eval additional_includedir=\"$includedir\" 45 | eval additional_libdir=\"$libdir\" 46 | ]) 47 | else 48 | additional_includedir="$withval/include" 49 | additional_libdir="$withval/$acl_libdirstem" 50 | fi 51 | fi 52 | ]) 53 | if test $use_additional = yes; then 54 | dnl Potentially add $additional_includedir to $CPPFLAGS. 55 | dnl But don't add it 56 | dnl 1. if it's the standard /usr/include, 57 | dnl 2. if it's already present in $CPPFLAGS, 58 | dnl 3. if it's /usr/local/include and we are using GCC on Linux, 59 | dnl 4. if it doesn't exist as a directory. 60 | if test "X$additional_includedir" != "X/usr/include"; then 61 | haveit= 62 | for x in $CPPFLAGS; do 63 | AC_LIB_WITH_FINAL_PREFIX([eval x=\"$x\"]) 64 | if test "X$x" = "X-I$additional_includedir"; then 65 | haveit=yes 66 | break 67 | fi 68 | done 69 | if test -z "$haveit"; then 70 | if test "X$additional_includedir" = "X/usr/local/include"; then 71 | if test -n "$GCC"; then 72 | case $host_os in 73 | linux* | gnu* | k*bsd*-gnu) haveit=yes;; 74 | esac 75 | fi 76 | fi 77 | if test -z "$haveit"; then 78 | if test -d "$additional_includedir"; then 79 | dnl Really add $additional_includedir to $CPPFLAGS. 80 | CPPFLAGS="${CPPFLAGS}${CPPFLAGS:+ }-I$additional_includedir" 81 | fi 82 | fi 83 | fi 84 | fi 85 | dnl Potentially add $additional_libdir to $LDFLAGS. 86 | dnl But don't add it 87 | dnl 1. if it's the standard /usr/lib, 88 | dnl 2. if it's already present in $LDFLAGS, 89 | dnl 3. if it's /usr/local/lib and we are using GCC on Linux, 90 | dnl 4. if it doesn't exist as a directory. 91 | if test "X$additional_libdir" != "X/usr/$acl_libdirstem"; then 92 | haveit= 93 | for x in $LDFLAGS; do 94 | AC_LIB_WITH_FINAL_PREFIX([eval x=\"$x\"]) 95 | if test "X$x" = "X-L$additional_libdir"; then 96 | haveit=yes 97 | break 98 | fi 99 | done 100 | if test -z "$haveit"; then 101 | if test "X$additional_libdir" = "X/usr/local/$acl_libdirstem"; then 102 | if test -n "$GCC"; then 103 | case $host_os in 104 | linux*) haveit=yes;; 105 | esac 106 | fi 107 | fi 108 | if test -z "$haveit"; then 109 | if test -d "$additional_libdir"; then 110 | dnl Really add $additional_libdir to $LDFLAGS. 111 | LDFLAGS="${LDFLAGS}${LDFLAGS:+ }-L$additional_libdir" 112 | fi 113 | fi 114 | fi 115 | fi 116 | fi 117 | ]) 118 | 119 | dnl AC_LIB_PREPARE_PREFIX creates variables acl_final_prefix, 120 | dnl acl_final_exec_prefix, containing the values to which $prefix and 121 | dnl $exec_prefix will expand at the end of the configure script. 122 | AC_DEFUN([AC_LIB_PREPARE_PREFIX], 123 | [ 124 | dnl Unfortunately, prefix and exec_prefix get only finally determined 125 | dnl at the end of configure. 126 | if test "X$prefix" = "XNONE"; then 127 | acl_final_prefix="$ac_default_prefix" 128 | else 129 | acl_final_prefix="$prefix" 130 | fi 131 | if test "X$exec_prefix" = "XNONE"; then 132 | acl_final_exec_prefix='${prefix}' 133 | else 134 | acl_final_exec_prefix="$exec_prefix" 135 | fi 136 | acl_save_prefix="$prefix" 137 | prefix="$acl_final_prefix" 138 | eval acl_final_exec_prefix=\"$acl_final_exec_prefix\" 139 | prefix="$acl_save_prefix" 140 | ]) 141 | 142 | dnl AC_LIB_WITH_FINAL_PREFIX([statement]) evaluates statement, with the 143 | dnl variables prefix and exec_prefix bound to the values they will have 144 | dnl at the end of the configure script. 145 | AC_DEFUN([AC_LIB_WITH_FINAL_PREFIX], 146 | [ 147 | acl_save_prefix="$prefix" 148 | prefix="$acl_final_prefix" 149 | acl_save_exec_prefix="$exec_prefix" 150 | exec_prefix="$acl_final_exec_prefix" 151 | $1 152 | exec_prefix="$acl_save_exec_prefix" 153 | prefix="$acl_save_prefix" 154 | ]) 155 | 156 | dnl AC_LIB_PREPARE_MULTILIB creates 157 | dnl - a variable acl_libdirstem, containing the basename of the libdir, either 158 | dnl "lib" or "lib64" or "lib/64", 159 | dnl - a variable acl_libdirstem2, as a secondary possible value for 160 | dnl acl_libdirstem, either the same as acl_libdirstem or "lib/sparcv9" or 161 | dnl "lib/amd64". 162 | AC_DEFUN([AC_LIB_PREPARE_MULTILIB], 163 | [ 164 | dnl There is no formal standard regarding lib and lib64. 165 | dnl On glibc systems, the current practice is that on a system supporting 166 | dnl 32-bit and 64-bit instruction sets or ABIs, 64-bit libraries go under 167 | dnl $prefix/lib64 and 32-bit libraries go under $prefix/lib. We determine 168 | dnl the compiler's default mode by looking at the compiler's library search 169 | dnl path. If at least one of its elements ends in /lib64 or points to a 170 | dnl directory whose absolute pathname ends in /lib64, we assume a 64-bit ABI. 171 | dnl Otherwise we use the default, namely "lib". 172 | dnl On Solaris systems, the current practice is that on a system supporting 173 | dnl 32-bit and 64-bit instruction sets or ABIs, 64-bit libraries go under 174 | dnl $prefix/lib/64 (which is a symlink to either $prefix/lib/sparcv9 or 175 | dnl $prefix/lib/amd64) and 32-bit libraries go under $prefix/lib. 176 | AC_REQUIRE([AC_CANONICAL_HOST]) 177 | acl_libdirstem=lib 178 | acl_libdirstem2= 179 | case "$host_os" in 180 | solaris*) 181 | dnl See Solaris 10 Software Developer Collection > Solaris 64-bit Developer's Guide > The Development Environment 182 | dnl . 183 | dnl "Portable Makefiles should refer to any library directories using the 64 symbolic link." 184 | dnl But we want to recognize the sparcv9 or amd64 subdirectory also if the 185 | dnl symlink is missing, so we set acl_libdirstem2 too. 186 | AC_CACHE_CHECK([for 64-bit host], [gl_cv_solaris_64bit], 187 | [AC_RUN_IFELSE([ 188 | AC_LANG_PROGRAM([], [[ 189 | return sizeof(void*) == 8 ? 0 : 1; 190 | ]]) 191 | ], [gl_cv_solaris_64bit=yes], [gl_cv_solaris_64bit=no]) 192 | ]) 193 | if test $gl_cv_solaris_64bit = yes; then 194 | acl_libdirstem=lib/64 195 | case "$host_cpu" in 196 | sparc*) acl_libdirstem2=lib/sparcv9 ;; 197 | i*86 | x86_64) acl_libdirstem2=lib/amd64 ;; 198 | esac 199 | fi 200 | ;; 201 | *) 202 | searchpath=`(LC_ALL=C $CC -print-search-dirs) 2>/dev/null | sed -n -e 's,^libraries: ,,p' | sed -e 's,^=,,'` 203 | if test -n "$searchpath"; then 204 | acl_save_IFS="${IFS= }"; IFS=":" 205 | for searchdir in $searchpath; do 206 | if test -d "$searchdir"; then 207 | case "$searchdir" in 208 | */lib64/ | */lib64 ) acl_libdirstem=lib64 ;; 209 | *) searchdir=`cd "$searchdir" && pwd` 210 | case "$searchdir" in 211 | */lib64 ) acl_libdirstem=lib64 ;; 212 | esac ;; 213 | esac 214 | fi 215 | done 216 | IFS="$acl_save_IFS" 217 | fi 218 | ;; 219 | esac 220 | test -n "$acl_libdirstem2" || acl_libdirstem2="$acl_libdirstem" 221 | ]) 222 | -------------------------------------------------------------------------------- /m4/po.m4: -------------------------------------------------------------------------------- 1 | # po.m4 serial 17 (gettext-0.18) 2 | dnl Copyright (C) 1995-2010 Free Software Foundation, Inc. 3 | dnl This file is free software; the Free Software Foundation 4 | dnl gives unlimited permission to copy and/or distribute it, 5 | dnl with or without modifications, as long as this notice is preserved. 6 | dnl 7 | dnl This file can can be used in projects which are not available under 8 | dnl the GNU General Public License or the GNU Library General Public 9 | dnl License but which still want to provide support for the GNU gettext 10 | dnl functionality. 11 | dnl Please note that the actual code of the GNU gettext library is covered 12 | dnl by the GNU Library General Public License, and the rest of the GNU 13 | dnl gettext package package is covered by the GNU General Public License. 14 | dnl They are *not* in the public domain. 15 | 16 | dnl Authors: 17 | dnl Ulrich Drepper , 1995-2000. 18 | dnl Bruno Haible , 2000-2003. 19 | 20 | AC_PREREQ([2.50]) 21 | 22 | dnl Checks for all prerequisites of the po subdirectory. 23 | AC_DEFUN([AM_PO_SUBDIRS], 24 | [ 25 | AC_REQUIRE([AC_PROG_MAKE_SET])dnl 26 | AC_REQUIRE([AC_PROG_INSTALL])dnl 27 | AC_REQUIRE([AM_PROG_MKDIR_P])dnl defined by automake 28 | AC_REQUIRE([AM_NLS])dnl 29 | 30 | dnl Release version of the gettext macros. This is used to ensure that 31 | dnl the gettext macros and po/Makefile.in.in are in sync. 32 | AC_SUBST([GETTEXT_MACRO_VERSION], [0.18]) 33 | 34 | dnl Perform the following tests also if --disable-nls has been given, 35 | dnl because they are needed for "make dist" to work. 36 | 37 | dnl Search for GNU msgfmt in the PATH. 38 | dnl The first test excludes Solaris msgfmt and early GNU msgfmt versions. 39 | dnl The second test excludes FreeBSD msgfmt. 40 | AM_PATH_PROG_WITH_TEST(MSGFMT, msgfmt, 41 | [$ac_dir/$ac_word --statistics /dev/null >&]AS_MESSAGE_LOG_FD[ 2>&1 && 42 | (if $ac_dir/$ac_word --statistics /dev/null 2>&1 >/dev/null | grep usage >/dev/null; then exit 1; else exit 0; fi)], 43 | :) 44 | AC_PATH_PROG([GMSGFMT], [gmsgfmt], [$MSGFMT]) 45 | 46 | dnl Test whether it is GNU msgfmt >= 0.15. 47 | changequote(,)dnl 48 | case `$MSGFMT --version | sed 1q | sed -e 's,^[^0-9]*,,'` in 49 | '' | 0.[0-9] | 0.[0-9].* | 0.1[0-4] | 0.1[0-4].*) MSGFMT_015=: ;; 50 | *) MSGFMT_015=$MSGFMT ;; 51 | esac 52 | changequote([,])dnl 53 | AC_SUBST([MSGFMT_015]) 54 | changequote(,)dnl 55 | case `$GMSGFMT --version | sed 1q | sed -e 's,^[^0-9]*,,'` in 56 | '' | 0.[0-9] | 0.[0-9].* | 0.1[0-4] | 0.1[0-4].*) GMSGFMT_015=: ;; 57 | *) GMSGFMT_015=$GMSGFMT ;; 58 | esac 59 | changequote([,])dnl 60 | AC_SUBST([GMSGFMT_015]) 61 | 62 | dnl Search for GNU xgettext 0.12 or newer in the PATH. 63 | dnl The first test excludes Solaris xgettext and early GNU xgettext versions. 64 | dnl The second test excludes FreeBSD xgettext. 65 | AM_PATH_PROG_WITH_TEST(XGETTEXT, xgettext, 66 | [$ac_dir/$ac_word --omit-header --copyright-holder= --msgid-bugs-address= /dev/null >&]AS_MESSAGE_LOG_FD[ 2>&1 && 67 | (if $ac_dir/$ac_word --omit-header --copyright-holder= --msgid-bugs-address= /dev/null 2>&1 >/dev/null | grep usage >/dev/null; then exit 1; else exit 0; fi)], 68 | :) 69 | dnl Remove leftover from FreeBSD xgettext call. 70 | rm -f messages.po 71 | 72 | dnl Test whether it is GNU xgettext >= 0.15. 73 | changequote(,)dnl 74 | case `$XGETTEXT --version | sed 1q | sed -e 's,^[^0-9]*,,'` in 75 | '' | 0.[0-9] | 0.[0-9].* | 0.1[0-4] | 0.1[0-4].*) XGETTEXT_015=: ;; 76 | *) XGETTEXT_015=$XGETTEXT ;; 77 | esac 78 | changequote([,])dnl 79 | AC_SUBST([XGETTEXT_015]) 80 | 81 | dnl Search for GNU msgmerge 0.11 or newer in the PATH. 82 | AM_PATH_PROG_WITH_TEST(MSGMERGE, msgmerge, 83 | [$ac_dir/$ac_word --update -q /dev/null /dev/null >&]AS_MESSAGE_LOG_FD[ 2>&1], :) 84 | 85 | dnl Installation directories. 86 | dnl Autoconf >= 2.60 defines localedir. For older versions of autoconf, we 87 | dnl have to define it here, so that it can be used in po/Makefile. 88 | test -n "$localedir" || localedir='${datadir}/locale' 89 | AC_SUBST([localedir]) 90 | 91 | dnl Support for AM_XGETTEXT_OPTION. 92 | test -n "${XGETTEXT_EXTRA_OPTIONS+set}" || XGETTEXT_EXTRA_OPTIONS= 93 | AC_SUBST([XGETTEXT_EXTRA_OPTIONS]) 94 | 95 | AC_CONFIG_COMMANDS([po-directories], [[ 96 | for ac_file in $CONFIG_FILES; do 97 | # Support "outfile[:infile[:infile...]]" 98 | case "$ac_file" in 99 | *:*) ac_file=`echo "$ac_file"|sed 's%:.*%%'` ;; 100 | esac 101 | # PO directories have a Makefile.in generated from Makefile.in.in. 102 | case "$ac_file" in */Makefile.in) 103 | # Adjust a relative srcdir. 104 | ac_dir=`echo "$ac_file"|sed 's%/[^/][^/]*$%%'` 105 | ac_dir_suffix="/`echo "$ac_dir"|sed 's%^\./%%'`" 106 | ac_dots=`echo "$ac_dir_suffix"|sed 's%/[^/]*%../%g'` 107 | # In autoconf-2.13 it is called $ac_given_srcdir. 108 | # In autoconf-2.50 it is called $srcdir. 109 | test -n "$ac_given_srcdir" || ac_given_srcdir="$srcdir" 110 | case "$ac_given_srcdir" in 111 | .) top_srcdir=`echo $ac_dots|sed 's%/$%%'` ;; 112 | /*) top_srcdir="$ac_given_srcdir" ;; 113 | *) top_srcdir="$ac_dots$ac_given_srcdir" ;; 114 | esac 115 | # Treat a directory as a PO directory if and only if it has a 116 | # POTFILES.in file. This allows packages to have multiple PO 117 | # directories under different names or in different locations. 118 | if test -f "$ac_given_srcdir/$ac_dir/POTFILES.in"; then 119 | rm -f "$ac_dir/POTFILES" 120 | test -n "$as_me" && echo "$as_me: creating $ac_dir/POTFILES" || echo "creating $ac_dir/POTFILES" 121 | cat "$ac_given_srcdir/$ac_dir/POTFILES.in" | sed -e "/^#/d" -e "/^[ ]*\$/d" -e "s,.*, $top_srcdir/& \\\\," | sed -e "\$s/\(.*\) \\\\/\1/" > "$ac_dir/POTFILES" 122 | POMAKEFILEDEPS="POTFILES.in" 123 | # ALL_LINGUAS, POFILES, UPDATEPOFILES, DUMMYPOFILES, GMOFILES depend 124 | # on $ac_dir but don't depend on user-specified configuration 125 | # parameters. 126 | if test -f "$ac_given_srcdir/$ac_dir/LINGUAS"; then 127 | # The LINGUAS file contains the set of available languages. 128 | if test -n "$OBSOLETE_ALL_LINGUAS"; then 129 | test -n "$as_me" && echo "$as_me: setting ALL_LINGUAS in configure.in is obsolete" || echo "setting ALL_LINGUAS in configure.in is obsolete" 130 | fi 131 | ALL_LINGUAS_=`sed -e "/^#/d" -e "s/#.*//" "$ac_given_srcdir/$ac_dir/LINGUAS"` 132 | # Hide the ALL_LINGUAS assigment from automake < 1.5. 133 | eval 'ALL_LINGUAS''=$ALL_LINGUAS_' 134 | POMAKEFILEDEPS="$POMAKEFILEDEPS LINGUAS" 135 | else 136 | # The set of available languages was given in configure.in. 137 | # Hide the ALL_LINGUAS assigment from automake < 1.5. 138 | eval 'ALL_LINGUAS''=$OBSOLETE_ALL_LINGUAS' 139 | fi 140 | # Compute POFILES 141 | # as $(foreach lang, $(ALL_LINGUAS), $(srcdir)/$(lang).po) 142 | # Compute UPDATEPOFILES 143 | # as $(foreach lang, $(ALL_LINGUAS), $(lang).po-update) 144 | # Compute DUMMYPOFILES 145 | # as $(foreach lang, $(ALL_LINGUAS), $(lang).nop) 146 | # Compute GMOFILES 147 | # as $(foreach lang, $(ALL_LINGUAS), $(srcdir)/$(lang).gmo) 148 | case "$ac_given_srcdir" in 149 | .) srcdirpre= ;; 150 | *) srcdirpre='$(srcdir)/' ;; 151 | esac 152 | POFILES= 153 | UPDATEPOFILES= 154 | DUMMYPOFILES= 155 | GMOFILES= 156 | for lang in $ALL_LINGUAS; do 157 | POFILES="$POFILES $srcdirpre$lang.po" 158 | UPDATEPOFILES="$UPDATEPOFILES $lang.po-update" 159 | DUMMYPOFILES="$DUMMYPOFILES $lang.nop" 160 | GMOFILES="$GMOFILES $srcdirpre$lang.gmo" 161 | done 162 | # CATALOGS depends on both $ac_dir and the user's LINGUAS 163 | # environment variable. 164 | INST_LINGUAS= 165 | if test -n "$ALL_LINGUAS"; then 166 | for presentlang in $ALL_LINGUAS; do 167 | useit=no 168 | if test "%UNSET%" != "$LINGUAS"; then 169 | desiredlanguages="$LINGUAS" 170 | else 171 | desiredlanguages="$ALL_LINGUAS" 172 | fi 173 | for desiredlang in $desiredlanguages; do 174 | # Use the presentlang catalog if desiredlang is 175 | # a. equal to presentlang, or 176 | # b. a variant of presentlang (because in this case, 177 | # presentlang can be used as a fallback for messages 178 | # which are not translated in the desiredlang catalog). 179 | case "$desiredlang" in 180 | "$presentlang"*) useit=yes;; 181 | esac 182 | done 183 | if test $useit = yes; then 184 | INST_LINGUAS="$INST_LINGUAS $presentlang" 185 | fi 186 | done 187 | fi 188 | CATALOGS= 189 | if test -n "$INST_LINGUAS"; then 190 | for lang in $INST_LINGUAS; do 191 | CATALOGS="$CATALOGS $lang.gmo" 192 | done 193 | fi 194 | test -n "$as_me" && echo "$as_me: creating $ac_dir/Makefile" || echo "creating $ac_dir/Makefile" 195 | sed -e "/^POTFILES =/r $ac_dir/POTFILES" -e "/^# Makevars/r $ac_given_srcdir/$ac_dir/Makevars" -e "s|@POFILES@|$POFILES|g" -e "s|@UPDATEPOFILES@|$UPDATEPOFILES|g" -e "s|@DUMMYPOFILES@|$DUMMYPOFILES|g" -e "s|@GMOFILES@|$GMOFILES|g" -e "s|@CATALOGS@|$CATALOGS|g" -e "s|@POMAKEFILEDEPS@|$POMAKEFILEDEPS|g" "$ac_dir/Makefile.in" > "$ac_dir/Makefile" 196 | for f in "$ac_given_srcdir/$ac_dir"/Rules-*; do 197 | if test -f "$f"; then 198 | case "$f" in 199 | *.orig | *.bak | *~) ;; 200 | *) cat "$f" >> "$ac_dir/Makefile" ;; 201 | esac 202 | fi 203 | done 204 | fi 205 | ;; 206 | esac 207 | done]], 208 | [# Capture the value of obsolete ALL_LINGUAS because we need it to compute 209 | # POFILES, UPDATEPOFILES, DUMMYPOFILES, GMOFILES, CATALOGS. But hide it 210 | # from automake < 1.5. 211 | eval 'OBSOLETE_ALL_LINGUAS''="$ALL_LINGUAS"' 212 | # Capture the value of LINGUAS because we need it to compute CATALOGS. 213 | LINGUAS="${LINGUAS-%UNSET%}" 214 | ]) 215 | ]) 216 | 217 | dnl Postprocesses a Makefile in a directory containing PO files. 218 | AC_DEFUN([AM_POSTPROCESS_PO_MAKEFILE], 219 | [ 220 | # When this code is run, in config.status, two variables have already been 221 | # set: 222 | # - OBSOLETE_ALL_LINGUAS is the value of LINGUAS set in configure.in, 223 | # - LINGUAS is the value of the environment variable LINGUAS at configure 224 | # time. 225 | 226 | changequote(,)dnl 227 | # Adjust a relative srcdir. 228 | ac_dir=`echo "$ac_file"|sed 's%/[^/][^/]*$%%'` 229 | ac_dir_suffix="/`echo "$ac_dir"|sed 's%^\./%%'`" 230 | ac_dots=`echo "$ac_dir_suffix"|sed 's%/[^/]*%../%g'` 231 | # In autoconf-2.13 it is called $ac_given_srcdir. 232 | # In autoconf-2.50 it is called $srcdir. 233 | test -n "$ac_given_srcdir" || ac_given_srcdir="$srcdir" 234 | case "$ac_given_srcdir" in 235 | .) top_srcdir=`echo $ac_dots|sed 's%/$%%'` ;; 236 | /*) top_srcdir="$ac_given_srcdir" ;; 237 | *) top_srcdir="$ac_dots$ac_given_srcdir" ;; 238 | esac 239 | 240 | # Find a way to echo strings without interpreting backslash. 241 | if test "X`(echo '\t') 2>/dev/null`" = 'X\t'; then 242 | gt_echo='echo' 243 | else 244 | if test "X`(printf '%s\n' '\t') 2>/dev/null`" = 'X\t'; then 245 | gt_echo='printf %s\n' 246 | else 247 | echo_func () { 248 | cat < "$ac_file.tmp" 408 | if grep -l '@TCLCATALOGS@' "$ac_file" > /dev/null; then 409 | # Add dependencies that cannot be formulated as a simple suffix rule. 410 | for lang in $ALL_LINGUAS; do 411 | frobbedlang=`echo $lang | sed -e 's/\..*$//' -e 'y/ABCDEFGHIJKLMNOPQRSTUVWXYZ/abcdefghijklmnopqrstuvwxyz/'` 412 | cat >> "$ac_file.tmp" < /dev/null; then 420 | # Add dependencies that cannot be formulated as a simple suffix rule. 421 | for lang in $ALL_LINGUAS; do 422 | frobbedlang=`echo $lang | sed -e 's/_/-/g' -e 's/^sr-CS/sr-SP/' -e 's/@latin$/-Latn/' -e 's/@cyrillic$/-Cyrl/' -e 's/^sr-SP$/sr-SP-Latn/' -e 's/^uz-UZ$/uz-UZ-Latn/'` 423 | cat >> "$ac_file.tmp" <> "$ac_file.tmp" <, 1996. 18 | 19 | AC_PREREQ([2.50]) 20 | 21 | # Search path for a program which passes the given test. 22 | 23 | dnl AM_PATH_PROG_WITH_TEST(VARIABLE, PROG-TO-CHECK-FOR, 24 | dnl TEST-PERFORMED-ON-FOUND_PROGRAM [, VALUE-IF-NOT-FOUND [, PATH]]) 25 | AC_DEFUN([AM_PATH_PROG_WITH_TEST], 26 | [ 27 | # Prepare PATH_SEPARATOR. 28 | # The user is always right. 29 | if test "${PATH_SEPARATOR+set}" != set; then 30 | echo "#! /bin/sh" >conf$$.sh 31 | echo "exit 0" >>conf$$.sh 32 | chmod +x conf$$.sh 33 | if (PATH="/nonexistent;."; conf$$.sh) >/dev/null 2>&1; then 34 | PATH_SEPARATOR=';' 35 | else 36 | PATH_SEPARATOR=: 37 | fi 38 | rm -f conf$$.sh 39 | fi 40 | 41 | # Find out how to test for executable files. Don't use a zero-byte file, 42 | # as systems may use methods other than mode bits to determine executability. 43 | cat >conf$$.file <<_ASEOF 44 | #! /bin/sh 45 | exit 0 46 | _ASEOF 47 | chmod +x conf$$.file 48 | if test -x conf$$.file >/dev/null 2>&1; then 49 | ac_executable_p="test -x" 50 | else 51 | ac_executable_p="test -f" 52 | fi 53 | rm -f conf$$.file 54 | 55 | # Extract the first word of "$2", so it can be a program name with args. 56 | set dummy $2; ac_word=[$]2 57 | AC_MSG_CHECKING([for $ac_word]) 58 | AC_CACHE_VAL([ac_cv_path_$1], 59 | [case "[$]$1" in 60 | [[\\/]]* | ?:[[\\/]]*) 61 | ac_cv_path_$1="[$]$1" # Let the user override the test with a path. 62 | ;; 63 | *) 64 | ac_save_IFS="$IFS"; IFS=$PATH_SEPARATOR 65 | for ac_dir in ifelse([$5], , $PATH, [$5]); do 66 | IFS="$ac_save_IFS" 67 | test -z "$ac_dir" && ac_dir=. 68 | for ac_exec_ext in '' $ac_executable_extensions; do 69 | if $ac_executable_p "$ac_dir/$ac_word$ac_exec_ext"; then 70 | echo "$as_me: trying $ac_dir/$ac_word..." >&AS_MESSAGE_LOG_FD 71 | if [$3]; then 72 | ac_cv_path_$1="$ac_dir/$ac_word$ac_exec_ext" 73 | break 2 74 | fi 75 | fi 76 | done 77 | done 78 | IFS="$ac_save_IFS" 79 | dnl If no 4th arg is given, leave the cache variable unset, 80 | dnl so AC_PATH_PROGS will keep looking. 81 | ifelse([$4], , , [ test -z "[$]ac_cv_path_$1" && ac_cv_path_$1="$4" 82 | ])dnl 83 | ;; 84 | esac])dnl 85 | $1="$ac_cv_path_$1" 86 | if test ifelse([$4], , [-n "[$]$1"], ["[$]$1" != "$4"]); then 87 | AC_MSG_RESULT([$][$1]) 88 | else 89 | AC_MSG_RESULT([no]) 90 | fi 91 | AC_SUBST([$1])dnl 92 | ]) 93 | -------------------------------------------------------------------------------- /start_suspended.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | # 3 | # Libeatmydata 4 | # 5 | # Copyright (C) 2017 Stewart Smith (stewart@flamingspork.com) 6 | # All rights reserved. 7 | # 8 | # Use and distribution licensed under the BSD license. See the 9 | # COPYING file in the root project directory for full text. 10 | # 11 | 12 | # A helper script to start a process in suspended state with macOS dynamic 13 | # library preloaded, neccessitated by bash version < 4 there which does not 14 | # have $BASHPID enabling an inline solution 15 | # (kill -s STOP $BASPID; exec foo arg) & 16 | 17 | kill -TSTP $$ 18 | 19 | export DYLD_LIBRARY_PATH=libeatmydata/.libs 20 | export DYLD_FORCE_FLAT_NAMESPACE=1 21 | export DYLD_INSERT_LIBRARIES=./.libs/libeatmydata.dylib 22 | 23 | exec $@ 24 | exit $? 25 | -------------------------------------------------------------------------------- /test_run.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | # 3 | # Libeatmydata 4 | # 5 | # Copyright (C) 2010-2014 Stewart Smith (stewart@flamingspork.com) 6 | # Based heavily on work by: 7 | # Copyright (C) 2010 Eric Day (eday@oddments.org) 8 | # All rights reserved. 9 | # 10 | # Use and distribution licensed under the BSD license. See the 11 | # COPYING file in the root project directory for full text. 12 | # 13 | 14 | # Get filename we want to run without path 15 | name=`echo $1 | sed 's/.*\/\(libeatmydata\/.*[^\/]*\)$/\1/'` 16 | 17 | ext=`echo $name | sed 's/.*\.\([^.]*$\)/\1/'` 18 | if [ "x$ext" = "x$name" ] 19 | then 20 | ext="" 21 | fi 22 | 23 | if [ ! "x$ext" = "xsh" ] 24 | then 25 | libtool_prefix="libtool --mode=execute" 26 | fi 27 | 28 | # Set prefix if it was given through environment 29 | if [ -n "$LIBEATMYDATA_TEST_PREFIX" ] 30 | then 31 | if [ -n "$LIBEATMYDATA_TEST_FILTER" ] 32 | then 33 | # If filter variable is set, only apply prefix to those that match 34 | for x in $LIBEATMYDATA_TEST_FILTER 35 | do 36 | if [ "x$x" = "x$name" ] 37 | then 38 | prefix="$libtool_prefix $LIBEATMYDATA_TEST_PREFIX" 39 | with=" (with prefix after filter)" 40 | break 41 | fi 42 | done 43 | else 44 | prefix="$libtool_prefix $LIBEATMYDATA_TEST_PREFIX" 45 | with=" (with prefix)" 46 | fi 47 | fi 48 | 49 | # Set this to fix broken libtool test 50 | ECHO=`which echo` 51 | export ECHO 52 | 53 | if [[ $OSTYPE == *"darwin"* ]]; then 54 | ${srcdir}/start_suspended.sh "$1" "$LIBEATMYDATA_TEST_ARGS" & 55 | test_pid=$! 56 | # Wait for the test program launcher to become suspended 57 | while [[ "$(ps -o state= -p $test_pid)" != *"T+"* ]]; do 58 | sleep 1 59 | done 60 | dtruss -p $test_pid 2>> $name-test.result.run & 61 | dtruss_pid=$! 62 | kill -CONT $test_pid 63 | eret=wait $test_pid 64 | kill $dtruss_pid 65 | wait $dtruss_pid 66 | else 67 | export LD_PRELOAD=./.libs/libeatmydata.so 68 | strace -o $name-test.result.run "$1" "$LIBEATMYDATA_TEST_ARGS" 69 | eret=$? 70 | fi 71 | 72 | if [ $eret != 0 ]; then 73 | exit 2; 74 | fi 75 | 76 | SYNC_IN_TRACE='^[a-z]*sync\|O_SYNC' 77 | if [[ $OSTYPE == *"darwin"* ]]; then 78 | # 0x33 == F_FULLFSYNC 79 | SYNC_IN_TRACE="$SYNC_IN_TRACE|^fcntl\\\(.*, 0x33" 80 | fi 81 | 82 | grep "$SYNC_IN_TRACE" $name-test.result.run 83 | ret=$? 84 | rm $name-test.result.run 85 | if [ $ret == 1 ]; then 86 | exit 0; 87 | else 88 | exit 1; 89 | fi 90 | 91 | --------------------------------------------------------------------------------