Makefile 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  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. IMPH = src/internal/stdio_impl.h src/internal/pthread_impl.h src/internal/libc.h
  21. LDFLAGS =
  22. LIBCC = -lgcc
  23. CPPFLAGS =
  24. CFLAGS = -Os -pipe
  25. CFLAGS_C99FSE = -std=c99 -ffreestanding -nostdinc
  26. CFLAGS_ALL = $(CFLAGS_C99FSE)
  27. CFLAGS_ALL += -D_XOPEN_SOURCE=700 -I./arch/$(ARCH) -I./src/internal -I./include
  28. CFLAGS_ALL += $(CPPFLAGS) $(CFLAGS)
  29. CFLAGS_ALL_STATIC = $(CFLAGS_ALL)
  30. CFLAGS_ALL_SHARED = $(CFLAGS_ALL) -fPIC -DSHARED -O3
  31. AR = $(CROSS_COMPILE)ar
  32. RANLIB = $(CROSS_COMPILE)ranlib
  33. ALL_INCLUDES = $(sort $(wildcard include/*.h include/*/*.h) $(GENH))
  34. EMPTY_LIB_NAMES = m rt pthread crypt util xnet resolv dl
  35. EMPTY_LIBS = $(EMPTY_LIB_NAMES:%=lib/lib%.a)
  36. CRT_LIBS = lib/crt1.o lib/Scrt1.o lib/crti.o lib/crtn.o
  37. STATIC_LIBS = lib/libc.a
  38. SHARED_LIBS = lib/libc.so
  39. TOOL_LIBS = lib/musl-gcc.specs
  40. ALL_LIBS = $(CRT_LIBS) $(STATIC_LIBS) $(SHARED_LIBS) $(EMPTY_LIBS) $(TOOL_LIBS)
  41. ALL_TOOLS = tools/musl-gcc
  42. LDSO_PATHNAME = $(syslibdir)/ld-musl-$(ARCH).so.1
  43. -include config.mak
  44. all: $(ALL_LIBS) $(ALL_TOOLS)
  45. install: $(ALL_LIBS:lib/%=$(DESTDIR)$(libdir)/%) $(ALL_INCLUDES:include/%=$(DESTDIR)$(includedir)/%) $(ALL_TOOLS:tools/%=$(DESTDIR)$(bindir)/%) $(if $(SHARED_LIBS),$(DESTDIR)$(LDSO_PATHNAME),)
  46. clean:
  47. rm -f crt/*.o
  48. rm -f $(OBJS)
  49. rm -f $(LOBJS)
  50. rm -f $(ALL_LIBS) lib/*.[ao] lib/*.so
  51. rm -f $(ALL_TOOLS)
  52. rm -f $(GENH)
  53. rm -f include/bits
  54. distclean: clean
  55. rm -f config.mak
  56. include/bits:
  57. @test "$(ARCH)" || { echo "Please set ARCH in config.mak before running make." ; exit 1 ; }
  58. ln -sf ../arch/$(ARCH)/bits $@
  59. include/bits/alltypes.h.sh: include/bits
  60. include/bits/alltypes.h: include/bits/alltypes.h.sh
  61. sh $< > $@
  62. %.o: $(ARCH)/%.s
  63. $(CC) $(CFLAGS_ALL_STATIC) -c -o $@ $<
  64. %.o: %.c $(GENH) $(IMPH)
  65. $(CC) $(CFLAGS_ALL_STATIC) -c -o $@ $<
  66. %.lo: $(ARCH)/%.s
  67. $(CC) $(CFLAGS_ALL_SHARED) -c -o $@ $<
  68. %.lo: %.c $(GENH) $(IMPH)
  69. $(CC) $(CFLAGS_ALL_SHARED) -c -o $@ $<
  70. lib/libc.so: $(LOBJS)
  71. $(CC) $(CFLAGS_ALL_SHARED) $(LDFLAGS) -nostdlib -shared \
  72. -Wl,-e,_start -Wl,-Bsymbolic-functions \
  73. -Wl,-soname=libc.so -o $@ $(LOBJS) $(LIBCC)
  74. lib/libc.a: $(OBJS)
  75. rm -f $@
  76. $(AR) rc $@ $(OBJS)
  77. $(RANLIB) $@
  78. $(EMPTY_LIBS):
  79. rm -f $@
  80. $(AR) rc $@
  81. lib/%.o: crt/%.o
  82. cp $< $@
  83. lib/musl-gcc.specs: tools/musl-gcc.specs.sh config.mak
  84. sh $< "$(includedir)" "$(libdir)" "$(LDSO_PATHNAME)" > $@
  85. tools/musl-gcc: config.mak
  86. printf '#!/bin/sh\nexec gcc "$$@" -specs "%s/musl-gcc.specs"\n' "$(libdir)" > $@
  87. chmod +x $@
  88. $(DESTDIR)$(bindir)/%: tools/%
  89. install -D $< $@
  90. $(DESTDIR)$(libdir)/%.so: lib/%.so
  91. install -D -m 755 $< $@
  92. $(DESTDIR)$(libdir)/%: lib/%
  93. install -D -m 644 $< $@
  94. $(DESTDIR)$(includedir)/%: include/%
  95. install -D -m 644 $< $@
  96. $(DESTDIR)$(LDSO_PATHNAME): $(DESTDIR)$(syslibdir)
  97. ln -sf $(libdir)/libc.so $@ || true
  98. $(DESTDIR)$(syslibdir):
  99. install -d -m 755 $(DESTDIR)$(syslibdir)
  100. .PRECIOUS: $(CRT_LIBS:lib/%=crt/%)
  101. .PHONY: all clean install