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