flisp/Makefile
2025-03-30 00:07:15 +01:00

73 lines
1.6 KiB
Makefile
Executable file

# /!\ Warning /!\
# Parallel build doesn't work with w64devkit
OUTNAME = flisp
CFLAGS = -std=c99 -O0 -flto -Wall -Wextra -g -pipe -Wno-cast-function-type
CC = gcc
LDFLAGS_UNIX = -lm
LDFLAGS_WIN = -lm
# ===== End of what should be edited =====
OUTPUT = "${OUTNAME}.amd64"
LDFLAGS = $(LDFLAGS_UNIX)
BUILD_DIR = build
SRC_DIR = src
OBJS = $(patsubst $(SRC_DIR)/%.c,build-tmp/%.o,$(wildcard $(SRC_DIR)/*.c))
all: | builddir yacc build builddir2
windef:
$(eval OUTPUT = "$(OUTNAME).exe")
$(eval BUILD_DIR = build-win)
$(eval LDFLAGS = $(LDFLAGS_WIN))
$(eval CFLAGS += -mno-ms-bitfields -D win)
builddir:
@- mkdir $(BUILD_DIR)
@- mkdir build-tmp
@- rm -rf $(wildcard build-tmp/*)
@- mv $(wildcard $(BUILD_DIR)/*.o) build-tmp/
yacc: src/parser.y src/parser.l
cd src && bison -y -d parser.y && lex parser.l
$(CC) -c src/y.tab.c -o build-tmp/y.tab.o $(CFLAGS)
$(CC) -c src/lex.yy.c -o build-tmp/lex.yy.o $(CFLAGS)
ifneq ($(filter $(OBJS), build-tmp/y.tab.o),build-tmp/y.tab.o)
$(eval OBJS += build-tmp/y.tab.o build-tmp/lex.yy.o)
endif
build-tmp/%.o : $(SRC_DIR)/%.c
${CC} -c $< -o $@ ${CFLAGS}
build: $(OBJS)
${CC} ${CFLAGS} -o ${OUTPUT} $(OBJS) ${LDFLAGS}
builddir2:
@mv $(OBJS) $(BUILD_DIR)
@rm -rf build-tmp
win: | windef all
testwin: win
./$(OUTPUT)
test: all
@echo "===== Program output ====="
@./${OUTPUT}
clean:
- rm -rf ${BUILD_DIR}
- rm -rf build-win
- rm -rf build-tmp
- rm "$(OUTNAME).amd64" "$(OUTNAME).exe"
- rm src/lex.yy.c src/y.tab.c src/y.tab.h
.NOTPARALLEL: builddir yacc builddir2
.PHONY: all test clean win windef builddir builddir2 testwin yacc