{simple,shoddy,smart} minsize-oriented linker
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

82 lines
3.0 KiB

4 years ago
3 years ago
4 years ago
4 years ago
3 years ago
3 years ago
3 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
3 years ago
3 years ago
4 years ago
4 years ago
  1. OBJDIR := obj
  2. BINDIR := bin
  3. SRCDIR := rt
  4. TESTDIR:= test
  5. NASM ?= nasm
  6. OBJCOPY ?= objcopy
  7. BITS ?= $(shell getconf LONG_BIT)
  8. # -mpreferred-stack-boundary=3 messes up the stack and kills SSE!
  9. #COPTFLAGS=-Os -fvisibility=hidden -fwhole-program -fno-plt \
  10. # -ffast-math -funsafe-math-optimizations -fno-stack-protector -fomit-frame-pointer \
  11. # -fno-exceptions -fno-unwind-tables -fno-asynchronous-unwind-tables
  12. COPTFLAGS=-Os -fno-plt -fno-stack-protector -fno-stack-check -fno-unwind-tables \
  13. -fno-asynchronous-unwind-tables -fomit-frame-pointer -ffast-math -no-pie \
  14. -fno-pic -fno-PIE -ffunction-sections -fdata-sections -fno-plt \
  15. -fmerge-all-constants -mno-fancy-math-387 -mno-ieee-fp
  16. CXXOPTFLAGS=$(COPTFLAGS) -fno-exceptions \
  17. -fno-rtti -fno-enforce-eh-specs -fnothrow-opt -fno-use-cxa-get-exception-ptr \
  18. -fno-implicit-templates -fno-threadsafe-statics -fno-use-cxa-atexit
  19. CFLAGS=-Wall -Wextra -Wpedantic -std=gnu11 -nostartfiles -fno-PIC $(COPTFLAGS) #-DUSE_DL_FINI
  20. CXXFLAGS=-Wall -Wextra -Wpedantic -std=c++11 $(CXXOPTFLAGS) -nostartfiles -fno-PIC
  21. CFLAGS += -m$(BITS) $(shell pkg-config --cflags sdl2)
  22. CXXFLAGS += -m$(BITS) $(shell pkg-config --cflags sdl2)
  23. ifeq ($(BITS),32)
  24. # I think prescott is basically nocona but 32-bit only, althought I'm not sure
  25. # if this one is optimal
  26. CFLAGS += -march=prescott
  27. else
  28. # I've heard nocona gets slightly smaller binaries than core2
  29. CFLAGS += -march=nocona
  30. endif
  31. LIBS = $(filter-out -pthread,$(shell pkg-config --libs sdl2)) -lX11 -lm -lc #-lGL
  32. PWD ?= .
  33. SMOLFLAGS = --smolrt "$(PWD)/rt" --smolld "$(PWD)/ld" \
  34. -falign-stack -fuse-interp -fifunc-support \
  35. --verbose #--keeptmp
  36. # -fuse-dnload-loader -fskip-zero-value -fuse-nx -fskip-entries -fuse-dt-debug
  37. # -fuse-dl-fini -fno-start-arg -funsafe-dynamic
  38. PYTHON3 ?= python3
  39. all: $(BINDIR)/hello-crt $(BINDIR)/sdl-crt $(BINDIR)/flag $(BINDIR)/hello-_start
  40. clean:
  41. @$(RM) -vrf $(OBJDIR) $(BINDIR)
  42. %/:
  43. @mkdir -vp "$@"
  44. .SECONDARY:
  45. $(OBJDIR)/%.lto.o: $(SRCDIR)/%.c $(OBJDIR)/
  46. $(CC) -flto $(CFLAGS) -c "$<" -o "$@"
  47. $(OBJDIR)/%.lto.o: $(TESTDIR)/%.c $(OBJDIR)/
  48. $(CC) -flto $(CFLAGS) -c "$<" -o "$@"
  49. $(OBJDIR)/%.o: $(SRCDIR)/%.c $(OBJDIR)/
  50. $(CC) $(CFLAGS) -c "$<" -o "$@"
  51. $(OBJDIR)/%.o: $(TESTDIR)/%.c $(OBJDIR)/
  52. $(CC) $(CFLAGS) -c "$<" -o "$@"
  53. $(BINDIR)/%.dbg $(BINDIR)/%: $(OBJDIR)/%.o $(BINDIR)/
  54. $(PYTHON3) ./smold.py --debugout $(SMOLFLAGS) --ldflags=-Wl,-Map=$(BINDIR)/$*.map $(LIBS) "$<" "$@.dbg"
  55. $(PYTHON3) ./smold.py $(SMOLFLAGS) --ldflags=-Wl,-Map=$(BINDIR)/$*.map $(LIBS) "$<" "$@"
  56. $(PYTHON3) ./smoltrunc.py "$@" "$(OBJDIR)/$(notdir $@)" && mv "$(OBJDIR)/$(notdir $@)" "$@" && chmod +x "$@"
  57. $(BINDIR)/%-crt.dbg $(BINDIR)/%-crt: $(OBJDIR)/%.lto.o $(OBJDIR)/crt1.lto.o $(BINDIR)/
  58. $(PYTHON3) ./smold.py --debugout $(SMOLFLAGS) --ldflags=-Wl,-Map=$(BINDIR)/$*-crt.map $(LIBS) "$<" $(OBJDIR)/crt1.lto.o "$@.dbg"
  59. $(PYTHON3) ./smold.py $(SMOLFLAGS) --ldflags=-Wl,-Map=$(BINDIR)/$*-crt.map $(LIBS) "$<" $(OBJDIR)/crt1.lto.o "$@"
  60. $(PYTHON3) ./smoltrunc.py "$@" "$(OBJDIR)/$(notdir $@)" && mv "$(OBJDIR)/$(notdir $@)" "$@" && chmod +x "$@"
  61. .PHONY: all clean