update.sh 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. #!/bin/sh -e
  2. unweak() {
  3. sed --in-place --expression 's/DEF_WEAK(.\+);//g' "$1"
  4. }
  5. get_string_method() {
  6. curl "https://raw.githubusercontent.com/openbsd/src/master/lib/libc/string/$1" --output "$1" && unweak "$1"
  7. }
  8. fix_tabs() {
  9. sed --in-place --expression 's/\t/ /g' "$1"
  10. }
  11. fix_decls() {
  12. sed --in-place --expression 's/__BEGIN_DECLS/#ifdef __cplusplus\nextern "C" {\n#endif/g' "$1"
  13. sed --in-place --expression 's/__END_DECLS/#ifdef __cplusplus\n} \/\/ extern "C"\n#endif/g' "$1"
  14. }
  15. get_string_method "strlcpy.c"
  16. get_string_method "strlcat.c"
  17. get_string_method "strsep.c"
  18. # strcasestr uses strncasecmp, which is platform dependent, so include local string.h
  19. get_string_method "strcasestr.c" && sed --in-place 's/#include <string.h>/#include "string.h"/g' "strcasestr.c"
  20. get_string_method "memrchr.c"
  21. get_string_method "stpcpy.c"
  22. mkdir -p include/windows/sys
  23. curl "https://raw.githubusercontent.com/openbsd/src/master/sys/sys/queue.h" --output "include/windows/sys/queue.h"
  24. mkdir -p include/readpassphrase
  25. curl "https://raw.githubusercontent.com/openbsd/src/master/include/readpassphrase.h" --output "include/readpassphrase/readpassphrase.h" && fix_decls "include/readpassphrase/readpassphrase.h"
  26. curl "https://raw.githubusercontent.com/openbsd/src/master/lib/libc/gen/readpassphrase.c" --output "readpassphrase.c" && unweak "readpassphrase.c" && fix_tabs "readpassphrase.c"
  27. curl "https://raw.githubusercontent.com/freebsd/freebsd/master/include/glob.h" --output "glob.h"
  28. curl "https://raw.githubusercontent.com/freebsd/freebsd/master/lib/libc/gen/glob.c" --output "glob.c"
  29. curl "https://raw.githubusercontent.com/openbsd/src/master/lib/libc/stdlib/reallocarray.c" --output "reallocarray.c" && unweak "reallocarray.c"
  30. > "collate.h"
  31. > "stdlib.h"
  32. > "unistd.h"
  33. mkdir -p include/uchar
  34. curl "https://git.musl-libc.org/cgit/musl/plain/include/uchar.h" --output "include/uchar/uchar.h"
  35. # TODO: provide c16rtomb, mbrtoc16, c32rtomb, mbrtoc32 implementations for uchar
  36. # if any code actually needs them
  37. mkdir -p include/random/sys
  38. curl "https://git.musl-libc.org/cgit/musl/plain/include/sys/random.h" --output "include/random/sys/random.h"
  39. curl "https://git.musl-libc.org/cgit/musl/plain/src/linux/getrandom.c" --output "getrandom.c"
  40. curl "https://git.musl-libc.org/cgit/musl/plain/src/linux/memfd_create.c" --output "memfd_create.c"
  41. # WARN: do not use github.com/morristech/android-ifaddrs, it is a long-ago abandoned fork
  42. curl "https://raw.githubusercontent.com/oliviertilmans/android-ifaddrs/master/ifaddrs.c" --output "ifaddrs.c"
  43. curl "https://raw.githubusercontent.com/oliviertilmans/android-ifaddrs/master/ifaddrs.h" --output "include/ifaddrs/ifaddrs.h"
  44. # apply patches if necessary
  45. for patch in patches/*.patch; do
  46. echo "Applying patch from $patch"
  47. patch -p1 < $patch
  48. done