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:
Sébastien Hinderer 2019-09-11 09:16:15 +02:00 committed by GitHub
parent 24cf2f926f
commit 5ec649f0cb
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 35 additions and 25 deletions

View File

@ -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)$@ $<

View File

@ -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)|' \

View File

@ -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

View File

@ -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 $@

View File

@ -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 \

View File

@ -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)$@ $<