Build system: share rules to compile C files (#8930)
This commit deduplicates some of the Makefile rules used to compile C files. Rather than having one such rule per Makefile for each directory containing C files, the relevant rules are moved to Makefile.common.in.
This commit is contained in:
parent
24cf2f926f
commit
5ec649f0cb
|
@ -15,7 +15,8 @@
|
|||
#* *
|
||||
#**************************************************************************
|
||||
|
||||
# This makefile contains common definitions shared by other Makefiles
|
||||
# This makefile contains common definitions and rules shared by
|
||||
# other Makefiles
|
||||
# We assume that Makefile.config has already been included
|
||||
|
||||
INSTALL ?= @INSTALL@
|
||||
|
@ -67,3 +68,11 @@ endif
|
|||
|
||||
# By default, request ocamllex to be quiet
|
||||
OCAMLLEX_FLAGS ?= -q
|
||||
|
||||
# The rule to compile C files
|
||||
|
||||
# This rule is similar to GNU make's implicit rule, except that it is more
|
||||
# general (it supports both .o and .obj)
|
||||
|
||||
%.$(O): %.c
|
||||
$(CC) -c $(OC_CFLAGS) $(OC_CPPFLAGS) $(OUTPUTOBJ)$@ $<
|
||||
|
|
|
@ -220,9 +220,6 @@ ocamltest.opt$(EXE): $(native_modules)
|
|||
%.ml: %.mll
|
||||
$(ocamllex) $(OCAMLLEX_FLAGS) $<
|
||||
|
||||
%.$(O): %.c
|
||||
$(CC) -c $(OC_CFLAGS) $(OC_CPPFLAGS) $(OUTPUTOBJ)$@ $<
|
||||
|
||||
ocamltest_config.ml: ocamltest_config.ml.in Makefile ../Makefile.config
|
||||
sed \
|
||||
-e 's|@@AFL_INSTRUMENT@@|$(AFL_INSTRUMENT)|' \
|
||||
|
|
|
@ -18,6 +18,13 @@ ROOTDIR=../..
|
|||
include $(ROOTDIR)/Makefile.config
|
||||
include $(ROOTDIR)/Makefile.common
|
||||
|
||||
OC_CFLAGS += $(SHAREDLIB_CFLAGS)
|
||||
|
||||
OC_CPPFLAGS += -I$(ROOTDIR)/runtime
|
||||
|
||||
NATIVE_CPPFLAGS = \
|
||||
-DNATIVE_CODE -DTARGET_$(ARCH) -DMODEL_$(MODEL) -DSYS_$(SYSTEM)
|
||||
|
||||
CAMLRUN ?= $(ROOTDIR)/boot/ocamlrun
|
||||
|
||||
LIBS = -nostdlib -I $(ROOTDIR)/stdlib -I $(ROOTDIR)/otherlibs/$(UNIXLIB)
|
||||
|
@ -92,15 +99,13 @@ $(LIBNAME).cmxa: $(THREADS_NCOBJS)
|
|||
# st_stubs_n.$(O) from the same source file st_stubs.c (it is compiled
|
||||
# twice, each time with different options).
|
||||
|
||||
st_stubs_n.$(O): OC_CPPFLAGS += $(NATIVE_CPPFLAGS)
|
||||
|
||||
st_stubs_b.$(O): st_stubs.c $(HEADER)
|
||||
$(CC) -c $(OC_CFLAGS) $(OC_CPPFLAGS) -I$(ROOTDIR)/runtime \
|
||||
$(SHAREDLIB_CFLAGS) $(OUTPUTOBJ)$@ $<
|
||||
$(CC) -c $(OC_CFLAGS) $(OC_CPPFLAGS) $(OUTPUTOBJ)$@ $<
|
||||
|
||||
st_stubs_n.$(O): st_stubs.c $(HEADER)
|
||||
$(CC) $(OC_CFLAGS) $(OC_CPPFLAGS) \
|
||||
-I$(ROOTDIR)/runtime $(SHAREDLIB_CFLAGS) -DNATIVE_CODE \
|
||||
-DTARGET_$(ARCH) -DMODEL_$(MODEL) -DSYS_$(SYSTEM) \
|
||||
$(OUTPUTOBJ)$@ -c $<
|
||||
$(CC) -c $(OC_CFLAGS) $(OC_CPPFLAGS) $(OUTPUTOBJ)$@ $<
|
||||
|
||||
partialclean:
|
||||
rm -f *.cm*
|
||||
|
@ -154,11 +159,10 @@ depend:
|
|||
$(error Dependencies cannot be regenerated using the MSVC ports)
|
||||
else
|
||||
depend:
|
||||
$(CC) -MM $(OC_CPPFLAGS) -I$(ROOTDIR)/runtime st_stubs.c \
|
||||
$(CC) -MM $(OC_CPPFLAGS) st_stubs.c \
|
||||
| sed -e 's/st_stubs\.o/st_stubs_b.$$(O)/' \
|
||||
-e 's/ st_\(posix\|win32\)\.h//g' > .depend
|
||||
$(CC) -MM $(OC_CPPFLAGS) -I$(ROOTDIR)/runtime \
|
||||
-DNATIVE_CODE -DTARGET_$(ARCH) -DMODEL_$(MODEL) -DSYS_$(SYSTEM) \
|
||||
$(CC) -MM $(OC_CPPFLAGS) $(NATIVE_CPPFLAGS) \
|
||||
st_stubs.c | sed -e 's/st_stubs\.o/st_stubs_n.$$(O)/' \
|
||||
-e 's/ st_\(posix\|win32\)\.h//g' >> .depend
|
||||
$(CAMLRUN) $(ROOTDIR)/boot/ocamlc -depend -slash *.mli *.ml >> .depend
|
||||
|
|
|
@ -179,10 +179,11 @@ ifneq "$(UNIX_OR_WIN32)" "win32"
|
|||
strip $@
|
||||
endif
|
||||
|
||||
$(HEADERPROGRAM)%$(O): \
|
||||
OC_CPPFLAGS += -DRUNTIME_NAME='"$(HEADER_PATH)ocamlrun$(subst .,,$*)"'
|
||||
|
||||
$(HEADERPROGRAM)%$(O): $(HEADERPROGRAM).c
|
||||
$(CC) -c $(OC_CFLAGS) $(OC_CPPFLAGS) \
|
||||
-DRUNTIME_NAME='"$(HEADER_PATH)ocamlrun$(subst .,,$*)"' \
|
||||
$(OUTPUTOBJ)$@ $^
|
||||
$(CC) -c $(OC_CFLAGS) $(OC_CPPFLAGS) $(OUTPUTOBJ)$@ $^
|
||||
|
||||
camlheader_ur: camlheader
|
||||
cp camlheader $@
|
||||
|
|
|
@ -267,9 +267,13 @@ else
|
|||
DEF_SYMBOL_PREFIX = '-Dsymbol_prefix=""'
|
||||
endif
|
||||
|
||||
objinfo_helper$(EXE): objinfo_helper.c $(ROOTDIR)/runtime/caml/s.h
|
||||
$(CC) $(OC_CFLAGS) $(OC_CPPFLAGS) -I$(ROOTDIR)/runtime $(OUTPUTEXE)$@ \
|
||||
$(DEF_SYMBOL_PREFIX) $(LIBBFD_INCLUDE) $< $(LIBBFD_LINK)
|
||||
objinfo_helper$(EXE): objinfo_helper.$(O)
|
||||
$(CC) $(OC_CFLAGS) $(OUTPUTEXE)$@ $< $(LIBBFD_LINK)
|
||||
|
||||
objinfo_helper.$(O): $(ROOTDIR)/runtime/caml/s.h
|
||||
|
||||
objinfo_helper.$(O): \
|
||||
OC_CPPFLAGS += -I$(ROOTDIR)/runtime $(DEF_SYMBOL_PREFIX) $(LIBBFD_INCLUDE)
|
||||
|
||||
OBJINFO=$(ROOTDIR)/compilerlibs/ocamlcommon.cma \
|
||||
$(ROOTDIR)/compilerlibs/ocamlbytecomp.cma \
|
||||
|
|
|
@ -18,6 +18,7 @@
|
|||
ROOTDIR = ..
|
||||
|
||||
include $(ROOTDIR)/Makefile.config
|
||||
include $(ROOTDIR)/Makefile.common
|
||||
|
||||
OC_CPPFLAGS += -I$(ROOTDIR)/runtime
|
||||
|
||||
|
@ -58,9 +59,3 @@ skeleton.$(O): defs.h
|
|||
symtab.$(O): defs.h
|
||||
verbose.$(O): defs.h
|
||||
warshall.$(O): defs.h
|
||||
|
||||
# The following rule is similar to make's default one, except that it
|
||||
# also works for .obj files.
|
||||
|
||||
%.$(O): %.c
|
||||
$(CC) -c $(OC_CFLAGS) $(OC_CPPFLAGS) $(OUTPUTOBJ)$@ $<
|
||||
|
|
Loading…
Reference in New Issue