Makefile 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  1. #
  2. # Makefile for musl (requires GNU make)
  3. #
  4. # This is how simple every makefile should be...
  5. # No, I take that back - actually most should be less than half this size.
  6. #
  7. # Use config.mak to override any of the following variables.
  8. # Do not make changes here.
  9. #
  10. exec_prefix = /usr/local
  11. bindir = $(exec_prefix)/bin
  12. prefix = /usr/local/musl
  13. includedir = $(prefix)/include
  14. libdir = $(prefix)/lib
  15. syslibdir = /lib
  16. SRCS = $(sort $(wildcard src/*/*.c))
  17. OBJS = $(SRCS:.c=.o)
  18. LOBJS = $(OBJS:.o=.lo)
  19. GENH = include/bits/alltypes.h
  20. LDFLAGS =
  21. CPPFLAGS =
  22. CFLAGS = -Os -pipe
  23. CFLAGS_C99FSE = -std=c99 -ffreestanding -nostdinc
  24. CFLAGS_ALL = $(CFLAGS_C99FSE)
  25. CFLAGS_ALL += -D_XOPEN_SOURCE=700 -I./src/internal -I./include -I./arch/$(ARCH)
  26. CFLAGS_ALL += $(CPPFLAGS) $(CFLAGS)
  27. CFLAGS_ALL_STATIC = $(CFLAGS_ALL)
  28. CFLAGS_ALL_SHARED = $(CFLAGS_ALL) -fPIC -DSHARED -O3
  29. AR = $(CROSS_COMPILE)ar
  30. RANLIB = $(CROSS_COMPILE)ranlib
  31. ALL_INCLUDES = $(sort $(wildcard include/*.h include/*/*.h) $(GENH))
  32. EMPTY_LIB_NAMES = m rt pthread crypt util xnet resolv dl
  33. EMPTY_LIBS = $(EMPTY_LIB_NAMES:%=lib/lib%.a)
  34. CRT_LIBS = lib/crt1.o lib/Scrt1.o lib/crti.o lib/crtn.o
  35. STATIC_LIBS = lib/libc.a
  36. SHARED_LIBS = lib/libc.so
  37. TOOL_LIBS = lib/musl-gcc.specs
  38. ALL_LIBS = $(CRT_LIBS) $(STATIC_LIBS) $(SHARED_LIBS) $(EMPTY_LIBS) $(TOOL_LIBS)
  39. ALL_TOOLS = tools/musl-gcc
  40. LDSO_PATHNAME = $(syslibdir)/ld-musl-$(ARCH).so.1
  41. -include config.mak
  42. all: $(ALL_LIBS) $(ALL_TOOLS)
  43. install: $(ALL_LIBS:lib/%=$(DESTDIR)$(libdir)/%) $(ALL_INCLUDES:include/%=$(DESTDIR)$(includedir)/%) $(ALL_TOOLS:tools/%=$(DESTDIR)$(bindir)/%) $(if $(SHARED_LIBS),$(DESTDIR)$(LDSO_PATHNAME),)
  44. clean:
  45. rm -f crt/*.o
  46. rm -f $(OBJS)
  47. rm -f $(LOBJS)
  48. rm -f $(ALL_LIBS) lib/*.[ao] lib/*.so
  49. rm -f $(ALL_TOOLS)
  50. rm -f $(GENH)
  51. rm -f include/bits
  52. distclean: clean
  53. rm -f config.mak
  54. include/bits:
  55. @test "$(ARCH)" || { echo "Please set ARCH in config.mak before running make." ; exit 1 ; }
  56. ln -sf ../arch/$(ARCH)/bits $@
  57. include/bits/alltypes.h.sh: include/bits
  58. include/bits/alltypes.h: include/bits/alltypes.h.sh
  59. sh $< > $@
  60. %.o: $(ARCH)/%.s
  61. $(CC) $(CFLAGS_ALL_STATIC) -c -o $@ $<
  62. %.o: %.c $(GENH)
  63. $(CC) $(CFLAGS_ALL_STATIC) -c -o $@ $<
  64. %.lo: $(ARCH)/%.s
  65. $(CC) $(CFLAGS_ALL_SHARED) -c -o $@ $<
  66. %.lo: %.c $(GENH)
  67. $(CC) $(CFLAGS_ALL_SHARED) -c -o $@ $<
  68. lib/libc.so: $(LOBJS)
  69. $(CC) $(CFLAGS_ALL_SHARED) $(LDFLAGS) -nostdlib -shared \
  70. -Wl,-e,_start -Wl,-Bsymbolic-functions \
  71. -Wl,-soname=libc.so -o $@ $(LOBJS) -lgcc
  72. lib/libc.a: $(OBJS)
  73. rm -f $@
  74. $(AR) rc $@ $(OBJS)
  75. $(RANLIB) $@
  76. $(EMPTY_LIBS):
  77. rm -f $@
  78. $(AR) rc $@
  79. lib/%.o: crt/%.o
  80. cp $< $@
  81. lib/musl-gcc.specs: tools/musl-gcc.specs.sh config.mak
  82. sh $< "$(includedir)" "$(libdir)" "$(LDSO_PATHNAME)" > $@
  83. tools/musl-gcc: config.mak
  84. printf '#!/bin/sh\nexec gcc "$$@" -specs "%s/musl-gcc.specs"\n' "$(libdir)" > $@
  85. chmod +x $@
  86. $(DESTDIR)$(bindir)/%: tools/%
  87. install -D $< $@
  88. $(DESTDIR)$(libdir)/%.so: lib/%.so
  89. install -D -m 755 $< $@
  90. $(DESTDIR)$(libdir)/%: lib/%
  91. install -D -m 644 $< $@
  92. $(DESTDIR)$(includedir)/%: include/%
  93. install -D -m 644 $< $@
  94. $(DESTDIR)$(LDSO_PATHNAME): lib/libc.so
  95. install -d -m 755 $(DESTDIR)$(syslibdir) || true
  96. ln -sf $(libdir)/libc.so $@ || true
  97. .PRECIOUS: $(CRT_LIBS:lib/%=crt/%)
  98. .PHONY: all clean install