Skip to content

Commit

Permalink
move all config variables to Makefile.config.in
Browse files Browse the repository at this point in the history
Summary:
Hardcoding `variable@` in Makefiles is Bad™ because it prevents the users from
overwriting them easily with `make variable="my custom value"`. The right way
to do it is thus:

```
variable = variable@
# then use $(variable) everywhere
```

This diff puts all the `variable = variable@` lines in Makefile.config.in, and
changes every occurrence of a `variable@` to `$(variable)` everywhere else.

I mostly automated generating this diff. Here are the steps I did:

- find out which `variable@`s we use:

  find . -name 'Makefile*' -exec grep -e '@[^@ []\+@' -o -h \{\} \+ | sort | uniq > config_variables

- write this `replace.sh` script to replace every `variable@` with `$(variable)`:

```
#!/bin/sh

config_vars_file=$1
shift

for line in $(cat $config_vars_file); do
  var=$(echo $line | tr -d @)
  sed -i -e "s/$line/\$($var)/g" $@ > /dev/null
done
```

- run the script as such:

  find . -name 'Makefile.*in' \( -not -wholename './Makefile.config.in' \) -exec ./replace.sh config_variables \{\} \+

- put all the `VARIABLE = VARIABLE@` lines in Makefile.config.in

- move all `Makefile.in` to `Makefile`, since they don't need to be generated by `./configure` anymore:

```
for i in $(find . -name 'Makefile.*in' \( -not -wholename './Makefile.config.in' \)); do \
  rm $(dirname $i)/$(basename $i .in) && git mv $i $(dirname $i)/$(basename $i .in) ; \
done
```

- delete all Makefile except Makefile.config from configure.ac

- manually inspect and remove remaining instances of `VAR = $(VAR)` in makefiles, looking at the output of `git grep '^\(\w\+\) = $(\1)'`

Reviewed By: jberdine

Differential Revision: D3358379

fbshipit-source-id: 5d37f02
  • Loading branch information
jvillard authored and Facebook Github Bot 4 committed May 27, 2016
1 parent 0f895b0 commit 533831a
Show file tree
Hide file tree
Showing 10 changed files with 73 additions and 328 deletions.
7 changes: 0 additions & 7 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,6 @@ _build
/config.status
/configure
/Makefile.config
/Makefile
/infer/models/Makefile
/infer/models/c/Makefile
/infer/models/cpp/Makefile
/infer/models/java/Makefile
/infer/models/objc/Makefile
/infer/src/Makefile
/.buckversion

# IntelliJ files
Expand Down
67 changes: 49 additions & 18 deletions Makefile.config.in
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,56 @@
# LICENSE file in the root directory of this source tree. An additional grant
# of patent rights can be found in the PATENTS file in the same directory.

@SET_MAKE@

PLATFORM = $(shell uname)

ATDGEN = @ATDGEN@
bindir = @bindir@
BUILD_C_ANALYZERS = @BUILD_C_ANALYZERS@
BUILD_JAVA_ANALYZERS = @BUILD_JAVA_ANALYZERS@
BUILD_LLVM_ANALYZERS = @BUILD_LLVM_ANALYZERS@
CC = @CC@
CFLAGS = @CFLAGS@
CLANG_INCLUDES = @CLANG_INCLUDES@
CLANG_PREFIX = @CLANG_PREFIX@
CPP = @CPP@
CXX = @CXX@
CXXFLAGS = @CXXFLAGS@
ENABLE_OCAML_ANNOT = @ENABLE_OCAML_ANNOT@
ENABLE_OCAML_BINANNOT = @ENABLE_OCAML_BINANNOT@
exec_prefix = @exec_prefix@
INFER_MAJOR = @INFER_MAJOR@
INFER_MINOR = @INFER_MINOR@
INFER_PATCH = @INFER_PATCH@
INSTALL = @INSTALL@
INSTALL_DATA = @INSTALL_DATA@
INSTALL_PROGRAM = @INSTALL_PROGRAM@
IS_FACEBOOK_TREE = @IS_FACEBOOK_TREE@
IS_RELEASE_TREE = @IS_RELEASE_TREE@
LDFLAGS = @LDFLAGS@
libdir = @libdir@
LIBS = @LIBS@
LN_S = @LN_S@
MKDIR_P_CMD = case "@MKDIR_P@" in \
./*) printf "$(ROOT_DIR)/@MKDIR_P@\n";; \
*) printf "@MKDIR_P@\n";; \
esac
MKDIR_P = $(shell $(MKDIR_P_CMD))
NCPU = @NCPU@
prefix = @prefix@
USER_JAVA_HOME = @USER_JAVA_HOME@
XCODE_SELECT = @XCODE_SELECT@

ifneq (,$(findstring s,$(MAKEFLAGS)))
REMOVE = rm -f
REMOVE_DIR = rm -rf
else
REMOVE = rm -vf
REMOVE_DIR = rm -rvf
endif
COPY = cp -f -p
COPY_DIR = cp -Rf

ABSOLUTE_ROOT_DIR = $(shell cd $(ROOT_DIR) && pwd)

Expand Down Expand Up @@ -45,8 +92,8 @@ INFERTRACEBUGS_BIN = $(BIN_DIR)/inferTraceBugs
INFER_BIN_RELPATH = infer/bin/infer
INFERTRACEBUGS_BIN_RELPATH = infer/bin/inferTraceBugs

ifeq (@BUILD_JAVA_ANALYZERS@,yes)
JAVA_HOME=@USER_JAVA_HOME@
ifeq ($(BUILD_JAVA_ANALYZERS),yes)
JAVA_HOME=$(USER_JAVA_HOME)
endif

JAVA_DEPS = $(addprefix $(PYTHON_LIB_DIR)/, \
Expand All @@ -66,19 +113,3 @@ CLANG_DEPS = $(addprefix $(PYTHON_LIB_DIR)/, \
$(INFERPRINT_BIN)

JAVA_MODELS_JAR = $(LIB_DIR)/java/models.jar

ifneq (,$(findstring s,$(MAKEFLAGS)))
REMOVE = rm -f
REMOVE_DIR = rm -rf
else
REMOVE = rm -vf
REMOVE_DIR = rm -rvf
endif
COPY = cp -f -p
COPY_DIR = cp -Rf
MKDIR_P_CMD = case "@MKDIR_P@" in \
./*) printf "$(ROOT_DIR)/@MKDIR_P@\n";; \
*) printf "@MKDIR_P@\n";; \
esac
MKDIR_P = $(shell $(MKDIR_P_CMD))
LN_S = @LN_S@
260 changes: 0 additions & 260 deletions Makefile.in

This file was deleted.

7 changes: 0 additions & 7 deletions configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -267,13 +267,6 @@ AC_SUBST([NCPU])

AC_CONFIG_FILES([
Makefile.config
Makefile
infer/models/Makefile
infer/models/c/Makefile
infer/models/cpp/Makefile
infer/models/objc/Makefile
infer/models/java/Makefile
infer/src/Makefile
])

AC_OUTPUT
Loading

0 comments on commit 533831a

Please sign in to comment.