^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1) # SPDX-License-Identifier: GPL-2.0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2) PROG= aicasm
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4) OUTDIR ?= ./
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6) .SUFFIXES= .l .y .c .h
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8) CSRCS= aicasm.c aicasm_symbol.c
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9) YSRCS= aicasm_gram.y aicasm_macro_gram.y
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10) LSRCS= aicasm_scan.l aicasm_macro_scan.l
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12) GENHDRS= $(addprefix ${OUTDIR}/,aicdb.h $(YSRCS:.y=.h))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13) GENSRCS= $(addprefix ${OUTDIR}/,$(YSRCS:.y=.c) $(LSRCS:.l=.c))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15) SRCS= ${CSRCS} ${GENSRCS}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16) LIBS= -ldb
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17) clean-files:= ${GENSRCS} ${GENHDRS} $(YSRCS:.y=.output) $(PROG)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18) # Override default kernel CFLAGS. This is a userland app.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19) AICASM_CFLAGS:= -I/usr/include -I. -I$(OUTDIR)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20) LEX= flex
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21) YACC= bison
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22) YFLAGS= -d
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24) NOMAN= noman
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26) ifneq ($(HOSTCC),)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27) AICASM_CC= $(HOSTCC)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29) AICASM_CC= $(CC)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30) endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32) ifdef DEBUG
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33) CFLAGS+= -DDEBUG -g
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34) YFLAGS+= -t -v
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35) LFLAGS= -d
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36) endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38) $(PROG): $(OUTDIR) ${GENHDRS} $(SRCS)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39) $(AICASM_CC) $(AICASM_CFLAGS) $(SRCS) -o $(OUTDIR)/$(PROG) $(LIBS)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41) $(OUTDIR):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42) mkdir -p $(OUTDIR)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44) $(OUTDIR)/aicdb.h:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45) @if [ -e "/usr/include/db4/db_185.h" ]; then \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46) echo "#include <db4/db_185.h>" > $@; \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47) elif [ -e "/usr/include/db3/db_185.h" ]; then \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48) echo "#include <db3/db_185.h>" > $@; \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49) elif [ -e "/usr/include/db2/db_185.h" ]; then \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50) echo "#include <db2/db_185.h>" > $@; \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51) elif [ -e "/usr/include/db1/db_185.h" ]; then \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52) echo "#include <db1/db_185.h>" > $@; \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53) elif [ -e "/usr/include/db/db_185.h" ]; then \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54) echo "#include <db/db_185.h>" > $@; \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55) elif [ -e "/usr/include/db_185.h" ]; then \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56) echo "#include <db_185.h>" > $@; \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57) else \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 58) echo "*** Install db development libraries"; \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 59) fi
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 60)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 61) clean:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 62) rm -f $(clean-files)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 63)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 64) # Create a dependency chain in generated files
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 65) # to avoid concurrent invocations of the single
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 66) # rule that builds them all.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 67) $(OUTDIR)/aicasm_gram.c: $(OUTDIR)/aicasm_gram.h
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 68) $(OUTDIR)/aicasm_gram.c $(OUTDIR)/aicasm_gram.h: aicasm_gram.y
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 69) $(YACC) $(YFLAGS) -b $(<:.y=) $<
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 70) mv $(<:.y=).tab.c $(OUTDIR)/$(<:.y=.c)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 71) mv $(<:.y=).tab.h $(OUTDIR)/$(<:.y=.h)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 72)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 73) # Create a dependency chain in generated files
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 74) # to avoid concurrent invocations of the single
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 75) # rule that builds them all.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 76) $(OUTDIR)/aicasm_macro_gram.c: $(OUTDIR)/aicasm_macro_gram.h
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 77) $(OUTDIR)/aicasm_macro_gram.c $(OUTDIR)/aicasm_macro_gram.h: aicasm_macro_gram.y
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 78) $(YACC) $(YFLAGS) -b $(<:.y=) -p mm $<
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 79) mv $(<:.y=).tab.c $(OUTDIR)/$(<:.y=.c)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 80) mv $(<:.y=).tab.h $(OUTDIR)/$(<:.y=.h)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 81)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 82) $(OUTDIR)/aicasm_scan.c: aicasm_scan.l
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 83) $(LEX) $(LFLAGS) -o $@ $<
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 84)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 85) $(OUTDIR)/aicasm_macro_scan.c: aicasm_macro_scan.l
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 86) $(LEX) $(LFLAGS) -Pmm -o $@ $<