Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Папка build #1

Closed
dzanis opened this issue Feb 25, 2017 · 2 comments
Closed

Папка build #1

dzanis opened this issue Feb 25, 2017 · 2 comments

Comments

@dzanis
Copy link

dzanis commented Feb 25, 2017

Помогите,как сделать ,что-бы многофайловый проект компилировался в папку build ?Что прописать в Makefile? На примере переменной OUTPUT_DIR=build/ .

@eddyem
Copy link
Owner

eddyem commented Feb 25, 2017

Вот пример заготовки Makefile, которая весь мусор в директорию mk сбрасывает:

run make DEF=... to add extra defines

PROGRAM :=
LDFLAGS := -fdata-sections -ffunction-sections -Wl,--gc-sections -Wl,--discard-all
SRCS := $(wildcard *.c)
DEFINES := $(DEF) -D_XOPEN_SOURCE=1111
OBJDIR := mk
CFLAGS += -O2 -Wall -Werror -Wextra -Wno-trampolines -std=gnu99
OBJS := $(addprefix $(OBJDIR)/, $(SRCS:%.c=%.o))
DEPS := $(OBJS:.o=.d)
CC = gcc
#CXX = g++

all : $(OBJDIR) $(PROGRAM)

$(PROGRAM) : $(OBJS)
@echo -e "\t\tLD $(PROGRAM)"
$(CC) $(LDFLAGS) $(OBJS) -o $(PROGRAM)

$(OBJDIR):
mkdir $(OBJDIR)

ifneq ($(MAKECMDGOALS),clean)
-include $(DEPS)
endif

$(OBJDIR)/%.o: %.c
@echo -e "\t\tCC $<"
$(CC) -MD -c $(LDFLAGS) $(CFLAGS) $(DEFINES) -o $@ $&lt;

clean:
@echo -e "\t\tCLEAN"
@rm -f $(OBJS) $(DEPS)
@rmdir $(OBJDIR) 2>/dev/null || true

xclean: clean
@rm -f $(PROGRAM)

gentags:
CFLAGS="$(CFLAGS) $(DEFINES)" geany -g $(PROGRAM).c.tags *[hc] 2>/dev/null

.PHONY: gentags clean xclean

@dzanis
Copy link
Author

dzanis commented Feb 25, 2017

Спасибо это помогло.И вот что получилось

#Makefile for stm8 sdcc project
NAME=testproj
SDCC=sdcc
INCLUDES=-I../ -I/usr/share/sdcc/include 
DEFINES=-D STM8S103
CCFLAGS= -mstm8 --out-fmt-ihx
LDFLAGS= -mstm8 --out-fmt-ihx -lstm8
FLASHFLAGS=-c stlinkv2 -p stm8s103f3
OBJDIR=build
SRC=$(wildcard *.c)
OBJS= $(addprefix $(OBJDIR)/,$(SRC:%.c=%.rel))

all: $(OBJDIR) $(NAME).ihx 
	
$(OBJDIR):
	mkdir $(OBJDIR)	
clean:
	rm -Rrf $(OBJDIR)

flash: $(NAME).ihx
	stm8flash $(FLASHFLAGS) -w $(OBJDIR)/$(NAME).ihx

$(OBJDIR)/%.rel: %.c
	$(SDCC) $(CCFLAGS) $(INCLUDES) $(DEFINES) -o $@ -c  $<

$(NAME).ihx: $(OBJS)
	$(SDCC) $(LDFLAGS)  $(OBJS) -o $(OBJDIR)/$(NAME).ihx

.PHONY: all

@eddyem eddyem closed this as completed Feb 26, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants