18c2ecf20Sopenharmony_ci# SPDX-License-Identifier: GPL-2.0
28c2ecf20Sopenharmony_ciPROG=	aicasm
38c2ecf20Sopenharmony_ci
48c2ecf20Sopenharmony_ciOUTDIR ?= ./
58c2ecf20Sopenharmony_ci
68c2ecf20Sopenharmony_ci.SUFFIXES= .l .y .c .h
78c2ecf20Sopenharmony_ci
88c2ecf20Sopenharmony_ciCSRCS=	aicasm.c aicasm_symbol.c
98c2ecf20Sopenharmony_ciYSRCS=	aicasm_gram.y aicasm_macro_gram.y
108c2ecf20Sopenharmony_ciLSRCS=	aicasm_scan.l aicasm_macro_scan.l
118c2ecf20Sopenharmony_ci
128c2ecf20Sopenharmony_ciGENHDRS=	$(addprefix ${OUTDIR}/,aicdb.h $(YSRCS:.y=.h))
138c2ecf20Sopenharmony_ciGENSRCS=	$(addprefix ${OUTDIR}/,$(YSRCS:.y=.c) $(LSRCS:.l=.c))
148c2ecf20Sopenharmony_ci
158c2ecf20Sopenharmony_ciSRCS=	${CSRCS} ${GENSRCS}
168c2ecf20Sopenharmony_ciLIBS=	-ldb
178c2ecf20Sopenharmony_ciclean-files:= ${GENSRCS} ${GENHDRS} $(YSRCS:.y=.output) $(PROG)
188c2ecf20Sopenharmony_ci# Override default kernel CFLAGS.  This is a userland app.
198c2ecf20Sopenharmony_ciAICASM_CFLAGS:= -I/usr/include -I. -I$(OUTDIR)
208c2ecf20Sopenharmony_ciLEX= flex
218c2ecf20Sopenharmony_ciYACC= bison
228c2ecf20Sopenharmony_ciYFLAGS= -d
238c2ecf20Sopenharmony_ci
248c2ecf20Sopenharmony_ciNOMAN=	noman
258c2ecf20Sopenharmony_ci
268c2ecf20Sopenharmony_ciifneq ($(HOSTCC),)
278c2ecf20Sopenharmony_ciAICASM_CC= $(HOSTCC)
288c2ecf20Sopenharmony_cielse
298c2ecf20Sopenharmony_ciAICASM_CC= $(CC)
308c2ecf20Sopenharmony_ciendif
318c2ecf20Sopenharmony_ci
328c2ecf20Sopenharmony_ciifdef DEBUG
338c2ecf20Sopenharmony_ciCFLAGS+= -DDEBUG -g
348c2ecf20Sopenharmony_ciYFLAGS+= -t -v
358c2ecf20Sopenharmony_ciLFLAGS= -d
368c2ecf20Sopenharmony_ciendif
378c2ecf20Sopenharmony_ci
388c2ecf20Sopenharmony_ci$(PROG):  $(OUTDIR) ${GENHDRS} $(SRCS)
398c2ecf20Sopenharmony_ci	$(AICASM_CC) $(AICASM_CFLAGS) $(SRCS) -o $(OUTDIR)/$(PROG) $(LIBS)
408c2ecf20Sopenharmony_ci
418c2ecf20Sopenharmony_ci$(OUTDIR):
428c2ecf20Sopenharmony_ci	mkdir -p $(OUTDIR)
438c2ecf20Sopenharmony_ci
448c2ecf20Sopenharmony_ci$(OUTDIR)/aicdb.h:
458c2ecf20Sopenharmony_ci	@if [ -e "/usr/include/db4/db_185.h" ]; then		\
468c2ecf20Sopenharmony_ci		echo "#include <db4/db_185.h>" > $@;	\
478c2ecf20Sopenharmony_ci	 elif [ -e "/usr/include/db3/db_185.h" ]; then		\
488c2ecf20Sopenharmony_ci		echo "#include <db3/db_185.h>" > $@;	\
498c2ecf20Sopenharmony_ci	 elif [ -e "/usr/include/db2/db_185.h" ]; then		\
508c2ecf20Sopenharmony_ci		echo "#include <db2/db_185.h>" > $@;	\
518c2ecf20Sopenharmony_ci	 elif [ -e "/usr/include/db1/db_185.h" ]; then		\
528c2ecf20Sopenharmony_ci		echo "#include <db1/db_185.h>" > $@;	\
538c2ecf20Sopenharmony_ci	 elif [ -e "/usr/include/db/db_185.h" ]; then		\
548c2ecf20Sopenharmony_ci		echo "#include <db/db_185.h>" > $@;	\
558c2ecf20Sopenharmony_ci	 elif [ -e "/usr/include/db_185.h" ]; then		\
568c2ecf20Sopenharmony_ci		echo "#include <db_185.h>" > $@;		\
578c2ecf20Sopenharmony_ci	 else							\
588c2ecf20Sopenharmony_ci		echo "*** Install db development libraries";	\
598c2ecf20Sopenharmony_ci	 fi
608c2ecf20Sopenharmony_ci
618c2ecf20Sopenharmony_ciclean:
628c2ecf20Sopenharmony_ci	rm -f $(clean-files)
638c2ecf20Sopenharmony_ci
648c2ecf20Sopenharmony_ci# Create a dependency chain in generated files
658c2ecf20Sopenharmony_ci# to avoid concurrent invocations of the single
668c2ecf20Sopenharmony_ci# rule that builds them all.
678c2ecf20Sopenharmony_ci$(OUTDIR)/aicasm_gram.c: $(OUTDIR)/aicasm_gram.h
688c2ecf20Sopenharmony_ci$(OUTDIR)/aicasm_gram.c $(OUTDIR)/aicasm_gram.h: aicasm_gram.y
698c2ecf20Sopenharmony_ci	$(YACC) $(YFLAGS) -b $(<:.y=) $<
708c2ecf20Sopenharmony_ci	mv $(<:.y=).tab.c $(OUTDIR)/$(<:.y=.c)
718c2ecf20Sopenharmony_ci	mv $(<:.y=).tab.h $(OUTDIR)/$(<:.y=.h)
728c2ecf20Sopenharmony_ci
738c2ecf20Sopenharmony_ci# Create a dependency chain in generated files
748c2ecf20Sopenharmony_ci# to avoid concurrent invocations of the single
758c2ecf20Sopenharmony_ci# rule that builds them all.
768c2ecf20Sopenharmony_ci$(OUTDIR)/aicasm_macro_gram.c: $(OUTDIR)/aicasm_macro_gram.h
778c2ecf20Sopenharmony_ci$(OUTDIR)/aicasm_macro_gram.c $(OUTDIR)/aicasm_macro_gram.h: aicasm_macro_gram.y
788c2ecf20Sopenharmony_ci	$(YACC) $(YFLAGS) -b $(<:.y=) -p mm $<
798c2ecf20Sopenharmony_ci	mv $(<:.y=).tab.c $(OUTDIR)/$(<:.y=.c)
808c2ecf20Sopenharmony_ci	mv $(<:.y=).tab.h $(OUTDIR)/$(<:.y=.h)
818c2ecf20Sopenharmony_ci
828c2ecf20Sopenharmony_ci$(OUTDIR)/aicasm_scan.c: aicasm_scan.l
838c2ecf20Sopenharmony_ci	$(LEX) $(LFLAGS) -o $@ $<
848c2ecf20Sopenharmony_ci
858c2ecf20Sopenharmony_ci$(OUTDIR)/aicasm_macro_scan.c: aicasm_macro_scan.l
868c2ecf20Sopenharmony_ci	$(LEX) $(LFLAGS) -Pmm -o $@ $<
87