smol/Makefile

81 lines
2.8 KiB
Makefile
Raw Normal View History

OBJDIR := obj
BINDIR := bin
SRCDIR := rt
TESTDIR:= test
2018-04-11 22:14:36 +00:00
NASM ?= nasm
2020-08-22 01:41:25 +00:00
OBJCOPY ?= objcopy
2019-01-30 23:14:36 +00:00
BITS ?= $(shell getconf LONG_BIT)
# -mpreferred-stack-boundary=3 messes up the stack and kills SSE!
2019-03-06 15:26:20 +00:00
#COPTFLAGS=-Os -fvisibility=hidden -fwhole-program -fno-plt \
# -ffast-math -funsafe-math-optimizations -fno-stack-protector -fomit-frame-pointer \
# -fno-exceptions -fno-unwind-tables -fno-asynchronous-unwind-tables
2019-03-06 16:53:02 +00:00
COPTFLAGS=-Os -fno-plt -fno-stack-protector -fno-stack-check -fno-unwind-tables \
2019-03-06 15:26:20 +00:00
-fno-asynchronous-unwind-tables -fomit-frame-pointer -ffast-math -no-pie \
2020-05-03 17:07:18 +00:00
-fno-pic -fno-PIE -ffunction-sections -fdata-sections -fno-plt \
-fmerge-all-constants -mno-fancy-math-387 -mno-ieee-fp
2019-03-06 15:26:20 +00:00
CXXOPTFLAGS=$(COPTFLAGS) -fno-exceptions \
2018-04-11 22:14:36 +00:00
-fno-rtti -fno-enforce-eh-specs -fnothrow-opt -fno-use-cxa-get-exception-ptr \
-fno-implicit-templates -fno-threadsafe-statics -fno-use-cxa-atexit
CFLAGS=-Wall -Wextra -Wpedantic -std=gnu11 -nostartfiles -fno-PIC $(COPTFLAGS) #-DUSE_DL_FINI
2018-04-11 22:14:36 +00:00
CXXFLAGS=-Wall -Wextra -Wpedantic -std=c++11 $(CXXOPTFLAGS) -nostartfiles -fno-PIC
CFLAGS += -m$(BITS) $(shell pkg-config --cflags sdl2)
CXXFLAGS += -m$(BITS) $(shell pkg-config --cflags sdl2)
2019-01-30 23:14:36 +00:00
ifeq ($(BITS),32)
2020-05-03 17:07:18 +00:00
# I think prescott is basically nocona but 32-bit only, althought I'm not sure
# if this one is optimal
CFLAGS += -march=prescott
2019-01-30 23:14:36 +00:00
else
2020-05-03 17:07:18 +00:00
# I've heard nocona gets slightly smaller binaries than core2
CFLAGS += -march=nocona
2019-01-30 23:14:36 +00:00
endif
2020-08-22 01:41:25 +00:00
LIBS = $(filter-out -pthread,$(shell pkg-config --libs sdl2)) -lX11 -lm -lc #-lGL
PWD ?= .
2018-04-11 22:14:36 +00:00
SMOLFLAGS = --smolrt "$(PWD)/rt" --smolld "$(PWD)/ld" \
2020-08-22 01:41:25 +00:00
-falign-stack -fuse-interp -fifunc-support \
--verbose #--keeptmp
# -fuse-dnload-loader -fskip-zero-value -fuse-nx -fskip-entries -fuse-dt-debug
# -fuse-dl-fini -fno-start-arg -funsafe-dynamic
PYTHON3 ?= python3
2018-04-11 22:14:36 +00:00
all: $(BINDIR)/hello-crt $(BINDIR)/sdl-crt $(BINDIR)/flag $(BINDIR)/hello-_start
2018-04-11 22:14:36 +00:00
clean:
@$(RM) -vrf $(OBJDIR) $(BINDIR)
2018-04-11 22:14:36 +00:00
%/:
@mkdir -vp "$@"
2018-04-11 22:14:36 +00:00
.SECONDARY:
2019-03-06 15:26:20 +00:00
$(OBJDIR)/%.lto.o: $(SRCDIR)/%.c $(OBJDIR)/
$(CC) -flto $(CFLAGS) -c "$<" -o "$@"
$(OBJDIR)/%.lto.o: $(TESTDIR)/%.c $(OBJDIR)/
$(CC) -flto $(CFLAGS) -c "$<" -o "$@"
$(OBJDIR)/%.o: $(SRCDIR)/%.c $(OBJDIR)/
2019-01-30 23:14:36 +00:00
$(CC) $(CFLAGS) -c "$<" -o "$@"
$(OBJDIR)/%.o: $(TESTDIR)/%.c $(OBJDIR)/
2019-01-30 23:14:36 +00:00
$(CC) $(CFLAGS) -c "$<" -o "$@"
2020-08-22 01:41:25 +00:00
$(BINDIR)/%.dbg $(BINDIR)/%: $(OBJDIR)/%.o $(BINDIR)/
$(PYTHON3) ./smold.py --debugout "$@.dbg" $(SMOLFLAGS) --ldflags=-Wl,-Map=$(BINDIR)/$*.map $(LIBS) "$<" "$@"
$(PYTHON3) ./smoltrunc.py "$@" "$(OBJDIR)/$(notdir $@)" && mv "$(OBJDIR)/$(notdir $@)" "$@" && chmod +x "$@"
2018-04-11 22:14:36 +00:00
2020-08-22 01:41:25 +00:00
$(BINDIR)/%-crt.dbg $(BINDIR)/%-crt: $(OBJDIR)/%.lto.o $(OBJDIR)/crt1.lto.o $(BINDIR)/
$(PYTHON3) ./smold.py --debugout "$@.dbg" $(SMOLFLAGS) --ldflags=-Wl,-Map=$(BINDIR)/$*-crt.map $(LIBS) "$<" $(OBJDIR)/crt1.lto.o "$@"
$(PYTHON3) ./smoltrunc.py "$@" "$(OBJDIR)/$(notdir $@)" && mv "$(OBJDIR)/$(notdir $@)" "$@" && chmod +x "$@"
.PHONY: all clean
2018-04-11 22:14:36 +00:00