Makefile 3.0 KB

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