It doesn't matter what type of remote debug connection I tried.. Full Remote Host, Remote Debug, Remote GDB Server etc.
Actually remote device starts working when I clicked the debug button. I can run it from my CLion but it never hits to my breakpoints..
I'm not professional on remote debugging, actually it is my second work but this time it is on already working ( readymade ) project on my Raspberry pi Lorawan device ( Debian ) .
Device connected to my home network and there is a package forwarder app in it. App listens 1680 port.
Normally it is working on remote device with no problem. I downloaded the app to my computer and built the project successfully in CLion. After I tried lots of things, almost every combination of remote debugging and settings. I understood I'm missing some point and I need help. If you can help me you will save my life
Makefile :
### get external defined data
include ../target.cfg
### Application-specific constants
APP_NAME := lora_pkt_fwd
### Environment constants
LGW_PATH ?= ../libloragw
LIB_PATH ?= ../libtools
ARCH ?=
CROSS_COMPILE ?=
OBJDIR = obj
INCLUDES = $(wildcard inc/*.h)
### External constant definitions
# must get library build option to know if mpsse must be linked or not
include $(LGW_PATH)/library.cfg
RELEASE_VERSION := `cat ../VERSION`
### Constant symbols
CC := -g $(CROSS_COMPILE)gcc
AR := $(CROSS_COMPILE)ar
CFLAGS := -O2 -Wall -Wextra -std=c99 -Iinc -I. -I../libtools/inc
VFLAG := -D VERSION_STRING="\"$(RELEASE_VERSION)\""
### Constants for Lora concentrator HAL library
# List the library sub-modules that are used by the application
LGW_INC =
ifneq ($(wildcard $(LGW_PATH)/inc/config.h),)
# only for HAL version 1.3 and beyond
LGW_INC += $(LGW_PATH)/inc/config.h
endif
LGW_INC += $(LGW_PATH)/inc/loragw_hal.h
### Linking options
LIBS := -lloragw -ltinymt32 -lparson -lbase64 -lrt -lpthread -lm -lcursor
### General build targets
all: $(APP_NAME)
clean:
rm -f $(OBJDIR)/*.o
rm -f $(APP_NAME)
ifneq ($(strip $(TARGET_IP)),)
ifneq ($(strip $(TARGET_DIR)),)
ifneq ($(strip $(TARGET_USR)),)
install:
#echo "---- Copying packet_forwarder files to $(TARGET_IP):$(TARGET_DIR)"
#ssh $(TARGET_USR)#$(TARGET_IP) "mkdir -p $(TARGET_DIR)"
#scp lora_pkt_fwd $(TARGET_USR)#$(TARGET_IP):$(TARGET_DIR)
install_conf:
#echo "---- Copying packet_forwarder conf files to $(TARGET_IP):$(TARGET_DIR)"
#ssh $(TARGET_USR)#$(TARGET_IP) "mkdir -p $(TARGET_DIR)"
#scp global_conf.json.sx1250.* $(TARGET_USR)#$(TARGET_IP):$(TARGET_DIR)
#scp global_conf.json.sx1257.* $(TARGET_USR)#$(TARGET_IP):$(TARGET_DIR)
else
#echo "ERROR: TARGET_USR is not configured in target.cfg"
endif
else
#echo "ERROR: TARGET_DIR is not configured in target.cfg"
endif
else
#echo "ERROR: TARGET_IP is not configured in target.cfg"
endif
### Sub-modules compilation
$(OBJDIR):
mkdir -p $(OBJDIR)
$(OBJDIR)/%.o: src/%.c $(INCLUDES) | $(OBJDIR)
$(CC) -c $(CFLAGS) -I$(LGW_PATH)/inc $< -o $#
### Main program compilation and assembly
$(OBJDIR)/$(APP_NAME).o: src/$(APP_NAME).c $(LGW_INC) $(INCLUDES) | $(OBJDIR)
$(CC) -c $(CFLAGS) $(VFLAG) -I$(LGW_PATH)/inc $< -o $#
$(APP_NAME): $(OBJDIR)/$(APP_NAME).o $(LGW_PATH)/libloragw.a $(OBJDIR)/jitqueue.o
$(CC) -L$(LGW_PATH) -L$(LIB_PATH) $< $(OBJDIR)/jitqueue.o -o $# $(LIBS)
### EOF
I'm sharing my last try screenshots with you : Full Remot Host.
If I add -g to CXXFLAGS in https://github.com/remonbonbon/makefile-example, I can debug the app target just fine.
link -> https://intellij-support.jetbrains.com/hc/en-us/community/posts/360009699119-Debugging-not-working-when-using-the-Makefile-feature-in-2020-2-EAP-
Related
I am trying to write makefile for ms-windows application. The idea is very simple. I have to generate the output .o, .exe files into the build directory. I have written makefile which will compile source directory, but is not able to generate the build directory and compilation process is perfectly working.
Please have a look for the makefile. It looks like i am not able to generate the build directory using mkdir command.
CC= gcc
CFLAG= -g -Wall
TARGET_EXEC ?= test.exe
RELEASE= Release
RELEASE_BIN= bin
RELEASE_CNFG= config
RELEASE_LOG= log
RELEASE_DATA=data
BUILD_DIR ?= build
SRC_DIRS ?= src
#OS dependent cleaning command
ifdef OS
RM = rd /s /q
else
ifeq ($(shell uname), Linux)
RM = rm -f
endif
endif
SRCS := $(wildcard $(SRC_DIRS)/*.c)
OBJS := $(SRCS:%=$(BUILD_DIR)/%.o)
DEPS := $(OBJS:.o=.d)
INC_DIRS := $(wildcard $(SRC_DIRS) -type d)
INC_FLAGS := $(addprefix -I,$(INC_DIRS))
#find the directory for the include file
#this is best otpion to search curl directory
USR_INC := /usr/include
FILES :=
INCLUDES = -Iinclude
LIBS= -lm
CPPFLAGS ?= $(INC_FLAGS) -MMD -MP
$(BUILD_DIR)/$(TARGET_EXEC): $(OBJS)
$(CC) $(OBJS) -o $# $(LIBS) $(LLFLAGS)
# c source
$(BUILD_DIR)/%.c.o: %.c
#echo Compiling $<
# here I am trying to generate the file into the build/src/xxxc.o
# $(MKDIR_P) $#
$(CC) $(CFLAG) -c $< -o $# $(INCLUDES)
.PHONY: install
install:
# echo "Installing..........."
# echo "Creating $(RELEASE) Directory..."
# $(MKDIR_P) $(RELEASE)
# echo "Creating $(RELEASE)/$(RELEASE_BIN) Directory.."
# $(MKDIR_P) $(RELEASE)/$(RELEASE_BIN)
# echo "Creating $(RELEASE)/$(RELEASE_CNFG) Directory..."
# $(MKDIR_P) $(RELEASE)/$(RELEASE_CNFG)
# echo "Creating $(RELEASE)/$(RELEASE_LOG) Directory..."
# $(MKDIR_P) $(RELEASE)/$(RELEASE_LOG)
# echo "Creating $(RELEASE)/$(RELEASE_DATA) Directory..."
# $(MKDIR_P) $(RELEASE)/$(RELEASE_DATA)
# echo "Makking Release folder ready.."
#cp $(BUILD_DIR)/$(TARGET_EXEC) $(RELEASE)/$(RELEASE_BIN)
# echo "copy certificate file to Release"
#cp -r cert $(RELEASE)
# echo "copy .ini file to Release"
#cp -r config/*.ini $(RELEASE)/$(RELEASE_CNFG)
.PHONY: clean
clean:
$(RM) $(BUILD_DIR) $(RELEASE)
-include $(DEPS)
MKDIR_P ?= mkdir
I do understand what your are trying. But please be aware that some differences in platforms and dependencies will force you to create something that is similar to a "configure" and "make" step.
So you will start to generate a custom Makefile in a tool to be invented by you sooner or later :).
It is mentioned in the comments: This has already been done and cmake is now "industrial standard"
It works on Windows, Linux, OSX and so on with great toolchain support. Have a look at it!
Example:
cmake_minimum_required(VERSION 3.4)
project(HelloWorldCMake)
set(MY_SOURCES
hello_world.c
)
add_executable(HelloWorldCMake
${MY_SOURCES}
)
And hello_world.c
#include <stdio.h>
int main()
{
printf("Hello world (cmake)");
}
If you want to link additional libraries, please research
the CMake command: target_link_libraries
https://cmake.org/cmake/help/latest/command/target_link_libraries.html
Im trying to create a Makefile which compiles some files and creates some outputs but first I want it to execute the configuration only one time and the next time I type make it wont re-execute the configuration unless I change the parameters for example the prefix.
I tried using touch , FORCE and if, after searching a bit in other posts but Im newbie in gcc and Makefiles so I cant make it work.
My code now is (did not include the other rules because they dont affect the configuration):
XLEN := 32
RISCV_PREFIX := riscv$(XLEN)-unknown-elf-
RISCV_GCC := $(RISCV_PREFIX)gcc
CFLAGS := -O2
WORKING_DIR:= $(shell pwd)
LIBRARY_DIR:= $(abspath $(dir $(lastword $(MAKEFILE_LIST)))/..)
B := $(shell echo $(LIBRARY_DIR))
$(info $(B))
--->(execute this only once)---> CONFIGURATION := configure --prefix=$(LIBRARY_DIR) --with-arch=rv32if --with-abi=ilp32d
RISCV_TEST_DIR:=$(shell pwd)
SCRIPTDIR:=$(RISCV_TEST_DIR)/../../tools
RISCV_OPTIONS = -o
RISCV_LINK = $(RISCV_GCC) $(PROGRAMS) $(RISCV_OPTIONS) $# $(CFLAGS) #produces .elf file!
RISCV_OBJDUMP = $(RISCV_PREFIX)objdump -D #produces a dump file to see the assembly code!
RISCV_OBJCOPY = $(RISCV_PREFIX)objcopy -O binary #produces a bin file!
%.elf: %.c
$(info Generating .elf file from files: $(PROGRAMS_NO_EX))
$(RISCV_LINK)
$(info Success!)
$(info ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~)
%.dump: %.elf
$(info Copying assembly to dump file $(PROGRAMS_NO_EX).dump)
#$(RISCV_OBJDUMP) $< > $#
$(info Success!)
$(info ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~)
%.bin: %.elf
$(info Generating bin file)
#$(RISCV_OBJCOPY) $< $#
$(info Success!)
$(info ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~)
%.hex: %.bin
$(info Generating hex file)
echo cd $(SCRIPTDIR)
$(info Running binary to hex >>>)
python $(SCRIPTDIR)/bin2hex.py $< -a 0x0 > $# || exit -1
$(info Hex Generation Successful!)
$(info ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~)
all: $(PROGRAMS_TO_CREATE); if [ -a $(LIBRARY_DIR)/config.status ]; then cd $(LIBRARY_DIR) && $(CONFIGURATION); fi;
configure: config.status
touch configure
config.status:
cd $(LIBRARY_DIR) && $(CONFIGURATION);
.PHONY: all clean
clean:
$(info Cleaning files...)
#rm -rf *.elf *.hex *.map *.objdump *.i *.s *.bin *.dump
$(info Done cleaning!)
Thank you in advance!
I believe the only problem with your configuration statements are incorrect paths in rules for config.status and configure, since they really will be located within $(LIBRARY_DIR). When the paths are correct, it will correctly run configuration only once:
$ cat Makefile
LIBRARY_DIR := library
all: $(LIBRARY_DIR)/config.status
$(info Making $#)
$(LIBRARY_DIR)/config.status: $(LIBRARY_DIR)/configure
cd $(<D) && ./$(<F)
Output:
$ make
cd library && ./configure
Making all
$ make # <--- Invoking second time, no configure step
Making all
make: 'all' is up to date.
With #raspy's help managed to solve the problem like this:
all: $(PROGRAMS_TO_CREATE)
$(PROGRAMS_TO_CREATE):$(LIBRARY_DIR)/config.status
$(LIBRARY_DIR)/config.status:
cd $(LIBRARY_DIR) && $(CONFIGURATION)
I have a question regarding my Makefile. The Makefile intends to compile C files containing code for a STM8 µC using the Cosmic compiler. The problem is that everytime I invoke the build target, all available source file are getting recompiled without any change. I'm really new in the field of Makefiles and I have no idea how to fix it.
The second questions is related to the two targets "%.o: src/%.c" and %.o: src/stm8/%.c. They do exactly the same and I would prefer a generic one that is able to deal with all subdirectories within the src folder. With this solution it ist required to add an additional rule for each subfolder of the src folder
#***************PROJECT INFORMATIONS****************
PROJECT_NAME = stm8template
MODULES = stm8
#****************SET BUILD MODE*********************
ifeq ($(MODE), )
MODE=Debug
endif
#***************DIRECTORY INFORMATION***************
SRCDIR = src
INCLUDES = includes
OUTPUT_DIR = bin/$(MODE)
#**************HELPER FUNCTIONS*********************
rwildcard=$(wildcard $1$2) $(foreach d,$(wildcard $1*),$(call rwildcard,$d/,$2))
#***************FILE SPECIFICATIONS***************
SOURCE_FILES = $(foreach d, $(call rwildcard,$(SRCDIR),*.c), $(notdir $d))
OBJECT_FILES = $(patsubst %.c, %.o, $(SOURCE_FILES))
HEADER_FILES = $(wildcard $(INCLUDES)/*.h) $(wildcard $(INCLUDES)/**/*.h)
INCLUDE_DIRS_PARAM=$(foreach d, $(MODULES), -iincludes/$d) -iincludes -iC:\Hstm8
#***************COMPILER INFORMATIONS***************
CC = cxstm8
LIBS = -l +mods0
ifeq ("$(MODE)","Debug")
CFLAGS = $(INCLUDE_DIRS_PARAM) -cl$(OUTPUT_DIR) -co$(OUTPUT_DIR) -pxp -no -pp +debug
else
CFLAGS = $(INCLUDE_DIRS_PARAM) -cl$(OUTPUT_DIR) -co$(OUTPUT_DIR) -pxp -no -pp
endif
#***************LINKER INFORMATIONS***************
LINKFILE=$(OUTPUT_DIR)\$(PROJECT_NAME).lkf
OUTFILE=$(PROJECT_NAME)
LFLAGS = -lC:\Lib
#*************FLASHER CONFIGURATIONS***************
FLASHER_PATH="C:\Program Files (x86)\STMicroelectronics\st_toolset\stvp\STVP_CmdLine.exe"
DEVICE=STM8S105x6
PORT=USB
PROG_MODE=SWIM
BOARD_NAME=ST-LINK
FLASHER_PARAM = -no_loop
#***************BUILT TARGETS***************
all: build run
%.o: src/%.c
$(info ********** Compile $< ***********)
$(CC) $(CFLAGS) $(LIBS) $<
%.o: src/stm8/%.c
$(info ********** Compile $< ***********)
$(CC) $(CFLAGS) $(LIBS) $<
build: $(OBJECT_FILES)
$(info ********** Build the Application ***********)
clnk -m $(OUTPUT_DIR)\$(OUTFILE).map -o $(OUTPUT_DIR)\$(OUTFILE).sm8 $(LINKFILE)
cvdwarf $(OUTPUT_DIR)\$(OUTFILE).sm8
chex -o $(OUTPUT_DIR)\$(OUTFILE).s19 $(OUTPUT_DIR)\$(OUTFILE).sm8
run:
$(info ********** Flashing the Application ***********)
$(FLASHER_PATH) -BoardName=$(BOARD_NAME) -Device=$(DEVICE) -Port=$(PORT) -ProgMode=$(PROG_MODE) -FileProg="$(OUTPUT_DIR)\$(OUTFILE).s19" $(FLASHER_PARAM)
The build target never gets created, so the commands after it are executed every time you run make (or make all or make build), so the program is linked each time.
Change your build target so that it is phony:
.PHONY: build clean
and so that it depends on the program, not the object files:
build: $(OUTPUT_DIR)\$(OUTFILE).sm8
and then have a rule (recipe) that builds the program if the object files are more recent:
$(OUTPUT_DIR)\$(OUTFILE).sm8: $(OBJECT_FILES)
$(info ********** Build the Application ***********)
clnk -m $(OUTPUT_DIR)\$(OUTFILE).map -o $(OUTPUT_DIR)\$(OUTFILE).sm8 $(LINKFILE)
cvdwarf $(OUTPUT_DIR)\$(OUTFILE).sm8
chex -o $(OUTPUT_DIR)\$(OUTFILE).s19 $(OUTPUT_DIR)\$(OUTFILE).sm8
It isn't 100% clear to me that I chose the correct suffix for the program. I would also create series of macros to avoid the repetition I see:
OUTFILE.sm8 = $(OUTPUT_DIR)\$(OUTFILE).sm8
OUTFILE.s19 = $(OUTPUT_DIR)\$(OUTFILE).s19
OUTFILE.map = $(OUTPUT_DIR)\$(OUTFILE).map
build: $(OUTFILE.sm8)
$(OUTFILE.sm8): $(OBJECT_FILES)
$(info ********** Build the Application ***********)
clnk -m $(OUTFILE.map) -o $(OUTFILE.sm8) $(LINKFILE)
cvdwarf $(OUTFILE.sm8)
chex -o $(OUTFILE.s19) $(OUTFILE.sm8)
Also, since I work on Unix mostly, I'd use / instead of \, but that's a minor detail.
Update:
Thank you all for your help. I changed the Makefile in the way shown below. The second problem is now fixed but the first problem still remains.
Every time the build rule is invoked all .c files are recompiled. Compiling only the changed files is the main purpose/benefit of using make, I thought. So something is wrong but unfortunately I don't find the mistake.
#***************PROJECT INFORMATIONS****************
PROJECT_NAME = stm8template
MODULES = stm8
#****************SET BUILD MODE*********************
ifeq ($(MODE), )
MODE=Debug
endif
#***************DIRECTORY INFORMATION***************
SRCDIR = src
INCLUDES = includes
#**************HELPER FUNCTIONS*********************
rwildcard=$(wildcard $1$2) $(foreach d,$(wildcard $1*),$(call rwildcard,$d/,$2))
#***************FILE SPECIFICATIONS***************
SOURCE_FILES = $(foreach d, $(call rwildcard,$(SRCDIR),*.c), $(notdir $d))
OBJECT_FILES = $(patsubst %.c, %.o, $(call rwildcard,$(SRCDIR),*.c))
HEADER_FILES = $(wildcard $(INCLUDES)/*.h) $(wildcard $(INCLUDES)/**/*.h)
INCLUDE_DIRS_PARAM=$(foreach d, $(MODULES), -iincludes/$d) -iincludes -iC:\Hstm8
#***************COMPILER INFORMATIONS***************
CC = cxstm8
LIBS = -l +mods0
ifeq ("$(MODE)","Debug")
CFLAGS = $(INCLUDE_DIRS_PARAM) -cl$(OUTPUT_DIR) -co$(OUTPUT_DIR) -pxp -no -pp +debug
else
CFLAGS = $(INCLUDE_DIRS_PARAM) -cl$(OUTPUT_DIR) -co$(OUTPUT_DIR) -pxp -no -pp
endif
#***************LINKER INFORMATIONS***************
LINKFILE=$(OUTPUT_DIR)\$(PROJECT_NAME).lkf
LFLAGS = -LC:\Lib
#*******************OUTPUT FILES********************
OUTPUT_DIR = bin/$(MODE)
OUTFILE=$(PROJECT_NAME)
OUTFILE.sm8 = $(OUTPUT_DIR)\$(OUTFILE).sm8
OUTFILE.s19 = $(OUTPUT_DIR)\$(OUTFILE).s19
OUTFILE.map = $(OUTPUT_DIR)\$(OUTFILE).map
TARGET_FILE=$(OUTPUT_DIR)\$(PROJECT_NAME).elf
#*************FLASHER CONFIGURATIONS***************
FLASHER_PATH="C:\Program Files (x86)\STMicroelectronics\st_toolset\stvp\STVP_CmdLine.exe"
DEVICE := STM8S105x6
PORT=USB
PROG_MODE=SWIM
BOARD_NAME=ST-LINK
FLASHER_PARAM = -no_loop
#***************BUILT TARGETS***************
.PHONY: all run build clean
all: build run
%.o: %.c
$(info ********** Compile $< ***********)
$(CC) $(CFLAGS) $(LIBS) $<
build: $(OUTPUT_DIR)\$(PROJECT_NAME).elf
$(TARGET_FILE): $(OBJECT_FILES)
$(info ********** Build the Application ***********)
clnk -m $(OUTFILE.map) -o $(OUTFILE.sm8) $(LINKFILE)
cvdwarf $(OUTFILE.sm8)
chex -o $(OUTFILE.s19) $(OUTFILE.sm8)
run:
$(info ********** Flashing the Application ***********)
$(FLASHER_PATH) -BoardName=$(BOARD_NAME) -Device=$(DEVICE) -Port=$(PORT) -ProgMode=$(PROG_MODE) -FileProg="$(OUTPUT_DIR)\$(OUTFILE).s19" $(FLASHER_PARAM)
I think to organize my project as follows:
my_project
|--src
|--include
|--test
The core files reside in the directories src and include, whereas the different test applications of the core are within test directory (multiple *.c containing each a main() function). The core should be build as static library which will be linked to all applications).
How to write a basic Makefile to match these requirements? I already googled and found the following website providing a Makefile template for building an executable 1 . How can this Makefile be extended for my needs?
If you think my project organization is bad or you have a better idea, let me know!
Any help is appreciated!
Thanks, Jonas
You haven't said where you want the library to go, so I'll assume it should go into src/ where the objects already go.
src/libcore.a: $(OBJECTS)
$(AR) -cvq $# $^
It looks as if the makefile you have will build test/testfoo.o from test/testfoo.c so I'll assume that that works. And you haven't said where you want the executable tests (e.g. testfoo) to go, so I'll put them in test/.
test/%: test/%.o src/libcore.a
$(CC) -o $# $< -Lsrc -lcore
EDIT:
If you want Make to build all of the tests by default, then you should have this before any other rule in the makefile:
TESTS := $(patsubst %.c,%,$(wildcard test/*.c))
all: $(TESTS)
There is a small project called dotmk which turns the creation of a Makefile very easy.
Here is the link:
https://github.com/swrh/dotmk
You just have to run the install script and create the Makefile like the examples
my Makefile now looks as follows:
SHELL = /bin/sh
CC = gcc
AR = ar
CFLAGS = -std=gnu99 -Iinclude -pedantic -Wall -Wextra -march=native -ggdb3
DEBUGFLAGS = -O0 -D _DEBUG
RELEASEFLAGS = -O2 -D NDEBUG -combine -fwhole-program
PROFILEFLAGS = -pg
ARFLAGS = -cvq
# core and test common includes
COMMON_INC = include/definitions.h include/debug.h
# core stuff
CORE_LIB = lib/libcore.a
CORE_SRC = $(shell echo src/*.c)
CORE_INC = $(shell echo include/*.h)
CORE_OBJ = $(CORE_SRC:.c=.o)
CORE_PUB_INC =
# test stuff
TEST_SERVER = test/server/server
TEST_SERVER_SRC = $(shell echo test/server/*.c)
TEST_SERVER_INC = $(shell echo test/server/*.h)
TEST_SERVER_OBJ = $(TEST_SERVER_SRC:.c=.o)
TEST_CLIENT = test/client/client
TEST_CLIENT_SRC = $(shell echo test/client/*.c)
TEST_CLIENT_INC = $(shell echo test/client/*.h)
TEST_CLIENT_OBJ = $(TEST_CLIENT_SRC:.c=.o)
all: $(CORE_LIB) $(TEST_SERVER) $(TEST_CLIENT)
core: $(CORE_LIB)
server: core $(TEST_SERVER)
client: core $(TEST_CLIENT)
$(CORE_LIB): $(CORE_OBJ)
$(AR) -cvq $# $^
$(TEST_SERVER): $(TEST_SERVER_OBJ)
$(CC) $(CFLAGS) -o $# $< -Llib -lcore
$(TEST_CLIENT): $(TEST_CLIENT_OBJ)
$(CC) $(CFLAGS) -o $# $< -Llib -lcore
debug: CFLAGS += $(DEBUGFLAGS)
debug: all
profile: CFLAGS += $(PROFILEFLAGS)
profile: all
release: CFLAGS += $(RELEASEFLAGS)
release: all
.PHONY : clean depend
clean:
-rm -f $(CORE_LIB) $(CORE_OBJ)
-rm -f $(TEST_SERVER) $(TEST_SERVER_OBJ)
-rm -f $(TEST_CLIENT) $(TEST_CLIENT_OBJ)
-rm -f gmon.out
depend:
#makedepend -- $(CFLAGS) -- $(CORE_SRC) $(TEST_SERVER_SRC) $(TEST_CLIENT_SRC)
I still have some problems:
- make creates the lib, the server and client test app. If I know modify one of the source files of the core (lib), make builds the lib newly, but not the server and client apps. Do I have a dependency problem?
- make or make all should build by default as DEBUG, whereas release and profile build a release, or profile version respectively.
I wonder, what is wrong in my makefile.
Thanks again!
I am trying to make my Makefiles platform conditional with statements like:
ifeq ($(UNAME), Linux)
# LINUX version
program_NAME := lib$(TARGET).so
OBJDIR = ../build/linux
endif
ifeq ($(UNAME), MINGW32_NT-6.1)
# WINDOWS version
program_NAME := lib$(TARGET).dll
OBJDIR = ../build/windows
endif
and:
ifeq ($(UNAME), Linux)
# LINUX version
program_INCLUDE_DIRS := \
/home/ben/projects/g2/src \
/home/ben/projects/pulse_IO/src \
/home/ben/projects/core/src
endif
ifeq ($(UNAME), MINGW32_NT-6.1)
# WINDOWS Virtual Machine version
program_INCLUDE_DIRS := \
E:/g2/src \
E:/pulse_IO/src \
E:/core/src
endif
I then compile the src either under Linux or Windows 7 running as a VM (via virtualbox) on a Linux host OS. Problem I haven't managed to solve is how to get the object files and resulting shared libraries or executables to be written to a platform specific directory, e.g. /build/linux or /build/windows where the source code is in /src
As you can see I've added an OBJDIR variable but I can't figure out how to use that to redirect the .o, .so, .dll, .exe files to the correct dir conditional on platform. I'm sure it should be easy but my research keeps bogging down with articles on vpath usage which I don't think is what I'm after.
The part of my Makefile I think I need to modify is as follows:
LINK.c := $(CC) $(CFLAGS) $(CPPFLAGS) $(LDFLAGS) $(TARGET_ARCH)
$(program_NAME): $(program_OBJS)
$(LINK.c) -shared -Wl,-soname,$(program_NAME) $(program_OBJS) -o $(program_NAME)
I should probably be using something smarter like autotools or cmake but it would be great just to get this working for now.
should also add, my list of object files is created as follows:
program_C_OBJS := ${program_C_SRCS:.c=.o}
Have tried:
program_OBJS := $(addprefix $(OBJDIR)/$program_C_OBJS)
but make compains that addprefix has the wrong no. of arguments
For gmake, see Here:
OBJDIR := objdir
OBJS := $(addprefix $(OBJDIR)/,foo.o bar.o baz.o)
$(OBJDIR)/%.o : %.c
$(COMPILE.c) $(OUTPUT_OPTION) $<
all: $(OBJS)
$(OBJS): | $(OBJDIR)
$(OBJDIR):
mkdir $(OBJDIR)
What compiler and toolset are you using? In the case of QNX, it has macros like:
$OS
$CPU
$PRODUCT
$PROJECT
$SECTION
$VARIANT ($VARIANTLIST, $EXCLUDE_VARIANTLIST)
These allow you to customize the target folder and filename for the results of your build.
http://www.qnx.com/developers/docs/6.3.2/neutrino/prog/make_convent.html
Other compilers/toolchains have similar facilities.