cleanup project structure
This commit is contained in:
parent
dbe774272b
commit
8a9ea0a422
5 changed files with 115 additions and 34 deletions
1
.gitignore
vendored
Normal file
1
.gitignore
vendored
Normal file
|
@ -0,0 +1 @@
|
|||
build/*
|
|
@ -6,9 +6,11 @@ LFUSE = 0xf1
|
|||
HFUSE = 0xdf
|
||||
|
||||
TARGET = main
|
||||
SRC = $(TARGET).cpp
|
||||
SRC = col.cpp hal.cpp main.cpp
|
||||
|
||||
OBJDIR = obj
|
||||
SRCDIR = src
|
||||
INCDIR = inc
|
||||
OBJDIR = build/avr
|
||||
BACKUPDIR = backup
|
||||
|
||||
|
||||
|
@ -17,9 +19,9 @@ BACKUPDIR = backup
|
|||
|
||||
OPT = s
|
||||
|
||||
CFLAGS = -mmcu=$(MCU) -I.
|
||||
CFLAGS += -DF_CPU=$(F_CPU)UL
|
||||
CFLAGS += -O$(OPT)
|
||||
CPU = -mmcu=$(MCU) -I.
|
||||
CPU += -DF_CPU=$(F_CPU)UL
|
||||
CPU += -O$(OPT)
|
||||
#CFLAGS += -mint8
|
||||
#CFLAGS += -mshort-calls
|
||||
CFLAGS += -funsigned-char
|
||||
|
@ -29,13 +31,19 @@ CFLAGS += -fshort-enums
|
|||
#CFLAGS += -fno-unit-at-a-time
|
||||
CFLAGS += -Wall
|
||||
CFLAGS += -Wstrict-prototypes
|
||||
hCFLAGS += -Wundef
|
||||
CFLAGS += -Wundef
|
||||
#CFLAGS += -Wunreachable-code
|
||||
#CFLAGS += -Wsign-compare
|
||||
CFLAGS += -std=gnu99
|
||||
#CFLAGS += -Wa,-adhlns=$(<:%.c=$(OBJDIR)/%.lst)
|
||||
#CFLAGS += -flto
|
||||
|
||||
CFLAGS += -std=gnu99
|
||||
CXXFLAGS += -std=c++11
|
||||
|
||||
|
||||
CFLAGS += -I$(INCDIR) -DAVR
|
||||
CXXFLAGS += -I$(INCDIR) -DAVR
|
||||
|
||||
#LDFLAGS =
|
||||
|
||||
|
||||
|
@ -54,7 +62,8 @@ AVRDUDE_FLAGS = -p $(MCU) -P $(AVRDUDE_PORT) -b $(AVRDUDE_BAUD) -c $(AVRDUDE_PRO
|
|||
|
||||
#==== Targets ==================================================================
|
||||
|
||||
CC = avr-g++
|
||||
CC = avr-gcc
|
||||
CXX = avr-g++
|
||||
OBJCOPY = avr-objcopy
|
||||
OBJDUMP = avr-objdump
|
||||
AVRDUDE = avrdude
|
||||
|
@ -64,7 +73,11 @@ REMOVEDIR = rm -rf
|
|||
TAIL = tail
|
||||
AWK = awk
|
||||
|
||||
OBJ = $(SRC:%.c=$(OBJDIR)/%.o)
|
||||
|
||||
SRC_PATH = $(SRC:%=$(SRCDIR)/%)
|
||||
|
||||
OBJ = $(SRC_PATH:$(SRCDIR)/%.cpp=$(OBJDIR)/%.o)
|
||||
|
||||
|
||||
AVRDUDE_WRITE_FLASH = -U flash:w:$(TARGET).hex
|
||||
AVRDUDE_WRITE_EEPROM = -U eeprom:w:$(TARGET).eep
|
||||
|
@ -72,6 +85,8 @@ AVRDUDE_WRITE_EEPROM = -U eeprom:w:$(TARGET).eep
|
|||
MEMORYTYPES = flash eeprom fuse lfuse hfuse efuse boot calibration lock signature application apptable prodsig usersig
|
||||
|
||||
|
||||
avr: build
|
||||
|
||||
all: build
|
||||
|
||||
|
||||
|
@ -103,10 +118,11 @@ help:
|
|||
build: elf hex eep lss size
|
||||
|
||||
|
||||
elf: $(TARGET).elf
|
||||
hex: $(TARGET).hex
|
||||
eep: $(TARGET).eep
|
||||
lss: $(TARGET).lss
|
||||
elf: $(OBJDIR)/$(TARGET).elf
|
||||
hex: $(OBJDIR)/$(TARGET).hex
|
||||
eep: $(OBJDIR)/$(TARGET).eep
|
||||
lss: $(OBJDIR)/$(TARGET).lss
|
||||
size: $(OBJDIR)/$(TARGET).size
|
||||
|
||||
|
||||
program: flash eeprom
|
||||
|
@ -141,46 +157,55 @@ printfuses: $(TARGET).elf
|
|||
@echo 'FUSES = $(FUSES)'
|
||||
|
||||
|
||||
%.hex: %.elf
|
||||
$(OBJCOPY) -O ihex -j .text -j .data $< $@
|
||||
$(OBJDIR)/%.hex: $(OBJDIR)/%.elf
|
||||
@$(OBJCOPY) -O ihex -j .text -j .data $< $@
|
||||
|
||||
|
||||
%.eep: %.elf
|
||||
-$(OBJCOPY) -j .eeprom --set-section-flags=.eeprom="alloc,load" --change-section-lma .eeprom=0 -O ihex $< $@
|
||||
$(OBJDIR)/%.eep: $(OBJDIR)/%.elf
|
||||
@$(OBJCOPY) -j .eeprom --set-section-flags=.eeprom="alloc,load" --change-section-lma .eeprom=0 -O ihex $< $@
|
||||
|
||||
|
||||
%.lss: %.elf
|
||||
$(OBJDUMP) -h -S $< > $@
|
||||
$(OBJDIR)/%.lss: $(OBJDIR)/%.elf
|
||||
@$(OBJDUMP) -h -S $< > $@
|
||||
|
||||
|
||||
.SECONDARY: $(TARGET).elf
|
||||
.PRECIOUS: $(OBJ)
|
||||
%.elf: $(OBJ)
|
||||
$(CC) $(CFLAGS) $^ --output $@ $(LDFLAGS)
|
||||
$(OBJDIR)/%.elf: $(OBJ)
|
||||
@echo link $^
|
||||
@$(CXX) $(CPU) $^ -o $@ $(LDFLAGS) #-lstdc++
|
||||
|
||||
|
||||
$(OBJDIR)/%.o: %.c
|
||||
$(shell mkdir -p $(OBJDIR) 2>/dev/null)
|
||||
$(CC) -c $(CFLAGS) $< -o $@
|
||||
$(OBJDIR)/%.o: $(SRCDIR)/%.c
|
||||
@$(shell mkdir -p $(OBJDIR) 2>/dev/null)
|
||||
@echo compile $<
|
||||
@$(CC) -c $(CPU) $(CFLAGS) $< -o $@
|
||||
|
||||
$(OBJDIR)/%.o: $(SRCDIR)/%.cpp
|
||||
@$(shell mkdir -p $(OBJDIR) 2>/dev/null)
|
||||
@echo compile $<
|
||||
@$(CXX) -c $(CPU) $(CXXFLAGS) $< -o $@
|
||||
|
||||
|
||||
size: $(TARGET).elf
|
||||
$(AVRSIZE) -A $(TARGET).elf
|
||||
$(OBJDIR)/%.size: $(OBJDIR)/%.elf
|
||||
@$(AVRSIZE) -A $< | tee $@
|
||||
|
||||
|
||||
clean:
|
||||
$(REMOVE) "$(TARGET).hex"
|
||||
$(REMOVE) "$(TARGET).eep"
|
||||
$(REMOVE) "$(TARGET).elf"
|
||||
$(REMOVE) "$(TARGET).lss"
|
||||
$(REMOVEDIR) "$(OBJDIR)"
|
||||
@$(REMOVE) "size"
|
||||
@$(REMOVE) "$(TARGET).hex"
|
||||
@$(REMOVE) "$(TARGET).eep"
|
||||
@$(REMOVE) "$(TARGET).elf"
|
||||
@$(REMOVE) "$(TARGET).lss"
|
||||
@$(REMOVEDIR) "$(OBJDIR)"
|
||||
@echo clean $(TARGET)
|
||||
|
||||
|
||||
backup:
|
||||
$(shell mkdir -p $(BACKUPDIR) 2>/dev/null)
|
||||
@$(shell mkdir -p $(BACKUPDIR) 2>/dev/null)
|
||||
@for memory in $(MEMORYTYPES); do \
|
||||
$(AVRDUDE) $(AVRDUDE_FLAGS) -U $$memory:r:$(BACKUPDIR)/$(MCU).$$memory.hex:i; \
|
||||
done
|
||||
|
||||
|
||||
.PHONY: all size build elf hex eep lss clean program flash eeprom readfuses writefuses printfuses backup help
|
||||
.PHONY: all build elf hex eep lss clean program flash eeprom readfuses writefuses printfuses backup help
|
11
generics.Makefile
Normal file
11
generics.Makefile
Normal file
|
@ -0,0 +1,11 @@
|
|||
|
||||
all: linux avr
|
||||
|
||||
linux:
|
||||
@make -f linux.Makefile linux
|
||||
|
||||
avr:
|
||||
@make -f avr.Makefile avr
|
||||
|
||||
flash:
|
||||
@make -f avr.Makefile flash
|
41
linux.Makefile
Normal file
41
linux.Makefile
Normal file
|
@ -0,0 +1,41 @@
|
|||
|
||||
TARGET = main
|
||||
|
||||
SRC = col.cpp hal.cpp main.cpp
|
||||
|
||||
SRCDIR = src
|
||||
INCDIR = inc
|
||||
OBJDIR = build/linux
|
||||
|
||||
SRC_PATH = $(SRC:%=$(SRCDIR)/%)
|
||||
OBJ = $(SRC_PATH:$(SRCDIR)/%.cpp=$(OBJDIR)/%.o)
|
||||
|
||||
|
||||
CFLAGS += -std=gnu99
|
||||
CXXFLAGS += -std=c++17
|
||||
|
||||
|
||||
CFLAGS += -I$(INCDIR) -DLINUX
|
||||
CXXFLAGS += -I$(INCDIR) -DLINUX
|
||||
|
||||
linux: $(OBJDIR)/$(TARGET)
|
||||
|
||||
all: $(OBJDIR)/$(TARGET)
|
||||
|
||||
|
||||
.SECONDARY: $(TARGET)
|
||||
.PRECIOUS: $(OBJ)
|
||||
$(OBJDIR)/$(TARGET): $(OBJ) | $(OBJDIR)
|
||||
@$(CXX) -o $@ $^
|
||||
|
||||
$(OBJDIR)/%.o: $(SRCDIR)/%.c | $(OBJDIR)
|
||||
@echo compile $<
|
||||
@$(CC) -c $(CFLAGS) $< -o $@
|
||||
|
||||
$(OBJDIR)/%.o: $(SRCDIR)/%.cpp | $(OBJDIR)
|
||||
@echo compile $<
|
||||
@$(CXX) -c $(CXXFLAGS) $< -o $@
|
||||
|
||||
|
||||
$(OBJDIR):
|
||||
mkdir -p $(OBJDIR)
|
|
@ -1,3 +1,6 @@
|
|||
|
||||
|
||||
int main() {
|
||||
|
||||
|
||||
return 0;
|
||||
}
|
Loading…
Reference in a new issue