Hi,

I am trying to make a sublime text plugin to compile C using a make file, unfortunately it is all in python and I cannot get things to work :( could you please give me advice on passing data to the g++ make command?

Thanks in advance.

Here's a little blurb from Linux's 'man make'


6.9 Variables from the Environment
==================================

Variables in `make' can come from the environment in which `make' is
run. Every environment variable that `make' sees when it starts up is
transformed into a `make' variable with the same name and value.
However, an explicit assignment in the makefile, or with a command
argument, overrides the environment. (If the `-e' flag is specified,
then values from the environment override assignments in the makefile.
*Note Summary of Options: Options Summary. But this is not recommended
practice.)

Thus, by setting the variable `CFLAGS' in your environment, you can
cause all C compilations in most makefiles to use the compiler switches
you prefer. This is safe for variables with standard or conventional
meanings because you know that no makefile will use them for other
things. (Note this is not totally reliable; some makefiles set
`CFLAGS' explicitly and therefore are not affected by the value in the
environment.)

When `make' runs a command script, variables defined in the makefile
are placed into the environment of that command. This allows you to
pass values to sub-`make' invocations (*note Recursive Use of `make':
Recursion.). By default, only variables that came from the environment
or the command line are passed to recursive invocations. You can use
the `export' directive to pass other variables. *Note Communicating
Variables to a Sub-`make': Variables/Recursion, for full details.

Other use of variables from the environment is not recommended. It
is not wise for makefiles to depend for their functioning on
environment variables set up outside their control, since this would
cause different users to get different results from the same makefile.
This is against the whole purpose of most makefiles.

Such problems would be especially likely with the variable `SHELL',
which is normally present in the environment to specify the user's
choice of interactive shell. It would be very undesirable for this
choice to affect `make'; so, `make' handles the `SHELL' environment
variable in a special way; see *Note Choosing the Shell::.

Edited 6 Years Ago by gerard4143: n/a

Here is a typical make file created by DevCPP for the TextColor2 console C project ...

# Project: TextColor2
# Makefile created by Dev-C++ 4.9.9.1

CPP  = g++.exe
CC   = gcc.exe
WINDRES = windres.exe
RES  = 
OBJ  = main.o $(RES)
LINKOBJ  = main.o $(RES)
LIBS =  -L"D:/Dev-Cpp/lib"  
INCS =  -I"D:/Dev-Cpp/include" 
CXXINCS =  -I"D:/Dev-Cpp/include/c++/3.3.1"  -I"D:/Dev-Cpp/include/c++/3.3.1/mingw32"  -I"D:/Dev-Cpp/include/c++/3.3.1/backward"  -I"D:/Dev-Cpp/lib/gcc-lib/mingw32/3.3.1/include"  -I"D:/Dev-Cpp/include" 
BIN  = TextColor2.exe
CXXFLAGS = $(CXXINCS)  
CFLAGS = $(INCS)  

.PHONY: all all-before all-after clean clean-custom

all: all-before TextColor2.exe all-after


clean: clean-custom
	rm -f $(OBJ) $(BIN)

$(BIN): $(OBJ)
	$(CC) $(LINKOBJ) -o "TextColor2.exe" $(LIBS)

main.o: main.c
	$(CC) -c main.c -o main.o $(CFLAGS)

Edited 6 Years Ago by vegaseat: n/a

This article has been dead for over six months. Start a new discussion instead.