Makefile 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  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
  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: install-libs install-headers install-tools
  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. src/ldso/dynlink.lo: arch/$(ARCH)/reloc.h
  63. %.o: $(ARCH)/%.s
  64. $(CC) $(CFLAGS_ALL_STATIC) -c -o $@ $<
  65. %.o: %.c $(GENH) $(IMPH)
  66. $(CC) $(CFLAGS_ALL_STATIC) -c -o $@ $<
  67. %.lo: $(ARCH)/%.s
  68. $(CC) $(CFLAGS_ALL_SHARED) -c -o $@ $<
  69. %.lo: %.c $(GENH) $(IMPH)
  70. $(CC) $(CFLAGS_ALL_SHARED) -c -o $@ $<
  71. lib/libc.so: $(LOBJS)
  72. $(CC) $(CFLAGS_ALL_SHARED) $(LDFLAGS) -nostdlib -shared \
  73. -Wl,-e,_start -Wl,-Bsymbolic-functions \
  74. -Wl,-soname=libc.so -o $@ $(LOBJS) $(LIBCC)
  75. lib/libc.a: $(OBJS)
  76. rm -f $@
  77. $(AR) rc $@ $(OBJS)
  78. $(RANLIB) $@
  79. $(EMPTY_LIBS):
  80. rm -f $@
  81. $(AR) rc $@
  82. lib/%.o: crt/%.o
  83. cp $< $@
  84. lib/musl-gcc.specs: tools/musl-gcc.specs.sh config.mak
  85. sh $< "$(includedir)" "$(libdir)" "$(LDSO_PATHNAME)" > $@
  86. tools/musl-gcc: config.mak
  87. printf '#!/bin/sh\nexec gcc "$$@" -specs "%s/musl-gcc.specs"\n' "$(libdir)" > $@
  88. chmod +x $@
  89. $(DESTDIR)$(bindir)/%: tools/%
  90. install -D $< $@
  91. $(DESTDIR)$(libdir)/%.so: lib/%.so
  92. install -D -m 755 $< $@
  93. $(DESTDIR)$(libdir)/%: lib/%
  94. install -D -m 644 $< $@
  95. $(DESTDIR)$(includedir)/%: include/%
  96. install -D -m 644 $< $@
  97. $(DESTDIR)$(LDSO_PATHNAME): $(DESTDIR)$(syslibdir)
  98. ln -sf $(libdir)/libc.so $@ || true
  99. $(DESTDIR)$(syslibdir):
  100. install -d -m 755 $(DESTDIR)$(syslibdir)
  101. install-libs: $(ALL_LIBS:lib/%=$(DESTDIR)$(libdir)/%) $(if $(SHARED_LIBS),$(DESTDIR)$(LDSO_PATHNAME),)
  102. install-headers: $(ALL_INCLUDES:include/%=$(DESTDIR)$(includedir)/%)
  103. install-tools: $(ALL_TOOLS:tools/%=$(DESTDIR)$(bindir)/%)
  104. .PRECIOUS: $(CRT_LIBS:lib/%=crt/%)
  105. .PHONY: all clean install install-libs install-headers install-tools