1
0

Makefile 3.3 KB

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