1
0

Makefile 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  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 -pipe
  20. LDFLAGS = -nostdlib -shared -Wl,-Bsymbolic
  21. INC = -I./include -I./src/internal
  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/*
  41. rm -f $(ALL_TOOLS)
  42. rm -f $(GENH)
  43. include/bits/alltypes.h: include/bits/alltypes.h.sh
  44. sh $< > $@
  45. %.o: $(ARCH)/%.s
  46. $(CC) $(CFLAGS) $(INC) -c -o $@ $<
  47. %.o: %.c $(GENH)
  48. $(CC) $(CFLAGS) $(INC) -c -o $@ $<
  49. %.lo: $(ARCH)/%.s
  50. $(CC) $(CFLAGS) $(INC) $(PIC) -c -o $@ $<
  51. %.lo: %.c $(GENH)
  52. $(CC) $(CFLAGS) $(INC) $(PIC) -c -o $@ $<
  53. lib/libc.so: $(LOBJS)
  54. $(CC) $(LDFLAGS) -o $@ $(LOBJS) -lgcc
  55. $(OBJCOPY) --weaken $@
  56. lib/libc.a: $(OBJS)
  57. rm -f $@
  58. $(AR) rc $@ $(OBJS)
  59. $(RANLIB) $@
  60. $(EMPTY_LIBS):
  61. $(AR) rc $@
  62. lib/%.o: crt/%.o
  63. cp $< $@
  64. tools/musl-gcc: tools/gen-musl-gcc.sh config.mak
  65. sh $< "$(prefix)" > $@ || { rm -f $@ ; exit 1 ; }
  66. chmod +x $@
  67. $(DESTDIR)$(bindir)/%: tools/%
  68. install -D $< $@
  69. $(DESTDIR)$(prefix)/%: %
  70. install -D -m 644 $< $@
  71. .PRECIOUS: $(CRT_LIBS:lib/%=crt/%)
  72. .PHONY: all clean install