1
0

Makefile 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  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. SRCS = $(sort $(wildcard src/*/*.c))
  16. OBJS = $(SRCS:.c=.o)
  17. LOBJS = $(OBJS:.o=.lo)
  18. GENH = include/bits/alltypes.h
  19. CFLAGS = -Os -nostdinc -ffreestanding -std=c99 -D_XOPEN_SOURCE=700 -pipe
  20. LDFLAGS = -nostdlib -shared -Wl,-Bsymbolic
  21. INC = -I./include -I./src/internal -I./arch/$(ARCH)
  22. PIC = -fPIC
  23. AR = $(CROSS_COMPILE)ar
  24. RANLIB = $(CROSS_COMPILE)ranlib
  25. OBJCOPY = $(CROSS_COMPILE)objcopy
  26. ALL_INCLUDES = $(sort $(wildcard include/*.h include/*/*.h) $(GENH))
  27. EMPTY_LIB_NAMES = m rt pthread crypt util xnet resolv
  28. EMPTY_LIBS = $(EMPTY_LIB_NAMES:%=lib/lib%.a)
  29. CRT_LIBS = lib/crt1.o lib/crti.o lib/crtn.o
  30. LIBC_LIBS = lib/libc.a
  31. ALL_LIBS = $(LIBC_LIBS) $(CRT_LIBS) $(EMPTY_LIBS)
  32. ALL_TOOLS = tools/musl-gcc
  33. -include config.mak
  34. all: $(ALL_LIBS) $(ALL_TOOLS)
  35. install: $(ALL_LIBS:lib/%=$(DESTDIR)$(libdir)/%) $(ALL_INCLUDES:include/%=$(DESTDIR)$(includedir)/%) $(ALL_TOOLS:tools/%=$(DESTDIR)$(bindir)/%)
  36. clean:
  37. rm -f crt/*.o
  38. rm -f $(OBJS)
  39. rm -f $(LOBJS)
  40. rm -f $(ALL_LIBS) lib/*.[ao] lib/*.so
  41. rm -f $(ALL_TOOLS)
  42. rm -f $(GENH)
  43. rm -f include/bits
  44. include/bits:
  45. @test "$(ARCH)" || { echo "Please set ARCH in config.mak before running make." ; exit 1 ; }
  46. ln -sf ../arch/$(ARCH)/bits $@
  47. include/bits/alltypes.h.sh: include/bits
  48. include/bits/alltypes.h: include/bits/alltypes.h.sh
  49. sh $< > $@
  50. %.o: $(ARCH)/%.s
  51. $(CC) $(CFLAGS) $(INC) -c -o $@ $<
  52. %.o: %.c $(GENH)
  53. $(CC) $(CFLAGS) $(INC) -c -o $@ $<
  54. %.lo: $(ARCH)/%.s
  55. $(CC) $(CFLAGS) $(INC) $(PIC) -c -o $@ $<
  56. %.lo: %.c $(GENH)
  57. $(CC) $(CFLAGS) $(INC) $(PIC) -c -o $@ $<
  58. lib/libc.so: $(LOBJS)
  59. $(CC) $(LDFLAGS) -o $@ $(LOBJS) -lgcc
  60. $(OBJCOPY) --weaken $@
  61. lib/libc.a: $(OBJS)
  62. rm -f $@
  63. $(AR) rc $@ $(OBJS)
  64. $(RANLIB) $@
  65. $(EMPTY_LIBS):
  66. rm -f $@
  67. $(AR) rc $@
  68. lib/%.o: crt/%.o
  69. cp $< $@
  70. tools/musl-gcc: tools/gen-musl-gcc.sh config.mak
  71. sh $< "$(prefix)" > $@ || { rm -f $@ ; exit 1 ; }
  72. chmod +x $@
  73. $(DESTDIR)$(bindir)/%: tools/%
  74. install -D $< $@
  75. $(DESTDIR)$(prefix)/%: %
  76. install -D -m 644 $< $@
  77. .PRECIOUS: $(CRT_LIBS:lib/%=crt/%)
  78. .PHONY: all clean install